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

Commit

Permalink
Merge pull request #21 from omgnetwork/inomurko/nonce
Browse files Browse the repository at this point in the history
Inomurko/nonce
  • Loading branch information
cypherhat authored Oct 5, 2020
2 parents 530ca73 + ed440cd commit be3f76e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 50 deletions.
9 changes: 7 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ jobs:
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
command: |
make test
working_directory: /home/circleci/project/docker
command: docker-compose up vault_server
no_output_timeout: 2400s
- run:
name: Save Docker image
Expand Down
28 changes: 5 additions & 23 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,29 +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
```
```
9 changes: 7 additions & 2 deletions docker/config/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,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
23 changes: 11 additions & 12 deletions ethereum/path_plasma.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ 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.",
},
"nonce": {
Type: framework.TypeString,
Expand Down Expand Up @@ -117,20 +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 needs nonce. Use supplied nonce is > 0
transactOpts.GasPrice = util.ValidNumber(gasPriceRaw)

//transactOpts needs nonce. Use supplied nonce
nonceRaw := data.Get("nonce").(string)

if nonceRaw != "0" {
transactOpts.Nonce = util.ValidNumber(nonceRaw)
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 Down
30 changes: 24 additions & 6 deletions scripts/smoke.plasma.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,21 @@ echo "UNAUTHORIZED=$UNAUTHORIZED"
banner
vault write -format=json -f -output-curl-string immutability-eth-plugin/wallets/plasma-deployer/accounts
banner

echo "*** SHOULD FAIL! ***"
echo "UNAUTHORIZED SUBMISSION OF BLOCK BY $UNAUTHORIZED"
echo "vault write -format=json immutability-eth-plugin/wallets/plasma-deployer/accounts/$UNAUTHORIZED/plasma/submitBlock nonce=0 block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT"
vault write -format=json immutability-eth-plugin/wallets/plasma-deployer/accounts/$UNAUTHORIZED/plasma/submitBlock nonce=0 block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT
echo "vault write -format=json immutability-eth-plugin/wallets/plasma-deployer/accounts/$UNAUTHORIZED/plasma/submitBlock nonce=0 gas_price=$GAS_PRICE_HIGH block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT"
vault write -format=json immutability-eth-plugin/wallets/plasma-deployer/accounts/$UNAUTHORIZED/plasma/submitBlock nonce=0 gas_price=$GAS_PRICE_HIGH block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT
banner
vault write -output-curl-string immutability-eth-plugin/wallets/plasma-deployer/accounts/$UNAUTHORIZED/plasma/submitBlock nonce=0 block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT
vault write -output-curl-string immutability-eth-plugin/wallets/plasma-deployer/accounts/$UNAUTHORIZED/plasma/submitBlock nonce=0 gas_price=$GAS_PRICE_HIGH block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT

banner
echo "*** SHOULD SUCCEED ***"
echo "AUTHORIZED SUBMISSION OF BLOCK BY $ORIGINAL_AUTHORITY"
echo "vault write -format=json immutability-eth-plugin/wallets/plasma-deployer/accounts/$ORIGINAL_AUTHORITY/plasma/submitBlock nonce=0 block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT"
vault write -format=json immutability-eth-plugin/wallets/plasma-deployer/accounts/$ORIGINAL_AUTHORITY/plasma/submitBlock nonce=0 block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT
echo "vault write -format=json immutability-eth-plugin/wallets/plasma-deployer/accounts/$ORIGINAL_AUTHORITY/plasma/submitBlock nonce=0 gas_price=$GAS_PRICE_HIGH block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT"
vault write -format=json immutability-eth-plugin/wallets/plasma-deployer/accounts/$ORIGINAL_AUTHORITY/plasma/submitBlock nonce=0 gas_price=$GAS_PRICE_HIGH block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT
banner
vault write -output-curl-string immutability-eth-plugin/wallets/plasma-deployer/accounts/$ORIGINAL_AUTHORITY/plasma/submitBlock nonce=0 block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT
vault write -output-curl-string immutability-eth-plugin/wallets/plasma-deployer/accounts/$ORIGINAL_AUTHORITY/plasma/submitBlock nonce=0 gas_price=$GAS_PRICE_HIGH block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT

banner
echo "*** SHOULD SUCCEED ***"
Expand All @@ -77,3 +78,20 @@ echo "vault write -format=json immutability-eth-plugin/wallets/plasma-deployer/a
vault write -format=json immutability-eth-plugin/wallets/plasma-deployer/accounts/$ORIGINAL_AUTHORITY/plasma/submitBlock nonce=1 gas_price=$GAS_PRICE_HIGH block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT
banner
vault write -output-curl-string immutability-eth-plugin/wallets/plasma-deployer/accounts/$ORIGINAL_AUTHORITY/plasma/submitBlock nonce=1 gas_price=$GAS_PRICE_HIGH block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT

banner
echo "*** SHOULD FAIL! ***"
echo "AUTHORIZED SUBMISSION OF BLOCK BY $ORIGINAL_AUTHORITY - USER SUPPLIED GAS PRICE WITHOUT NONCE"
echo "vault write -format=json immutability-eth-plugin/wallets/plasma-deployer/accounts/$ORIGINAL_AUTHORITY/plasma/submitBlock gas_price=$GAS_PRICE_HIGH block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT"
vault write -format=json immutability-eth-plugin/wallets/plasma-deployer/accounts/$ORIGINAL_AUTHORITY/plasma/submitBlock gas_price=$GAS_PRICE_HIGH block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT
banner
vault write -output-curl-string immutability-eth-plugin/wallets/plasma-deployer/accounts/$ORIGINAL_AUTHORITY/plasma/submitBlock gas_price=$GAS_PRICE_HIGH block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT

banner
echo "*** SHOULD FAIL! ***"
echo "AUTHORIZED SUBMISSION OF BLOCK BY $ORIGINAL_AUTHORITY - USER SUPPLIED NONCE WITHOUT GAS PRICE"
echo "vault write -format=json immutability-eth-plugin/wallets/plasma-deployer/accounts/$ORIGINAL_AUTHORITY/plasma/submitBlock nonce=1 block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT"
vault write -format=json immutability-eth-plugin/wallets/plasma-deployer/accounts/$ORIGINAL_AUTHORITY/plasma/submitBlock nonce=1 block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT
banner
vault write -output-curl-string immutability-eth-plugin/wallets/plasma-deployer/accounts/$ORIGINAL_AUTHORITY/plasma/submitBlock nonce=1 block_root=$BLOCK_ROOT contract=$PLASMA_CONTRACT

0 comments on commit be3f76e

Please sign in to comment.