From 91deff097e903c50359263bc7180878598fe2617 Mon Sep 17 00:00:00 2001 From: Xavier Romero Date: Thu, 16 Jan 2025 10:22:58 +0100 Subject: [PATCH] Double quotes --- scripts/upgrade_forkid.sh | 102 +++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/scripts/upgrade_forkid.sh b/scripts/upgrade_forkid.sh index 8ce17195..83a34075 100755 --- a/scripts/upgrade_forkid.sh +++ b/scripts/upgrade_forkid.sh @@ -16,15 +16,15 @@ elif ! [[ $1 =~ ^[0-9]+$ ]] || ! [[ $2 =~ ^[0-9]+$ ]]; then echo "Forkids must be integers" exit 1 # check source forkid is 9, 11 or 12 -elif [ $1 -ne 9 ] && [ $1 -ne 11 ] && [ $1 -ne 12 ]; then +elif [ "$1" -ne "9" ] && [ "$1" -ne "11" ] && [ "$1" -ne "12" ]; then echo "Source forkid must be 9, 11 or 12" exit 1 # check target forkid is 11, 12 or 13 -elif [ $2 -ne 11 ] && [ $2 -ne 12 ] && [ $2 -ne 13 ]; then +elif [ "$2" -ne "11" ] && [ "$2" -ne "12" ] && [ "$2" -ne "13" ]; then echo "Target forkid must be 11, 12 or 13" exit 1 # check target forkid is greater than source forkid -elif [ $1 -ge $2 ]; then +elif [ "$1" -ge "$2" ]; then echo "Target forkid must be greater than source forkid" exit 1 fi @@ -34,11 +34,11 @@ TARGET_FORKID=$2 ERIGON_IMAGE=hermeznetwork/cdk-erigon:v2.61.4-RC1 STACK_NAME=upgradeCDK-$(tr -dc A-Za-z0-9 > $KURTOSIS_CONFIG +sed -ni '/cdk_erigon_node_image/!p' "$KURTOSIS_CONFIG" +echo " cdk_erigon_node_image: $ERIGON_IMAGE" >> "$KURTOSIS_CONFIG" # DEPLOY STACK -kurtosis run --enclave $STACK_NAME --args-file $KURTOSIS_CONFIG . +kurtosis run --enclave "$STACK_NAME" --args-file $KURTOSIS_CONFIG . # SERVICE NAMES SVC_SEQUENCER=cdk-erigon-sequencer-001 @@ -64,45 +64,45 @@ SVC_CDKNODE=cdk-node-001 # send test tx PRIV_KEY=0x12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625 -cast send --rpc-url $(kurtosis port print $STACK_NAME $SVC_RPC rpc) --legacy --private-key $PRIV_KEY --value 0.01ether 0x0000000000000000000000000000000000000000 +cast send --rpc-url $(kurtosis port print "$STACK_NAME" $SVC_RPC rpc) --legacy --private-key $PRIV_KEY --value 0.01ether 0x0000000000000000000000000000000000000000 # Halt sequencer echo "Halting sequencer..." -kurtosis service exec $STACK_NAME $SVC_SEQUENCER \ +kurtosis service exec "$STACK_NAME" $SVC_SEQUENCER \ "HALTON=\$(printf \"%d\\n\" \$((\$(curl -s -X POST -H \"Content-Type: application/json\" -d '{\"method\":\"zkevm_batchNumber\",\"id\":1,\"jsonrpc\":\"2.0\"}' http://localhost:8123 | jq -r .result)+2))); \ sed -i 's/zkevm.sequencer-halt-on-batch-number: 0/zkevm.sequencer-halt-on-batch-number: '\$HALTON'/' /etc/cdk-erigon/config.yaml" # echo \"zkevm.sequencer-halt-on-batch-number: \$HALTON\" >> /etc/erigon/erigon-sequencer.yaml" -kurtosis service stop $STACK_NAME $SVC_SEQUENCER -kurtosis service start $STACK_NAME $SVC_SEQUENCER +kurtosis service stop "$STACK_NAME" $SVC_SEQUENCER +kurtosis service start "$STACK_NAME" $SVC_SEQUENCER # Wait for sequencer to be halted -while ! kurtosis service logs -n 1 $STACK_NAME $SVC_SEQUENCER | grep -q "Halt sequencer on batch"; do +while ! kurtosis service logs -n 1 "$STACK_NAME" $SVC_SEQUENCER | grep -q "Halt sequencer on batch"; do echo "Waiting for sequencer to halt" sleep 3 done echo "Sequencer halted !" # Update contracts folder -kurtosis service exec $STACK_NAME $SVC_CONTRACTS "cd /opt/zkevm-contracts && git stash && git checkout main && git pull && git checkout $TAG_TARGET_FORKID" +kurtosis service exec "$STACK_NAME" $SVC_CONTRACTS "cd /opt/zkevm-contracts && git stash && git checkout main && git pull && git checkout $TAG_TARGET_FORKID" # create env file for the commands we need to execute on contracts service -kurtosis service exec $STACK_NAME $SVC_CONTRACTS "echo 'cd /opt' > /opt/commands.sh" -kurtosis service exec $STACK_NAME $SVC_CONTRACTS "echo 'export ETH_RPC_URL=http://el-1-geth-lighthouse:8545' >> /opt/commands.sh" -kurtosis service exec $STACK_NAME $SVC_CONTRACTS "echo 'ROLLUP_MAN=\$(cat zkevm/combined.json | jq -r .polygonRollupManagerAddress)' >> /opt/commands.sh" -kurtosis service exec $STACK_NAME $SVC_CONTRACTS "echo 'ROLLUP=\$(cat zkevm/combined.json | jq -r .rollupAddress)' >> /opt/commands.sh" -kurtosis service exec $STACK_NAME $SVC_CONTRACTS "echo 'GENESIS=\$(cat zkevm/combined.json | jq -r .genesis)' >> /opt/commands.sh" -kurtosis service exec $STACK_NAME $SVC_CONTRACTS "echo \"CONSENSUS=\\\$(cast call \\\$ROLLUP_MAN 'rollupTypeMap(uint32)(address,address,uint64,uint8,bool,bytes32)' 1 | head -1)\" >> /opt/commands.sh" -kurtosis service exec $STACK_NAME $SVC_CONTRACTS "echo PRIV_KEY=0x12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625 >> /opt/commands.sh" -kurtosis service exec $STACK_NAME $SVC_CONTRACTS "echo 'cd /opt/zkevm-contracts && git checkout $TAG_TARGET_FORKID' >> /opt/commands.sh" -kurtosis service exec $STACK_NAME $SVC_CONTRACTS "chmod +x /opt/commands.sh" +kurtosis service exec "$STACK_NAME" $SVC_CONTRACTS "echo 'cd /opt' > /opt/commands.sh" +kurtosis service exec "$STACK_NAME" $SVC_CONTRACTS "echo 'export ETH_RPC_URL=http://el-1-geth-lighthouse:8545' >> /opt/commands.sh" +kurtosis service exec "$STACK_NAME" $SVC_CONTRACTS "echo 'ROLLUP_MAN=\$(cat zkevm/combined.json | jq -r .polygonRollupManagerAddress)' >> /opt/commands.sh" +kurtosis service exec "$STACK_NAME" $SVC_CONTRACTS "echo 'ROLLUP=\$(cat zkevm/combined.json | jq -r .rollupAddress)' >> /opt/commands.sh" +kurtosis service exec "$STACK_NAME" $SVC_CONTRACTS "echo 'GENESIS=\$(cat zkevm/combined.json | jq -r .genesis)' >> /opt/commands.sh" +kurtosis service exec "$STACK_NAME" $SVC_CONTRACTS "echo \"CONSENSUS=\\\$(cast call \\\$ROLLUP_MAN 'rollupTypeMap(uint32)(address,address,uint64,uint8,bool,bytes32)' 1 | head -1)\" >> /opt/commands.sh" +kurtosis service exec "$STACK_NAME" $SVC_CONTRACTS "echo PRIV_KEY=0x12d7de8621a77640c9241b2595ba78ce443d05e94090365ab3bb5e19df82c625 >> /opt/commands.sh" +kurtosis service exec "$STACK_NAME" $SVC_CONTRACTS "echo 'cd /opt/zkevm-contracts && git checkout $TAG_TARGET_FORKID' >> /opt/commands.sh" +kurtosis service exec "$STACK_NAME" $SVC_CONTRACTS "chmod +x /opt/commands.sh" # wait for batches to be verified on sequencer echo "Waiting for everything to verify and sync on sequencer" DONE=0 while [ $DONE -ne 1 ]; do - TRUSTED__ON_SEQCR=$(printf "%d" $(cast rpc --json --rpc-url $(kurtosis port print $STACK_NAME $SVC_SEQUENCER rpc) zkevm_batchNumber | jq -r)) - VERIFIED_ON_SEQCR=$(printf "%d" $(cast rpc --json --rpc-url $(kurtosis port print $STACK_NAME $SVC_SEQUENCER rpc) zkevm_verifiedBatchNumber | jq -r)) - VERIFIED_ON_CHAIN=$(kurtosis service exec $STACK_NAME $SVC_CONTRACTS ". /opt/commands.sh && cast call \$ROLLUP_MAN \"rollupIDToRollupData(uint32)(address,uint64,address,uint64,bytes32,uint64,uint64,uint64,uint64,uint64,uint64,uint8)\" 1 | head -6 | tail -1" | tail -2 | head -1) + TRUSTED__ON_SEQCR=$(printf "%d" $(cast rpc --json --rpc-url $(kurtosis port print "$STACK_NAME" $SVC_SEQUENCER rpc) zkevm_batchNumber | jq -r)) + VERIFIED_ON_SEQCR=$(printf "%d" $(cast rpc --json --rpc-url $(kurtosis port print "$STACK_NAME" $SVC_SEQUENCER rpc) zkevm_verifiedBatchNumber | jq -r)) + VERIFIED_ON_CHAIN=$(kurtosis service exec "$STACK_NAME" $SVC_CONTRACTS ". /opt/commands.sh && cast call \$ROLLUP_MAN \"rollupIDToRollupData(uint32)(address,uint64,address,uint64,bytes32,uint64,uint64,uint64,uint64,uint64,uint64,uint8)\" 1 | head -6 | tail -1" | tail -2 | head -1) echo "Trusted batch number on sequencer: $TRUSTED__ON_SEQCR, Verified batch number on sequencer: $VERIFIED_ON_SEQCR, Verified batch number on chain: $VERIFIED_ON_CHAIN" if [ "$TRUSTED__ON_SEQCR" -ne "$VERIFIED_ON_SEQCR" ] || [ "$TRUSTED__ON_SEQCR" -ne "$VERIFIED_ON_CHAIN" ]; then sleep 5 @@ -116,9 +116,9 @@ echo "DONE: Sequencer status is up to date" echo "Waiting for RPC to be totally synced" DONE=0 while [ $DONE -ne 1 ]; do - TRUSTED__ON_RPC=$(printf "%d" $(cast rpc --json --rpc-url $(kurtosis port print $STACK_NAME $SVC_RPC rpc) zkevm_batchNumber | jq -r)) - VERIFIED_ON_RPC=$(printf "%d" $(cast rpc --json --rpc-url $(kurtosis port print $STACK_NAME $SVC_RPC rpc) zkevm_verifiedBatchNumber | jq -r)) - VERIFIED_ON_CHAIN=$(kurtosis service exec $STACK_NAME $SVC_CONTRACTS ". /opt/commands.sh && cast call \$ROLLUP_MAN \"rollupIDToRollupData(uint32)(address,uint64,address,uint64,bytes32,uint64,uint64,uint64,uint64,uint64,uint64,uint8)\" 1 | head -6 | tail -1" | tail -2 | head -1) + TRUSTED__ON_RPC=$(printf "%d" $(cast rpc --json --rpc-url $(kurtosis port print "$STACK_NAME" $SVC_RPC rpc) zkevm_batchNumber | jq -r)) + VERIFIED_ON_RPC=$(printf "%d" $(cast rpc --json --rpc-url $(kurtosis port print "$STACK_NAME" $SVC_RPC rpc) zkevm_verifiedBatchNumber | jq -r)) + VERIFIED_ON_CHAIN=$(kurtosis service exec "$STACK_NAME" $SVC_CONTRACTS ". /opt/commands.sh && cast call \$ROLLUP_MAN \"rollupIDToRollupData(uint32)(address,uint64,address,uint64,bytes32,uint64,uint64,uint64,uint64,uint64,uint64,uint8)\" 1 | head -6 | tail -1" | tail -2 | head -1) echo "Trusted batch number on rpc: $TRUSTED__ON_RPC, Verified batch number on rpc: $VERIFIED_ON_RPC, Verified batch number on chain: $VERIFIED_ON_CHAIN" if [ "$TRUSTED__ON_RPC" -ne "$VERIFIED_ON_RPC" ] || [ "$TRUSTED__ON_RPC" -ne "$VERIFIED_ON_CHAIN" ]; then sleep 5 @@ -130,16 +130,16 @@ echo "DONE: RPC status is up to date" # Stop services echo "Stopping services..." -kurtosis service stop $STACK_NAME $SVC_CDKNODE -kurtosis service stop $STACK_NAME $SVC_PROVER -kurtosis service stop $STACK_NAME $SVC_BRIDGE -kurtosis service stop $STACK_NAME $SVC_RPC -kurtosis service stop $STACK_NAME $SVC_SEQUENCER -kurtosis service stop $STACK_NAME $SVC_SLESS_EXECUTOR +kurtosis service stop "$STACK_NAME" $SVC_CDKNODE +kurtosis service stop "$STACK_NAME" $SVC_PROVER +kurtosis service stop "$STACK_NAME" $SVC_BRIDGE +kurtosis service stop "$STACK_NAME" $SVC_RPC +kurtosis service stop "$STACK_NAME" $SVC_SEQUENCER +kurtosis service stop "$STACK_NAME" $SVC_SLESS_EXECUTOR # Depoly verifier echo "Deploying verifier..." -kurtosis service exec $STACK_NAME $SVC_CONTRACTS \ +kurtosis service exec "$STACK_NAME" $SVC_CONTRACTS \ ". /opt/commands.sh && \ forge create \ --broadcast \ @@ -149,7 +149,7 @@ kurtosis service exec $STACK_NAME $SVC_CONTRACTS \ # Add new rollup type echo "Adding new rollup type..." -kurtosis service exec $STACK_NAME $SVC_CONTRACTS \ +kurtosis service exec "$STACK_NAME" $SVC_CONTRACTS \ ". /opt/commands.sh && \ cast send \ --json \ @@ -163,7 +163,7 @@ kurtosis service exec $STACK_NAME $SVC_CONTRACTS \ # Update rollup echo "Updating rollup..." -kurtosis service exec $STACK_NAME $SVC_CONTRACTS \ +kurtosis service exec "$STACK_NAME" $SVC_CONTRACTS \ ". /opt/commands.sh && \ cast send \ --json \ @@ -176,7 +176,7 @@ kurtosis service exec $STACK_NAME $SVC_CONTRACTS \ # Verify forkid on chain echo "Checking on chain forkid..." -FORKID_ON_CHAIN=$(kurtosis service exec $STACK_NAME $SVC_CONTRACTS ". /opt/commands.sh && cast call \$ROLLUP_MAN \"rollupIDToRollupData(uint32)(address,uint64,address,uint64,bytes32,uint64,uint64,uint64,uint64,uint64,uint64,uint8)\" 1 | head -4 | tail -1" | tail -2 | head -1) +FORKID_ON_CHAIN=$(kurtosis service exec "$STACK_NAME" $SVC_CONTRACTS ". /opt/commands.sh && cast call \$ROLLUP_MAN \"rollupIDToRollupData(uint32)(address,uint64,address,uint64,bytes32,uint64,uint64,uint64,uint64,uint64,uint64,uint8)\" 1 | head -4 | tail -1" | tail -2 | head -1) if [ "$FORKID_ON_CHAIN" -ne $TARGET_FORKID ]; then echo "KO: Forkid not updated on chain!" exit 1 @@ -186,16 +186,16 @@ fi # Unhalt sequencer echo "Unhalting sequencer..." -kurtosis service start $STACK_NAME $SVC_SEQUENCER -kurtosis service exec $STACK_NAME $SVC_SEQUENCER \ +kurtosis service start "$STACK_NAME" $SVC_SEQUENCER +kurtosis service exec "$STACK_NAME" $SVC_SEQUENCER \ "sed -ni '/zkevm.sequencer-halt-on-batch-number/"\!"p' /etc/cdk-erigon/config.yaml; \ echo \"zkevm.sequencer-halt-on-batch-number: 0\" >> /etc/cdk-erigon/config.yaml" -kurtosis service stop $STACK_NAME $SVC_SEQUENCER -kurtosis service start $STACK_NAME $SVC_SEQUENCER +kurtosis service stop "$STACK_NAME" $SVC_SEQUENCER +kurtosis service start "$STACK_NAME" $SVC_SEQUENCER # Wait for sequencer to become responsive echo "Waiting for Sequencer's rpc port to become available" -until cast rpc --json --rpc-url $(kurtosis port print $STACK_NAME $SVC_SEQUENCER rpc) zkevm_getForkId &> /dev/null; do +until cast rpc --json --rpc-url $(kurtosis port print "$STACK_NAME" $SVC_SEQUENCER rpc) zkevm_getForkId &> /dev/null; do printf '.' sleep 3 done @@ -204,18 +204,18 @@ echo # Check forkid on Sequencer FORKID=$SOURCE_FORKID while [ $FORKID -ne $TARGET_FORKID ]; do - FORKID=$(printf "%d" $(cast rpc --json --rpc-url $(kurtosis port print $STACK_NAME $SVC_SEQUENCER rpc) zkevm_getForkId | jq -r)) + FORKID=$(printf "%d" $(cast rpc --json --rpc-url $(kurtosis port print "$STACK_NAME" $SVC_SEQUENCER rpc) zkevm_getForkId | jq -r)) echo "Current Sequencer forkid: $FORKID" sleep 3 done echo "SEQUENCER SUCCESSFULLY UPGRADED TO FORKID $TARGET_FORKID" # Start RPC as well -kurtosis service start $STACK_NAME $SVC_RPC +kurtosis service start "$STACK_NAME" $SVC_RPC # Wait for rpc to become responsive echo "Waiting for RPC's rpc port to become available" -until cast rpc --json --rpc-url $(kurtosis port print $STACK_NAME $SVC_RPC rpc) zkevm_getForkId &> /dev/null; do +until cast rpc --json --rpc-url $(kurtosis port print "$STACK_NAME" $SVC_RPC rpc) zkevm_getForkId &> /dev/null; do printf '.' sleep 3 done @@ -227,7 +227,7 @@ COUNTER=0 MAX_RETRIES=25 while [ $FORKID -ne $TARGET_FORKID ]; do ((COUNTER++)) - FORKID=$(printf "%d" $(cast rpc --json --rpc-url $(kurtosis port print $STACK_NAME $SVC_RPC rpc) zkevm_getForkId | jq -r)) + FORKID=$(printf "%d" $(cast rpc --json --rpc-url $(kurtosis port print "$STACK_NAME" $SVC_RPC rpc) zkevm_getForkId | jq -r)) echo "Current RPC forkid: $FORKID" if [[ $COUNTER -ge $MAX_RETRIES ]]; then FORKID=$TARGET_FORKID # To break the loop @@ -245,7 +245,7 @@ fi # clean up echo "Cleaning up deployed enclave..." rm $KURTOSIS_CONFIG -kurtosis enclave stop $STACK_NAME -kurtosis enclave rm $STACK_NAME +kurtosis enclave stop "$STACK_NAME" +kurtosis enclave rm "$STACK_NAME" exit 0