Skip to content

Commit

Permalink
wormchain: add upgrade vaa and upgrade handler. Removes set params va…
Browse files Browse the repository at this point in the history
…a. (#3292)

* Add chain upgrade vaa and upgrade handler. Removes set params vaa.

* Update node package

* Fix vaa payload test
  • Loading branch information
misko9 authored Aug 17, 2023
1 parent 0dcc53c commit 6b3819c
Show file tree
Hide file tree
Showing 10 changed files with 998 additions and 685 deletions.
86 changes: 68 additions & 18 deletions node/cmd/guardiand/admintemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ var wormchainMigrateContractInstantiationMsg *string
var wormchainWasmInstantiateAllowlistCodeId *string
var wormchainWasmInstantiateAllowlistContractAddress *string

var gatewayScheduleUpgradeName *string
var gatewayScheduleUpgradeHeight *string
var gatewayIbcComposabilityMwContractAddress *string

var ibcUpdateChannelChainTargetChainId *string
Expand Down Expand Up @@ -138,6 +140,16 @@ func init() {
AdminClientGatewayIbcComposabilityMwSetContractCmd.Flags().AddFlagSet(gatewayIbcComposabilityMwFlagSet)
TemplateCmd.AddCommand(AdminClientGatewayIbcComposabilityMwSetContractCmd)

// 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)

// flags for the ibc-receiver-update-channel-chain and ibc-translator-update-channel-chain commands
ibcUpdateChannelChainFlagSet := pflag.NewFlagSet("ibc-mapping", pflag.ExitOnError)
ibcUpdateChannelChainTargetChainId = ibcUpdateChannelChainFlagSet.String("target-chain-id", "", "Target Chain ID for the governance VAA")
Expand All @@ -147,9 +159,6 @@ func init() {
AdminClientIbcTranslatorUpdateChannelChainCmd.Flags().AddFlagSet(ibcUpdateChannelChainFlagSet)
TemplateCmd.AddCommand(AdminClientIbcReceiverUpdateChannelChainCmd)
TemplateCmd.AddCommand(AdminClientIbcTranslatorUpdateChannelChainCmd)

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

var TemplateCmd = &cobra.Command{
Expand Down Expand Up @@ -229,18 +238,24 @@ var AdminClientWormchainDeleteWasmInstantiateAllowlistCmd = &cobra.Command{
Run: runWormchainDeleteWasmInstantiateAllowlistTemplate,
}

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 AdminClientGatewayIbcComposabilityMwSetContractCmd = &cobra.Command{
Use: "gateway-ibc-composability-mw-set-contract",
Short: "Set the contract that the IBC Composability middleware will query",
Run: runGatewayIbcComposabilityMwSetContractTemplate,
}

var AdminClientGatewaySetTokenfactoryPfmDefaultParamsCmd = &cobra.Command{
Use: "gateway-set-tokenfactory-pfm-default-params",
Short: "Generate an empty gateway set tokenfactory pfm default params template at specified path",
Run: runGatewaySetTokenfactoryPfmDefaultParamsTemplate,
}

var AdminClientIbcReceiverUpdateChannelChainCmd = &cobra.Command{
Use: "ibc-receiver-update-channel-chain",
Short: "Generate an empty ibc receiver channelId to chainId mapping update template at specified path",
Expand Down Expand Up @@ -683,9 +698,18 @@ func runWormchainWasmInstantiateAllowlistTemplate(action nodev1.WormchainWasmIns
fmt.Print(string(b))
}

func runGatewayIbcComposabilityMwSetContractTemplate(cmd *cobra.Command, args []string) {
if *gatewayIbcComposabilityMwContractAddress == "" {
log.Fatal("--contract-address must be specified")
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{
Expand All @@ -694,9 +718,10 @@ func runGatewayIbcComposabilityMwSetContractTemplate(cmd *cobra.Command, args []
{
Sequence: rand.Uint64(),
Nonce: rand.Uint32(),
Payload: &nodev1.GovernanceMessage_GatewayIbcComposabilityMwSetContract{
GatewayIbcComposabilityMwSetContract: &nodev1.GatewayIbcComposabilityMwSetContract{
Contract: *gatewayIbcComposabilityMwContractAddress,
Payload: &nodev1.GovernanceMessage_GatewayScheduleUpgrade{
GatewayScheduleUpgrade: &nodev1.GatewayScheduleUpgrade{
Name: *gatewayScheduleUpgradeName,
Height: height,
},
},
},
Expand All @@ -710,15 +735,40 @@ func runGatewayIbcComposabilityMwSetContractTemplate(cmd *cobra.Command, args []
fmt.Print(string(b))
}

func runGatewaySetTokenfactoryPfmDefaultParamsTemplate(cmd *cobra.Command, args []string) {
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 runGatewayIbcComposabilityMwSetContractTemplate(cmd *cobra.Command, args []string) {
if *gatewayIbcComposabilityMwContractAddress == "" {
log.Fatal("--contract-address must be specified")
}

m := &nodev1.InjectGovernanceVAARequest{
CurrentSetIndex: uint32(*templateGuardianIndex),
Messages: []*nodev1.GovernanceMessage{
{
Sequence: rand.Uint64(),
Nonce: rand.Uint32(),
Payload: &nodev1.GovernanceMessage_GatewaySetTokenfactoryPfmDefaultParams{
GatewaySetTokenfactoryPfmDefaultParams: &nodev1.GatewaySetTokenfactoryPfmDefaultParams{},
Payload: &nodev1.GovernanceMessage_GatewayIbcComposabilityMwSetContract{
GatewayIbcComposabilityMwSetContract: &nodev1.GatewayIbcComposabilityMwSetContract{
Contract: *gatewayIbcComposabilityMwContractAddress,
},
},
},
},
Expand Down
51 changes: 32 additions & 19 deletions node/pkg/adminrpc/adminserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,34 @@ func wormchainWasmInstantiateAllowlist(
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
}

func gatewayIbcComposabilityMwSetContract(
req *nodev1.GatewayIbcComposabilityMwSetContract,
timestamp time.Time,
Expand All @@ -360,23 +388,6 @@ func gatewayIbcComposabilityMwSetContract(
return v, nil
}

func gatewaySetTokenfactoryPfmDefaultParams(
timestamp time.Time,
guardianSetIndex uint32,
nonce uint32,
sequence uint64,
) *vaa.VAA {
v := vaa.CreateGovernanceVAA(
timestamp,
nonce,
sequence,
guardianSetIndex,
vaa.EmptyPayloadVaa(vaa.GatewayModuleStr, vaa.ActionSetTokenfactoryPfmDefaultParams, vaa.ChainIDWormchain),
)

return v
}

// 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 @@ -548,10 +559,12 @@ func GovMsgToVaa(message *nodev1.GovernanceMessage, currentSetIndex uint32, time
v, err = wormchainMigrateContract(payload.WormchainMigrateContract, timestamp, currentSetIndex, message.Nonce, message.Sequence)
case *nodev1.GovernanceMessage_WormchainWasmInstantiateAllowlist:
v, err = wormchainWasmInstantiateAllowlist(payload.WormchainWasmInstantiateAllowlist, timestamp, currentSetIndex, message.Nonce, message.Sequence)
case *nodev1.GovernanceMessage_GatewayScheduleUpgrade:
v, err = gatewayScheduleUpgrade(payload.GatewayScheduleUpgrade, timestamp, currentSetIndex, message.Nonce, message.Sequence)
case *nodev1.GovernanceMessage_GatewayCancelUpgrade:
v, err = gatewayCancelUpgrade(timestamp, currentSetIndex, message.Nonce, message.Sequence)
case *nodev1.GovernanceMessage_GatewayIbcComposabilityMwSetContract:
v, err = gatewayIbcComposabilityMwSetContract(payload.GatewayIbcComposabilityMwSetContract, timestamp, currentSetIndex, message.Nonce, message.Sequence)
case *nodev1.GovernanceMessage_GatewaySetTokenfactoryPfmDefaultParams:
v = gatewaySetTokenfactoryPfmDefaultParams(timestamp, currentSetIndex, message.Nonce, message.Sequence)
case *nodev1.GovernanceMessage_CircleIntegrationUpdateWormholeFinality:
v, err = circleIntegrationUpdateWormholeFinality(payload.CircleIntegrationUpdateWormholeFinality, timestamp, currentSetIndex, message.Nonce, message.Sequence)
case *nodev1.GovernanceMessage_CircleIntegrationRegisterEmitterAndDomain:
Expand Down
Loading

0 comments on commit 6b3819c

Please sign in to comment.