Skip to content

Commit

Permalink
Merge pull request #1212 from maticnetwork/v1.1.0-new-span-msg-zero-h…
Browse files Browse the repository at this point in the history
…eight-ready

V1.1.0 new span msg zero height ready
  • Loading branch information
avalkov authored Dec 10, 2024
2 parents 0f90239 + 15a8f62 commit bafc9e6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bor/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions bor/handler.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package bor

import (
"errors"
"strconv"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/maticnetwork/heimdall/bor/types"
"github.com/maticnetwork/heimdall/common"
"github.com/maticnetwork/heimdall/helper"
)

// NewHandler returns a handler for "bor" type messages.
Expand All @@ -29,6 +31,11 @@ func HandleMsgProposeSpan(ctx sdk.Context, msg sdk.Msg, k Keeper) sdk.Result {
var proposeMsg types.MsgProposeSpanV2
switch msg := msg.(type) {
case types.MsgProposeSpan:
if ctx.BlockHeight() >= helper.GetAntevortaHeight() {
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,
Expand All @@ -38,10 +45,16 @@ func HandleMsgProposeSpan(ctx sdk.Context, msg sdk.Msg, k Keeper) sdk.Result {
Seed: msg.Seed,
}
case types.MsgProposeSpanV2:
if ctx.BlockHeight() < helper.GetAntevortaHeight() {
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,
Expand Down
21 changes: 20 additions & 1 deletion bor/side_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 Antevorta hardfork height")
return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
}
proposeMsg = types.MsgProposeSpanV2{
ID: msg.ID,
Proposer: msg.Proposer,
Expand All @@ -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 Antevorta hardfork height")
return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
}
proposeMsg = msg
}

Expand All @@ -80,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(),
)
Expand All @@ -92,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(),
Expand Down Expand Up @@ -167,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
Expand Down
4 changes: 2 additions & 2 deletions helper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ func InitHeimdallConfigWith(homeDir string, heimdallConfigFileFromFLag string) {
spanOverrideHeight = 0
newHexToStringAlgoHeight = 0
aalborgHeight = 0
jorvikHeight = 100
antevortaHeight = 150
jorvikHeight = 0
antevortaHeight = 0
}
}

Expand Down

0 comments on commit bafc9e6

Please sign in to comment.