Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #22 from omgnetwork/infra_v2
Browse files Browse the repository at this point in the history
Infra v2 to master
  • Loading branch information
immutajeff authored Oct 6, 2020
2 parents 7f2c1d7 + 6c903bb commit dbc3d04
Show file tree
Hide file tree
Showing 37 changed files with 2,689 additions and 230 deletions.
11 changes: 11 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ jobs:
command: |
make docker-build
no_output_timeout: 2400s
- run: sudo chown -R 100:1000 docker/config/ && sudo chmod -R 777 docker/config/
- run:
name: Infra standup
working_directory: /home/circleci/project/docker
command: docker-compose up ganache truffle
background: true
- run:
name: Test
working_directory: /home/circleci/project/docker
command: docker-compose up vault_server
no_output_timeout: 2400s
- run:
name: Save Docker image
command: |
Expand Down
47 changes: 4 additions & 43 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,14 @@ Submits the Merkle root of a Plasma block
| name | Name of the wallet - provided in the URI. |
| address | Account address which will submit the block - provided in the URI. |
| contract | The address of the Block Controller contract. |
| gas_price | The gas price for the transaction in wei. Defaults to 0 - which means use the estimated gas price. |
| gas_price | The gas price for the transaction in wei. |
| block_root | The Merkle root of a Plasma block. |
| nonce | Transaction order. |

### EXAMPLE

```sh
curl -X PUT -H "X-Vault-Request: true" -H "X-Vault-Token: $(vault print token)" -d '{"block_root":"1234qweradgf1234qweradgf","contract":"0xd185aff7fb18d2045ba766287ca64992fdd79b1e"}' http://127.0.0.1:8900/v1/immutability-eth-plugin/wallets/plasma-deployer/accounts/0x888a65279D4a3A4E3cbA57D5B3Bd3eB0726655a6/plasma/submitBlock
curl -X PUT -H "X-Vault-Request: true" -H "X-Vault-Token: $(vault print token)" -d '{"block_root":"1234qweradgf1234qweradgf","contract":"0xd185aff7fb18d2045ba766287ca64992fdd79b1e", "gas_price: "20000000000", nonce: "0""}' http://127.0.0.1:8900/v1/immutability-eth-plugin/wallets/plasma-deployer/accounts/0x888a65279D4a3A4E3cbA57D5B3Bd3eB0726655a6/plasma/submitBlock

{
"request_id": "00a614f3-9bd3-60f4-25be-384a8d3cc5ff",
Expand All @@ -258,50 +259,10 @@ curl -X PUT -H "X-Vault-Request: true" -H "X-Vault-Token: $(vault print token)"
"from": "0x4BC91c7fA64017a94007B7452B75888cD82185F7",
"gas_limit": 73623,
"gas_price": 20000000000,
"nonce": 1,
"nonce": 0,
"signed_transaction": "0xf889018504a817c80083011f9794d185aff7fb18d2045ba766287ca64992fdd79b1e80a4baa4769431323334717765726164676631323334717765726164676600000000000000001ca04b14e95372a41a74585c04c7967c45f2d1d51e4f5cd59b7c95a2c16ecbd63e79a04fcc461cfd165d8ba1f9cafe37ce7c025c0cec0533880abda3df754c9c749d9a",
"transaction_hash": "0x6cfad4034bf147accb815922bb4f71ed8ae676e65580ab259d9d1d8713047c7f"
},
"warnings": null
}
```

### ACTIVATE CHILD CHAIN

Activates the child chain so that child chain can start to submit child blocks to root chain.

#### INPUTS

| Parameter | Description |
| --- | ----------- |
| name | Name of the wallet - provided in the URI. |
| address | Account address which will submit the block - provided in the URI. |
| contract | The address of the Block Controller contract. |
| gas_price | The gas price for the transaction in wei. Defaults to 0 - which means use the estimated gas price. |

### EXAMPLE

```sh
curl -X PUT -H "X-Vault-Request: true" -H "X-Vault-Token: $(vault print token)" -d '{"contract":"0xd185aff7fb18d2045ba766287ca64992fdd79b1e"}' http://127.0.0.1:8900/v1/immutability-eth-plugin/wallets/plasma-deployer/accounts/0x888a65279D4a3A4E3cbA57D5B3Bd3eB0726655a6/plasma/activateChildChain
```

### SUBMIT DEPOSIT BLOCK

Submits a block for deposit

#### INPUTS

| Parameter | Description |
| --- | ----------- |
| name | Name of the wallet - provided in the URI. |
| address | Account address which will submit the block - provided in the URI. |
| contract | The address of the Block Controller contract. |
| gas_price | The gas price for the transaction in wei. Defaults to 0 - which means use the estimated gas price. |
| block_root | The Merkle root of a Plasma block. |

### EXAMPLE

```sh
curl -X PUT -H "X-Vault-Request: true" -H "X-Vault-Token: $(vault print token)" -d '{"block_root":"1234qweradgf1234qweradgf","contract":"0xd185aff7fb18d2045ba766287ca64992fdd79b1e"}' http://127.0.0.1:8900/v1/immutability-eth-plugin/wallets/plasma-deployer/accounts/0x4BC91c7fA64017a94007B7452B75888cD82185F7/plasma/submitDepositBlock

```
19 changes: 17 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
## 0.0.7 (xx yy, 2020)

