Skip to content

Commit

Permalink
Update naming of governance VAA to reflect new mapping of channelId -…
Browse files Browse the repository at this point in the history
…> chainId
  • Loading branch information
nik-suri committed Apr 13, 2023
1 parent b137350 commit 7530f0c
Show file tree
Hide file tree
Showing 7 changed files with 404 additions and 405 deletions.
20 changes: 10 additions & 10 deletions node/cmd/guardiand/adminserver.go
Expand Up @@ -360,8 +360,8 @@ func circleIntegrationUpgradeContractImplementation(req *nodev1.CircleIntegratio
return v, nil
}

func ibcReceiverUpdateChainConnection(
req *nodev1.IbcReceiverUpdateChainConnection,
func ibcReceiverUpdateChannelChain(
req *nodev1.IbcReceiverUpdateChannelChain,
timestamp time.Time,
guardianSetIndex uint32,
nonce uint32,
Expand All @@ -372,16 +372,16 @@ func ibcReceiverUpdateChainConnection(
return nil, fmt.Errorf("invalid chain id, must be <= %d", math.MaxUint16)
}

if len(req.ConnectionId) > 64 {
return nil, fmt.Errorf("invalid connection ID length, must be <= 64")
if len(req.ChannelId) > 64 {
return nil, fmt.Errorf("invalid channel ID length, must be <= 64")
}
connectionId := vaa.GetIbcConnectionIdBytes(req.ConnectionId)
channelId := vaa.LeftPadIbcChannelId(req.ChannelId)

// create governance VAA
v := vaa.CreateGovernanceVAA(timestamp, nonce, sequence, guardianSetIndex,
vaa.BodyIbcReceiverUpdateChainConnection{
ConnectionId: connectionId,
ChainId: vaa.ChainID(req.ChainId),
vaa.BodyIbcReceiverUpdateChannelChain{
ChannelId: channelId,
ChainId: vaa.ChainID(req.ChainId),
}.Serialize())

return v, nil
Expand Down Expand Up @@ -423,8 +423,8 @@ func (s *nodePrivilegedService) InjectGovernanceVAA(ctx context.Context, req *no
v, err = circleIntegrationRegisterEmitterAndDomain(payload.CircleIntegrationRegisterEmitterAndDomain, timestamp, req.CurrentSetIndex, message.Nonce, message.Sequence)
case *nodev1.GovernanceMessage_CircleIntegrationUpgradeContractImplementation:
v, err = circleIntegrationUpgradeContractImplementation(payload.CircleIntegrationUpgradeContractImplementation, timestamp, req.CurrentSetIndex, message.Nonce, message.Sequence)
case *nodev1.GovernanceMessage_IbcReceiverUpdateChainConnection:
v, err = ibcReceiverUpdateChainConnection(payload.IbcReceiverUpdateChainConnection, timestamp, req.CurrentSetIndex, message.Nonce, message.Sequence)
case *nodev1.GovernanceMessage_IbcReceiverUpdateChannelChain:
v, err = ibcReceiverUpdateChannelChain(payload.IbcReceiverUpdateChannelChain, timestamp, req.CurrentSetIndex, message.Nonce, message.Sequence)
default:
panic(fmt.Sprintf("unsupported VAA type: %T", payload))
}
Expand Down
46 changes: 23 additions & 23 deletions node/cmd/guardiand/admintemplate.go
Expand Up @@ -38,8 +38,8 @@ var circleIntegrationForeignEmitterAddress *string
var circleIntegrationCircleDomain *string
var circleIntegrationNewImplementationAddress *string

var ibcReceiverUpdateChainConnectionConnectionId *string
var ibcReceiverUpdateChainConnectionChainId *string
var ibcReceiverUpdateChannelChainChannelId *string
var ibcReceiverUpdateChannelChainChainId *string

func init() {
governanceFlagSet := pflag.NewFlagSet("governance", pflag.ExitOnError)
Expand Down Expand Up @@ -95,12 +95,12 @@ func init() {
AdminClientCircleIntegrationUpgradeContractImplementationCmd.Flags().AddFlagSet(circleIntegrationUpgradeContractImplementationFlagSet)
TemplateCmd.AddCommand(AdminClientCircleIntegrationUpgradeContractImplementationCmd)

// flags for the ibc-receiver-update-chain-connection command
ibcReceiverUpdateChainConnectionFlagSet := pflag.NewFlagSet("ibc-mapping", pflag.ExitOnError)
ibcReceiverUpdateChainConnectionConnectionId = ibcReceiverUpdateChainConnectionFlagSet.String("connection-id", "", "IBC Connection ID on Wormchain")
ibcReceiverUpdateChainConnectionChainId = ibcReceiverUpdateChainConnectionFlagSet.String("chain-id", "", "IBC Chain ID that the connection ID corresponds to")
AdminClientIbcReceiverUpdateChainConnectionCmd.Flags().AddFlagSet(ibcReceiverUpdateChainConnectionFlagSet)
TemplateCmd.AddCommand(AdminClientIbcReceiverUpdateChainConnectionCmd)
// flags for the ibc-receiver-update-channel-chain command
ibcReceiverUpdateChannelChainFlagSet := pflag.NewFlagSet("ibc-mapping", pflag.ExitOnError)
ibcReceiverUpdateChannelChainChannelId = ibcReceiverUpdateChannelChainFlagSet.String("channel-id", "", "IBC Channel ID on Wormchain")
ibcReceiverUpdateChannelChainChainId = ibcReceiverUpdateChannelChainFlagSet.String("chain-id", "", "IBC Chain ID that the channel ID corresponds to")
AdminClientIbcReceiverUpdateChannelChainCmd.Flags().AddFlagSet(ibcReceiverUpdateChannelChainFlagSet)
TemplateCmd.AddCommand(AdminClientIbcReceiverUpdateChannelChainCmd)
}

var TemplateCmd = &cobra.Command{
Expand Down Expand Up @@ -155,10 +155,10 @@ var AdminClientCircleIntegrationUpgradeContractImplementationCmd = &cobra.Comman
Run: runCircleIntegrationUpgradeContractImplementationTemplate,
}

var AdminClientIbcReceiverUpdateChainConnectionCmd = &cobra.Command{
Use: "ibc-receiver-update-chain-connection",
Short: "Generate an empty ibc receiver connectionId to chainId mapping update template at specified path",
Run: runIbcReceiverUpdateChainConnectionTemplate,
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",
Run: runIbcReceiverUpdateChannelChainTemplate,
}

func runGuardianSetTemplate(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -470,18 +470,18 @@ func runCircleIntegrationUpgradeContractImplementationTemplate(cmd *cobra.Comman
fmt.Print(string(b))
}

func runIbcReceiverUpdateChainConnectionTemplate(cmd *cobra.Command, args []string) {
if *ibcReceiverUpdateChainConnectionConnectionId == "" {
log.Fatal("--connection-id must be specified")
func runIbcReceiverUpdateChannelChainTemplate(cmd *cobra.Command, args []string) {
if *ibcReceiverUpdateChannelChainChannelId == "" {
log.Fatal("--channel-id must be specified")
}
if len(*ibcReceiverUpdateChainConnectionConnectionId) > 64 {
log.Fatal("invalid connection id length, must be <= 64")
if len(*ibcReceiverUpdateChannelChainChannelId) > 64 {
log.Fatal("invalid channel id length, must be <= 64")
}

if *ibcReceiverUpdateChainConnectionChainId == "" {
if *ibcReceiverUpdateChannelChainChainId == "" {
log.Fatal("--chain-id must be specified")
}
chainId, err := parseChainID(*ibcReceiverUpdateChainConnectionChainId)
chainId, err := parseChainID(*ibcReceiverUpdateChannelChainChainId)
if err != nil {
log.Fatal("failed to parse chain id: ", err)
}
Expand All @@ -492,10 +492,10 @@ func runIbcReceiverUpdateChainConnectionTemplate(cmd *cobra.Command, args []stri
{
Sequence: rand.Uint64(),
Nonce: rand.Uint32(),
Payload: &nodev1.GovernanceMessage_IbcReceiverUpdateChainConnection{
IbcReceiverUpdateChainConnection: &nodev1.IbcReceiverUpdateChainConnection{
ConnectionId: *ibcReceiverUpdateChainConnectionConnectionId,
ChainId: uint32(chainId),
Payload: &nodev1.GovernanceMessage_IbcReceiverUpdateChannelChain{
IbcReceiverUpdateChannelChain: &nodev1.IbcReceiverUpdateChannelChain{
ChannelId: *ibcReceiverUpdateChannelChainChannelId,
ChainId: uint32(chainId),
},
},
},
Expand Down

0 comments on commit 7530f0c

Please sign in to comment.