Skip to content

Commit

Permalink
Merge v1.1.0-new-span-msg (#1226)
Browse files Browse the repository at this point in the history
* New propose span msg

* helper: temporarily set antevortaHeight for testing

* bor: fix nil author clause

* bor: fix TestProposeSpanOne and TestGetNextSpanSeed

* bor: avoid nil ptr deref

* Add support for new msg propose span in cli and rest

* Enable all hardforks at zero height

* helper: temporarily add non-zero hf heights for testing

* bor: fix handler

* When proposing span query height from the node

* Enable all forks on zero height

* Add temporary commands to test malicious cases

* Add temporary commands to test malicious cases

* Let the bridge propose only the first two spans

* Dont enable antevorta from zero height

* Restrict new msg pre-hardfork

* set non-zero height for antevorta

* Add debug logging

* Lower enable fork height

* Clean up

* Cleanup

* Fix lint

* Fix comments

* fix: nil logger

* Unify how we check for Jorvik height

* Allow new and old span propose messages only at correct heights in PostHandle

* Propose span only if proposedSpanID-2 is finished

* Propose span only if proposedSpanID-2 is finished

* rm: useless tests (#1223)

Co-authored-by: marcello33 <[email protected]>

* bor,bridge,helper: rename antevorta to danelaw fork

* bor,bridge: rebase and renaming to danelaw

* Fix rollback command (#1217)

* cmd: fix rollback

* cmd: init rootmultistore from given db

* cmd: disable rollback

* align go deps

* cmd: renable rollback

* Rename Antevorta to Danelaw in error logs

* helper: set danelaw height for amoy

* Fixes for profiles, removing some unecessary postinst file, update to prerm, and postrm.profile

---------

Co-authored-by: Angel Valkov <[email protected]>
Co-authored-by: marcello33 <[email protected]>
Co-authored-by: Daniel Jones <[email protected]>
  • Loading branch information
4 people authored Jan 16, 2025
1 parent 628f019 commit 58bd98e
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 1,558 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ clean:
tests:
# go test -v ./...

go test -v ./app/ ./auth/ ./clerk/ ./sidechannel/ ./bank/ ./chainmanager/ ./topup/ ./checkpoint/ ./staking/ -cover -coverprofile=cover.out -parallel 1
go test -v ./app/ ./auth/ ./clerk/ ./sidechannel/ ./bank/ ./chainmanager/ ./topup/ ./checkpoint/ ./staking/ ./gov/ -cover -coverprofile=cover.out -parallel 1

# make build
build: clean
Expand Down
2 changes: 1 addition & 1 deletion bor/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func GetPreparedProposeSpan(cdc *codec.Codec) *cobra.Command {

var result []byte

if nodeStatus.SyncInfo.LatestBlockHeight < helper.GetAntevortaHeight() {
if nodeStatus.SyncInfo.LatestBlockHeight < helper.GetDanelawHeight() {
msg := types.NewMsgProposeSpan(
spanID,
proposer,
Expand Down
2 changes: 1 addition & 1 deletion bor/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func PostSendProposeSpanTx(cdc *codec.Codec) *cobra.Command {
}

var msg sdk.Msg
if nodeStatus.SyncInfo.LatestBlockHeight < helper.GetAntevortaHeight() {
if nodeStatus.SyncInfo.LatestBlockHeight < helper.GetDanelawHeight() {
msg = types.NewMsgProposeSpan(
spanID,
proposer,
Expand Down
2 changes: 1 addition & 1 deletion bor/client/rest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func postProposeSpanHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
}

var msg sdk.Msg
if nodeStatus.SyncInfo.LatestBlockHeight < helper.GetAntevortaHeight() {
if nodeStatus.SyncInfo.LatestBlockHeight < helper.GetDanelawHeight() {
// draft a propose span message
msg = types.NewMsgProposeSpan(
req.ID,
Expand Down
8 changes: 4 additions & 4 deletions bor/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ 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")
if ctx.BlockHeight() >= helper.GetDanelawHeight() {
err := errors.New("msg span is not allowed after Danelaw hardfork height")
k.Logger(ctx).Error(err.Error())
return sdk.ErrTxDecode(err.Error()).Result()
}
Expand All @@ -45,8 +45,8 @@ 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")
if ctx.BlockHeight() < helper.GetDanelawHeight() {
err := errors.New("msg span v2 is not allowed before Danelaw hardfork height")
k.Logger(ctx).Error(err.Error())
return sdk.ErrTxDecode(err.Error()).Result()
}
Expand Down
4 changes: 2 additions & 2 deletions bor/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func (k *Keeper) FreezeSet(ctx sdk.Context, id uint64, startBlock uint64, endBlo

// SelectNextProducers selects producers for next span
func (k *Keeper) SelectNextProducers(ctx sdk.Context, seed common.Hash, prevVals []hmTypes.Validator) (vals []hmTypes.Validator, err error) {
if ctx.BlockHeader().Height < helper.GetJorvikHeight() {
if ctx.BlockHeight() < helper.GetJorvikHeight() {
prevVals = nil
}

Expand Down Expand Up @@ -358,7 +358,7 @@ func (k *Keeper) GetNextSpanSeed(ctx sdk.Context, id uint64) (common.Hash, commo
author *common.Address
)

if ctx.BlockHeader().Height < helper.GetJorvikHeight() {
if ctx.BlockHeight() < helper.GetJorvikHeight() {
lastEthBlock := k.GetLastEthBlock(ctx)
// increment last processed header block number
newEthBlock := lastEthBlock.Add(lastEthBlock, big.NewInt(1))
Expand Down
22 changes: 15 additions & 7 deletions bor/side_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ 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")
if ctx.BlockHeight() >= helper.GetDanelawHeight() {
k.Logger(ctx).Error("Msg span is not allowed after Danelaw hardfork height")
return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
}
proposeMsg = types.MsgProposeSpanV2{
Expand All @@ -66,8 +66,8 @@ 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")
if ctx.BlockHeight() < helper.GetDanelawHeight() {
k.Logger(ctx).Error("Msg span v2 is not allowed before Danelaw hardfork height")
return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
}
proposeMsg = msg
Expand Down Expand Up @@ -97,7 +97,7 @@ func SideHandleMsgSpan(ctx sdk.Context, k Keeper, msg sdk.Msg, contractCaller he
return hmCommon.ErrorSideTx(k.Codespace(), common.CodeInvalidMsg)
}

if ctx.BlockHeight() >= helper.GetAntevortaHeight() {
if ctx.BlockHeight() >= helper.GetDanelawHeight() {
// check if span seed author matches or not.
if !bytes.Equal(proposeMsg.SeedAuthor.Bytes(), seedAuthor.Bytes()) {
k.Logger(ctx).Error(
Expand Down Expand Up @@ -161,6 +161,10 @@ func PostHandleMsgEventSpan(ctx sdk.Context, k Keeper, msg sdk.Msg, sideTxResult
var proposeMsg types.MsgProposeSpanV2
switch msg := msg.(type) {
case types.MsgProposeSpan:
if ctx.BlockHeight() >= helper.GetDanelawHeight() {
k.Logger(ctx).Error("Msg span is not allowed after Danelaw hardfork height")
return common.ErrSideTxValidation(k.Codespace()).Result()
}
proposeMsg = types.MsgProposeSpanV2{
ID: msg.ID,
Proposer: msg.Proposer,
Expand All @@ -170,6 +174,10 @@ func PostHandleMsgEventSpan(ctx sdk.Context, k Keeper, msg sdk.Msg, sideTxResult
Seed: msg.Seed,
}
case types.MsgProposeSpanV2:
if ctx.BlockHeight() < helper.GetDanelawHeight() {
k.Logger(ctx).Error("Msg span v2 is not allowed before Danelaw hardfork height")
return common.ErrSideTxValidation(k.Codespace()).Result()
}
proposeMsg = msg
}

Expand All @@ -188,7 +196,7 @@ func PostHandleMsgEventSpan(ctx sdk.Context, k Keeper, msg sdk.Msg, sideTxResult
"seed", proposeMsg.Seed.String(),
)

if ctx.BlockHeader().Height >= helper.GetJorvikHeight() {
if ctx.BlockHeight() >= helper.GetJorvikHeight() {
var seedSpanID uint64
if proposeMsg.ID < 2 {
seedSpanID = proposeMsg.ID - 1
Expand All @@ -204,7 +212,7 @@ func PostHandleMsgEventSpan(ctx sdk.Context, k Keeper, msg sdk.Msg, sideTxResult

var producer *ethCommon.Address

if ctx.BlockHeight() < helper.GetAntevortaHeight() {
if ctx.BlockHeight() < helper.GetDanelawHeight() {
// store the seed producer
_, producer, err = k.getBorBlockForSpanSeed(ctx, lastSpan, proposeMsg.ID)
if err != nil {
Expand Down
21 changes: 20 additions & 1 deletion bridge/setu/processor/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ func (sp *SpanProcessor) checkAndPropose() {
return
}

nodeStatus, err := helper.GetNodeStatus(sp.cliCtx)
if err != nil {
sp.Logger.Error("Error while fetching heimdall node status", "error", err)
return
}

if nodeStatus.SyncInfo.LatestBlockHeight >= helper.GetDanelawHeight() {
latestBlock, err := sp.contractConnector.GetMaticChainBlock(nil)
if err != nil {
sp.Logger.Error("Error fetching current child block", "error", err)
return
}

if latestBlock.Number.Uint64() < lastSpan.StartBlock {
sp.Logger.Debug("Current bor block is less than last span start block, skipping proposing span", "currentBlock", latestBlock.Number.Uint64(), "lastSpanStartBlock", lastSpan.StartBlock)
return
}
}

sp.Logger.Debug("Found last span", "lastSpan", lastSpan.ID, "startBlock", lastSpan.StartBlock, "endBlock", lastSpan.EndBlock)

nextSpanMsg, err := sp.fetchNextSpanDetails(lastSpan.ID+1, lastSpan.EndBlock+1)
Expand Down Expand Up @@ -122,7 +141,7 @@ func (sp *SpanProcessor) propose(lastSpan *types.Span, nextSpanMsg *types.Span)

var txRes sdk.TxResponse

if nodeStatus.SyncInfo.LatestBlockHeight < helper.GetAntevortaHeight() {
if nodeStatus.SyncInfo.LatestBlockHeight < helper.GetDanelawHeight() {
// broadcast to heimdall
msg := borTypes.MsgProposeSpan{
ID: nextSpanMsg.ID,
Expand Down
22 changes: 17 additions & 5 deletions cmd/heimdalld/service/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/store/rootmulti"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/maticnetwork/heimdall/app"
"github.com/maticnetwork/heimdall/helper"
stakingcli "github.com/maticnetwork/heimdall/staking/client/cli"
"github.com/spf13/cobra"
Expand All @@ -15,6 +16,8 @@ import (
"github.com/tendermint/tendermint/libs/cli"
)

const flagForce = "force"

func rollbackCmd(ctx *server.Context) *cobra.Command {
cmd := &cobra.Command{
Use: "rollback",
Expand All @@ -27,8 +30,8 @@ The application also roll back to height n - 1. No blocks are removed, so upon
restarting Tendermint the transactions in block n will be re-executed against the
application.
`,
Args: cobra.NoArgs,
RunE: func(_ *cobra.Command, _ []string) error {
RunE: func(_ *cobra.Command, args []string) error {
forceRollback := viper.GetBool(flagForce)
config := ctx.Config
config.SetRoot(viper.GetString(cli.HomeFlag))

Expand All @@ -37,19 +40,28 @@ application.
return err
}

height, hash, err := commands.RollbackState(config)
height, hash, err := commands.RollbackState(config, forceRollback)

if err != nil {
return fmt.Errorf("failed to rollback tendermint state: %w", err)
}
// rollback the multistore
cms := rootmulti.NewStore(db)
cms.RollbackToVersion(height)
hApp := app.NewHeimdallApp(logger, db)
cms := hApp.BaseApp.GetCommitMultiStore()
rs, ok := cms.(*rootmulti.Store)
if !ok {
panic("store not of type rootmultistore")
}

if err := rs.RollbackToVersion(height); err != nil {
return err
}
fmt.Printf("Rolled back state to height %d and hash %X", height, hash)
return nil
},
}

cmd.Flags().Bool(flagForce, false, "force rollback")
cmd.Flags().String(cli.HomeFlag, helper.DefaultNodeHome, "Node's home directory")
cmd.Flags().String(helper.FlagClientHome, helper.DefaultCLIHome, "Client's home directory")
cmd.Flags().String(client.FlagChainID, "", "Genesis file chain-id, if left blank will be randomly created")
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/maticnetwork/heimdall

go 1.22
go 1.22.5

require (
github.com/RichardKnop/machinery v1.10.6
Expand Down Expand Up @@ -169,11 +169,11 @@ require (
gopkg.in/yaml.v3 v3.0.1
)

replace github.com/tendermint/tendermint => github.com/maticnetwork/tendermint v0.33.2
replace github.com/tendermint/tendermint => github.com/maticnetwork/tendermint v0.33.3

replace github.com/tendermint/tm-db => github.com/tendermint/tm-db v0.2.0

replace github.com/cosmos/cosmos-sdk => github.com/maticnetwork/cosmos-sdk v0.38.4
replace github.com/cosmos/cosmos-sdk => github.com/maticnetwork/cosmos-sdk v0.38.5-polygon

replace github.com/ethereum/go-ethereum => github.com/maticnetwork/bor v1.4.1

Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2219,16 +2219,16 @@ github.com/mailgun/raymond/v2 v2.0.48/go.mod h1:lsgvL50kgt1ylcFJYZiULi5fjPBkkhNf
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/maticnetwork/bor v1.4.1 h1:IS6/ap7TgUYIEzM5uwq776NxOkx4rziyit32UZUPDyU=
github.com/maticnetwork/bor v1.4.1/go.mod h1:DSIYFopCa1PqDOI6f3cTunTbSCL2VpBhGwAsTFiYMbo=
github.com/maticnetwork/cosmos-sdk v0.38.4 h1:PAfkMXzHDHJoAf4bXQL4UWgwbu/U3yYuXoXxPhXdpBw=
github.com/maticnetwork/cosmos-sdk v0.38.4/go.mod h1:NbuVdUoqlRF6RrFJp27hpbqSoRB8cJJfUxCzUJWtaLA=
github.com/maticnetwork/cosmos-sdk v0.38.5-polygon h1:2KpGeMOYjhBlVlsa08LtTAhAu02haTA/1CuCCCYkEdA=
github.com/maticnetwork/cosmos-sdk v0.38.5-polygon/go.mod h1:pQ7A1CnHMIQko4QTD6EVj+Qp3EniTsR5C6utLPStDHI=
github.com/maticnetwork/crand v1.0.2 h1:Af0tAivC8zrxXDpGWNWVT/0s1fOz8w0eRbahZgURS8I=
github.com/maticnetwork/crand v1.0.2/go.mod h1:/NRNL3bj2eYdqpWmoIP5puxndTpi0XRxpj5ZKxfHjyg=
github.com/maticnetwork/heimdall v1.0.7/go.mod h1:+ANI5+VV28ahwfdl7oMzrcNwaTEs1Fn6z39BqBGcvaA=
github.com/maticnetwork/polyproto v0.0.3-0.20230216113155-340ea926ca53/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
github.com/maticnetwork/polyproto v0.0.4 h1:qQ/qwcO6UNGS4mJlzlLJn1AUMfJK9Rqmf1v+KJgnPsk=
github.com/maticnetwork/polyproto v0.0.4/go.mod h1:e1mU2EXSwEpn5jM7GfNwu3AupsV6WAGoPFFfswXOF0o=
github.com/maticnetwork/tendermint v0.33.2 h1:R9M7jgAmON8K/LbzMvtWPDhtPkNcqzkUUHp1ict/h3s=
github.com/maticnetwork/tendermint v0.33.2/go.mod h1:D2fcnxGk6bje+LoPwImuKSSYLiK7/G06IynGNDSEcJk=
github.com/maticnetwork/tendermint v0.33.3 h1:s1/Ubxh7Axv2bClr+aFMWNn5qzbRKEHEw/uEVxLTc0I=
github.com/maticnetwork/tendermint v0.33.3/go.mod h1:D2fcnxGk6bje+LoPwImuKSSYLiK7/G06IynGNDSEcJk=
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2/go.mod h1:0KeJpeMD6o+O4hW7qJOT7vyQPKrWmj26uf5wMc/IiIs=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
Expand Down
Loading

0 comments on commit 58bd98e

Please sign in to comment.