NEW FEATURES:

* Backup / Restore scripts created for Vault Raft Data
* Creation of the gen_overrides.sh script

REFACTOR:

* updated `VERSION` file to `0.0.7`
* Regionalized SSD Persistent Data Volumes for Vault Raft Data
* Vault Auditing is now enabled
* Fix Vault Raft Peering
* Replaced the Custom Vault Helm Chart with the officially supported Helm Chart from Hashicorp
* Nonce refactored to be passed in
* Only --build on test

## 0.0.6 (August 15, 2020)

NEW FEATURES:
Expand All @@ -7,8 +24,6 @@ NEW FEATURES:
* Enable GCR and KMS in the Vault GCP project with service accounts
* CircleCI config to push `omgnetwork/vault` images into GCR

N/A

REFACTOR:

* updated `VERSION` file to `0.0.6`
Expand Down
5 changes: 2 additions & 3 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ If this project is in `$GOPATH/src/github.com/omgnetwork/immutability-eth-plugin
You will need to trust the signer to use the vault CLI:

```bash
export VAULT_CACERT="$GOPATH/src/github.com/omgnetwork/immutability-eth-plugin/docker/config/ca/certs/ca.crt"
export VAULT_CACERT="$GOPATH/src/github.com/omgnetwork/immutability-eth-plugin/docker/config/ca.crt"
```

2. Unseal Key and Root Token: `$GOPATH/src/github.com/omgnetwork/immutability-eth-plugin/docker/config/unseal.json`
Expand All @@ -54,7 +54,6 @@ Don't mess with this.
If you want to re-initialize the Vault, then delete these:

```bash
rm -fr $GOPATH/src/github.com/omgnetwork/immutability-eth-plugin/docker/config/ca
rm $GOPATH/src/github.com/omgnetwork/immutability-eth-plugin/config/docker/unseal.json
rm -fr $GOPATH/src/github.com/omgnetwork/immutability-eth-plugin/docker/config/data
```
Expand All @@ -63,7 +62,7 @@ I would strongly advise using the Vault CLI. This way you can use vault with the

```bash
export VAULT_ADDR="https://127.0.0.1:8200"
export VAULT_CACERT="$GOPATH/src/github.com/omgnetwork/immutability-eth-plugin/docker/config/ca/certs/ca.crt"
export VAULT_CACERT="$GOPATH/src/github.com/omgnetwork/immutability-eth-plugin/docker/config/ca.crt"
export VAULT_TOKEN=$(cat $GOPATH/src/github.com/omgnetwork/immutability-eth-plugin/docker/config/unseal.json | jq -r .root_token)

vault read -format=json immutability-eth-plugin/config
Expand Down
13 changes: 11 additions & 2 deletions docker/config/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,14 @@ function test_plugin {
}

if [ -f "$VAULT_CREDENTIALS" ]; then
sleep 10
unseal
vault status
vault secrets list
test_banner
test_plugin
else
sleep 10
VAULT_INIT=$(vault operator init -key-shares=1 -key-threshold=1 -format=json | jq .)
echo $VAULT_INIT > $VAULT_CREDENTIALS
unseal
Expand All @@ -184,6 +188,11 @@ else
test_plugin
fi

# Don't exit until vault dies

wait $VAULT_PID
if [ -n "$TEST" ]; then
echo "Dying."
else
echo "Don't exit until vault dies."
wait $VAULT_PID
fi

7 changes: 2 additions & 5 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@ services:
- testnet
ports:
- "8200:8900"
depends_on:
- "ganache"
links:
- "ganache"
- "truffle"
environment:
- TEST=true
volumes:
- "./config:/home/vault/config:rw"
- "../contracts:/home/vault/contracts:ro"
Expand Down
17 changes: 17 additions & 0 deletions docker/lean-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3.3"

