From 02dd6fd363a4bcb4ae8ef9ad115ce6bb6b440a9f Mon Sep 17 00:00:00 2001 From: james Date: Tue, 13 Aug 2024 17:51:48 +0800 Subject: [PATCH 1/6] remove todo: abstract out staking message back to staking --- types/tx_msg.go | 6 ++++++ x/genutil/collect.go | 6 ++---- x/staking/types/msg.go | 5 +++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/types/tx_msg.go b/types/tx_msg.go index 22e785e898e1..5ed49f25d8a5 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -80,6 +80,12 @@ type ( GetMemo() string } + // MsgWithMoniker must have GetMoniker() method to use CollectTx + MsgWithMoniker interface { + Msg + GetMoniker() string + } + // TxWithTimeoutTimeStamp extends the Tx interface by allowing a transaction to // set a timeout timestamp. TxWithTimeoutTimeStamp interface { diff --git a/x/genutil/collect.go b/x/genutil/collect.go index d070f92c62f6..9175619ec3cc 100644 --- a/x/genutil/collect.go +++ b/x/genutil/collect.go @@ -12,7 +12,6 @@ import ( cfg "github.com/cometbft/cometbft/config" "cosmossdk.io/core/address" - stakingtypes "cosmossdk.io/x/staking/types" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" @@ -120,11 +119,10 @@ func CollectTxs(txJSONDecoder sdk.TxDecoder, moniker, genTxsDir string, // genesis transactions must be single-message msgs := genTx.GetMsgs() - // TODO abstract out staking message validation back to staking - msg := msgs[0].(*stakingtypes.MsgCreateValidator) + msg := msgs[0].(sdk.MsgWithMoniker) // exclude itself from persistent peers - if msg.Description.Moniker != moniker { + if msg.GetMoniker() != moniker { addressesIPs = append(addressesIPs, nodeAddrIP) } } diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index 782183ff0684..b68818275ddf 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -90,6 +90,11 @@ func (msg MsgCreateValidator) Validate(ac address.Codec) error { return nil } +// GetMoniker returns the moniker of the validator +func (msg MsgCreateValidator) GetMoniker() string { + return msg.Description.GetMoniker() +} + // UnpackInterfaces implements UnpackInterfacesMessage.UnpackInterfaces func (msg MsgCreateValidator) UnpackInterfaces(unpacker gogoprotoany.AnyUnpacker) error { var pubKey cryptotypes.PubKey From 75b339c2fcb247d6ce961f4f1d5a3de9b535c802 Mon Sep 17 00:00:00 2001 From: james Date: Wed, 14 Aug 2024 10:11:04 +0800 Subject: [PATCH 2/6] inline in the interface check in genutil --- types/tx_msg.go | 5 ----- x/genutil/collect.go | 7 ++++++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/types/tx_msg.go b/types/tx_msg.go index 5ed49f25d8a5..6b0df73764a5 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -80,11 +80,6 @@ type ( GetMemo() string } - // MsgWithMoniker must have GetMoniker() method to use CollectTx - MsgWithMoniker interface { - Msg - GetMoniker() string - } // TxWithTimeoutTimeStamp extends the Tx interface by allowing a transaction to // set a timeout timestamp. diff --git a/x/genutil/collect.go b/x/genutil/collect.go index 9175619ec3cc..dbdc259b14a2 100644 --- a/x/genutil/collect.go +++ b/x/genutil/collect.go @@ -119,7 +119,7 @@ func CollectTxs(txJSONDecoder sdk.TxDecoder, moniker, genTxsDir string, // genesis transactions must be single-message msgs := genTx.GetMsgs() - msg := msgs[0].(sdk.MsgWithMoniker) + msg := msgs[0].(MsgWithMoniker) // exclude itself from persistent peers if msg.GetMoniker() != moniker { @@ -132,3 +132,8 @@ func CollectTxs(txJSONDecoder sdk.TxDecoder, moniker, genTxsDir string, return appGenTxs, persistentPeers, nil } + +// MsgWithMoniker must have GetMoniker() method to use CollectTx +type MsgWithMoniker interface { + GetMoniker() string +} From da536a7e503b4f9bdc63164ad73d3121ccc2411f Mon Sep 17 00:00:00 2001 From: "james.zhang" <68689915+zenzenless@users.noreply.github.com> Date: Wed, 14 Aug 2024 14:11:25 +0800 Subject: [PATCH 3/6] Update x/genutil/collect.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- x/genutil/collect.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/genutil/collect.go b/x/genutil/collect.go index dbdc259b14a2..6fdf79b2628d 100644 --- a/x/genutil/collect.go +++ b/x/genutil/collect.go @@ -134,6 +134,6 @@ func CollectTxs(txJSONDecoder sdk.TxDecoder, moniker, genTxsDir string, } // MsgWithMoniker must have GetMoniker() method to use CollectTx -type MsgWithMoniker interface { +type msgWithMoniker interface { GetMoniker() string } From a58560b80fb5cc7c277079e94a1644913bb1a6e4 Mon Sep 17 00:00:00 2001 From: james Date: Wed, 14 Aug 2024 14:14:33 +0800 Subject: [PATCH 4/6] fixed: MsgWithMoniker rename msgWithMoniker --- x/genutil/collect.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/genutil/collect.go b/x/genutil/collect.go index 6fdf79b2628d..16f221186343 100644 --- a/x/genutil/collect.go +++ b/x/genutil/collect.go @@ -119,7 +119,7 @@ func CollectTxs(txJSONDecoder sdk.TxDecoder, moniker, genTxsDir string, // genesis transactions must be single-message msgs := genTx.GetMsgs() - msg := msgs[0].(MsgWithMoniker) + msg := msgs[0].(msgWithMoniker) // exclude itself from persistent peers if msg.GetMoniker() != moniker { From 8b26bafa23c807a4aaade78e70be5e3751d50055 Mon Sep 17 00:00:00 2001 From: james Date: Wed, 14 Aug 2024 14:36:50 +0800 Subject: [PATCH 5/6] Use a type assertion with a check to prevent runtime panic. --- x/genutil/collect.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/x/genutil/collect.go b/x/genutil/collect.go index 16f221186343..11b8db747d2b 100644 --- a/x/genutil/collect.go +++ b/x/genutil/collect.go @@ -119,8 +119,10 @@ func CollectTxs(txJSONDecoder sdk.TxDecoder, moniker, genTxsDir string, // genesis transactions must be single-message msgs := genTx.GetMsgs() - msg := msgs[0].(msgWithMoniker) - + msg, ok := msgs[0].(msgWithMoniker) + if !ok { + return appGenTxs, persistentPeers, fmt.Errorf("expected msgWithMoniker, got %T", msgs[0]) + } // exclude itself from persistent peers if msg.GetMoniker() != moniker { addressesIPs = append(addressesIPs, nodeAddrIP) From c904e9df6db519c8a801150e46fef9a9716e0ddf Mon Sep 17 00:00:00 2001 From: james Date: Wed, 14 Aug 2024 15:43:17 +0800 Subject: [PATCH 6/6] make lint-fix --- types/tx_msg.go | 1 - 1 file changed, 1 deletion(-) diff --git a/types/tx_msg.go b/types/tx_msg.go index 6b0df73764a5..22e785e898e1 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -80,7 +80,6 @@ type ( GetMemo() string } - // TxWithTimeoutTimeStamp extends the Tx interface by allowing a transaction to // set a timeout timestamp. TxWithTimeoutTimeStamp interface {