scripts: Update scripts/contract-upgrade-governance.sh

Now it prints instructions on checking out the current git hash + some refactoring
This commit is contained in:
Csongor Kiss 2022-08-09 00:50:05 +01:00 committed by Csongor Kiss
parent 650beaa79a
commit 33f1b28662
1 changed files with 80 additions and 27 deletions

View File

@ -44,6 +44,12 @@ EOF
exit 1 exit 1
} }
# Check if guardiand command exists. It's needed for generating the protoxt and
# computing the digest.
if ! command -v guardiand >/dev/null 2>&1; then
echo "ERROR: guardiand binary not found" >&2
exit 1
fi
### Parse command line options ### Parse command line options
address="" address=""
@ -149,7 +155,7 @@ case "$chain_name" in
chain=12 chain=12
explorer="https://blockscout.acala.network/address/" explorer="https://blockscout.acala.network/address/"
evm=true evm=true
;; ;;
klaytn) klaytn)
chain=13 chain=13
explorer="https://scope.klaytn.com/account/" explorer="https://scope.klaytn.com/account/"
@ -176,52 +182,90 @@ if [ "$chain_name" = "terra" ]; then
address="\$(printf \"%064x\" $terra_code_id)" address="\$(printf \"%064x\" $terra_code_id)"
fi fi
create_governance="" # Generate the command to create the governance prototxt
evm_artifact="" function create_governance() {
solana_artifact="" case "$module" in
terra_artifact=""
case "$module" in
bridge|core) bridge|core)
create_governance="\ echo "\
guardiand template contract-upgrade \\ guardiand template contract-upgrade \\
--chain-id $chain \\ --chain-id $chain \\
--new-address $address" --new-address $address"
evm_artifact="build/contracts/Implementation.json"
solana_artifact="artifacts-mainnet/bridge.so"
terra_artifact="artifacts/wormhole.wasm"
;; ;;
token_bridge) token_bridge)
create_governance="\ echo "\
guardiand template token-bridge-upgrade-contract \\ guardiand template token-bridge-upgrade-contract \\
--chain-id $chain --module \"TokenBridge\" \\ --chain-id $chain --module \"TokenBridge\" \\
--new-address $address" --new-address $address"
evm_artifact="build/contracts/BridgeImplementation.json"
solana_artifact="artifacts-mainnet/token_bridge.so"
terra_artifact="artifacts/token_bridge_terra.wasm"
;; ;;
nft_bridge) nft_bridge)
create_governance="\ echo "\
guardiand template token-bridge-upgrade-contract \\ guardiand template token-bridge-upgrade-contract \\
--chain-id $chain --module \"NFTBridge\" \\ --chain-id $chain --module \"NFTBridge\" \\
--new-address $address" --new-address $address"
evm_artifact="build/contracts/NFTBridgeImplementation.json"
solana_artifact="artifacts-mainnet/nft_bridge.so"
terra_artifact="artifacts/nft_bridge.wasm"
;; ;;
*) echo "unknown module $module" >&2 *) echo "unknown module $module" >&2
usage usage
;; ;;
esac esac
}
function evm_artifact() {
case "$module" in
bridge|core)
echo "build/contracts/Implementation.json"
;;
token_bridge)
echo "build/contracts/BridgeImplementation.json"
;;
nft_bridge)
echo "build/contracts/NFTBridgeImplementation.json"
;;
*) echo "unknown module $module" >&2
usage
;;
esac
}
function solana_artifact() {
case "$module" in
bridge|core)
echo "artifacts-mainnet/bridge.so"
;;
token_bridge)
echo "artifacts-mainnet/token_bridge.so"
;;
nft_bridge)
echo "artifacts-mainnet/nft_bridge.so"
;;
*) echo "unknown module $module" >&2
usage
;;
esac
}
function terra_artifact() {
case "$module" in
bridge|core)
echo "artifacts/wormhole.wasm"
;;
token_bridge)
echo "artifacts/token_bridge_terra.wasm"
;;
nft_bridge)
echo "artifacts/nft_bridge.wasm"
;;
*) echo "unknown module $module" >&2
usage
;;
esac
}
################################################################################ ################################################################################
# Construct the governance proto # Construct the governance proto
echo "# $module upgrade on $chain_name" >> "$gov_msg_file" echo "# $module upgrade on $chain_name" >> "$gov_msg_file"
# Append the new governance message to the gov file # Append the new governance message to the gov file
eval "$create_governance" >> "$gov_msg_file" eval "$(create_governance)" >> "$gov_msg_file"
# Multiple messages will include multiple 'current_set_index' fields, but the # Multiple messages will include multiple 'current_set_index' fields, but the
# proto format only takes one. This next part cleans up the file so there's only # proto format only takes one. This next part cleans up the file so there's only
@ -275,6 +319,15 @@ EOD
echo "# Verification steps ($chain_name $module) echo "# Verification steps ($chain_name $module)
" >> "$instructions_file" " >> "$instructions_file"
# Print instructions on checking out the current git hash:
git_hash=$(git rev-parse HEAD)
echo "
## Checkout the current git hash
\`\`\`shell
git fetch
git checkout $git_hash
\`\`\`" >> "$instructions_file"
# Verification steps depend on the chain. # Verification steps depend on the chain.
if [ "$evm" = true ]; then if [ "$evm" = true ]; then
@ -290,7 +343,7 @@ if [ "$evm" = true ]; then
Next, use the \`verify\` script to verify that the deployed bytecodes we are upgrading to match the build artifacts: Next, use the \`verify\` script to verify that the deployed bytecodes we are upgrading to match the build artifacts:
\`\`\`shell \`\`\`shell
wormhole/ethereum $ ./verify -r $(worm rpc mainnet $chain_name) -c $chain_name $evm_artifact $address wormhole/ethereum $ ./verify -r $(worm rpc mainnet $chain_name) -c $chain_name $(evm_artifact) $address
\`\`\` \`\`\`
EOF EOF
@ -311,7 +364,7 @@ elif [ "$chain_name" = "solana" ]; then
\`\`\`shell \`\`\`shell
# $module # $module
wormhole/solana$ ./verify -n mainnet $solana_artifact $address wormhole/solana$ ./verify -n mainnet $(solana_artifact) $address
\`\`\` \`\`\`
EOF EOF
elif [ "$chain_name" = "terra" ]; then elif [ "$chain_name" = "terra" ]; then
@ -330,7 +383,7 @@ elif [ "$chain_name" = "terra" ]; then
\`\`\`shell \`\`\`shell
# $module # $module
wormhole/terra$ ./verify -n mainnet $terra_artifact $terra_code_id wormhole/terra$ ./verify -n mainnet $(terra_artifact) $terra_code_id
\`\`\` \`\`\`
EOF EOF
else else
@ -343,7 +396,7 @@ fi
cat <<-EOF >> "$instructions_file" cat <<-EOF >> "$instructions_file"
## Create governance ## Create governance
\`\`\`shell \`\`\`shell
$create_governance $(create_governance)
\`\`\` \`\`\`
EOF EOF