Skip to content

Commit

Permalink
wormchain: add support for scheduled upgrades (#3291)
Browse files Browse the repository at this point in the history
* Add Gateway support for scheduled upgrades

* Add node package updates

* check out specific sandbox version

---------

Co-authored-by: Ben Guidarelli <ben.guidarelli@gmail.com>
  • Loading branch information
misko9 and barnjamin authored Aug 17, 2023
1 parent e54b213 commit b43cc44
Show file tree
Hide file tree
Showing 17 changed files with 1,446 additions and 1,105 deletions.
3 changes: 3 additions & 0 deletions algorand/runPythonUnitTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
if [ ! -d _sandbox ]; then
echo We need to create it...
git clone https://github.com/algorand/sandbox.git _sandbox
cd _sandbox
git checkout 4e613dcff61523693c18584894ee6de9bd469ec1
cd ..
fi

sed -i -e 's@export ALGOD_URL=""@export ALGOD_URL="https://github.com/algorand/go-algorand"@' \
Expand Down
21 changes: 21 additions & 0 deletions node/cmd/guardiand/adminserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,23 @@ func wormchainMigrateContract(req *nodev1.WormchainMigrateContract, timestamp ti
return v, nil
}

func gatewayScheduleUpgrade(req *nodev1.GatewayScheduleUpgrade, timestamp time.Time, guardianSetIndex uint32, nonce uint32, sequence uint64) (*vaa.VAA, error) { //nolint:unparam // error is always nil but kept to mirror function signature of other functions
v := vaa.CreateGovernanceVAA(timestamp, nonce, sequence, guardianSetIndex, vaa.BodyGatewayScheduleUpgrade{
Name: req.Name,
Height: req.Height,
}.Serialize())

return v, nil
}

func gatewayCancelUpgrade(timestamp time.Time, guardianSetIndex uint32, nonce uint32, sequence uint64) (*vaa.VAA, error) { //nolint:unparam // error is always nil but kept to mirror function signature of other functions
v := vaa.CreateGovernanceVAA(timestamp, nonce, sequence, guardianSetIndex,
vaa.EmptyPayloadVaa(vaa.GatewayModuleStr, vaa.ActionCancelUpgrade, vaa.ChainIDWormchain),
)

return v, nil
}

// circleIntegrationUpdateWormholeFinality converts a nodev1.CircleIntegrationUpdateWormholeFinality to its canonical VAA representation
// Returns an error if the data is invalid
func circleIntegrationUpdateWormholeFinality(req *nodev1.CircleIntegrationUpdateWormholeFinality, timestamp time.Time, guardianSetIndex uint32, nonce uint32, sequence uint64) (*vaa.VAA, error) {
Expand Down Expand Up @@ -422,6 +439,10 @@ func (s *nodePrivilegedService) InjectGovernanceVAA(ctx context.Context, req *no
v, err = wormchainInstantiateContract(payload.WormchainInstantiateContract, timestamp, req.CurrentSetIndex, message.Nonce, message.Sequence)
case *nodev1.GovernanceMessage_WormchainMigrateContract:
v, err = wormchainMigrateContract(payload.WormchainMigrateContract, timestamp, req.CurrentSetIndex, message.Nonce, message.Sequence)
case *nodev1.GovernanceMessage_GatewayScheduleUpgrade:
v, err = gatewayScheduleUpgrade(payload.GatewayScheduleUpgrade, timestamp, req.CurrentSetIndex, message.Nonce, message.Sequence)
case *nodev1.GovernanceMessage_GatewayCancelUpgrade:
v, err = gatewayCancelUpgrade(timestamp, req.CurrentSetIndex, message.Nonce, message.Sequence)
case *nodev1.GovernanceMessage_CircleIntegrationUpdateWormholeFinality:
v, err = circleIntegrationUpdateWormholeFinality(payload.CircleIntegrationUpdateWormholeFinality, timestamp, req.CurrentSetIndex, message.Nonce, message.Sequence)
case *nodev1.GovernanceMessage_CircleIntegrationRegisterEmitterAndDomain:
Expand Down
81 changes: 81 additions & 0 deletions node/cmd/guardiand/admintemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ var module *string
var shutdownGuardianKey *string
var shutdownPubKey *string

var gatewayScheduleUpgradeName *string
var gatewayScheduleUpgradeHeight *string

var circleIntegrationChainID *string
var circleIntegrationFinality *string
var circleIntegrationForeignEmitterChainID *string
Expand Down Expand Up @@ -73,6 +76,16 @@ func init() {
AdminClientShutdownProofCmd.Flags().AddFlagSet(authProofFlagSet)
TemplateCmd.AddCommand(AdminClientShutdownProofCmd)

// flags for the gateway-schedule-upgrade command
gatewayScheduleUpgradeFlagSet := pflag.NewFlagSet("gateway-schedule-upgrade", pflag.ExitOnError)
gatewayScheduleUpgradeName = gatewayScheduleUpgradeFlagSet.String("name", "", "Scheduled upgrade name")
gatewayScheduleUpgradeHeight = gatewayScheduleUpgradeFlagSet.String("height", "", "Scheduled upgrade height")
AdminClientGatewayScheduleUpgradeCmd.Flags().AddFlagSet(gatewayScheduleUpgradeFlagSet)
TemplateCmd.AddCommand(AdminClientGatewayScheduleUpgradeCmd)

// AdminClientGatewayCancelUpgradeCmd doesn't have any flags
TemplateCmd.AddCommand(AdminClientGatewayCancelUpgradeCmd)

circleIntegrationChainIDFlagSet := pflag.NewFlagSet("circle-integ", pflag.ExitOnError)
circleIntegrationChainID = circleIntegrationChainIDFlagSet.String("chain-id", "", "Target chain ID")

Expand Down Expand Up @@ -139,6 +152,18 @@ var AdminClientShutdownProofCmd = &cobra.Command{
Run: runShutdownProofTemplate,
}

var AdminClientGatewayScheduleUpgradeCmd = &cobra.Command{
Use: "gateway-schedule-upgrade",
Short: "Schedule an upgrade on Gateway with a specified name for a specified height",
Run: runGatewayScheduleUpgradeTemplate,
}

var AdminClientGatewayCancelUpgradeCmd = &cobra.Command{
Use: "gateway-cancel-upgrade",
Short: "Cancel a scheduled upgrade on Gateway",
Run: runGatewayCancelUpgradeTemplate,
}

var AdminClientCircleIntegrationUpdateWormholeFinalityCmd = &cobra.Command{
Use: "circle-integration-update-wormhole-finality",
Short: "Generate an empty circle integration update wormhole finality template at specified path",
Expand Down Expand Up @@ -339,6 +364,62 @@ func runShutdownProofTemplate(cmd *cobra.Command, args []string) {
fmt.Print(proofHex)
}

func runGatewayScheduleUpgradeTemplate(cmd *cobra.Command, args []string) {
if *gatewayScheduleUpgradeName == "" {
log.Fatal("--name must be specified")
}

if *gatewayScheduleUpgradeHeight == "" {
log.Fatal("--height must be specified")
}

height, err := strconv.ParseUint(*gatewayScheduleUpgradeHeight, 10, 64)
if err != nil {
log.Fatal("failed to parse height as uint64: ", err)
}

m := &nodev1.InjectGovernanceVAARequest{
CurrentSetIndex: uint32(*templateGuardianIndex),
Messages: []*nodev1.GovernanceMessage{
{
Sequence: rand.Uint64(),
Nonce: rand.Uint32(),
Payload: &nodev1.GovernanceMessage_GatewayScheduleUpgrade{
GatewayScheduleUpgrade: &nodev1.GatewayScheduleUpgrade{
Name: *gatewayScheduleUpgradeName,
Height: height,
},
},
},
},
}

b, err := prototext.MarshalOptions{Multiline: true}.Marshal(m)
if err != nil {
panic(err)
}
fmt.Print(string(b))
}

func runGatewayCancelUpgradeTemplate(cmd *cobra.Command, args []string) {
m := &nodev1.InjectGovernanceVAARequest{
CurrentSetIndex: uint32(*templateGuardianIndex),
Messages: []*nodev1.GovernanceMessage{
{
Sequence: rand.Uint64(),
Nonce: rand.Uint32(),
Payload: &nodev1.GovernanceMessage_GatewayCancelUpgrade{},
},
},
}

b, err := prototext.MarshalOptions{Multiline: true}.Marshal(m)
if err != nil {
panic(err)
}
fmt.Print(string(b))
}

func runCircleIntegrationUpdateWormholeFinalityTemplate(cmd *cobra.Command, args []string) {
if *circleIntegrationChainID == "" {
log.Fatal("--chain-id must be specified.")
Expand Down
Loading

0 comments on commit b43cc44

Please sign in to comment.