From 76ccdf3eec148f9db612f1f80effe4701a4a32bb Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Tue, 18 Apr 2023 16:56:08 +0530 Subject: [PATCH] Gracefully shutdown optimism batcher and op-geth containers --- .../fixturenet-optimism/optimism-contracts/run.sh | 1 + .../config/fixturenet-optimism/run-op-batcher.sh | 15 ++++++++++++++- .../config/fixturenet-optimism/run-op-geth.sh | 15 ++++++++++++++- app/data/stacks/fixturenet-optimism/README.md | 3 +++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/data/config/fixturenet-optimism/optimism-contracts/run.sh b/app/data/config/fixturenet-optimism/optimism-contracts/run.sh index a256ea64..9890da8f 100755 --- a/app/data/config/fixturenet-optimism/optimism-contracts/run.sh +++ b/app/data/config/fixturenet-optimism/optimism-contracts/run.sh @@ -13,6 +13,7 @@ CERC_L1_ADDRESS_2="${CERC_L1_ADDRESS_2:-${DEFAULT_CERC_L1_ADDRESS_2}}" CERC_L1_PRIV_KEY_2="${CERC_L1_PRIV_KEY_2:-${DEFAULT_CERC_L1_PRIV_KEY_2}}" echo "Using L1 RPC endpoint ${CERC_L1_RPC}" +export L1_RPC=${CERC_L1_RPC} IMPORT_1="import './verify-contract-deployment'" IMPORT_2="import './rekey-json'" diff --git a/app/data/config/fixturenet-optimism/run-op-batcher.sh b/app/data/config/fixturenet-optimism/run-op-batcher.sh index ff549213..4bee6036 100755 --- a/app/data/config/fixturenet-optimism/run-op-batcher.sh +++ b/app/data/config/fixturenet-optimism/run-op-batcher.sh @@ -9,6 +9,15 @@ CERC_L1_RPC="${CERC_L1_RPC:-${DEFAULT_CERC_L1_RPC}}" # Get BACTHER_KEY from keys.json BATCHER_KEY=$(jq -r '.Batcher.privateKey' /l2-accounts/keys.json | tr -d '"') +cleanup() { + echo "Signal received, cleaning up..." + kill ${batcher_pid} + + wait + echo "Done" +} +trap 'cleanup' INT TERM + op-batcher \ --l2-eth-rpc=http://op-geth:8545 \ --rollup-rpc=http://op-node:8547 \ @@ -23,4 +32,8 @@ op-batcher \ --max-channel-duration=1 \ --target-l1-tx-size-bytes=2048 \ --l1-eth-rpc=$CERC_L1_RPC \ - --private-key=$BATCHER_KEY + --private-key=$BATCHER_KEY \ + & + +batcher_pid=$! +wait $batcher_pid diff --git a/app/data/config/fixturenet-optimism/run-op-geth.sh b/app/data/config/fixturenet-optimism/run-op-geth.sh index 68f6c5c5..48391d73 100755 --- a/app/data/config/fixturenet-optimism/run-op-geth.sh +++ b/app/data/config/fixturenet-optimism/run-op-geth.sh @@ -47,6 +47,15 @@ fi SEQUENCER_ADDRESS=$(jq -r '.Sequencer.address' /l2-accounts/keys.json | tr -d '"') echo "SEQUENCER_ADDRESS: ${SEQUENCER_ADDRESS}" +cleanup() { + echo "Signal received, cleaning up..." + kill ${geth_pid} + + wait + echo "Done" +} +trap 'cleanup' INT TERM + # Run op-geth geth \ --datadir ./datadir \ @@ -74,4 +83,8 @@ geth \ --allow-insecure-unlock \ --mine \ --miner.etherbase=$SEQUENCER_ADDRESS \ - --unlock=$SEQUENCER_ADDRESS + --unlock=$SEQUENCER_ADDRESS \ + & + +geth_pid=$! +wait $geth_pid diff --git a/app/data/stacks/fixturenet-optimism/README.md b/app/data/stacks/fixturenet-optimism/README.md index 502e3305..5099cdd3 100644 --- a/app/data/stacks/fixturenet-optimism/README.md +++ b/app/data/stacks/fixturenet-optimism/README.md @@ -91,6 +91,9 @@ docker volume rm $(docker volume ls -q --filter "name=.*fixturenet_geth_accounts ``` * This means that the data directory that `op-geth` is using is corrupted and needs to be reinitialized; the containers `op-geth`, `op-node` and `op-batcher` need to be started afresh: + + WARNING: This will reset the L2 chain; consequently, all the data on it will be lost + * Stop and remove the concerned containers: ```bash