services:
vault_server:
image: omgnetwork/vault:latest
networks:
- testnet
ports:
- "8200:8900"
volumes:
- "./config:/home/vault/config:rw"
- "../contracts:/home/vault/contracts:ro"
- "../scripts:/home/vault/scripts:ro"
entrypoint: /home/vault/config/entrypoint.sh
networks:
testnet:
driver: bridge
142 changes: 18 additions & 124 deletions ethereum/path_plasma.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,39 +44,11 @@ Allows the authority to submit the Merkle root of a Plasma block.
},
"gas_price": {
Type: framework.TypeString,
Description: "The gas price for the transaction in wei. Defaults to 0 - which means use the estimated gas price.",
Default: "0",
Description: "The gas price for the transaction in wei.",
},
"block_root": {
Type: framework.TypeString,
Description: "The Merkle root of a Plasma block.",
},
},
ExistenceCheck: pathExistenceCheck,
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.CreateOperation: b.pathPlasmaSubmitBlock,
logical.UpdateOperation: b.pathPlasmaSubmitBlock,
},
},
{
Pattern: ContractPath(plasmaContract, "submitDepositBlock"),
HelpSynopsis: "Submits a block for deposit",
HelpDescription: `
Submits a block for deposit.
`,
Fields: map[string]*framework.FieldSchema{
"name": {Type: framework.TypeString},
"address": {Type: framework.TypeString},
"contract": {
Type: framework.TypeString,
Description: "The address of the Block Controller.",
},
"gas_price": {
"nonce": {
Type: framework.TypeString,
Description: "The gas price for the transaction in wei. Defaults to 0 - which means use the estimated gas price.",
Default: "0",
Description: "The nonce for the transaction.",
},
"block_root": {
Type: framework.TypeString,
Expand All @@ -85,8 +57,8 @@ Submits a block for deposit.
},
ExistenceCheck: pathExistenceCheck,
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.CreateOperation: b.pathPlasmaSubmitDepositBlock,
logical.UpdateOperation: b.pathPlasmaSubmitDepositBlock,
logical.CreateOperation: b.pathPlasmaSubmitBlock,
logical.UpdateOperation: b.pathPlasmaSubmitBlock,
},
},
}
Expand Down Expand Up @@ -144,13 +116,20 @@ func (b *PluginBackend) pathPlasmaSubmitBlock(ctx context.Context, req *logical.
if err != nil {
return nil, err
}
//transactOpts needs gas etc. Use supplied gas_price if > 0
//transactOpts needs gas etc. Use supplied gas_price
gasPriceRaw := data.Get("gas_price").(string)

if gasPriceRaw != "0" {
transactOpts.GasPrice = util.ValidNumber(gasPriceRaw)
}

if gasPriceRaw == "" {
return nil, fmt.Errorf("invalid gas_price")
}
transactOpts.GasPrice = util.ValidNumber(gasPriceRaw)

//transactOpts needs nonce. Use supplied nonce
nonceRaw := data.Get("nonce").(string)
if nonceRaw == "" {
return nil, fmt.Errorf("invalid nonce")
}
transactOpts.Nonce = util.ValidNumber(nonceRaw)

plasmaSession := &plasma.PlasmaSession{
Contract: instance, // Generic contract caller binding to set the session for
CallOpts: *callOpts, // Call options to use throughout this session
Expand All @@ -176,88 +155,3 @@ func (b *PluginBackend) pathPlasmaSubmitBlock(ctx context.Context, req *logical.
},
}, nil
}

func (b *PluginBackend) pathPlasmaSubmitDepositBlock(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
config, err := b.configured(ctx, req)
if err != nil {
return nil, err
}
address := data.Get("address").(string)
name := data.Get("name").(string)
contractAddress := common.HexToAddress(data.Get("contract").(string))
accountJSON, err := readAccount(ctx, req, name, address)
if err != nil || accountJSON == nil {
return nil, fmt.Errorf("error reading address")
}

chainID := util.ValidNumber(config.ChainID)
if chainID == nil {
return nil, fmt.Errorf("invalid chain ID")
}

client, err := ethclient.Dial(config.getRPCURL())
if err != nil {
return nil, err
}

walletJSON, err := readWallet(ctx, req, name)
if err != nil {
return nil, err
}

wallet, account, err := getWalletAndAccount(*walletJSON, accountJSON.Index)
if err != nil {
return nil, err
}

instance, err := plasma.NewPlasma(contractAddress, client)
if err != nil {
return nil, err
}
callOpts := &bind.CallOpts{}

blockRoot := [32]byte{}

inputBlockRoot, ok := data.GetOk("block_root")
if ok {
copy(blockRoot[:], []byte(inputBlockRoot.(string)))
} else {
return nil, fmt.Errorf("invalid block root")
}

transactOpts, err := b.NewWalletTransactor(chainID, wallet, account)
if err != nil {
return nil, err
}

//transactOpts needs gas etc. Use supplied gas_price if > 0
gasPriceRaw := data.Get("gas_price").(string)

if gasPriceRaw != "0" {
transactOpts.GasPrice = util.ValidNumber(gasPriceRaw)
}
plasmaSession := &plasma.PlasmaSession{
Contract: instance, // Generic contract caller binding to set the session for
CallOpts: *callOpts, // Call options to use throughout this session
TransactOpts: *transactOpts,
}

tx, err := plasmaSession.SubmitDepositBlock(blockRoot)
if err != nil {
return nil, err
}

var signedTxBuff bytes.Buffer
tx.EncodeRLP(&signedTxBuff)
return &logical.Response{
Data: map[string]interface{}{
"contract": contractAddress.Hex(),
"transaction_hash": tx.Hash().Hex(),
"signed_transaction": hexutil.Encode(signedTxBuff.Bytes()),
"from": account.Address.Hex(),
"nonce": tx.Nonce(),
"gas_price": tx.GasPrice(),
"gas_limit": tx.Gas(),
},
}, nil
}
Binary file added immutability-eth-plugin
Binary file not shown.
Loading

0 comments on commit dbc3d04

Please sign in to comment.