From c6e6122516f07240d64d5775e235735fa7237bdc Mon Sep 17 00:00:00 2001 From: prathamesh0 <42446521+prathamesh0@users.noreply.github.com> Date: Wed, 19 Apr 2023 12:48:38 +0530 Subject: [PATCH] Gracefully shutdown optimism batcher and op-geth containers (#345) * Gracefully shutdown optimism batcher and op-geth containers * Remove unnecessary env export --- .../config/fixturenet-optimism/run-op-batcher.sh | 15 ++++++++++++++- .../config/fixturenet-optimism/run-op-geth.sh | 15 ++++++++++++++- app/data/stacks/fixturenet-optimism/README.md | 3 +++ 3 files changed, 31 insertions(+), 2 deletions(-) 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