update-guardian-set.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/usr/bin/env bash
  2. # This script submits a guardian set update using the VAA injection admin command.
  3. # First argument is the number of guardians for the new guardian set.
  4. set -e
  5. # wait for the guardians to establish networking
  6. sleep 20
  7. newNumGuardians=$1
  8. echo "new number of guardians: ${newNumGuardians}"
  9. webHost=$2
  10. echo "webHost ${webHost}"
  11. namespace=$3
  12. echo "namespace ${namespace}"
  13. # file & path to save governance VAA
  14. fileName=new-guardianset.prototxt
  15. localPath=./scripts/$fileName
  16. containerPath=/tmp/$fileName
  17. echo "localPath: ${localPath}"
  18. echo "containerPath: ${containerPath}"
  19. # the admin socket of the devnet guardians. used for executing commands in guardian pods.
  20. sock=/tmp/admin.sock
  21. guardianPublicWebBaseUrl="${webHost}:7071"
  22. currentGuardianSetUrl="${guardianPublicWebBaseUrl}/v1/guardianset/current"
  23. # fetch result and parse json body:
  24. guardianSet=$(curl ${currentGuardianSetUrl} | jq ".guardianSet")
  25. currentIndex=$(echo ${guardianSet} | jq ".index")
  26. currentNumGuardians=$(echo ${guardianSet} | jq ".addresses | length")
  27. echo "currentIndex: ${currentIndex}"
  28. echo "currentNumGuardians ${currentNumGuardians}"
  29. if [ ${currentNumGuardians} == ${newNumGuardians} ]; then
  30. echo "number of guardians is as expected."
  31. exit 0
  32. fi
  33. echo "creating guardian set update governance message template prototext"
  34. minikube kubectl -- exec -n ${namespace} guardian-0 -c guardiand -- /guardiand template guardian-set-update --num=${newNumGuardians} --idx=${currentIndex} > ${localPath}
  35. # for i in $(seq ${newNumGuardians})
  36. for i in $(seq ${currentNumGuardians})
  37. do
  38. # create guardian index: [0-18]
  39. guardianIndex=$((i-1))
  40. # create the governance guardian set update prototxt file in the container
  41. echo "created governance file for guardian-${guardianIndex}"
  42. minikube kubectl -- cp ${localPath} ${namespace}/guardian-${guardianIndex}:${containerPath} -c guardiand
  43. # inject the guardian set update
  44. minikube kubectl -- exec -n ${namespace} guardian-${guardianIndex} -c guardiand -- /guardiand admin governance-vaa-inject --socket $sock $containerPath
  45. echo "injected governance VAA for guardian-${guardianIndex}"
  46. done
  47. # wait for the guardians to reach quorum about the new guardian set
  48. sleep 30 # probably overkill, but some waiting is required.
  49. function get_sequence_from_prototext {
  50. path=${1}
  51. while IFS= read -r line
  52. do
  53. parts=($line)
  54. if [ ${parts[0]} == "sequence:" ]; then
  55. echo "${parts[1]}"
  56. fi
  57. done < "$path"
  58. }
  59. sequence=$(get_sequence_from_prototext ${localPath})
  60. echo "got sequence: ${sequence} from ${localPath}"
  61. # get vaa
  62. governanceChain="1"
  63. governanceAddress="0000000000000000000000000000000000000000000000000000000000000004"
  64. vaaUrl="${guardianPublicWebBaseUrl}/v1/signed_vaa/${governanceChain}/${governanceAddress}/${sequence}"
  65. echo "going to call to fetch VAA: ${vaaUrl}"
  66. # proto endpoints supply a base64 encoded VAA
  67. b64Vaa=$(curl ${vaaUrl} | jq ".vaaBytes")
  68. echo "got bas64 VAA: ${b64Vaa}"
  69. function base64_to_hex {
  70. b64Str=${1}
  71. echo $b64Str | base64 -d -i | hexdump -v -e '/1 "%02x" '
  72. }
  73. # transform base54 to hex
  74. hexVaa=$(base64_to_hex ${b64Vaa})
  75. echo "got hex VAA: ${hexVaa}"
  76. # fire off the Golang script in clients/eth:
  77. ./scripts/send-vaa.sh $webHost $hexVaa
  78. # give some time for guardians to observe the tx and update their state
  79. sleep 30
  80. # fetch result and parse json body:
  81. echo "going to fetch current guardianset from ${currentGuardianSetUrl}"
  82. nextGuardianSet=$(curl ${currentGuardianSetUrl} | jq ".guardianSet")
  83. nextIndex=$(echo ${nexGuardianSet} | jq ".index")
  84. nextNumGuardians=$(echo ${nextGuardianSet} | jq ".addresses | length")
  85. echo "nextIndex: ${nextIndex}"
  86. echo "nextNumGuardians ${nextNumGuardians}"
  87. if [ ${nextNumGuardians} == ${newNumGuardians} ]; then
  88. echo "number of guardians is as expected."
  89. else
  90. echo "number of guardians is not as expected. number of guardians in set: ${nextNumGuardians}."
  91. exit 1
  92. fi
  93. echo "update-guardian-set.sh succeeded."