Skip to content

Commit

Permalink
wormchain: setparams gov vaa (#3285)
Browse files Browse the repository at this point in the history
* node: add new governance VAA for setting default tokenfactory and packet forward middleware params on Gateway

* wormchain: add msg_server handler to set default tokenfactory and pfm params

* node: add gateway template command

* node: fix lint errors

* Update goverance message to be generic

* x/wormhole: add RunInPlaceUpgrade tx cli command

* Merge gateway governance VAAs into a single rpc handler

* update admin client naming for gateway governance messages
  • Loading branch information
nik-suri authored Aug 15, 2023
1 parent 793abe6 commit 6aa80d4
Show file tree
Hide file tree
Showing 18 changed files with 1,353 additions and 1,234 deletions.
58 changes: 44 additions & 14 deletions node/cmd/guardiand/admintemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var wormchainMigrateContractInstantiationMsg *string
var wormchainWasmInstantiateAllowlistCodeId *string
var wormchainWasmInstantiateAllowlistContractAddress *string

var wormchainIbcComposabilityMwContractAddress *string
var gatewayIbcComposabilityMwContractAddress *string

var ibcUpdateChannelChainTargetChainId *string
var ibcUpdateChannelChainChannelId *string
Expand Down Expand Up @@ -132,11 +132,11 @@ func init() {
TemplateCmd.AddCommand(AdminClientWormchainAddWasmInstantiateAllowlistCmd)
TemplateCmd.AddCommand(AdminClientWormchainDeleteWasmInstantiateAllowlistCmd)

// flags for the wormchain-ibc-composability-mw-set-contract command
wormchainIbcComposabilityMwFlagSet := pflag.NewFlagSet("wormchain-ibc-composability-mw-set-contract", pflag.ExitOnError)
wormchainIbcComposabilityMwContractAddress = wormchainIbcComposabilityMwFlagSet.String("contract-address", "", "contract address to set in the ibc composability middleware")
AdminClientWormchainIbcComposabilityMwSetContractCmd.Flags().AddFlagSet(wormchainIbcComposabilityMwFlagSet)
TemplateCmd.AddCommand(AdminClientWormchainIbcComposabilityMwSetContractCmd)
// flags for the gateway-ibc-composability-mw-set-contract command
gatewayIbcComposabilityMwFlagSet := pflag.NewFlagSet("gateway-ibc-composability-mw-set-contract", pflag.ExitOnError)
gatewayIbcComposabilityMwContractAddress = gatewayIbcComposabilityMwFlagSet.String("contract-address", "", "contract address to set in the ibc composability middleware")
AdminClientGatewayIbcComposabilityMwSetContractCmd.Flags().AddFlagSet(gatewayIbcComposabilityMwFlagSet)
TemplateCmd.AddCommand(AdminClientGatewayIbcComposabilityMwSetContractCmd)

// flags for the ibc-receiver-update-channel-chain and ibc-translator-update-channel-chain commands
ibcUpdateChannelChainFlagSet := pflag.NewFlagSet("ibc-mapping", pflag.ExitOnError)
Expand All @@ -147,6 +147,9 @@ 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 @@ -226,10 +229,16 @@ var AdminClientWormchainDeleteWasmInstantiateAllowlistCmd = &cobra.Command{
Run: runWormchainDeleteWasmInstantiateAllowlistTemplate,
}

var AdminClientWormchainIbcComposabilityMwSetContractCmd = &cobra.Command{
Use: "wormchain-ibc-composability-mw-set-contract",
var AdminClientGatewayIbcComposabilityMwSetContractCmd = &cobra.Command{
Use: "gateway-ibc-composability-mw-set-contract",
Short: "Set the contract that the IBC Composability middleware will query",
Run: runWormchainIbcComposabilityMwSetContractTemplate,
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{
Expand Down Expand Up @@ -674,8 +683,8 @@ func runWormchainWasmInstantiateAllowlistTemplate(action nodev1.WormchainWasmIns
fmt.Print(string(b))
}

func runWormchainIbcComposabilityMwSetContractTemplate(cmd *cobra.Command, args []string) {
if *wormchainIbcComposabilityMwContractAddress == "" {
func runGatewayIbcComposabilityMwSetContractTemplate(cmd *cobra.Command, args []string) {
if *gatewayIbcComposabilityMwContractAddress == "" {
log.Fatal("--contract-address must be specified")
}

Expand All @@ -685,9 +694,9 @@ func runWormchainIbcComposabilityMwSetContractTemplate(cmd *cobra.Command, args
{
Sequence: rand.Uint64(),
Nonce: rand.Uint32(),
Payload: &nodev1.GovernanceMessage_WormchainIbcComposabilityMwSetContract{
WormchainIbcComposabilityMwSetContract: &nodev1.WormchainIbcComposabilityMwSetContract{
Contract: *wormchainIbcComposabilityMwContractAddress,
Payload: &nodev1.GovernanceMessage_GatewayIbcComposabilityMwSetContract{
GatewayIbcComposabilityMwSetContract: &nodev1.GatewayIbcComposabilityMwSetContract{
Contract: *gatewayIbcComposabilityMwContractAddress,
},
},
},
Expand All @@ -701,6 +710,27 @@ func runWormchainIbcComposabilityMwSetContractTemplate(cmd *cobra.Command, args
fmt.Print(string(b))
}

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

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

func runIbcReceiverUpdateChannelChainTemplate(cmd *cobra.Command, args []string) {
runIbcUpdateChannelChainTemplate(nodev1.IbcUpdateChannelChainModule_IBC_UPDATE_CHANNEL_CHAIN_MODULE_RECEIVER)
}
Expand Down
29 changes: 24 additions & 5 deletions node/pkg/adminrpc/adminserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ func wormchainWasmInstantiateAllowlist(
return v, nil
}

func wormchainIbcComposabilityMwSetContract(
req *nodev1.WormchainIbcComposabilityMwSetContract,
func gatewayIbcComposabilityMwSetContract(
req *nodev1.GatewayIbcComposabilityMwSetContract,
timestamp time.Time,
guardianSetIndex uint32,
nonce uint32,
Expand All @@ -353,13 +353,30 @@ func wormchainIbcComposabilityMwSetContract(
var decodedAddr32 [32]byte
copy(decodedAddr32[:], decodedAddr)

v := vaa.CreateGovernanceVAA(timestamp, nonce, sequence, guardianSetIndex, vaa.BodyWormchainIbcComposabilityMwContract{
v := vaa.CreateGovernanceVAA(timestamp, nonce, sequence, guardianSetIndex, vaa.BodyGatewayIbcComposabilityMwContract{
ContractAddr: decodedAddr32,
}.Serialize())

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 @@ -531,8 +548,10 @@ 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_WormchainIbcComposabilityMwSetContract:
v, err = wormchainIbcComposabilityMwSetContract(payload.WormchainIbcComposabilityMwSetContract, 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 6aa80d4

Please sign in to comment.