From d7acda8f4e4677d66fe7495aae9e5c8fb1a5004c Mon Sep 17 00:00:00 2001 From: Ino Murko Date: Sat, 3 Oct 2020 16:05:05 +0200 Subject: [PATCH 1/7] update testing, strict API --- .circleci/config.yml | 21 +++++++++++++++++++++ API.md | 28 +++++----------------------- docker/config/entrypoint.sh | 9 +++++++-- docker/docker-compose.yml | 2 ++ ethereum/path_plasma.go | 21 +++++++-------------- scripts/smoke.plasma.sh | 13 +++++++------ 6 files changed, 49 insertions(+), 45 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d85378348035..dbbb826ed0c3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,6 +11,27 @@ 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: /tmp/workspace/docker + command: docker-compose up ganache truffle + background: true + - run: + name: Contracts up? + command: | + sleep 10 + attempt_counter=0 + max_attempts=25 + until [ -z "$(docker ps | grep docker_truffle 2> /dev/null)" ] + do + if [ ${attempt_counter} -eq ${max_attempts} ];then + echo "Max attempts reached" + exit 1 + fi + printf '.' + attempt_counter=$(($attempt_counter+1)) + sleep 5 + done - run: name: Test command: | diff --git a/API.md b/API.md index 267db540461c..ef8ad7d2268b 100644 --- a/API.md +++ b/API.md @@ -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", @@ -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 -``` +``` \ No newline at end of file diff --git a/docker/config/entrypoint.sh b/docker/config/entrypoint.sh index 888f3a5ddb42..7be216bd4ef5 100755 --- a/docker/config/entrypoint.sh +++ b/docker/config/entrypoint.sh @@ -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 + diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 4d00f75db68e..e53528e46e75 100755 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -51,6 +51,8 @@ services: links: - "ganache" - "truffle" + environment: + - TEST=true volumes: - "./config:/home/vault/config:rw" - "../contracts:/home/vault/contracts:ro" diff --git a/ethereum/path_plasma.go b/ethereum/path_plasma.go index c34d380f17b4..fc41fd8b681a 100644 --- a/ethereum/path_plasma.go +++ b/ethereum/path_plasma.go @@ -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, @@ -117,20 +116,14 @@ 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) - } - - //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) - } - + 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 diff --git a/scripts/smoke.plasma.sh b/scripts/smoke.plasma.sh index 7940c16a095b..a413a79e6749 100755 --- a/scripts/smoke.plasma.sh +++ b/scripts/smoke.plasma.sh @@ -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 ***" From aa8dfb873beffe1b6b60c40d97c4a5a29230d522 Mon Sep 17 00:00:00 2001 From: Ino Murko Date: Sat, 3 Oct 2020 16:13:58 +0200 Subject: [PATCH 2/7] idk go --- ethereum/path_plasma.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereum/path_plasma.go b/ethereum/path_plasma.go index fc41fd8b681a..a4e302dbad66 100644 --- a/ethereum/path_plasma.go +++ b/ethereum/path_plasma.go @@ -44,7 +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." + Description: "The gas price for the transaction in wei.", }, "nonce": { Type: framework.TypeString, From ac43de37a271b5c2362da3f55383c413017e9189 Mon Sep 17 00:00:00 2001 From: Ino Murko Date: Sat, 3 Oct 2020 16:18:29 +0200 Subject: [PATCH 3/7] correct path --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index dbbb826ed0c3..62524b0b0eb7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,7 +13,7 @@ jobs: - run: sudo chown -R 100:1000 docker/config/ && sudo chmod -R 777 docker/config/ - run: name: Infra standup - working_directory: /tmp/workspace/docker + working_directory: /home/circleci/project/docker command: docker-compose up ganache truffle background: true - run: From 37c2979bd5ab8cc5d0b689ca5f04c48fdde14d1f Mon Sep 17 00:00:00 2001 From: Ino Murko Date: Sat, 3 Oct 2020 16:31:35 +0200 Subject: [PATCH 4/7] stand up vault --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 62524b0b0eb7..83622cbbebbf 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -34,8 +34,8 @@ jobs: done - 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 From e347124f01b8c1ee1338c711dca0551821e5e7d6 Mon Sep 17 00:00:00 2001 From: Ino Murko Date: Sat, 3 Oct 2020 16:44:15 +0200 Subject: [PATCH 5/7] rm dependencies --- docker/docker-compose.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index e53528e46e75..1176027fe1fe 100755 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -46,11 +46,6 @@ services: - testnet ports: - "8200:8900" - depends_on: - - "ganache" - links: - - "ganache" - - "truffle" environment: - TEST=true volumes: From b89e873fdadd28fe220bf075fbc00c9f320fb16a Mon Sep 17 00:00:00 2001 From: Ino Murko Date: Mon, 5 Oct 2020 09:19:44 +0200 Subject: [PATCH 6/7] stricter API, abort when empty --- ethereum/path_plasma.go | 6 ++++++ scripts/smoke.plasma.sh | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/ethereum/path_plasma.go b/ethereum/path_plasma.go index a4e302dbad66..6e701ddcc5ca 100644 --- a/ethereum/path_plasma.go +++ b/ethereum/path_plasma.go @@ -118,10 +118,16 @@ func (b *PluginBackend) pathPlasmaSubmitBlock(ctx context.Context, req *logical. } //transactOpts needs gas etc. Use supplied gas_price gasPriceRaw := data.Get("gas_price").(string) + 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{ diff --git a/scripts/smoke.plasma.sh b/scripts/smoke.plasma.sh index a413a79e6749..947a0bff20da 100755 --- a/scripts/smoke.plasma.sh +++ b/scripts/smoke.plasma.sh @@ -78,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 + From ed440cd1341bedec0df25145b4f12a69ef7c43cf Mon Sep 17 00:00:00 2001 From: Ino Murko Date: Mon, 5 Oct 2020 09:40:52 +0200 Subject: [PATCH 7/7] stricter API, abort when empty --- .circleci/config.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 83622cbbebbf..4e41bc37b85e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,22 +16,6 @@ jobs: working_directory: /home/circleci/project/docker command: docker-compose up ganache truffle background: true - - run: - name: Contracts up? - command: | - sleep 10 - attempt_counter=0 - max_attempts=25 - until [ -z "$(docker ps | grep docker_truffle 2> /dev/null)" ] - do - if [ ${attempt_counter} -eq ${max_attempts} ];then - echo "Max attempts reached" - exit 1 - fi - printf '.' - attempt_counter=$(($attempt_counter+1)) - sleep 5 - done - run: name: Test working_directory: /home/circleci/project/docker