Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cherry 13816c^..559cd (3d migration) #1322

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (m *Manager) applyBlock(block *types.Block, commit *types.Commit, blockMeta
// In case the following true, it means we crashed after the app commit but before updating the state
// In that case we'll want to align the state with the app commit result, as if the block was applied.
if isBlockAlreadyApplied {
err := m.UpdateStateFromApp(block.Header.Hash())
err := m.UpdateStateFromApp(block)
if err != nil {
return fmt.Errorf("update state from app: %w", err)
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func (m *Manager) applyBlock(block *types.Block, commit *types.Commit, blockMeta
}
// Update the state with the new app hash, and store height from the commit.
// Every one of those, if happens before commit, prevents us from re-executing the block in case failed during commit.
m.Executor.UpdateStateAfterCommit(m.State, responses, appHash, block.Header.Height, block.Header.Hash())
m.Executor.UpdateStateAfterCommit(m.State, responses, appHash, block)

}

Expand Down
2 changes: 1 addition & 1 deletion block/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type ExecutorI interface {
ExecuteBlock(block *types.Block) (*tmstate.ABCIResponses, error)
UpdateStateAfterInitChain(s *types.State, res *abci.ResponseInitChain)
UpdateMempoolAfterInitChain(s *types.State)
UpdateStateAfterCommit(s *types.State, resp *tmstate.ABCIResponses, appHash []byte, height uint64, lastHeaderHash [32]byte)
UpdateStateAfterCommit(s *types.State, resp *tmstate.ABCIResponses, appHash []byte, block *types.Block)
UpdateProposerFromBlock(s *types.State, seqSet *types.SequencerSet, block *types.Block) bool

/* Consensus Messages */
Expand Down
4 changes: 2 additions & 2 deletions block/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func TestApplyBlock(t *testing.T) {
require.NotNil(resp)
appHash, _, err := executor.Commit(state, block, resp)
require.NoError(err)
executor.UpdateStateAfterCommit(state, resp, appHash, block.Header.Height, block.Header.Hash())
executor.UpdateStateAfterCommit(state, resp, appHash, block)
assert.Equal(uint64(1), state.Height())
assert.Equal(mockAppHash, state.AppHash)

Expand Down Expand Up @@ -390,7 +390,7 @@ func TestApplyBlock(t *testing.T) {
require.NotNil(resp)
_, _, err = executor.Commit(state, block, resp)
require.NoError(err)
executor.UpdateStateAfterCommit(state, resp, appHash, block.Header.Height, block.Header.Hash())
executor.UpdateStateAfterCommit(state, resp, appHash, block)
assert.Equal(uint64(2), state.Height())

// check rollapp params update
Expand Down
12 changes: 6 additions & 6 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,6 @@ func NewManager(
return nil, err
}

// update dymint state with next revision info
err = m.updateStateForNextRevision()
if err != nil {
return nil, err
}

// validate configuration params and rollapp consensus params are in line
err = m.ValidateConfigWithRollappParams()
if err != nil {
Expand All @@ -222,6 +216,12 @@ func (m *Manager) Start(ctx context.Context) error {
}
}

// update dymint state with next revision info
err := m.updateStateForNextRevision()
if err != nil {
return err
}

// Check if a proposer on the rollapp is set. In case no proposer is set on the Rollapp, fallback to the hub proposer (If such exists).
// No proposer on the rollapp means that at some point there was no available proposer.
// In case there is also no proposer on the hub to our current height, it means that the chain is halted.
Expand Down
12 changes: 11 additions & 1 deletion block/slvalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/dymensionxyz/dymint/da"
"github.com/dymensionxyz/dymint/settlement"
"github.com/dymensionxyz/dymint/types"
"github.com/dymensionxyz/gerr-cosmos/gerrc"
)

// SettlementValidator validates batches from settlement layer with the corresponding blocks from DA and P2P.
Expand All @@ -31,7 +32,11 @@ func NewSettlementValidator(logger types.Logger, blockManager *Manager) *Settlem
logger: logger,
blockManager: blockManager,
}
validator.lastValidatedHeight.Store(lastValidatedHeight)

// if SkipValidationHeight is set, dont validate anything previous to that (used by 2D migration)
validationHeight := max(blockManager.Conf.SkipValidationHeight+1, lastValidatedHeight)

validator.lastValidatedHeight.Store(validationHeight)

return validator
}
Expand Down Expand Up @@ -235,6 +240,11 @@ func (v *SettlementValidator) NextValidationHeight() uint64 {
// validateDRS compares the DRS version stored for the specific height, obtained from rollapp params.
func (v *SettlementValidator) validateDRS(stateIndex uint64, height uint64, version uint32) error {
drs, err := v.blockManager.Store.LoadDRSVersion(height)
// it can happen DRS is not found for blocks applied previous to migration, in case of migration from 2D rollapps
if errors.Is(err, gerrc.ErrNotFound) {
v.logger.Error("Unable to validate BD DRS version. Height:%d Err:%w", height, err)
return nil
}
if err != nil {
return err
}
Expand Down
9 changes: 5 additions & 4 deletions block/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func NewStateFromGenesis(genDoc *tmtypes.GenesisDoc) (*types.State, error) {
}

// UpdateStateFromApp is responsible for aligning the state of the store from the abci app
func (m *Manager) UpdateStateFromApp(blockHeaderHash [32]byte) error {
func (m *Manager) UpdateStateFromApp(block *types.Block) error {
proxyAppInfo, err := m.Executor.GetAppInfo()
if err != nil {
return errorsmod.Wrap(err, "get app info")
Expand All @@ -87,7 +87,7 @@ func (m *Manager) UpdateStateFromApp(blockHeaderHash [32]byte) error {
}

// update the state with the app hashes created on the app commit
m.Executor.UpdateStateAfterCommit(m.State, resp, proxyAppInfo.LastBlockAppHash, appHeight, blockHeaderHash)
m.Executor.UpdateStateAfterCommit(m.State, resp, proxyAppInfo.LastBlockAppHash, block)

return nil
}
Expand Down Expand Up @@ -116,12 +116,13 @@ func (e *Executor) UpdateMempoolAfterInitChain(s *types.State) {
}

// UpdateStateAfterCommit updates the state with the app hash and last results hash
func (e *Executor) UpdateStateAfterCommit(s *types.State, resp *tmstate.ABCIResponses, appHash []byte, height uint64, lastHeaderHash [32]byte) {
func (e *Executor) UpdateStateAfterCommit(s *types.State, resp *tmstate.ABCIResponses, appHash []byte, block *types.Block) {
copy(s.AppHash[:], appHash[:])
copy(s.LastResultsHash[:], tmtypes.NewResults(resp.DeliverTxs).Hash())
lastHeaderHash := block.Header.Hash()
copy(s.LastHeaderHash[:], lastHeaderHash[:])

s.SetHeight(height)
s.SetHeight(block.Header.Height)
if resp.EndBlock.ConsensusParamUpdates != nil {
s.ConsensusParams.Block.MaxGas = resp.EndBlock.ConsensusParamUpdates.Block.MaxGas
s.ConsensusParams.Block.MaxBytes = resp.EndBlock.ConsensusParamUpdates.Block.MaxBytes
Expand Down
3 changes: 2 additions & 1 deletion block/submit.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ func (m *Manager) CreateBatch(maxBatchSize uint64, startHeight uint64, endHeight
}

drsVersion, err := m.Store.LoadDRSVersion(block.Header.Height)
if err != nil {
// if drsVersion is not found in store, batch is submitted using version 0 (it can happen for pending submission blocks for migrated rollapps)
if err != nil && !errors.Is(err, gerrc.ErrNotFound) {
return nil, fmt.Errorf("load drs version: h: %d: %w", h, err)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/dymint/commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func InitFilesWithConfig(config *cfg.Config) error {
ChainID: fmt.Sprintf("test-chain-%v", tmrand.Str(6)),
GenesisTime: tmtime.Now(),
ConsensusParams: types.DefaultConsensusParams(),
AppState: []byte("{\"app_state\": {\"rollappparams\": {\"params\": {\"da\": \"mock\",\"version\": \"646983ec41942854aa8b2fc2b755106307e50170\"}}}}"),
AppState: []byte("{\"rollappparams\": {\"params\": {\"da\": \"mock\",\"drs_version\": 0,\"min_gas_prices\":[]}}}"),
}
pubKey, err := pv.GetPubKey()
if err != nil {
Expand Down
47 changes: 47 additions & 0 deletions cmd/dymint/commands/migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package commands

import (
"fmt"

"github.com/cosmos/cosmos-sdk/server"
cfg "github.com/dymensionxyz/dymint/config"
"github.com/dymensionxyz/dymint/store"
"github.com/spf13/cobra"
)

var mainPrefix = []byte{0}

const rollappParamDAFlag = "rollappparam-da-mock"

// Run3dMigrationCmd migrates store to 3D version (1.3.0) for old rollapps.
func Run3dMigrationCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "run-3d-migration",
Aliases: []string{"run-3d-migration"},
Short: "Migrate dymint store to 3D",
RunE: run3dMigration,
}
cmd.Flags().Bool(rollappParamDAFlag, false, "migrate using mock DA")
cfg.AddNodeFlags(cmd)
return cmd
}

func run3dMigration(cmd *cobra.Command, args []string) error {
serverCtx := server.GetServerContextFromCmd(cmd)
cfg := serverCtx.Config

baseKV := store.NewDefaultKVStore(cfg.RootDir, cfg.DBPath, "dymint")
s := store.New(store.NewPrefixKV(baseKV, mainPrefix))

daMock := serverCtx.Viper.GetBool(rollappParamDAFlag)
da := "celestia"
if daMock {
da = "mock"
}
err := store.Run3DMigration(s, da)
if err != nil {
return fmt.Errorf("3D dymint store migration failed. err:%w", err)
}
fmt.Println("3D dymint store migration successful")
return nil
}
1 change: 1 addition & 0 deletions cmd/dymint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func main() {
commands.InitFilesCmd,
commands.ShowSequencer,
commands.ShowNodeIDCmd,
commands.Run3dMigrationCmd(),
debug.DebugCmd,
cli.NewCompletionCmd(rootCmd, true),
)
Expand Down
12 changes: 11 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,24 @@ require (
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
github.com/celestiaorg/go-square v1.0.1 // indirect
github.com/celestiaorg/go-square/merkle v0.0.0-20240429192549-dea967e1533b // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/coinbase/rosetta-sdk-go v0.7.9 // indirect
github.com/cosmos/cosmos-db v1.0.0 // indirect
github.com/cskr/pubsub v1.0.2 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger/v3 v3.2103.3 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/gogo/gateway v1.1.0 // indirect
github.com/gorilla/handlers v1.5.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/ipfs/go-block-format v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/rakyll/statik v0.1.7 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/rs/zerolog v1.29.1 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
nhooyr.io/websocket v1.8.7 // indirect
)

require (
Expand Down Expand Up @@ -94,7 +105,6 @@ require (
github.com/go-stack/stack v1.8.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 // indirect
github.com/hashicorp/go-uuid v1.0.1 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/ipfs/go-log v1.0.5 // indirect
github.com/klauspost/reedsolomon v1.11.8 // indirect
Expand Down
Loading
Loading