From eced43148fff78d77edf6254b2193345a98d1e8f Mon Sep 17 00:00:00 2001 From: Angel Valkov Date: Mon, 9 Dec 2024 12:10:32 +0200 Subject: [PATCH 01/13] Enable all forks on zero height --- helper/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helper/config.go b/helper/config.go index e426668ab..8aa56f7b4 100644 --- a/helper/config.go +++ b/helper/config.go @@ -435,8 +435,8 @@ func InitHeimdallConfigWith(homeDir string, heimdallConfigFileFromFLag string) { spanOverrideHeight = 0 newHexToStringAlgoHeight = 0 aalborgHeight = 0 - jorvikHeight = 100 - antevortaHeight = 150 + jorvikHeight = 0 + antevortaHeight = 0 } } From 21cd6121e89a70acef5bc94271e7bd0e870d0ae6 Mon Sep 17 00:00:00 2001 From: Angel Valkov Date: Mon, 9 Dec 2024 14:43:33 +0200 Subject: [PATCH 02/13] Add temporary commands to test malicious cases --- bor/client/cli/query.go | 2 +- bor/client/cli/tx.go | 216 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 217 insertions(+), 1 deletion(-) diff --git a/bor/client/cli/query.go b/bor/client/cli/query.go index b75e44760..62f9565e5 100644 --- a/bor/client/cli/query.go +++ b/bor/client/cli/query.go @@ -269,7 +269,7 @@ func GetNextSpanSeed(cdc *codec.Codec) *cobra.Command { return cmd } -// PostSendProposeSpanTx send propose span transaction +// GetPreparedProposeSpan generates a propose span transaction func GetPreparedProposeSpan(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ Use: "propose-span", diff --git a/bor/client/cli/tx.go b/bor/client/cli/tx.go index 0efdc9f65..f3516a32b 100644 --- a/bor/client/cli/tx.go +++ b/bor/client/cli/tx.go @@ -34,6 +34,8 @@ func GetTxCmd(cdc *codec.Codec) *cobra.Command { txCmd.AddCommand( client.PostCommands( PostSendProposeSpanTx(cdc), + PostSendProposeSpanOldTx(cdc), + PostSendProposeSpanNewTx(cdc), )..., ) @@ -165,3 +167,217 @@ func PostSendProposeSpanTx(cdc *codec.Codec) *cobra.Command { return cmd } + +func PostSendProposeSpanOldTx(cdc *codec.Codec) *cobra.Command { + cmd := &cobra.Command{ + Use: "propose-span-old", + Short: "send propose span tx", + RunE: func(cmd *cobra.Command, args []string) error { + cliCtx := context.NewCLIContext().WithCodec(cdc) + borChainID := viper.GetString(FlagBorChainId) + if borChainID == "" { + return fmt.Errorf("BorChainID cannot be empty") + } + + // get proposer + proposer := hmTypes.HexToHeimdallAddress(viper.GetString(FlagProposerAddress)) + if proposer.Empty() { + proposer = helper.GetFromAddress(cliCtx) + } + + // start block + + startBlockStr := viper.GetString(FlagStartBlock) + if startBlockStr == "" { + return fmt.Errorf("Start block cannot be empty") + } + + startBlock, err := strconv.ParseUint(startBlockStr, 10, 64) + if err != nil { + return err + } + + // span + + spanIDStr := viper.GetString(FlagSpanId) + if spanIDStr == "" { + return fmt.Errorf("Span Id cannot be empty") + } + + spanID, err := strconv.ParseUint(spanIDStr, 10, 64) + if err != nil { + return err + } + + // + // Query data + // + + // fetch duration + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", types.QuerierRoute, types.QueryParams, types.ParamSpan), nil) + if err != nil { + return err + } + if len(res) == 0 { + return errors.New("span duration not found") + } + + var spanDuration uint64 + if err := jsoniter.ConfigFastest.Unmarshal(res, &spanDuration); err != nil { + return err + } + + seedQueryParams, err := cliCtx.Codec.MarshalJSON(types.NewQuerySpanParams(spanID)) + if err != nil { + return err + } + + res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), seedQueryParams) + if err != nil { + return err + } + + if len(res) == 0 { + return errors.New("next span seed not found") + } + + var seedResponse types.QuerySpanSeedResponse + if err := jsoniter.ConfigFastest.Unmarshal(res, &seedResponse); err != nil { + return err + } + + msg := types.NewMsgProposeSpan( + spanID, + proposer, + startBlock, + startBlock+spanDuration-1, + borChainID, + seedResponse.Seed, + ) + + return helper.BroadcastMsgsWithCLI(cliCtx, []sdk.Msg{msg}) + }, + } + + cmd.Flags().StringP(FlagProposerAddress, "p", "", "--proposer=") + cmd.Flags().String(FlagSpanId, "", "--span-id=") + cmd.Flags().String(FlagBorChainId, "", "--bor-chain-id=") + cmd.Flags().String(FlagStartBlock, "", "--start-block=") + + if err := cmd.MarkFlagRequired(FlagBorChainId); err != nil { + cliLogger.Error("PostSendProposeSpanTx | MarkFlagRequired | FlagBorChainId", "Error", err) + } + + if err := cmd.MarkFlagRequired(FlagStartBlock); err != nil { + cliLogger.Error("PostSendProposeSpanTx | MarkFlagRequired | FlagStartBlock", "Error", err) + } + + return cmd +} + +func PostSendProposeSpanNewTx(cdc *codec.Codec) *cobra.Command { + cmd := &cobra.Command{ + Use: "propose-span-old", + Short: "send propose span tx", + RunE: func(cmd *cobra.Command, args []string) error { + cliCtx := context.NewCLIContext().WithCodec(cdc) + borChainID := viper.GetString(FlagBorChainId) + if borChainID == "" { + return fmt.Errorf("BorChainID cannot be empty") + } + + // get proposer + proposer := hmTypes.HexToHeimdallAddress(viper.GetString(FlagProposerAddress)) + if proposer.Empty() { + proposer = helper.GetFromAddress(cliCtx) + } + + // start block + + startBlockStr := viper.GetString(FlagStartBlock) + if startBlockStr == "" { + return fmt.Errorf("Start block cannot be empty") + } + + startBlock, err := strconv.ParseUint(startBlockStr, 10, 64) + if err != nil { + return err + } + + // span + + spanIDStr := viper.GetString(FlagSpanId) + if spanIDStr == "" { + return fmt.Errorf("Span Id cannot be empty") + } + + spanID, err := strconv.ParseUint(spanIDStr, 10, 64) + if err != nil { + return err + } + + // + // Query data + // + + // fetch duration + res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", types.QuerierRoute, types.QueryParams, types.ParamSpan), nil) + if err != nil { + return err + } + if len(res) == 0 { + return errors.New("span duration not found") + } + + var spanDuration uint64 + if err := jsoniter.ConfigFastest.Unmarshal(res, &spanDuration); err != nil { + return err + } + + seedQueryParams, err := cliCtx.Codec.MarshalJSON(types.NewQuerySpanParams(spanID)) + if err != nil { + return err + } + + res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), seedQueryParams) + if err != nil { + return err + } + + if len(res) == 0 { + return errors.New("next span seed not found") + } + + var seedResponse types.QuerySpanSeedResponse + if err := jsoniter.ConfigFastest.Unmarshal(res, &seedResponse); err != nil { + return err + } + + msg := types.NewMsgProposeSpan( + spanID, + proposer, + startBlock, + startBlock+spanDuration-1, + borChainID, + seedResponse.Seed, + ) + + return helper.BroadcastMsgsWithCLI(cliCtx, []sdk.Msg{msg}) + }, + } + + cmd.Flags().StringP(FlagProposerAddress, "p", "", "--proposer=") + cmd.Flags().String(FlagSpanId, "", "--span-id=") + cmd.Flags().String(FlagBorChainId, "", "--bor-chain-id=") + cmd.Flags().String(FlagStartBlock, "", "--start-block=") + + if err := cmd.MarkFlagRequired(FlagBorChainId); err != nil { + cliLogger.Error("PostSendProposeSpanTx | MarkFlagRequired | FlagBorChainId", "Error", err) + } + + if err := cmd.MarkFlagRequired(FlagStartBlock); err != nil { + cliLogger.Error("PostSendProposeSpanTx | MarkFlagRequired | FlagStartBlock", "Error", err) + } + + return cmd +} From c22c680f39566b946597935e1051d0b42975dfd7 Mon Sep 17 00:00:00 2001 From: Angel Valkov Date: Mon, 9 Dec 2024 15:22:49 +0200 Subject: [PATCH 03/13] Add temporary commands to test malicious cases --- bor/client/cli/tx.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bor/client/cli/tx.go b/bor/client/cli/tx.go index f3516a32b..42c76511d 100644 --- a/bor/client/cli/tx.go +++ b/bor/client/cli/tx.go @@ -277,7 +277,7 @@ func PostSendProposeSpanOldTx(cdc *codec.Codec) *cobra.Command { func PostSendProposeSpanNewTx(cdc *codec.Codec) *cobra.Command { cmd := &cobra.Command{ - Use: "propose-span-old", + Use: "propose-span-new", Short: "send propose span tx", RunE: func(cmd *cobra.Command, args []string) error { cliCtx := context.NewCLIContext().WithCodec(cdc) @@ -353,13 +353,14 @@ func PostSendProposeSpanNewTx(cdc *codec.Codec) *cobra.Command { return err } - msg := types.NewMsgProposeSpan( + msg := types.NewMsgProposeSpanV2( spanID, proposer, startBlock, startBlock+spanDuration-1, borChainID, seedResponse.Seed, + seedResponse.SeedAuthor, ) return helper.BroadcastMsgsWithCLI(cliCtx, []sdk.Msg{msg}) From 652b4da66e025f65ad70c370f275ce2ae55a3da1 Mon Sep 17 00:00:00 2001 From: Angel Valkov Date: Mon, 9 Dec 2024 15:37:36 +0200 Subject: [PATCH 04/13] Let the bridge propose only the first two spans --- bridge/setu/processor/span.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bridge/setu/processor/span.go b/bridge/setu/processor/span.go index 5a717862d..5f1ccd910 100644 --- a/bridge/setu/processor/span.go +++ b/bridge/setu/processor/span.go @@ -91,7 +91,9 @@ func (sp *SpanProcessor) checkAndPropose() { // check if current user is among next span producers if sp.isSpanProposer(nextSpanMsg.SelectedProducers) { - go sp.propose(lastSpan, nextSpanMsg) + if nextSpanMsg.ID < 2 { + go sp.propose(lastSpan, nextSpanMsg) + } } } From 61d3f00f1bf555f5d28f3d9f3eb9a4c36cd35081 Mon Sep 17 00:00:00 2001 From: Angel Valkov Date: Mon, 9 Dec 2024 22:53:39 +0200 Subject: [PATCH 05/13] Dont enable antevorta from zero height --- helper/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper/config.go b/helper/config.go index 8aa56f7b4..a5ea4428b 100644 --- a/helper/config.go +++ b/helper/config.go @@ -243,7 +243,7 @@ var newHexToStringAlgoHeight int64 = 0 var jorvikHeight int64 = 0 -var antevortaHeight int64 = 0 +var antevortaHeight int64 = 10000 type ChainManagerAddressMigration struct { MaticTokenAddress hmTypes.HeimdallAddress From fe80a4f25262f0e3a4b2c8b2b6f8e8f6f3efb47e Mon Sep 17 00:00:00 2001 From: Angel Valkov Date: Tue, 10 Dec 2024 08:31:34 +0200 Subject: [PATCH 06/13] Restrict new msg pre-hardfork --- bor/handler.go | 11 +++++++++++ bor/side_handler.go | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/bor/handler.go b/bor/handler.go index 8684197a4..3ff41c767 100644 --- a/bor/handler.go +++ b/bor/handler.go @@ -7,6 +7,7 @@ import ( "github.com/maticnetwork/heimdall/bor/types" "github.com/maticnetwork/heimdall/common" + "github.com/maticnetwork/heimdall/helper" ) // NewHandler returns a handler for "bor" type messages. @@ -29,6 +30,11 @@ func HandleMsgProposeSpan(ctx sdk.Context, msg sdk.Msg, k Keeper) sdk.Result { var proposeMsg types.MsgProposeSpanV2 switch msg := msg.(type) { case types.MsgProposeSpan: + k.Logger(ctx).Error("Msg span is received") + if ctx.BlockHeight() >= helper.GetAntevortaHeight() { + k.Logger(ctx).Error("Msg span is not allowed after hardfork height") + return sdk.ErrTxDecode("Msg span is not allowed after hardfork height").Result() + } proposeMsg = types.MsgProposeSpanV2{ ID: msg.ID, Proposer: msg.Proposer, @@ -38,6 +44,11 @@ func HandleMsgProposeSpan(ctx sdk.Context, msg sdk.Msg, k Keeper) sdk.Result { Seed: msg.Seed, } case types.MsgProposeSpanV2: + k.Logger(ctx).Error("Msg span v2 is received") + if ctx.BlockHeight() < helper.GetAntevortaHeight() { + k.Logger(ctx).Error("Msg span v2 is not allowed before hardfork height") + return sdk.ErrTxDecode("Msg span v2 is not allowed before hardfork height").Result() + } proposeMsg = msg } diff --git a/bor/side_handler.go b/bor/side_handler.go index 427acda1d..5771f9259 100644 --- a/bor/side_handler.go +++ b/bor/side_handler.go @@ -53,6 +53,10 @@ func SideHandleMsgSpan(ctx sdk.Context, k Keeper, msg sdk.Msg, contractCaller he var proposeMsg types.MsgProposeSpanV2 switch msg := msg.(type) { case types.MsgProposeSpan: + if ctx.BlockHeight() >= helper.GetAntevortaHeight() { + k.Logger(ctx).Error("Msg span is not allowed after hardfork height") + return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg) + } proposeMsg = types.MsgProposeSpanV2{ ID: msg.ID, Proposer: msg.Proposer, @@ -62,6 +66,10 @@ func SideHandleMsgSpan(ctx sdk.Context, k Keeper, msg sdk.Msg, contractCaller he Seed: msg.Seed, } case types.MsgProposeSpanV2: + if ctx.BlockHeight() < helper.GetAntevortaHeight() { + k.Logger(ctx).Error("Msg span v2 is not allowed before hardfork height") + return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg) + } proposeMsg = msg } From 221e037f304f4976827d89f11b7038e91336ef18 Mon Sep 17 00:00:00 2001 From: Angel Valkov Date: Tue, 10 Dec 2024 09:42:14 +0200 Subject: [PATCH 07/13] set non-zero height for antevorta --- helper/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper/config.go b/helper/config.go index a5ea4428b..1efd4fce0 100644 --- a/helper/config.go +++ b/helper/config.go @@ -436,7 +436,7 @@ func InitHeimdallConfigWith(homeDir string, heimdallConfigFileFromFLag string) { newHexToStringAlgoHeight = 0 aalborgHeight = 0 jorvikHeight = 0 - antevortaHeight = 0 + antevortaHeight = 10000 } } From 9323f1eb59f956e15b7f5b40bca52a844c8d9379 Mon Sep 17 00:00:00 2001 From: Angel Valkov Date: Tue, 10 Dec 2024 10:15:41 +0200 Subject: [PATCH 08/13] Add debug logging --- bor/client/cli/tx.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bor/client/cli/tx.go b/bor/client/cli/tx.go index 42c76511d..1246df826 100644 --- a/bor/client/cli/tx.go +++ b/bor/client/cli/tx.go @@ -126,8 +126,12 @@ func PostSendProposeSpanTx(cdc *codec.Codec) *cobra.Command { return err } + fmt.Printf("nodeStatus: %+v\n", nodeStatus) + fmt.Printf("nodeStatus.SyncInfo.LatestBlockHeight: %d\n", nodeStatus.SyncInfo.LatestBlockHeight) + fmt.Printf("helper.GetAntevortaHeight(): %d\n", helper.GetAntevortaHeight()) var msg sdk.Msg if nodeStatus.SyncInfo.LatestBlockHeight < helper.GetAntevortaHeight() { + fmt.Println("Old version") msg = types.NewMsgProposeSpan( spanID, proposer, @@ -137,6 +141,7 @@ func PostSendProposeSpanTx(cdc *codec.Codec) *cobra.Command { seedResponse.Seed, ) } else { + fmt.Println("New version") msg = types.NewMsgProposeSpanV2( spanID, proposer, From 35b725d5e3506a98a0eea7d827ceba9d9b947946 Mon Sep 17 00:00:00 2001 From: Angel Valkov Date: Tue, 10 Dec 2024 11:53:45 +0200 Subject: [PATCH 09/13] Lower enable fork height --- helper/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helper/config.go b/helper/config.go index 1efd4fce0..4bc6fbdf1 100644 --- a/helper/config.go +++ b/helper/config.go @@ -243,7 +243,7 @@ var newHexToStringAlgoHeight int64 = 0 var jorvikHeight int64 = 0 -var antevortaHeight int64 = 10000 +var antevortaHeight int64 = 3000 type ChainManagerAddressMigration struct { MaticTokenAddress hmTypes.HeimdallAddress From 76ac6d3200635470eb3650c9eec13215c9e71d74 Mon Sep 17 00:00:00 2001 From: Angel Valkov Date: Tue, 10 Dec 2024 13:32:47 +0200 Subject: [PATCH 10/13] Clean up --- bor/client/cli/tx.go | 222 ------------------------------------------- bor/handler.go | 2 - helper/config.go | 4 +- 3 files changed, 2 insertions(+), 226 deletions(-) diff --git a/bor/client/cli/tx.go b/bor/client/cli/tx.go index 1246df826..0efdc9f65 100644 --- a/bor/client/cli/tx.go +++ b/bor/client/cli/tx.go @@ -34,8 +34,6 @@ func GetTxCmd(cdc *codec.Codec) *cobra.Command { txCmd.AddCommand( client.PostCommands( PostSendProposeSpanTx(cdc), - PostSendProposeSpanOldTx(cdc), - PostSendProposeSpanNewTx(cdc), )..., ) @@ -126,12 +124,8 @@ func PostSendProposeSpanTx(cdc *codec.Codec) *cobra.Command { return err } - fmt.Printf("nodeStatus: %+v\n", nodeStatus) - fmt.Printf("nodeStatus.SyncInfo.LatestBlockHeight: %d\n", nodeStatus.SyncInfo.LatestBlockHeight) - fmt.Printf("helper.GetAntevortaHeight(): %d\n", helper.GetAntevortaHeight()) var msg sdk.Msg if nodeStatus.SyncInfo.LatestBlockHeight < helper.GetAntevortaHeight() { - fmt.Println("Old version") msg = types.NewMsgProposeSpan( spanID, proposer, @@ -141,7 +135,6 @@ func PostSendProposeSpanTx(cdc *codec.Codec) *cobra.Command { seedResponse.Seed, ) } else { - fmt.Println("New version") msg = types.NewMsgProposeSpanV2( spanID, proposer, @@ -172,218 +165,3 @@ func PostSendProposeSpanTx(cdc *codec.Codec) *cobra.Command { return cmd } - -func PostSendProposeSpanOldTx(cdc *codec.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "propose-span-old", - Short: "send propose span tx", - RunE: func(cmd *cobra.Command, args []string) error { - cliCtx := context.NewCLIContext().WithCodec(cdc) - borChainID := viper.GetString(FlagBorChainId) - if borChainID == "" { - return fmt.Errorf("BorChainID cannot be empty") - } - - // get proposer - proposer := hmTypes.HexToHeimdallAddress(viper.GetString(FlagProposerAddress)) - if proposer.Empty() { - proposer = helper.GetFromAddress(cliCtx) - } - - // start block - - startBlockStr := viper.GetString(FlagStartBlock) - if startBlockStr == "" { - return fmt.Errorf("Start block cannot be empty") - } - - startBlock, err := strconv.ParseUint(startBlockStr, 10, 64) - if err != nil { - return err - } - - // span - - spanIDStr := viper.GetString(FlagSpanId) - if spanIDStr == "" { - return fmt.Errorf("Span Id cannot be empty") - } - - spanID, err := strconv.ParseUint(spanIDStr, 10, 64) - if err != nil { - return err - } - - // - // Query data - // - - // fetch duration - res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", types.QuerierRoute, types.QueryParams, types.ParamSpan), nil) - if err != nil { - return err - } - if len(res) == 0 { - return errors.New("span duration not found") - } - - var spanDuration uint64 - if err := jsoniter.ConfigFastest.Unmarshal(res, &spanDuration); err != nil { - return err - } - - seedQueryParams, err := cliCtx.Codec.MarshalJSON(types.NewQuerySpanParams(spanID)) - if err != nil { - return err - } - - res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), seedQueryParams) - if err != nil { - return err - } - - if len(res) == 0 { - return errors.New("next span seed not found") - } - - var seedResponse types.QuerySpanSeedResponse - if err := jsoniter.ConfigFastest.Unmarshal(res, &seedResponse); err != nil { - return err - } - - msg := types.NewMsgProposeSpan( - spanID, - proposer, - startBlock, - startBlock+spanDuration-1, - borChainID, - seedResponse.Seed, - ) - - return helper.BroadcastMsgsWithCLI(cliCtx, []sdk.Msg{msg}) - }, - } - - cmd.Flags().StringP(FlagProposerAddress, "p", "", "--proposer=") - cmd.Flags().String(FlagSpanId, "", "--span-id=") - cmd.Flags().String(FlagBorChainId, "", "--bor-chain-id=") - cmd.Flags().String(FlagStartBlock, "", "--start-block=") - - if err := cmd.MarkFlagRequired(FlagBorChainId); err != nil { - cliLogger.Error("PostSendProposeSpanTx | MarkFlagRequired | FlagBorChainId", "Error", err) - } - - if err := cmd.MarkFlagRequired(FlagStartBlock); err != nil { - cliLogger.Error("PostSendProposeSpanTx | MarkFlagRequired | FlagStartBlock", "Error", err) - } - - return cmd -} - -func PostSendProposeSpanNewTx(cdc *codec.Codec) *cobra.Command { - cmd := &cobra.Command{ - Use: "propose-span-new", - Short: "send propose span tx", - RunE: func(cmd *cobra.Command, args []string) error { - cliCtx := context.NewCLIContext().WithCodec(cdc) - borChainID := viper.GetString(FlagBorChainId) - if borChainID == "" { - return fmt.Errorf("BorChainID cannot be empty") - } - - // get proposer - proposer := hmTypes.HexToHeimdallAddress(viper.GetString(FlagProposerAddress)) - if proposer.Empty() { - proposer = helper.GetFromAddress(cliCtx) - } - - // start block - - startBlockStr := viper.GetString(FlagStartBlock) - if startBlockStr == "" { - return fmt.Errorf("Start block cannot be empty") - } - - startBlock, err := strconv.ParseUint(startBlockStr, 10, 64) - if err != nil { - return err - } - - // span - - spanIDStr := viper.GetString(FlagSpanId) - if spanIDStr == "" { - return fmt.Errorf("Span Id cannot be empty") - } - - spanID, err := strconv.ParseUint(spanIDStr, 10, 64) - if err != nil { - return err - } - - // - // Query data - // - - // fetch duration - res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", types.QuerierRoute, types.QueryParams, types.ParamSpan), nil) - if err != nil { - return err - } - if len(res) == 0 { - return errors.New("span duration not found") - } - - var spanDuration uint64 - if err := jsoniter.ConfigFastest.Unmarshal(res, &spanDuration); err != nil { - return err - } - - seedQueryParams, err := cliCtx.Codec.MarshalJSON(types.NewQuerySpanParams(spanID)) - if err != nil { - return err - } - - res, _, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryNextSpanSeed), seedQueryParams) - if err != nil { - return err - } - - if len(res) == 0 { - return errors.New("next span seed not found") - } - - var seedResponse types.QuerySpanSeedResponse - if err := jsoniter.ConfigFastest.Unmarshal(res, &seedResponse); err != nil { - return err - } - - msg := types.NewMsgProposeSpanV2( - spanID, - proposer, - startBlock, - startBlock+spanDuration-1, - borChainID, - seedResponse.Seed, - seedResponse.SeedAuthor, - ) - - return helper.BroadcastMsgsWithCLI(cliCtx, []sdk.Msg{msg}) - }, - } - - cmd.Flags().StringP(FlagProposerAddress, "p", "", "--proposer=") - cmd.Flags().String(FlagSpanId, "", "--span-id=") - cmd.Flags().String(FlagBorChainId, "", "--bor-chain-id=") - cmd.Flags().String(FlagStartBlock, "", "--start-block=") - - if err := cmd.MarkFlagRequired(FlagBorChainId); err != nil { - cliLogger.Error("PostSendProposeSpanTx | MarkFlagRequired | FlagBorChainId", "Error", err) - } - - if err := cmd.MarkFlagRequired(FlagStartBlock); err != nil { - cliLogger.Error("PostSendProposeSpanTx | MarkFlagRequired | FlagStartBlock", "Error", err) - } - - return cmd -} diff --git a/bor/handler.go b/bor/handler.go index 3ff41c767..a581bf72e 100644 --- a/bor/handler.go +++ b/bor/handler.go @@ -30,7 +30,6 @@ func HandleMsgProposeSpan(ctx sdk.Context, msg sdk.Msg, k Keeper) sdk.Result { var proposeMsg types.MsgProposeSpanV2 switch msg := msg.(type) { case types.MsgProposeSpan: - k.Logger(ctx).Error("Msg span is received") if ctx.BlockHeight() >= helper.GetAntevortaHeight() { k.Logger(ctx).Error("Msg span is not allowed after hardfork height") return sdk.ErrTxDecode("Msg span is not allowed after hardfork height").Result() @@ -44,7 +43,6 @@ func HandleMsgProposeSpan(ctx sdk.Context, msg sdk.Msg, k Keeper) sdk.Result { Seed: msg.Seed, } case types.MsgProposeSpanV2: - k.Logger(ctx).Error("Msg span v2 is received") if ctx.BlockHeight() < helper.GetAntevortaHeight() { k.Logger(ctx).Error("Msg span v2 is not allowed before hardfork height") return sdk.ErrTxDecode("Msg span v2 is not allowed before hardfork height").Result() diff --git a/helper/config.go b/helper/config.go index 4bc6fbdf1..8aa56f7b4 100644 --- a/helper/config.go +++ b/helper/config.go @@ -243,7 +243,7 @@ var newHexToStringAlgoHeight int64 = 0 var jorvikHeight int64 = 0 -var antevortaHeight int64 = 3000 +var antevortaHeight int64 = 0 type ChainManagerAddressMigration struct { MaticTokenAddress hmTypes.HeimdallAddress @@ -436,7 +436,7 @@ func InitHeimdallConfigWith(homeDir string, heimdallConfigFileFromFLag string) { newHexToStringAlgoHeight = 0 aalborgHeight = 0 jorvikHeight = 0 - antevortaHeight = 10000 + antevortaHeight = 0 } } From 3024891d164c8d2301480abf4eb0135706a2ba66 Mon Sep 17 00:00:00 2001 From: Angel Valkov Date: Tue, 10 Dec 2024 13:38:36 +0200 Subject: [PATCH 11/13] Cleanup --- bridge/setu/processor/span.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bridge/setu/processor/span.go b/bridge/setu/processor/span.go index 5f1ccd910..5a717862d 100644 --- a/bridge/setu/processor/span.go +++ b/bridge/setu/processor/span.go @@ -91,9 +91,7 @@ func (sp *SpanProcessor) checkAndPropose() { // check if current user is among next span producers if sp.isSpanProposer(nextSpanMsg.SelectedProducers) { - if nextSpanMsg.ID < 2 { - go sp.propose(lastSpan, nextSpanMsg) - } + go sp.propose(lastSpan, nextSpanMsg) } } From 14251ca7570560a89b18f1603310f776964423a8 Mon Sep 17 00:00:00 2001 From: Angel Valkov Date: Tue, 10 Dec 2024 13:45:53 +0200 Subject: [PATCH 12/13] Fix lint --- bor/handler.go | 1 - bor/side_handler.go | 3 --- 2 files changed, 4 deletions(-) diff --git a/bor/handler.go b/bor/handler.go index a581bf72e..df0af22ad 100644 --- a/bor/handler.go +++ b/bor/handler.go @@ -36,7 +36,6 @@ func HandleMsgProposeSpan(ctx sdk.Context, msg sdk.Msg, k Keeper) sdk.Result { } proposeMsg = types.MsgProposeSpanV2{ ID: msg.ID, - Proposer: msg.Proposer, StartBlock: msg.StartBlock, EndBlock: msg.EndBlock, ChainID: msg.ChainID, diff --git a/bor/side_handler.go b/bor/side_handler.go index 5771f9259..b869361c9 100644 --- a/bor/side_handler.go +++ b/bor/side_handler.go @@ -59,10 +59,8 @@ func SideHandleMsgSpan(ctx sdk.Context, k Keeper, msg sdk.Msg, contractCaller he } proposeMsg = types.MsgProposeSpanV2{ ID: msg.ID, - Proposer: msg.Proposer, StartBlock: msg.StartBlock, EndBlock: msg.EndBlock, - ChainID: msg.ChainID, Seed: msg.Seed, } case types.MsgProposeSpanV2: @@ -159,7 +157,6 @@ func PostHandleMsgEventSpan(ctx sdk.Context, k Keeper, msg sdk.Msg, sideTxResult case types.MsgProposeSpan: proposeMsg = types.MsgProposeSpanV2{ ID: msg.ID, - Proposer: msg.Proposer, StartBlock: msg.StartBlock, EndBlock: msg.EndBlock, ChainID: msg.ChainID, From 15a8f6230f77fcceae6255c428f75e1ff405a12d Mon Sep 17 00:00:00 2001 From: Angel Valkov Date: Tue, 10 Dec 2024 14:29:34 +0200 Subject: [PATCH 13/13] Fix comments --- bor/handler.go | 13 +++++++++---- bor/side_handler.go | 20 +++++++++++++++++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/bor/handler.go b/bor/handler.go index df0af22ad..43c9d8f98 100644 --- a/bor/handler.go +++ b/bor/handler.go @@ -1,6 +1,7 @@ package bor import ( + "errors" "strconv" sdk "github.com/cosmos/cosmos-sdk/types" @@ -31,11 +32,13 @@ func HandleMsgProposeSpan(ctx sdk.Context, msg sdk.Msg, k Keeper) sdk.Result { switch msg := msg.(type) { case types.MsgProposeSpan: if ctx.BlockHeight() >= helper.GetAntevortaHeight() { - k.Logger(ctx).Error("Msg span is not allowed after hardfork height") - return sdk.ErrTxDecode("Msg span is not allowed after hardfork height").Result() + err := errors.New("msg span is not allowed after Antevorta hardfork height") + k.Logger(ctx).Error(err.Error()) + return sdk.ErrTxDecode(err.Error()).Result() } proposeMsg = types.MsgProposeSpanV2{ ID: msg.ID, + Proposer: msg.Proposer, StartBlock: msg.StartBlock, EndBlock: msg.EndBlock, ChainID: msg.ChainID, @@ -43,13 +46,15 @@ func HandleMsgProposeSpan(ctx sdk.Context, msg sdk.Msg, k Keeper) sdk.Result { } case types.MsgProposeSpanV2: if ctx.BlockHeight() < helper.GetAntevortaHeight() { - k.Logger(ctx).Error("Msg span v2 is not allowed before hardfork height") - return sdk.ErrTxDecode("Msg span v2 is not allowed before hardfork height").Result() + err := errors.New("msg span v2 is not allowed before Antevorta hardfork height") + k.Logger(ctx).Error(err.Error()) + return sdk.ErrTxDecode(err.Error()).Result() } proposeMsg = msg } k.Logger(ctx).Debug("✅ Validating proposed span msg", + "proposer", proposeMsg.Proposer.String(), "spanId", proposeMsg.ID, "startBlock", proposeMsg.StartBlock, "endBlock", proposeMsg.EndBlock, diff --git a/bor/side_handler.go b/bor/side_handler.go index b869361c9..16990dc96 100644 --- a/bor/side_handler.go +++ b/bor/side_handler.go @@ -54,18 +54,20 @@ func SideHandleMsgSpan(ctx sdk.Context, k Keeper, msg sdk.Msg, contractCaller he switch msg := msg.(type) { case types.MsgProposeSpan: if ctx.BlockHeight() >= helper.GetAntevortaHeight() { - k.Logger(ctx).Error("Msg span is not allowed after hardfork height") + k.Logger(ctx).Error("Msg span is not allowed after Antevorta hardfork height") return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg) } proposeMsg = types.MsgProposeSpanV2{ ID: msg.ID, + Proposer: msg.Proposer, StartBlock: msg.StartBlock, EndBlock: msg.EndBlock, + ChainID: msg.ChainID, Seed: msg.Seed, } case types.MsgProposeSpanV2: if ctx.BlockHeight() < helper.GetAntevortaHeight() { - k.Logger(ctx).Error("Msg span v2 is not allowed before hardfork height") + k.Logger(ctx).Error("Msg span v2 is not allowed before Antevorta hardfork height") return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg) } proposeMsg = msg @@ -86,6 +88,8 @@ func SideHandleMsgSpan(ctx sdk.Context, k Keeper, msg sdk.Msg, contractCaller he if !bytes.Equal(proposeMsg.Seed.Bytes(), seed.Bytes()) { k.Logger(ctx).Error( "Span Seed does not match", + "proposer", proposeMsg.Proposer.String(), + "chainID", proposeMsg.ChainID, "msgSeed", proposeMsg.Seed.String(), "mainchainSeed", seed.String(), ) @@ -98,6 +102,8 @@ func SideHandleMsgSpan(ctx sdk.Context, k Keeper, msg sdk.Msg, contractCaller he if !bytes.Equal(proposeMsg.SeedAuthor.Bytes(), seedAuthor.Bytes()) { k.Logger(ctx).Error( "Span Seed Author does not match", + "proposer", proposeMsg.Proposer.String(), + "chainID", proposeMsg.ChainID, "msgSeed", proposeMsg.Seed.String(), "msgSeedAuthor", proposeMsg.SeedAuthor.String(), "mainchainSeedAuthor", seedAuthor.String(), @@ -157,6 +163,7 @@ func PostHandleMsgEventSpan(ctx sdk.Context, k Keeper, msg sdk.Msg, sideTxResult case types.MsgProposeSpan: proposeMsg = types.MsgProposeSpanV2{ ID: msg.ID, + Proposer: msg.Proposer, StartBlock: msg.StartBlock, EndBlock: msg.EndBlock, ChainID: msg.ChainID, @@ -172,7 +179,14 @@ func PostHandleMsgEventSpan(ctx sdk.Context, k Keeper, msg sdk.Msg, sideTxResult return hmCommon.ErrOldTx(k.Codespace()).Result() } - logger.Debug("Persisting span state", "sideTxResult", sideTxResult) + logger.Debug("Persisting span state", + "sideTxResult", sideTxResult, + "proposer", proposeMsg.Proposer.String(), + "spanId", proposeMsg.ID, + "startBlock", proposeMsg.StartBlock, + "endBlock", proposeMsg.EndBlock, + "seed", proposeMsg.Seed.String(), + ) if ctx.BlockHeader().Height >= helper.GetJorvikHeight() { var seedSpanID uint64