Skip to content

Commit

Permalink
feat: new command for 3D dymint store migration (#1302)
Browse files Browse the repository at this point in the history
Co-authored-by: danwt <[email protected]>
  • Loading branch information
srene and danwt committed Jan 9, 2025
1 parent fc62125 commit bc834de
Show file tree
Hide file tree
Showing 26 changed files with 638 additions and 24 deletions.
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
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

0 comments on commit bc834de

Please sign in to comment.