From 02f5d61434976b7f6513f609c450047cf2a07cdf Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Thu, 26 Dec 2024 07:48:26 -0800 Subject: [PATCH 01/50] Export Distribution Only --- tools/migration/ss/migrator.go | 78 +++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 21 deletions(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index e737a86133..28475c8fab 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -30,47 +30,83 @@ func NewMigrator(db dbm.DB, stateStore types.StateStore) *Migrator { } func (m *Migrator) Migrate(version int64, homeDir string) error { + // Channel to send RawSnapshotNodes to the importer. ch := make(chan types.RawSnapshotNode, 1000) + // Channel to capture errors from both goroutines below. errCh := make(chan error, 2) - // Get the latest key, if any, to resume from - latestKey, err := m.stateStore.GetLatestMigratedKey() - if err != nil { - return fmt.Errorf("failed to get latest key: %w", err) - } + fmt.Printf("Starting migration for 'distribution' module from version %d to %d...\n", 100215000, 106789896) - latestModule, err := m.stateStore.GetLatestMigratedModule() - if err != nil { - return fmt.Errorf("failed to get latest module: %w", err) - } - - fmt.Println("Starting migration...") - - // Goroutine to iterate through IAVL and export leaf nodes + // Goroutine #1: Export distribution leaf nodes into ch go func() { defer close(ch) - errCh <- ExportLeafNodesFromKey(m.iavlDB, ch, latestKey, latestModule) + errCh <- exportDistributionLeafNodes(m.iavlDB, ch, 100215000, 106789896) }() - // Import nodes into PebbleDB + // Goroutine #2: Import those leaf nodes into PebbleDB go func() { errCh <- m.stateStore.RawImport(ch) }() - // Block until both processes complete + // Wait for both goroutines to complete for i := 0; i < 2; i++ { if err := <-errCh; err != nil { return err } } - // Set earliest and latest version in the database - err = m.stateStore.SetEarliestVersion(1, true) - if err != nil { - return err + return nil +} + +func exportDistributionLeafNodes( + db dbm.DB, + ch chan<- types.RawSnapshotNode, + startVersion, endVersion int64, +) error { + // Total counters for logging. + totalExported := 0 + startTime := time.Now() + + for ver := startVersion; ver <= endVersion; ver++ { + // Load only the distribution module prefix at this version. + tree, err := ReadTree(db, ver, []byte(utils.BuildTreePrefix("distribution"))) + if err != nil { + fmt.Printf("Error loading distribution tree at version %d: %s\n", ver, err.Error()) + return err + } + + var count int + _, err = tree.Iterate(func(key, value []byte) bool { + // Each leaf node is a single K/V for this version + ch <- types.RawSnapshotNode{ + StoreKey: "distribution", + Key: key, + Value: value, + Version: ver, + } + count++ + totalExported++ + if count%1000000 == 0 { + fmt.Printf("Exported %d distribution keys at version %d so far\n", count, ver) + // Optionally add metrics here if desired. + metrics.IncrCounterWithLabels([]string{"sei", "migration", "leaf_nodes_exported"}, float32(count), []metrics.Label{ + {Name: "module", Value: "distribution"}, + }) + } + return false // continue iteration + }) + if err != nil { + fmt.Printf("Error iterating distribution tree for version %d: %s\n", ver, err.Error()) + return err + } + fmt.Printf("Finished version %d: exported %d distribution keys.\n", ver, count) } - return m.stateStore.SetLatestVersion(version) + fmt.Printf( + "Completed exporting distribution module from %d to %d. Total keys: %d. Duration: %s\n", + startVersion, endVersion, totalExported, time.Since(startTime), + ) + return nil } func (m *Migrator) Verify(version int64) error { From 9e47cc539dd5837117c71e715b186b3c052df27c Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Thu, 26 Dec 2024 16:49:06 -0800 Subject: [PATCH 02/50] Migrate distribution tool --- tools/cmd.go | 1 + tools/migration/cmd/cmd.go | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/tools/cmd.go b/tools/cmd.go index dc9b79bd46..ea292d5ae0 100644 --- a/tools/cmd.go +++ b/tools/cmd.go @@ -14,6 +14,7 @@ func ToolCmd() *cobra.Command { } toolsCmd.AddCommand(scanner.ScanCmd()) toolsCmd.AddCommand(migration.MigrateCmd()) + toolsCmd.AddCommand(migration.MigrateSSCmd()) toolsCmd.AddCommand(migration.VerifyMigrationCmd()) toolsCmd.AddCommand(migration.GenerateStats()) return toolsCmd diff --git a/tools/migration/cmd/cmd.go b/tools/migration/cmd/cmd.go index be18c8ce3a..6cf47e13fa 100644 --- a/tools/migration/cmd/cmd.go +++ b/tools/migration/cmd/cmd.go @@ -48,6 +48,45 @@ func migrateSC(version int64, homeDir string, db dbm.DB) error { return migrator.Migrate(version) } +func MigrateSSCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "migrate-ss", + Short: "A tool to migrate full ss distribution module", + Run: executeSS, + } + cmd.PersistentFlags().String("home-dir", "/root/.sei", "Sei home directory") + return cmd +} + +func executeSS(cmd *cobra.Command, _ []string) { + homeDir, _ := cmd.Flags().GetString("home-dir") + dataDir := filepath.Join(homeDir, "data") + db, err := dbm.NewGoLevelDB("application", dataDir) + if err != nil { + panic(err) + } + latestVersion := rootmulti.GetLatestVersion(db) + fmt.Printf("latest version: %d\n", latestVersion) + + if err = migrateSS(latestVersion, homeDir, db); err != nil { + panic(err) + } +} + +func migrateSS(version int64, homeDir string, db dbm.DB) error { + ssConfig := config.DefaultStateStoreConfig() + ssConfig.Enable = true + ssConfig.KeepRecent = 0 + + stateStore, err := sstypes.NewStateStore(log.NewNopLogger(), homeDir, ssConfig) + if err != nil { + return err + } + + migrator := ss.NewMigrator(db, stateStore) + return migrator.Migrate(version, homeDir) +} + func VerifyMigrationCmd() *cobra.Command { cmd := &cobra.Command{ Use: "verify-migration", From 894b9cb260bb0cc901ddf59b11b04bdb2e48f9e2 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Fri, 27 Dec 2024 08:23:19 -0800 Subject: [PATCH 03/50] Check read --- tools/migration/ss/migrator.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 28475c8fab..7f7154a9ac 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -78,12 +78,12 @@ func exportDistributionLeafNodes( var count int _, err = tree.Iterate(func(key, value []byte) bool { // Each leaf node is a single K/V for this version - ch <- types.RawSnapshotNode{ - StoreKey: "distribution", - Key: key, - Value: value, - Version: ver, - } + // ch <- types.RawSnapshotNode{ + // StoreKey: "distribution", + // Key: key, + // Value: value, + // Version: ver, + // } count++ totalExported++ if count%1000000 == 0 { From f13a6d4dba1ceb99893204d246f43f22e1fe7af1 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Fri, 27 Dec 2024 08:30:16 -0800 Subject: [PATCH 04/50] More logs --- tools/migration/ss/migrator.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 7f7154a9ac..1b6e87d29c 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -63,6 +63,8 @@ func exportDistributionLeafNodes( ch chan<- types.RawSnapshotNode, startVersion, endVersion int64, ) error { + fmt.Printf("Starting export at time: %s\n", time.Now().Format(time.RFC3339)) + // Total counters for logging. totalExported := 0 startTime := time.Now() @@ -106,6 +108,7 @@ func exportDistributionLeafNodes( "Completed exporting distribution module from %d to %d. Total keys: %d. Duration: %s\n", startVersion, endVersion, totalExported, time.Since(startTime), ) + fmt.Printf("Finished export at time: %s\n", time.Now().Format(time.RFC3339)) return nil } From d68dd2ba4ca664de7bd800a1b6ed599333068882 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Fri, 27 Dec 2024 08:36:24 -0800 Subject: [PATCH 05/50] Timestamps --- tools/migration/ss/migrator.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 1b6e87d29c..b82eb4ac8c 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -73,7 +73,7 @@ func exportDistributionLeafNodes( // Load only the distribution module prefix at this version. tree, err := ReadTree(db, ver, []byte(utils.BuildTreePrefix("distribution"))) if err != nil { - fmt.Printf("Error loading distribution tree at version %d: %s\n", ver, err.Error()) + fmt.Printf("[%s] Error loading distribution tree at version %d: %s\n", time.Now().Format(time.RFC3339), ver, err.Error()) return err } @@ -89,7 +89,7 @@ func exportDistributionLeafNodes( count++ totalExported++ if count%1000000 == 0 { - fmt.Printf("Exported %d distribution keys at version %d so far\n", count, ver) + fmt.Printf("[%s] Exported %d distribution keys at version %d so far\n", time.Now().Format(time.RFC3339), count, ver) // Optionally add metrics here if desired. metrics.IncrCounterWithLabels([]string{"sei", "migration", "leaf_nodes_exported"}, float32(count), []metrics.Label{ {Name: "module", Value: "distribution"}, @@ -98,15 +98,15 @@ func exportDistributionLeafNodes( return false // continue iteration }) if err != nil { - fmt.Printf("Error iterating distribution tree for version %d: %s\n", ver, err.Error()) + fmt.Printf("[%s] Error iterating distribution tree for version %d: %s\n", time.Now().Format(time.RFC3339), ver, err.Error()) return err } - fmt.Printf("Finished version %d: exported %d distribution keys.\n", ver, count) + fmt.Printf("[%s] Finished version %d: exported %d distribution keys.\n", time.Now().Format(time.RFC3339), ver, count) } fmt.Printf( - "Completed exporting distribution module from %d to %d. Total keys: %d. Duration: %s\n", - startVersion, endVersion, totalExported, time.Since(startTime), + "[%s] Completed exporting distribution module from %d to %d. Total keys: %d. Duration: %s\n", + time.Now().Format(time.RFC3339), startVersion, endVersion, totalExported, time.Since(startTime), ) fmt.Printf("Finished export at time: %s\n", time.Now().Format(time.RFC3339)) return nil From b64e9c286692e5dbc594cb2f2f6e89562525c244 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Fri, 27 Dec 2024 09:10:05 -0800 Subject: [PATCH 06/50] prefix db --- tools/migration/ss/migrator.go | 104 +++++++++++++++++++++++---------- 1 file changed, 74 insertions(+), 30 deletions(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index b82eb4ac8c..e05a97ee40 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -62,51 +62,95 @@ func exportDistributionLeafNodes( db dbm.DB, ch chan<- types.RawSnapshotNode, startVersion, endVersion int64, + numGoroutines int, ) error { fmt.Printf("Starting export at time: %s\n", time.Now().Format(time.RFC3339)) // Total counters for logging. - totalExported := 0 startTime := time.Now() - for ver := startVersion; ver <= endVersion; ver++ { - // Load only the distribution module prefix at this version. - tree, err := ReadTree(db, ver, []byte(utils.BuildTreePrefix("distribution"))) + // for ver := startVersion; ver <= endVersion; ver++ { + // // Load only the distribution module prefix at this version. + // tree, err := ReadTree(db, ver, []byte(utils.BuildTreePrefix("distribution"))) + // if err != nil { + // fmt.Printf("[%s] Error loading distribution tree at version %d: %s\n", time.Now().Format(time.RFC3339), ver, err.Error()) + // return err + // } + + // var count int + // _, err = tree.Iterate(func(key, value []byte) bool { + // // Each leaf node is a single K/V for this version + // // ch <- types.RawSnapshotNode{ + // // StoreKey: "distribution", + // // Key: key, + // // Value: value, + // // Version: ver, + // // } + // count++ + // totalExported++ + // if count%1000000 == 0 { + // fmt.Printf("[%s] Exported %d distribution keys at version %d so far\n", time.Now().Format(time.RFC3339), count, ver) + // // Optionally add metrics here if desired. + // metrics.IncrCounterWithLabels([]string{"sei", "migration", "leaf_nodes_exported"}, float32(count), []metrics.Label{ + // {Name: "module", Value: "distribution"}, + // }) + // } + // return false // continue iteration + // }) + // if err != nil { + // fmt.Printf("[%s] Error iterating distribution tree for version %d: %s\n", time.Now().Format(time.RFC3339), ver, err.Error()) + // return err + // } + // fmt.Printf("[%s] Finished version %d: exported %d distribution keys.\n", time.Now().Format(time.RFC3339), ver, count) + // } + + prefixDB := dbm.NewPrefixDB(db, []byte(utils.BuildRawPrefix("distribution"))) + var itr dbm.Iterator + var err error + leafNodeCount := 0 + count := 0 + + // If there is a starting key, seek to it, otherwise start from the beginning + itr, err = prefixDB.Iterator(nil, nil) + + if err != nil { + fmt.Printf("SeiDB Archive Migration: Error creating iterator: %+v\n", err) + return fmt.Errorf("failed to create iterator: %w", err) + } + defer itr.Close() + + for ; itr.Valid(); itr.Next() { + value := bytes.Clone(itr.Value()) + + node, err := iavl.MakeNode(value) if err != nil { - fmt.Printf("[%s] Error loading distribution tree at version %d: %s\n", time.Now().Format(time.RFC3339), ver, err.Error()) - return err + fmt.Printf("SeiDB Archive Migration: Failed to make node: %+v\n", err) + return fmt.Errorf("failed to make node: %w", err) } - var count int - _, err = tree.Iterate(func(key, value []byte) bool { - // Each leaf node is a single K/V for this version - // ch <- types.RawSnapshotNode{ - // StoreKey: "distribution", - // Key: key, - // Value: value, - // Version: ver, - // } - count++ - totalExported++ - if count%1000000 == 0 { - fmt.Printf("[%s] Exported %d distribution keys at version %d so far\n", time.Now().Format(time.RFC3339), count, ver) - // Optionally add metrics here if desired. - metrics.IncrCounterWithLabels([]string{"sei", "migration", "leaf_nodes_exported"}, float32(count), []metrics.Label{ - {Name: "module", Value: "distribution"}, - }) + // Only export leaf nodes + if node.GetHeight() == 0 { + version := node.GetVersion() + if version < startVersion || version > endVersion { + continue } - return false // continue iteration - }) - if err != nil { - fmt.Printf("[%s] Error iterating distribution tree for version %d: %s\n", time.Now().Format(time.RFC3339), ver, err.Error()) - return err + leafNodeCount++ + } + + count++ + if count%1000000 == 0 { + fmt.Printf("[%s] SeiDB Archive Migration: Last 1,000,000 iterations. Total scanned: %d, leaf nodes exported: %d\n", time.Now().Format(time.RFC3339), count, leafNodeCount) } - fmt.Printf("[%s] Finished version %d: exported %d distribution keys.\n", time.Now().Format(time.RFC3339), ver, count) + } + + if err := itr.Error(); err != nil { + fmt.Printf("Iterator error: %+v\n", err) + return fmt.Errorf("iterator error: %w", err) } fmt.Printf( "[%s] Completed exporting distribution module from %d to %d. Total keys: %d. Duration: %s\n", - time.Now().Format(time.RFC3339), startVersion, endVersion, totalExported, time.Since(startTime), + time.Now().Format(time.RFC3339), startVersion, endVersion, leafNodeCount, time.Since(startTime), ) fmt.Printf("Finished export at time: %s\n", time.Now().Format(time.RFC3339)) return nil From 5dba22a13403c065fec14040f4c2cb72f6ebf83f Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Fri, 27 Dec 2024 09:12:13 -0800 Subject: [PATCH 07/50] Fix call --- tools/migration/ss/migrator.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index e05a97ee40..553b92a2d5 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -62,7 +62,6 @@ func exportDistributionLeafNodes( db dbm.DB, ch chan<- types.RawSnapshotNode, startVersion, endVersion int64, - numGoroutines int, ) error { fmt.Printf("Starting export at time: %s\n", time.Now().Format(time.RFC3339)) From 705b461ee3d106de0968248a7258f5a17c006226 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Fri, 27 Dec 2024 09:57:19 -0800 Subject: [PATCH 08/50] concurrent goroutines --- tools/migration/ss/migrator.go | 277 ++++++++++++++++++++++++--------- 1 file changed, 206 insertions(+), 71 deletions(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 553b92a2d5..9d7241f373 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -3,6 +3,7 @@ package ss import ( "bytes" "fmt" + "sync" "time" "github.com/armon/go-metrics" @@ -40,7 +41,7 @@ func (m *Migrator) Migrate(version int64, homeDir string) error { // Goroutine #1: Export distribution leaf nodes into ch go func() { defer close(ch) - errCh <- exportDistributionLeafNodes(m.iavlDB, ch, 100215000, 106789896) + errCh <- exportDistributionLeafNodes(m.iavlDB, ch, 100215000, 106789896, 30) }() // Goroutine #2: Import those leaf nodes into PebbleDB @@ -58,98 +59,232 @@ func (m *Migrator) Migrate(version int64, homeDir string) error { return nil } +// func exportDistributionLeafNodes( +// db dbm.DB, +// ch chan<- types.RawSnapshotNode, +// startVersion, endVersion int64, +// ) error { +// fmt.Printf("Starting export at time: %s\n", time.Now().Format(time.RFC3339)) + +// // Total counters for logging. +// startTime := time.Now() + +// // for ver := startVersion; ver <= endVersion; ver++ { +// // // Load only the distribution module prefix at this version. +// // tree, err := ReadTree(db, ver, []byte(utils.BuildTreePrefix("distribution"))) +// // if err != nil { +// // fmt.Printf("[%s] Error loading distribution tree at version %d: %s\n", time.Now().Format(time.RFC3339), ver, err.Error()) +// // return err +// // } + +// // var count int +// // _, err = tree.Iterate(func(key, value []byte) bool { +// // // Each leaf node is a single K/V for this version +// // // ch <- types.RawSnapshotNode{ +// // // StoreKey: "distribution", +// // // Key: key, +// // // Value: value, +// // // Version: ver, +// // // } +// // count++ +// // totalExported++ +// // if count%1000000 == 0 { +// // fmt.Printf("[%s] Exported %d distribution keys at version %d so far\n", time.Now().Format(time.RFC3339), count, ver) +// // // Optionally add metrics here if desired. +// // metrics.IncrCounterWithLabels([]string{"sei", "migration", "leaf_nodes_exported"}, float32(count), []metrics.Label{ +// // {Name: "module", Value: "distribution"}, +// // }) +// // } +// // return false // continue iteration +// // }) +// // if err != nil { +// // fmt.Printf("[%s] Error iterating distribution tree for version %d: %s\n", time.Now().Format(time.RFC3339), ver, err.Error()) +// // return err +// // } +// // fmt.Printf("[%s] Finished version %d: exported %d distribution keys.\n", time.Now().Format(time.RFC3339), ver, count) +// // } + +// prefixDB := dbm.NewPrefixDB(db, []byte(utils.BuildRawPrefix("distribution"))) +// var itr dbm.Iterator +// var err error +// leafNodeCount := 0 +// count := 0 + +// // If there is a starting key, seek to it, otherwise start from the beginning +// itr, err = prefixDB.Iterator(nil, nil) + +// if err != nil { +// fmt.Printf("SeiDB Archive Migration: Error creating iterator: %+v\n", err) +// return fmt.Errorf("failed to create iterator: %w", err) +// } +// defer itr.Close() + +// for ; itr.Valid(); itr.Next() { +// value := bytes.Clone(itr.Value()) + +// node, err := iavl.MakeNode(value) +// if err != nil { +// fmt.Printf("SeiDB Archive Migration: Failed to make node: %+v\n", err) +// return fmt.Errorf("failed to make node: %w", err) +// } + +// // Only export leaf nodes +// if node.GetHeight() == 0 { +// version := node.GetVersion() +// if version < startVersion || version > endVersion { +// continue +// } +// leafNodeCount++ +// } + +// count++ +// if count%1000000 == 0 { +// fmt.Printf("[%s] SeiDB Archive Migration: Last 1,000,000 iterations. Total scanned: %d, leaf nodes exported: %d\n", time.Now().Format(time.RFC3339), count, leafNodeCount) +// } +// } + +// if err := itr.Error(); err != nil { +// fmt.Printf("Iterator error: %+v\n", err) +// return fmt.Errorf("iterator error: %w", err) +// } + +// fmt.Printf( +// "[%s] Completed exporting distribution module from %d to %d. Total keys: %d. Duration: %s\n", +// time.Now().Format(time.RFC3339), startVersion, endVersion, leafNodeCount, time.Since(startTime), +// ) +// fmt.Printf("Finished export at time: %s\n", time.Now().Format(time.RFC3339)) +// return nil +// } + func exportDistributionLeafNodes( db dbm.DB, ch chan<- types.RawSnapshotNode, startVersion, endVersion int64, + concurrency int, ) error { - fmt.Printf("Starting export at time: %s\n", time.Now().Format(time.RFC3339)) + fmt.Printf("Starting export at time: %s with concurrency=%d\n", time.Now().Format(time.RFC3339), concurrency) - // Total counters for logging. - startTime := time.Now() + if concurrency < 1 { + concurrency = 1 + } - // for ver := startVersion; ver <= endVersion; ver++ { - // // Load only the distribution module prefix at this version. - // tree, err := ReadTree(db, ver, []byte(utils.BuildTreePrefix("distribution"))) - // if err != nil { - // fmt.Printf("[%s] Error loading distribution tree at version %d: %s\n", time.Now().Format(time.RFC3339), ver, err.Error()) - // return err - // } - - // var count int - // _, err = tree.Iterate(func(key, value []byte) bool { - // // Each leaf node is a single K/V for this version - // // ch <- types.RawSnapshotNode{ - // // StoreKey: "distribution", - // // Key: key, - // // Value: value, - // // Version: ver, - // // } - // count++ - // totalExported++ - // if count%1000000 == 0 { - // fmt.Printf("[%s] Exported %d distribution keys at version %d so far\n", time.Now().Format(time.RFC3339), count, ver) - // // Optionally add metrics here if desired. - // metrics.IncrCounterWithLabels([]string{"sei", "migration", "leaf_nodes_exported"}, float32(count), []metrics.Label{ - // {Name: "module", Value: "distribution"}, - // }) - // } - // return false // continue iteration - // }) - // if err != nil { - // fmt.Printf("[%s] Error iterating distribution tree for version %d: %s\n", time.Now().Format(time.RFC3339), ver, err.Error()) - // return err - // } - // fmt.Printf("[%s] Finished version %d: exported %d distribution keys.\n", time.Now().Format(time.RFC3339), ver, count) - // } - - prefixDB := dbm.NewPrefixDB(db, []byte(utils.BuildRawPrefix("distribution"))) - var itr dbm.Iterator - var err error - leafNodeCount := 0 - count := 0 + // We'll collect errors from each goroutine in a separate error channel + errCh := make(chan error, concurrency) - // If there is a starting key, seek to it, otherwise start from the beginning - itr, err = prefixDB.Iterator(nil, nil) + totalVersions := endVersion - startVersion + 1 + // Basic integer division to split up the version range + chunkSize := totalVersions / int64(concurrency) + remainder := totalVersions % int64(concurrency) - if err != nil { - fmt.Printf("SeiDB Archive Migration: Error creating iterator: %+v\n", err) - return fmt.Errorf("failed to create iterator: %w", err) - } - defer itr.Close() + var wg sync.WaitGroup + wg.Add(concurrency) - for ; itr.Valid(); itr.Next() { - value := bytes.Clone(itr.Value()) + startTime := time.Now() + // Atomic or shared counters for tracking exports + var mu sync.Mutex + totalExported := 0 - node, err := iavl.MakeNode(value) - if err != nil { - fmt.Printf("SeiDB Archive Migration: Failed to make node: %+v\n", err) - return fmt.Errorf("failed to make node: %w", err) - } + // Helper function that each goroutine will run + workerFunc := func(workerID int, vStart, vEnd int64) { + defer wg.Done() - // Only export leaf nodes - if node.GetHeight() == 0 { - version := node.GetVersion() - if version < startVersion || version > endVersion { - continue + // Local counter + localExportCount := 0 + + for ver := vStart; ver <= vEnd; ver++ { + // Load only the distribution module prefix at this version. + tree, err := ReadTree(db, ver, []byte(utils.BuildTreePrefix("distribution"))) + if err != nil { + errCh <- fmt.Errorf( + "[worker %d] Error loading distribution tree at version %d: %w", + workerID, ver, err, + ) + return } - leafNodeCount++ + + var count int + _, err = tree.Iterate(func(key, value []byte) bool { + // ch <- types.RawSnapshotNode{ + // StoreKey: "distribution", + // Key: key, + // Value: value, + // Version: ver, + // } + count++ + // Use a lock when incrementing total counters + mu.Lock() + totalExported++ + mu.Unlock() + + // Logging / metrics every 1,000,000 keys in this version subset + if count%1000000 == 0 { + fmt.Printf("[worker %d][%s] Exported %d distribution keys at version %d so far\n", + workerID, time.Now().Format(time.RFC3339), count, ver, + ) + metrics.IncrCounterWithLabels( + []string{"sei", "migration", "leaf_nodes_exported"}, + float32(count), + []metrics.Label{ + {Name: "module", Value: "distribution"}, + }, + ) + } + return false // continue iteration + }) + if err != nil { + errCh <- fmt.Errorf( + "[worker %d] Error iterating distribution tree for version %d: %w", + workerID, ver, err, + ) + return + } + + localExportCount += count + + fmt.Printf("[worker %d][%s] Finished versions %d: exported %d distribution keys.\n", + workerID, time.Now().Format(time.RFC3339), ver, localExportCount) } - count++ - if count%1000000 == 0 { - fmt.Printf("[%s] SeiDB Archive Migration: Last 1,000,000 iterations. Total scanned: %d, leaf nodes exported: %d\n", time.Now().Format(time.RFC3339), count, leafNodeCount) + fmt.Printf("[worker %d][%s] Finished versions [%d - %d]: exported %d distribution keys.\n", + workerID, time.Now().Format(time.RFC3339), vStart, vEnd, localExportCount) + // Signal that we're done successfully (no error). + errCh <- nil + } + + // Spawn the workers + var currentVersion int64 = startVersion + for i := 0; i < concurrency; i++ { + // Each goroutine gets a range: [currentVersion, currentVersion+chunkSize-1] + // plus we handle any remainder in the last chunk(s). + extra := int64(0) + if i < int(remainder) { + extra = 1 } + workerStart := currentVersion + workerEnd := currentVersion + chunkSize + extra - 1 + if i == concurrency-1 { + // Make sure the last one includes everything up to endVersion + workerEnd = endVersion + } + currentVersion = workerEnd + 1 + + go workerFunc(i, workerStart, workerEnd) } - if err := itr.Error(); err != nil { - fmt.Printf("Iterator error: %+v\n", err) - return fmt.Errorf("iterator error: %w", err) + // Wait for all goroutines to finish + wg.Wait() + + // Check error channel. If any goroutine returned a non-nil error, return that. + close(errCh) + for err := range errCh { + if err != nil { + return err + } } fmt.Printf( "[%s] Completed exporting distribution module from %d to %d. Total keys: %d. Duration: %s\n", - time.Now().Format(time.RFC3339), startVersion, endVersion, leafNodeCount, time.Since(startTime), + time.Now().Format(time.RFC3339), startVersion, endVersion, totalExported, time.Since(startTime), ) fmt.Printf("Finished export at time: %s\n", time.Now().Format(time.RFC3339)) return nil From cd3bef58541acbc0b273778977f54df8dcdcc728 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Mon, 30 Dec 2024 08:11:36 -0800 Subject: [PATCH 09/50] Concurrent export --- tools/migration/ss/migrator.go | 109 ++------------------------------- 1 file changed, 6 insertions(+), 103 deletions(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 9d7241f373..8f9213c5bd 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -59,103 +59,6 @@ func (m *Migrator) Migrate(version int64, homeDir string) error { return nil } -// func exportDistributionLeafNodes( -// db dbm.DB, -// ch chan<- types.RawSnapshotNode, -// startVersion, endVersion int64, -// ) error { -// fmt.Printf("Starting export at time: %s\n", time.Now().Format(time.RFC3339)) - -// // Total counters for logging. -// startTime := time.Now() - -// // for ver := startVersion; ver <= endVersion; ver++ { -// // // Load only the distribution module prefix at this version. -// // tree, err := ReadTree(db, ver, []byte(utils.BuildTreePrefix("distribution"))) -// // if err != nil { -// // fmt.Printf("[%s] Error loading distribution tree at version %d: %s\n", time.Now().Format(time.RFC3339), ver, err.Error()) -// // return err -// // } - -// // var count int -// // _, err = tree.Iterate(func(key, value []byte) bool { -// // // Each leaf node is a single K/V for this version -// // // ch <- types.RawSnapshotNode{ -// // // StoreKey: "distribution", -// // // Key: key, -// // // Value: value, -// // // Version: ver, -// // // } -// // count++ -// // totalExported++ -// // if count%1000000 == 0 { -// // fmt.Printf("[%s] Exported %d distribution keys at version %d so far\n", time.Now().Format(time.RFC3339), count, ver) -// // // Optionally add metrics here if desired. -// // metrics.IncrCounterWithLabels([]string{"sei", "migration", "leaf_nodes_exported"}, float32(count), []metrics.Label{ -// // {Name: "module", Value: "distribution"}, -// // }) -// // } -// // return false // continue iteration -// // }) -// // if err != nil { -// // fmt.Printf("[%s] Error iterating distribution tree for version %d: %s\n", time.Now().Format(time.RFC3339), ver, err.Error()) -// // return err -// // } -// // fmt.Printf("[%s] Finished version %d: exported %d distribution keys.\n", time.Now().Format(time.RFC3339), ver, count) -// // } - -// prefixDB := dbm.NewPrefixDB(db, []byte(utils.BuildRawPrefix("distribution"))) -// var itr dbm.Iterator -// var err error -// leafNodeCount := 0 -// count := 0 - -// // If there is a starting key, seek to it, otherwise start from the beginning -// itr, err = prefixDB.Iterator(nil, nil) - -// if err != nil { -// fmt.Printf("SeiDB Archive Migration: Error creating iterator: %+v\n", err) -// return fmt.Errorf("failed to create iterator: %w", err) -// } -// defer itr.Close() - -// for ; itr.Valid(); itr.Next() { -// value := bytes.Clone(itr.Value()) - -// node, err := iavl.MakeNode(value) -// if err != nil { -// fmt.Printf("SeiDB Archive Migration: Failed to make node: %+v\n", err) -// return fmt.Errorf("failed to make node: %w", err) -// } - -// // Only export leaf nodes -// if node.GetHeight() == 0 { -// version := node.GetVersion() -// if version < startVersion || version > endVersion { -// continue -// } -// leafNodeCount++ -// } - -// count++ -// if count%1000000 == 0 { -// fmt.Printf("[%s] SeiDB Archive Migration: Last 1,000,000 iterations. Total scanned: %d, leaf nodes exported: %d\n", time.Now().Format(time.RFC3339), count, leafNodeCount) -// } -// } - -// if err := itr.Error(); err != nil { -// fmt.Printf("Iterator error: %+v\n", err) -// return fmt.Errorf("iterator error: %w", err) -// } - -// fmt.Printf( -// "[%s] Completed exporting distribution module from %d to %d. Total keys: %d. Duration: %s\n", -// time.Now().Format(time.RFC3339), startVersion, endVersion, leafNodeCount, time.Since(startTime), -// ) -// fmt.Printf("Finished export at time: %s\n", time.Now().Format(time.RFC3339)) -// return nil -// } - func exportDistributionLeafNodes( db dbm.DB, ch chan<- types.RawSnapshotNode, @@ -204,12 +107,12 @@ func exportDistributionLeafNodes( var count int _, err = tree.Iterate(func(key, value []byte) bool { - // ch <- types.RawSnapshotNode{ - // StoreKey: "distribution", - // Key: key, - // Value: value, - // Version: ver, - // } + ch <- types.RawSnapshotNode{ + StoreKey: "distribution", + Key: key, + Value: value, + Version: ver, + } count++ // Use a lock when incrementing total counters mu.Lock() From e3051481e65e4cc4079173d320162589416f7f23 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Tue, 31 Dec 2024 06:57:07 -0800 Subject: [PATCH 10/50] Update to seidb migration --- cmd/seid/cmd/root.go | 2 +- go.mod | 2 +- go.sum | 4 +- tools/migration/cmd/cmd.go | 9 +- tools/migration/ss/migrator.go | 164 +++++++++------------------------ 5 files changed, 54 insertions(+), 127 deletions(-) diff --git a/cmd/seid/cmd/root.go b/cmd/seid/cmd/root.go index 07f9643b1e..c78055cd8d 100644 --- a/cmd/seid/cmd/root.go +++ b/cmd/seid/cmd/root.go @@ -312,7 +312,7 @@ func newApp( homeDir := cast.ToString(appOpts.Get(flags.FlagHome)) stateStore := app.GetStateStore() migrationHeight := cast.ToInt64(appOpts.Get("migrate-height")) - migrator := ss.NewMigrator(db, stateStore) + migrator := ss.NewMigrator(db, stateStore, stateStore) if err := migrator.Migrate(migrationHeight, homeDir); err != nil { panic(err) } diff --git a/go.mod b/go.mod index e1cc5b1b1f..09b60b8a55 100644 --- a/go.mod +++ b/go.mod @@ -352,7 +352,7 @@ replace ( github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-9.0.20241224143343-21ee50facc96 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.46 + github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20241231145352-8d79a16eac25 // Latest goleveldb is broken, we have to stick to this version github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.4.3 diff --git a/go.sum b/go.sum index a33d127827..beaad5d45c 100644 --- a/go.sum +++ b/go.sum @@ -1347,8 +1347,8 @@ github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQp github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8= github.com/sei-protocol/sei-cosmos v0.3.48 h1:kSDweeTaLZ4TByLqAD6/hmtgAhAJHwXU1beyqsVXJkQ= github.com/sei-protocol/sei-cosmos v0.3.48/go.mod h1:XC417pB6NwxP/cQ2XTSZLzVnP8dMZ//4uCXS3SxFgoM= -github.com/sei-protocol/sei-db v0.0.46 h1:naXfSp1I3UgJJm/iSvXpdFzr9nofEOxp/EekcAVj7wY= -github.com/sei-protocol/sei-db v0.0.46/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= +github.com/sei-protocol/sei-db v0.0.47-0.20241231145352-8d79a16eac25 h1:iSD8tiqcsYzTcIbpypCxfNM2HQgnm/xmOCpJslHucNg= +github.com/sei-protocol/sei-db v0.0.47-0.20241231145352-8d79a16eac25/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= github.com/sei-protocol/sei-iavl v0.2.0 h1:OisPjXiDT+oe+aeckzDEFgkZCYuUjHgs/PP8DPicN+I= github.com/sei-protocol/sei-iavl v0.2.0/go.mod h1:qRf8QYUPfrAO7K6VDB2B2l/N7K5L76OorioGBcJBIbw= github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 h1:0kg1giMHiKMLXOCFLqH/9kqdl5bH+unzI8qRF6qwXzw= diff --git a/tools/migration/cmd/cmd.go b/tools/migration/cmd/cmd.go index 6cf47e13fa..611b019d7c 100644 --- a/tools/migration/cmd/cmd.go +++ b/tools/migration/cmd/cmd.go @@ -83,7 +83,12 @@ func migrateSS(version int64, homeDir string, db dbm.DB) error { return err } - migrator := ss.NewMigrator(db, stateStore) + oldStateStore, err := sstypes.NewStateStore(log.NewNopLogger(), "/root/.old_sei", ssConfig) + if err != nil { + return err + } + + migrator := ss.NewMigrator(db, stateStore, oldStateStore) return migrator.Migrate(version, homeDir) } @@ -134,7 +139,7 @@ func verifySS(version int64, homeDir string, db dbm.DB) error { return err } - migrator := ss.NewMigrator(db, stateStore) + migrator := ss.NewMigrator(db, stateStore, stateStore) return migrator.Verify(version) } diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 8f9213c5bd..89df4bbb54 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -3,7 +3,6 @@ package ss import ( "bytes" "fmt" - "sync" "time" "github.com/armon/go-metrics" @@ -14,8 +13,9 @@ import ( ) type Migrator struct { - iavlDB dbm.DB - stateStore types.StateStore + iavlDB dbm.DB + stateStore types.StateStore + oldStateStore types.StateStore } // TODO: make this configurable? @@ -23,10 +23,11 @@ const ( DefaultCacheSize int = 10000 ) -func NewMigrator(db dbm.DB, stateStore types.StateStore) *Migrator { +func NewMigrator(db dbm.DB, stateStore types.StateStore, oldStateStore types.StateStore) *Migrator { return &Migrator{ - iavlDB: db, - stateStore: stateStore, + iavlDB: db, + stateStore: stateStore, + oldStateStore: oldStateStore, } } @@ -41,7 +42,7 @@ func (m *Migrator) Migrate(version int64, homeDir string) error { // Goroutine #1: Export distribution leaf nodes into ch go func() { defer close(ch) - errCh <- exportDistributionLeafNodes(m.iavlDB, ch, 100215000, 106789896, 30) + errCh <- exportDistributionLeafNodes(m.oldStateStore, ch, 100215000, 106789896) }() // Goroutine #2: Import those leaf nodes into PebbleDB @@ -60,136 +61,57 @@ func (m *Migrator) Migrate(version int64, homeDir string) error { } func exportDistributionLeafNodes( - db dbm.DB, + oldStateStore types.StateStore, ch chan<- types.RawSnapshotNode, startVersion, endVersion int64, - concurrency int, ) error { - fmt.Printf("Starting export at time: %s with concurrency=%d\n", time.Now().Format(time.RFC3339), concurrency) - - if concurrency < 1 { - concurrency = 1 - } - - // We'll collect errors from each goroutine in a separate error channel - errCh := make(chan error, concurrency) - - totalVersions := endVersion - startVersion + 1 - // Basic integer division to split up the version range - chunkSize := totalVersions / int64(concurrency) - remainder := totalVersions % int64(concurrency) - - var wg sync.WaitGroup - wg.Add(concurrency) + fmt.Printf("Starting export at %s for versions [%d..%d]\n", + time.Now().Format(time.RFC3339), startVersion, endVersion, + ) + var totalExported int startTime := time.Now() - // Atomic or shared counters for tracking exports - var mu sync.Mutex - totalExported := 0 - - // Helper function that each goroutine will run - workerFunc := func(workerID int, vStart, vEnd int64) { - defer wg.Done() - - // Local counter - localExportCount := 0 - - for ver := vStart; ver <= vEnd; ver++ { - // Load only the distribution module prefix at this version. - tree, err := ReadTree(db, ver, []byte(utils.BuildTreePrefix("distribution"))) - if err != nil { - errCh <- fmt.Errorf( - "[worker %d] Error loading distribution tree at version %d: %w", - workerID, ver, err, - ) - return - } - - var count int - _, err = tree.Iterate(func(key, value []byte) bool { - ch <- types.RawSnapshotNode{ - StoreKey: "distribution", - Key: key, - Value: value, - Version: ver, - } - count++ - // Use a lock when incrementing total counters - mu.Lock() - totalExported++ - mu.Unlock() - - // Logging / metrics every 1,000,000 keys in this version subset - if count%1000000 == 0 { - fmt.Printf("[worker %d][%s] Exported %d distribution keys at version %d so far\n", - workerID, time.Now().Format(time.RFC3339), count, ver, - ) - metrics.IncrCounterWithLabels( - []string{"sei", "migration", "leaf_nodes_exported"}, - float32(count), - []metrics.Label{ - {Name: "module", Value: "distribution"}, - }, - ) - } - return false // continue iteration - }) - if err != nil { - errCh <- fmt.Errorf( - "[worker %d] Error iterating distribution tree for version %d: %w", - workerID, ver, err, - ) - return - } - - localExportCount += count - fmt.Printf("[worker %d][%s] Finished versions %d: exported %d distribution keys.\n", - workerID, time.Now().Format(time.RFC3339), ver, localExportCount) + // RawIterate will scan *all* keys in the "distribution" store. + // We'll filter them by version in the callback. + stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { + // If the record’s version is outside our desired range, skip it. + if version < startVersion || version > endVersion { + return false // false => keep iterating } - fmt.Printf("[worker %d][%s] Finished versions [%d - %d]: exported %d distribution keys.\n", - workerID, time.Now().Format(time.RFC3339), vStart, vEnd, localExportCount) - // Signal that we're done successfully (no error). - errCh <- nil - } - - // Spawn the workers - var currentVersion int64 = startVersion - for i := 0; i < concurrency; i++ { - // Each goroutine gets a range: [currentVersion, currentVersion+chunkSize-1] - // plus we handle any remainder in the last chunk(s). - extra := int64(0) - if i < int(remainder) { - extra = 1 - } - workerStart := currentVersion - workerEnd := currentVersion + chunkSize + extra - 1 - if i == concurrency-1 { - // Make sure the last one includes everything up to endVersion - workerEnd = endVersion + // Otherwise, export it via the channel. + ch <- types.RawSnapshotNode{ + StoreKey: "distribution", + Key: key, + Value: value, + Version: version, } - currentVersion = workerEnd + 1 - go workerFunc(i, workerStart, workerEnd) - } - - // Wait for all goroutines to finish - wg.Wait() - - // Check error channel. If any goroutine returned a non-nil error, return that. - close(errCh) - for err := range errCh { - if err != nil { - return err + totalExported++ + // Optional progress logging every 1,000,000 keys: + if totalExported%1_000_000 == 0 { + fmt.Printf("[SingleWorker][%s] Exported %d distribution keys so far\n", + time.Now().Format(time.RFC3339), totalExported, + ) } + // Return false to continue iterating + return false + }) + if err != nil { + return fmt.Errorf("RawIterate error: %w", err) + } + if stop { + fmt.Printf("[SingleWorker][%s] Iteration stopped early; callback returned true at some point.\n", + time.Now().Format(time.RFC3339), + ) } fmt.Printf( - "[%s] Completed exporting distribution module from %d to %d. Total keys: %d. Duration: %s\n", + "[%s] Completed exporting distribution store for versions [%d..%d]. Total keys: %d. Duration: %s\n", time.Now().Format(time.RFC3339), startVersion, endVersion, totalExported, time.Since(startTime), ) - fmt.Printf("Finished export at time: %s\n", time.Now().Format(time.RFC3339)) + fmt.Printf("Finished export at %s\n", time.Now().Format(time.RFC3339)) return nil } From 8e51c4426c0eba25cd1a48f22c8541d0fc6d0c71 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Tue, 31 Dec 2024 06:58:06 -0800 Subject: [PATCH 11/50] Test --- tools/migration/ss/migrator.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 89df4bbb54..e20a89858b 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -81,12 +81,12 @@ func exportDistributionLeafNodes( } // Otherwise, export it via the channel. - ch <- types.RawSnapshotNode{ - StoreKey: "distribution", - Key: key, - Value: value, - Version: version, - } + // ch <- types.RawSnapshotNode{ + // StoreKey: "distribution", + // Key: key, + // Value: value, + // Version: version, + // } totalExported++ // Optional progress logging every 1,000,000 keys: From a5e47baace966295433715056f45b161d07875cc Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Tue, 31 Dec 2024 07:04:01 -0800 Subject: [PATCH 12/50] More dense logging --- tools/migration/ss/migrator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index e20a89858b..ba559d9ac6 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -90,7 +90,7 @@ func exportDistributionLeafNodes( totalExported++ // Optional progress logging every 1,000,000 keys: - if totalExported%1_000_000 == 0 { + if totalExported%100_000 == 0 { fmt.Printf("[SingleWorker][%s] Exported %d distribution keys so far\n", time.Now().Format(time.RFC3339), totalExported, ) From 36004b5255a476183eb0ed662503a1783e29b79f Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Tue, 31 Dec 2024 07:06:02 -0800 Subject: [PATCH 13/50] More dense --- tools/migration/ss/migrator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index ba559d9ac6..c87b4cc231 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -90,7 +90,7 @@ func exportDistributionLeafNodes( totalExported++ // Optional progress logging every 1,000,000 keys: - if totalExported%100_000 == 0 { + if totalExported%10_000 == 0 { fmt.Printf("[SingleWorker][%s] Exported %d distribution keys so far\n", time.Now().Format(time.RFC3339), totalExported, ) From 0dd34fab82087cd92b734e331efdca02b4a9a092 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Tue, 31 Dec 2024 07:30:08 -0800 Subject: [PATCH 14/50] Update seidb --- go.mod | 2 +- tools/migration/ss/migrator.go | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 09b60b8a55..6b0f67a99d 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( github.com/rs/cors v1.8.2 github.com/rs/zerolog v1.30.0 github.com/sei-protocol/goutils v0.0.2 - github.com/sei-protocol/sei-db v0.0.27-0.20240123064153-d6dfa112e760 + github.com/sei-protocol/sei-db v0.0.47-0.20241231152822-f02af9285b76 github.com/sirkon/goproxy v1.4.8 github.com/spf13/cast v1.5.0 github.com/spf13/cobra v1.6.1 diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index c87b4cc231..fcaefd3722 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -75,9 +75,10 @@ func exportDistributionLeafNodes( // RawIterate will scan *all* keys in the "distribution" store. // We'll filter them by version in the callback. stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { - // If the record’s version is outside our desired range, skip it. + // If the record's version is outside our desired range, skip it. + // fmt.Printf("Processing key: %s, value: %s, version: %d\n", string(key), string(value), version) if version < startVersion || version > endVersion { - return false // false => keep iterating + return false } // Otherwise, export it via the channel. From 929e5750be46c1c56b096a640b5955808cbe4ba3 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Tue, 31 Dec 2024 07:38:07 -0800 Subject: [PATCH 15/50] More logging --- go.mod | 2 +- go.sum | 4 ++-- tools/migration/ss/migrator.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 6b0f67a99d..2e647bad38 100644 --- a/go.mod +++ b/go.mod @@ -352,7 +352,7 @@ replace ( github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-9.0.20241224143343-21ee50facc96 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20241231145352-8d79a16eac25 + github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20241231153656-092c25d52072 // Latest goleveldb is broken, we have to stick to this version github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.4.3 diff --git a/go.sum b/go.sum index beaad5d45c..f19699aeff 100644 --- a/go.sum +++ b/go.sum @@ -1347,8 +1347,8 @@ github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQp github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8= github.com/sei-protocol/sei-cosmos v0.3.48 h1:kSDweeTaLZ4TByLqAD6/hmtgAhAJHwXU1beyqsVXJkQ= github.com/sei-protocol/sei-cosmos v0.3.48/go.mod h1:XC417pB6NwxP/cQ2XTSZLzVnP8dMZ//4uCXS3SxFgoM= -github.com/sei-protocol/sei-db v0.0.47-0.20241231145352-8d79a16eac25 h1:iSD8tiqcsYzTcIbpypCxfNM2HQgnm/xmOCpJslHucNg= -github.com/sei-protocol/sei-db v0.0.47-0.20241231145352-8d79a16eac25/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= +github.com/sei-protocol/sei-db v0.0.47-0.20241231153656-092c25d52072 h1:aoP/0zPDAs39BXT7hFfqW29XBYcWYp0Vn8b5OhyZGWM= +github.com/sei-protocol/sei-db v0.0.47-0.20241231153656-092c25d52072/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= github.com/sei-protocol/sei-iavl v0.2.0 h1:OisPjXiDT+oe+aeckzDEFgkZCYuUjHgs/PP8DPicN+I= github.com/sei-protocol/sei-iavl v0.2.0/go.mod h1:qRf8QYUPfrAO7K6VDB2B2l/N7K5L76OorioGBcJBIbw= github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 h1:0kg1giMHiKMLXOCFLqH/9kqdl5bH+unzI8qRF6qwXzw= diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index fcaefd3722..6ded4e79b1 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -76,7 +76,7 @@ func exportDistributionLeafNodes( // We'll filter them by version in the callback. stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { // If the record's version is outside our desired range, skip it. - // fmt.Printf("Processing key: %s, value: %s, version: %d\n", string(key), string(value), version) + fmt.Printf("Processing key: %s, value: %s, version: %d\n", string(key), string(value), version) if version < startVersion || version > endVersion { return false } From 9faf21a8471e6ad2f28152810cd947f6d5075248 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Tue, 31 Dec 2024 07:41:29 -0800 Subject: [PATCH 16/50] Remove log --- tools/migration/ss/migrator.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 6ded4e79b1..02c1c7b8f7 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -76,7 +76,6 @@ func exportDistributionLeafNodes( // We'll filter them by version in the callback. stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { // If the record's version is outside our desired range, skip it. - fmt.Printf("Processing key: %s, value: %s, version: %d\n", string(key), string(value), version) if version < startVersion || version > endVersion { return false } From 6000bd2e89b079bc87847f1c6bd628b9d55e6123 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Tue, 31 Dec 2024 07:43:42 -0800 Subject: [PATCH 17/50] Every million log --- tools/migration/ss/migrator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 02c1c7b8f7..9f4c355057 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -90,7 +90,7 @@ func exportDistributionLeafNodes( totalExported++ // Optional progress logging every 1,000,000 keys: - if totalExported%10_000 == 0 { + if totalExported%1_000_000 == 0 { fmt.Printf("[SingleWorker][%s] Exported %d distribution keys so far\n", time.Now().Format(time.RFC3339), totalExported, ) From f47a2af214f38b56611f16e2d89c9c8fa1eea9a7 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Tue, 31 Dec 2024 07:48:17 -0800 Subject: [PATCH 18/50] Update --- go.mod | 2 +- go.sum | 4 ++-- tools/migration/cmd/cmd.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 2e647bad38..e0488ce9d6 100644 --- a/go.mod +++ b/go.mod @@ -352,7 +352,7 @@ replace ( github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-9.0.20241224143343-21ee50facc96 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20241231153656-092c25d52072 + github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20241231154605-e29a09b9faa8 // Latest goleveldb is broken, we have to stick to this version github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.4.3 diff --git a/go.sum b/go.sum index f19699aeff..dc2b43cf19 100644 --- a/go.sum +++ b/go.sum @@ -1347,8 +1347,8 @@ github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQp github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8= github.com/sei-protocol/sei-cosmos v0.3.48 h1:kSDweeTaLZ4TByLqAD6/hmtgAhAJHwXU1beyqsVXJkQ= github.com/sei-protocol/sei-cosmos v0.3.48/go.mod h1:XC417pB6NwxP/cQ2XTSZLzVnP8dMZ//4uCXS3SxFgoM= -github.com/sei-protocol/sei-db v0.0.47-0.20241231153656-092c25d52072 h1:aoP/0zPDAs39BXT7hFfqW29XBYcWYp0Vn8b5OhyZGWM= -github.com/sei-protocol/sei-db v0.0.47-0.20241231153656-092c25d52072/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= +github.com/sei-protocol/sei-db v0.0.47-0.20241231154605-e29a09b9faa8 h1:fcbSw66ILFwfPVVWe0uhhmAb6bhN4kWX6DMTqhti8SM= +github.com/sei-protocol/sei-db v0.0.47-0.20241231154605-e29a09b9faa8/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= github.com/sei-protocol/sei-iavl v0.2.0 h1:OisPjXiDT+oe+aeckzDEFgkZCYuUjHgs/PP8DPicN+I= github.com/sei-protocol/sei-iavl v0.2.0/go.mod h1:qRf8QYUPfrAO7K6VDB2B2l/N7K5L76OorioGBcJBIbw= github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 h1:0kg1giMHiKMLXOCFLqH/9kqdl5bH+unzI8qRF6qwXzw= diff --git a/tools/migration/cmd/cmd.go b/tools/migration/cmd/cmd.go index 611b019d7c..aeb4c3b5c2 100644 --- a/tools/migration/cmd/cmd.go +++ b/tools/migration/cmd/cmd.go @@ -24,7 +24,7 @@ func MigrateCmd() *cobra.Command { Short: "A tool to migrate full IAVL data store to SeiDB. Use this tool to migrate IAVL to SeiDB SC and SS database.", Run: execute, } - cmd.PersistentFlags().String("home-dir", "/root/.sei", "Sei home directory") + cmd.PersistentFlags().String("home-dir", "/root/.old_sei", "Sei home directory") return cmd } @@ -83,7 +83,7 @@ func migrateSS(version int64, homeDir string, db dbm.DB) error { return err } - oldStateStore, err := sstypes.NewStateStore(log.NewNopLogger(), "/root/.old_sei", ssConfig) + oldStateStore, err := sstypes.NewStateStore(log.NewNopLogger(), "/root/.sei", ssConfig) if err != nil { return err } From ad12d1759a293df97229111faa1b56823af608ec Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Tue, 31 Dec 2024 07:49:34 -0800 Subject: [PATCH 19/50] Correct home dir --- tools/migration/cmd/cmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/migration/cmd/cmd.go b/tools/migration/cmd/cmd.go index aeb4c3b5c2..412bddab7f 100644 --- a/tools/migration/cmd/cmd.go +++ b/tools/migration/cmd/cmd.go @@ -54,7 +54,7 @@ func MigrateSSCmd() *cobra.Command { Short: "A tool to migrate full ss distribution module", Run: executeSS, } - cmd.PersistentFlags().String("home-dir", "/root/.sei", "Sei home directory") + cmd.PersistentFlags().String("home-dir", "/root/.old_sei", "Sei home directory") return cmd } From 2ecf3e9fa6550d50ba98ce480d81a35b9dbe21cd Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Tue, 31 Dec 2024 08:06:36 -0800 Subject: [PATCH 20/50] Update to write --- tools/migration/ss/migrator.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 9f4c355057..1c9e26f5b7 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -81,12 +81,12 @@ func exportDistributionLeafNodes( } // Otherwise, export it via the channel. - // ch <- types.RawSnapshotNode{ - // StoreKey: "distribution", - // Key: key, - // Value: value, - // Version: version, - // } + ch <- types.RawSnapshotNode{ + StoreKey: "distribution", + Key: key, + Value: value, + Version: version, + } totalExported++ // Optional progress logging every 1,000,000 keys: From 5db3504dc1be09a18ddfef613d89f95dadd64bd7 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Sun, 5 Jan 2025 09:33:13 -0500 Subject: [PATCH 21/50] Update whole distribution --- go.mod | 2 +- go.sum | 4 ++-- tools/migration/ss/migrator.go | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index e0488ce9d6..34aa327bdf 100644 --- a/go.mod +++ b/go.mod @@ -352,7 +352,7 @@ replace ( github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-9.0.20241224143343-21ee50facc96 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20241231154605-e29a09b9faa8 + github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250105142248-40df232f7c9c // Latest goleveldb is broken, we have to stick to this version github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.4.3 diff --git a/go.sum b/go.sum index dc2b43cf19..4b6beb7afe 100644 --- a/go.sum +++ b/go.sum @@ -1347,8 +1347,8 @@ github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQp github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8= github.com/sei-protocol/sei-cosmos v0.3.48 h1:kSDweeTaLZ4TByLqAD6/hmtgAhAJHwXU1beyqsVXJkQ= github.com/sei-protocol/sei-cosmos v0.3.48/go.mod h1:XC417pB6NwxP/cQ2XTSZLzVnP8dMZ//4uCXS3SxFgoM= -github.com/sei-protocol/sei-db v0.0.47-0.20241231154605-e29a09b9faa8 h1:fcbSw66ILFwfPVVWe0uhhmAb6bhN4kWX6DMTqhti8SM= -github.com/sei-protocol/sei-db v0.0.47-0.20241231154605-e29a09b9faa8/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= +github.com/sei-protocol/sei-db v0.0.47-0.20250105142248-40df232f7c9c h1:IB3mhlNntxpebBfb7tu/Qgpk6v5t91SGfWsKSvUIbmQ= +github.com/sei-protocol/sei-db v0.0.47-0.20250105142248-40df232f7c9c/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= github.com/sei-protocol/sei-iavl v0.2.0 h1:OisPjXiDT+oe+aeckzDEFgkZCYuUjHgs/PP8DPicN+I= github.com/sei-protocol/sei-iavl v0.2.0/go.mod h1:qRf8QYUPfrAO7K6VDB2B2l/N7K5L76OorioGBcJBIbw= github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 h1:0kg1giMHiKMLXOCFLqH/9kqdl5bH+unzI8qRF6qwXzw= diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 1c9e26f5b7..52fd76b742 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -76,9 +76,9 @@ func exportDistributionLeafNodes( // We'll filter them by version in the callback. stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { // If the record's version is outside our desired range, skip it. - if version < startVersion || version > endVersion { - return false - } + // if version < startVersion || version > endVersion { + // return false + // } // Otherwise, export it via the channel. ch <- types.RawSnapshotNode{ From 373d424fb32d9a62aa9b77843678d8050d83b51c Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Tue, 7 Jan 2025 22:59:40 -0500 Subject: [PATCH 22/50] Verify distribution --- tools/migration/ss/migrator.go | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 52fd76b742..e5a0a835c5 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -42,16 +42,11 @@ func (m *Migrator) Migrate(version int64, homeDir string) error { // Goroutine #1: Export distribution leaf nodes into ch go func() { defer close(ch) - errCh <- exportDistributionLeafNodes(m.oldStateStore, ch, 100215000, 106789896) - }() - - // Goroutine #2: Import those leaf nodes into PebbleDB - go func() { - errCh <- m.stateStore.RawImport(ch) + errCh <- exportDistributionLeafNodes(m.oldStateStore, m.stateStore, ch, 100215000, 106789896) }() // Wait for both goroutines to complete - for i := 0; i < 2; i++ { + for i := 0; i < 1; i++ { if err := <-errCh; err != nil { return err } @@ -62,6 +57,7 @@ func (m *Migrator) Migrate(version int64, homeDir string) error { func exportDistributionLeafNodes( oldStateStore types.StateStore, + newStateStore types.StateStore, ch chan<- types.RawSnapshotNode, startVersion, endVersion int64, ) error { @@ -70,29 +66,27 @@ func exportDistributionLeafNodes( ) var totalExported int + var totalMismatch int startTime := time.Now() // RawIterate will scan *all* keys in the "distribution" store. // We'll filter them by version in the callback. stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { - // If the record's version is outside our desired range, skip it. - // if version < startVersion || version > endVersion { - // return false - // } - - // Otherwise, export it via the channel. - ch <- types.RawSnapshotNode{ - StoreKey: "distribution", - Key: key, - Value: value, - Version: version, + bz, errorInner := newStateStore.Get("distribution", version, key) + if errorInner != nil { + panic(errorInner) + } + + if !bytes.Equal(bz, value) { + totalMismatch++ + fmt.Printf("values don't match for key %x: expected %s, got %s\n", key, string(value), string(bz)) } totalExported++ // Optional progress logging every 1,000,000 keys: if totalExported%1_000_000 == 0 { - fmt.Printf("[SingleWorker][%s] Exported %d distribution keys so far\n", - time.Now().Format(time.RFC3339), totalExported, + fmt.Printf("[SingleWorker][%s] Verified %d distribution keys so far mismatch %d\n", + time.Now().Format(time.RFC3339), totalExported, totalMismatch, ) } // Return false to continue iterating From 9c90cb3c6439ac315b87e8bc1d200eaf98d3853c Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Wed, 8 Jan 2025 09:43:50 -0500 Subject: [PATCH 23/50] Update to set on each mismatch --- app/test_state_store.go | 4 ++++ go.mod | 2 +- go.sum | 4 ++-- tools/migration/ss/migrator.go | 15 ++++++++++++++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/test_state_store.go b/app/test_state_store.go index 194390f863..c6750123b3 100644 --- a/app/test_state_store.go +++ b/app/test_state_store.go @@ -65,6 +65,10 @@ func (s *InMemoryStateStore) Has(storeKey string, version int64, key []byte) (bo return ok, nil } +func (db *InMemoryStateStore) Set(storeKey string, key, value []byte, version int64) error { + return nil +} + func (s *InMemoryStateStore) Iterator(storeKey string, version int64, start, end []byte) (types.DBIterator, error) { s.mu.RLock() defer s.mu.RUnlock() diff --git a/go.mod b/go.mod index 34aa327bdf..d64cf0f224 100644 --- a/go.mod +++ b/go.mod @@ -352,7 +352,7 @@ replace ( github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-9.0.20241224143343-21ee50facc96 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250105142248-40df232f7c9c + github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250108143409-8223beaedd9e // Latest goleveldb is broken, we have to stick to this version github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.4.3 diff --git a/go.sum b/go.sum index 4b6beb7afe..fea18b0512 100644 --- a/go.sum +++ b/go.sum @@ -1347,8 +1347,8 @@ github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQp github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8= github.com/sei-protocol/sei-cosmos v0.3.48 h1:kSDweeTaLZ4TByLqAD6/hmtgAhAJHwXU1beyqsVXJkQ= github.com/sei-protocol/sei-cosmos v0.3.48/go.mod h1:XC417pB6NwxP/cQ2XTSZLzVnP8dMZ//4uCXS3SxFgoM= -github.com/sei-protocol/sei-db v0.0.47-0.20250105142248-40df232f7c9c h1:IB3mhlNntxpebBfb7tu/Qgpk6v5t91SGfWsKSvUIbmQ= -github.com/sei-protocol/sei-db v0.0.47-0.20250105142248-40df232f7c9c/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= +github.com/sei-protocol/sei-db v0.0.47-0.20250108143409-8223beaedd9e h1:FD6thieZBi6w967fp0wL75hxnUTqNeVulQar4L156hM= +github.com/sei-protocol/sei-db v0.0.47-0.20250108143409-8223beaedd9e/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= github.com/sei-protocol/sei-iavl v0.2.0 h1:OisPjXiDT+oe+aeckzDEFgkZCYuUjHgs/PP8DPicN+I= github.com/sei-protocol/sei-iavl v0.2.0/go.mod h1:qRf8QYUPfrAO7K6VDB2B2l/N7K5L76OorioGBcJBIbw= github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 h1:0kg1giMHiKMLXOCFLqH/9kqdl5bH+unzI8qRF6qwXzw= diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index e5a0a835c5..90ec1ca91d 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -79,7 +79,20 @@ func exportDistributionLeafNodes( if !bytes.Equal(bz, value) { totalMismatch++ - fmt.Printf("values don't match for key %x: expected %s, got %s\n", key, string(value), string(bz)) + fmt.Printf("values don't match for key %s: expected %s, got %s\n", string(key), string(value), string(bz)) + + if err := newStateStore.Set("distribution", key, value, version); err != nil { + panic(err) + } + + // Verify the write was successful + verifyBz, verifyErr := newStateStore.Get("distribution", version, key) + if verifyErr != nil { + panic(fmt.Errorf("failed to verify write: %w", verifyErr)) + } + if !bytes.Equal(verifyBz, value) { + panic(fmt.Errorf("write verification failed: value mismatch after Set")) + } } totalExported++ From 94b196e33b10a395dc7549401a4fc13a189b96a5 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Thu, 9 Jan 2025 09:52:31 -0500 Subject: [PATCH 24/50] Only update specific versions --- tools/migration/ss/migrator.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 90ec1ca91d..3fb7ab69f8 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -67,11 +67,24 @@ func exportDistributionLeafNodes( var totalExported int var totalMismatch int + var catchupCounter int startTime := time.Now() // RawIterate will scan *all* keys in the "distribution" store. // We'll filter them by version in the callback. stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { + catchupCounter++ + if catchupCounter%1_000_000 == 0 { + fmt.Printf("[%s] Caught up %d distribution keys\n", + time.Now().Format(time.RFC3339), catchupCounter, + ) + } + if catchupCounter < 437000000 { + return false + } + if version >= 121234732 { + return false + } bz, errorInner := newStateStore.Get("distribution", version, key) if errorInner != nil { panic(errorInner) From ebe673b92297f958f4dfb26f094e2c8dbd230ccb Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Thu, 9 Jan 2025 10:18:15 -0500 Subject: [PATCH 25/50] new catchup --- tools/migration/ss/migrator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 3fb7ab69f8..dd1c0fbd63 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -79,7 +79,7 @@ func exportDistributionLeafNodes( time.Now().Format(time.RFC3339), catchupCounter, ) } - if catchupCounter < 437000000 { + if catchupCounter < 446000000 { return false } if version >= 121234732 { From 4b99f79f9df45f495938db48f5ded855e33f4b21 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Thu, 9 Jan 2025 11:50:39 -0500 Subject: [PATCH 26/50] Raw iterate versions --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d64cf0f224..6a6e1fb95c 100644 --- a/go.mod +++ b/go.mod @@ -352,7 +352,7 @@ replace ( github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-9.0.20241224143343-21ee50facc96 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250108143409-8223beaedd9e + github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250109164622-26a32eba3067 // Latest goleveldb is broken, we have to stick to this version github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.4.3 diff --git a/go.sum b/go.sum index fea18b0512..a75604fe34 100644 --- a/go.sum +++ b/go.sum @@ -1347,8 +1347,8 @@ github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQp github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8= github.com/sei-protocol/sei-cosmos v0.3.48 h1:kSDweeTaLZ4TByLqAD6/hmtgAhAJHwXU1beyqsVXJkQ= github.com/sei-protocol/sei-cosmos v0.3.48/go.mod h1:XC417pB6NwxP/cQ2XTSZLzVnP8dMZ//4uCXS3SxFgoM= -github.com/sei-protocol/sei-db v0.0.47-0.20250108143409-8223beaedd9e h1:FD6thieZBi6w967fp0wL75hxnUTqNeVulQar4L156hM= -github.com/sei-protocol/sei-db v0.0.47-0.20250108143409-8223beaedd9e/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= +github.com/sei-protocol/sei-db v0.0.47-0.20250109164622-26a32eba3067 h1:YWnro9cwq7ORmqLDX0bGm6jcLZ4bsQibN4qWIGQIdl8= +github.com/sei-protocol/sei-db v0.0.47-0.20250109164622-26a32eba3067/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= github.com/sei-protocol/sei-iavl v0.2.0 h1:OisPjXiDT+oe+aeckzDEFgkZCYuUjHgs/PP8DPicN+I= github.com/sei-protocol/sei-iavl v0.2.0/go.mod h1:qRf8QYUPfrAO7K6VDB2B2l/N7K5L76OorioGBcJBIbw= github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 h1:0kg1giMHiKMLXOCFLqH/9kqdl5bH+unzI8qRF6qwXzw= From 60145e8e07a794ea76ba4bd6660fcbc522404765 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Thu, 9 Jan 2025 11:52:00 -0500 Subject: [PATCH 27/50] update version --- tools/migration/ss/migrator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index dd1c0fbd63..e9361b88a7 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -79,7 +79,7 @@ func exportDistributionLeafNodes( time.Now().Format(time.RFC3339), catchupCounter, ) } - if catchupCounter < 446000000 { + if catchupCounter < 475000000 { return false } if version >= 121234732 { From 2d36b02d5363a938dda2575c4c27631d78a6cf9b Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Thu, 9 Jan 2025 11:58:06 -0500 Subject: [PATCH 28/50] Update --- go.mod | 2 +- go.sum | 4 ++-- tools/migration/ss/migrator.go | 10 ---------- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index 6a6e1fb95c..2ac87a6d3e 100644 --- a/go.mod +++ b/go.mod @@ -352,7 +352,7 @@ replace ( github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-9.0.20241224143343-21ee50facc96 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250109164622-26a32eba3067 + github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250109165643-a92fd8471157 // Latest goleveldb is broken, we have to stick to this version github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.4.3 diff --git a/go.sum b/go.sum index a75604fe34..f2e4e0e09f 100644 --- a/go.sum +++ b/go.sum @@ -1347,8 +1347,8 @@ github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQp github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8= github.com/sei-protocol/sei-cosmos v0.3.48 h1:kSDweeTaLZ4TByLqAD6/hmtgAhAJHwXU1beyqsVXJkQ= github.com/sei-protocol/sei-cosmos v0.3.48/go.mod h1:XC417pB6NwxP/cQ2XTSZLzVnP8dMZ//4uCXS3SxFgoM= -github.com/sei-protocol/sei-db v0.0.47-0.20250109164622-26a32eba3067 h1:YWnro9cwq7ORmqLDX0bGm6jcLZ4bsQibN4qWIGQIdl8= -github.com/sei-protocol/sei-db v0.0.47-0.20250109164622-26a32eba3067/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= +github.com/sei-protocol/sei-db v0.0.47-0.20250109165643-a92fd8471157 h1:4fmDdHr/uabqkQL7DlsIo7l1JTykDc24Ci7RERhbzTY= +github.com/sei-protocol/sei-db v0.0.47-0.20250109165643-a92fd8471157/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= github.com/sei-protocol/sei-iavl v0.2.0 h1:OisPjXiDT+oe+aeckzDEFgkZCYuUjHgs/PP8DPicN+I= github.com/sei-protocol/sei-iavl v0.2.0/go.mod h1:qRf8QYUPfrAO7K6VDB2B2l/N7K5L76OorioGBcJBIbw= github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 h1:0kg1giMHiKMLXOCFLqH/9kqdl5bH+unzI8qRF6qwXzw= diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index e9361b88a7..a8149c0686 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -67,21 +67,11 @@ func exportDistributionLeafNodes( var totalExported int var totalMismatch int - var catchupCounter int startTime := time.Now() // RawIterate will scan *all* keys in the "distribution" store. // We'll filter them by version in the callback. stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { - catchupCounter++ - if catchupCounter%1_000_000 == 0 { - fmt.Printf("[%s] Caught up %d distribution keys\n", - time.Now().Format(time.RFC3339), catchupCounter, - ) - } - if catchupCounter < 475000000 { - return false - } if version >= 121234732 { return false } From 2cbe6056b90dd66330c3b8f30c28fcfef7a6e14d Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Thu, 9 Jan 2025 12:01:39 -0500 Subject: [PATCH 29/50] Update seidb --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 2ac87a6d3e..cb1ea6c28f 100644 --- a/go.mod +++ b/go.mod @@ -352,7 +352,7 @@ replace ( github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-9.0.20241224143343-21ee50facc96 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250109165643-a92fd8471157 + github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250109170047-957853583630 // Latest goleveldb is broken, we have to stick to this version github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.4.3 diff --git a/go.sum b/go.sum index f2e4e0e09f..d641d7ceea 100644 --- a/go.sum +++ b/go.sum @@ -1347,8 +1347,8 @@ github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQp github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8= github.com/sei-protocol/sei-cosmos v0.3.48 h1:kSDweeTaLZ4TByLqAD6/hmtgAhAJHwXU1beyqsVXJkQ= github.com/sei-protocol/sei-cosmos v0.3.48/go.mod h1:XC417pB6NwxP/cQ2XTSZLzVnP8dMZ//4uCXS3SxFgoM= -github.com/sei-protocol/sei-db v0.0.47-0.20250109165643-a92fd8471157 h1:4fmDdHr/uabqkQL7DlsIo7l1JTykDc24Ci7RERhbzTY= -github.com/sei-protocol/sei-db v0.0.47-0.20250109165643-a92fd8471157/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= +github.com/sei-protocol/sei-db v0.0.47-0.20250109170047-957853583630 h1:sXjuZrvPPfiXafMEMiRzSsJfeADnsCfrdvw8VJUbd2k= +github.com/sei-protocol/sei-db v0.0.47-0.20250109170047-957853583630/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= github.com/sei-protocol/sei-iavl v0.2.0 h1:OisPjXiDT+oe+aeckzDEFgkZCYuUjHgs/PP8DPicN+I= github.com/sei-protocol/sei-iavl v0.2.0/go.mod h1:qRf8QYUPfrAO7K6VDB2B2l/N7K5L76OorioGBcJBIbw= github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 h1:0kg1giMHiKMLXOCFLqH/9kqdl5bH+unzI8qRF6qwXzw= From e5e45083d3b7736f84b9e6dd5b96c5a22e89db39 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Thu, 9 Jan 2025 13:39:02 -0500 Subject: [PATCH 30/50] more logging --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index cb1ea6c28f..9b527981a2 100644 --- a/go.mod +++ b/go.mod @@ -352,7 +352,7 @@ replace ( github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-9.0.20241224143343-21ee50facc96 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250109170047-957853583630 + github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250109183730-81c5c6f3c856 // Latest goleveldb is broken, we have to stick to this version github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.4.3 diff --git a/go.sum b/go.sum index d641d7ceea..1f5da1e4c5 100644 --- a/go.sum +++ b/go.sum @@ -1347,8 +1347,8 @@ github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQp github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8= github.com/sei-protocol/sei-cosmos v0.3.48 h1:kSDweeTaLZ4TByLqAD6/hmtgAhAJHwXU1beyqsVXJkQ= github.com/sei-protocol/sei-cosmos v0.3.48/go.mod h1:XC417pB6NwxP/cQ2XTSZLzVnP8dMZ//4uCXS3SxFgoM= -github.com/sei-protocol/sei-db v0.0.47-0.20250109170047-957853583630 h1:sXjuZrvPPfiXafMEMiRzSsJfeADnsCfrdvw8VJUbd2k= -github.com/sei-protocol/sei-db v0.0.47-0.20250109170047-957853583630/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= +github.com/sei-protocol/sei-db v0.0.47-0.20250109183730-81c5c6f3c856 h1:qej2gcxbtggeppJiZ6t+e7huOAUqpDfZzK8MvADzejw= +github.com/sei-protocol/sei-db v0.0.47-0.20250109183730-81c5c6f3c856/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= github.com/sei-protocol/sei-iavl v0.2.0 h1:OisPjXiDT+oe+aeckzDEFgkZCYuUjHgs/PP8DPicN+I= github.com/sei-protocol/sei-iavl v0.2.0/go.mod h1:qRf8QYUPfrAO7K6VDB2B2l/N7K5L76OorioGBcJBIbw= github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 h1:0kg1giMHiKMLXOCFLqH/9kqdl5bH+unzI8qRF6qwXzw= From 73bfe135db74f94f45add0bfbb65e2129f19c9e8 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Thu, 9 Jan 2025 13:44:56 -0500 Subject: [PATCH 31/50] Bump seidb --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 9b527981a2..70f13a5075 100644 --- a/go.mod +++ b/go.mod @@ -352,7 +352,7 @@ replace ( github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-9.0.20241224143343-21ee50facc96 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250109183730-81c5c6f3c856 + github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250109184418-96b286395aa7 // Latest goleveldb is broken, we have to stick to this version github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.4.3 diff --git a/go.sum b/go.sum index 1f5da1e4c5..c11d0d5520 100644 --- a/go.sum +++ b/go.sum @@ -1347,8 +1347,8 @@ github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQp github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8= github.com/sei-protocol/sei-cosmos v0.3.48 h1:kSDweeTaLZ4TByLqAD6/hmtgAhAJHwXU1beyqsVXJkQ= github.com/sei-protocol/sei-cosmos v0.3.48/go.mod h1:XC417pB6NwxP/cQ2XTSZLzVnP8dMZ//4uCXS3SxFgoM= -github.com/sei-protocol/sei-db v0.0.47-0.20250109183730-81c5c6f3c856 h1:qej2gcxbtggeppJiZ6t+e7huOAUqpDfZzK8MvADzejw= -github.com/sei-protocol/sei-db v0.0.47-0.20250109183730-81c5c6f3c856/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= +github.com/sei-protocol/sei-db v0.0.47-0.20250109184418-96b286395aa7 h1:ZmOXBRYPMdTdkg/Zs0QcoPAmyUmcS4WTIqjgPdLfdKg= +github.com/sei-protocol/sei-db v0.0.47-0.20250109184418-96b286395aa7/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= github.com/sei-protocol/sei-iavl v0.2.0 h1:OisPjXiDT+oe+aeckzDEFgkZCYuUjHgs/PP8DPicN+I= github.com/sei-protocol/sei-iavl v0.2.0/go.mod h1:qRf8QYUPfrAO7K6VDB2B2l/N7K5L76OorioGBcJBIbw= github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 h1:0kg1giMHiKMLXOCFLqH/9kqdl5bH+unzI8qRF6qwXzw= From b0df739830016169c5eb959d2eba0f1a25f9f5af Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Thu, 9 Jan 2025 13:51:48 -0500 Subject: [PATCH 32/50] Update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 70f13a5075..20aef90e42 100644 --- a/go.mod +++ b/go.mod @@ -352,7 +352,7 @@ replace ( github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-9.0.20241224143343-21ee50facc96 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250109184418-96b286395aa7 + github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250109184613-5c060631edf6 // Latest goleveldb is broken, we have to stick to this version github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.4.3 diff --git a/go.sum b/go.sum index c11d0d5520..35332437ea 100644 --- a/go.sum +++ b/go.sum @@ -1347,8 +1347,8 @@ github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQp github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8= github.com/sei-protocol/sei-cosmos v0.3.48 h1:kSDweeTaLZ4TByLqAD6/hmtgAhAJHwXU1beyqsVXJkQ= github.com/sei-protocol/sei-cosmos v0.3.48/go.mod h1:XC417pB6NwxP/cQ2XTSZLzVnP8dMZ//4uCXS3SxFgoM= -github.com/sei-protocol/sei-db v0.0.47-0.20250109184418-96b286395aa7 h1:ZmOXBRYPMdTdkg/Zs0QcoPAmyUmcS4WTIqjgPdLfdKg= -github.com/sei-protocol/sei-db v0.0.47-0.20250109184418-96b286395aa7/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= +github.com/sei-protocol/sei-db v0.0.47-0.20250109184613-5c060631edf6 h1:vKkmyUTRMKYp4WDFEE2c9HEYF60Sw1rHoi5O4KLmGuc= +github.com/sei-protocol/sei-db v0.0.47-0.20250109184613-5c060631edf6/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= github.com/sei-protocol/sei-iavl v0.2.0 h1:OisPjXiDT+oe+aeckzDEFgkZCYuUjHgs/PP8DPicN+I= github.com/sei-protocol/sei-iavl v0.2.0/go.mod h1:qRf8QYUPfrAO7K6VDB2B2l/N7K5L76OorioGBcJBIbw= github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 h1:0kg1giMHiKMLXOCFLqH/9kqdl5bH+unzI8qRF6qwXzw= From 6d0b6c5acece39b0048fbff6c6c412d14400ea3b Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Thu, 9 Jan 2025 13:58:04 -0500 Subject: [PATCH 33/50] Update --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 20aef90e42..94317a5dc3 100644 --- a/go.mod +++ b/go.mod @@ -352,7 +352,7 @@ replace ( github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-9.0.20241224143343-21ee50facc96 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250109184613-5c060631edf6 + github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250109185538-18c578b45fcd // Latest goleveldb is broken, we have to stick to this version github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.4.3 diff --git a/go.sum b/go.sum index 35332437ea..01f04f183d 100644 --- a/go.sum +++ b/go.sum @@ -1347,8 +1347,8 @@ github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQp github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8= github.com/sei-protocol/sei-cosmos v0.3.48 h1:kSDweeTaLZ4TByLqAD6/hmtgAhAJHwXU1beyqsVXJkQ= github.com/sei-protocol/sei-cosmos v0.3.48/go.mod h1:XC417pB6NwxP/cQ2XTSZLzVnP8dMZ//4uCXS3SxFgoM= -github.com/sei-protocol/sei-db v0.0.47-0.20250109184613-5c060631edf6 h1:vKkmyUTRMKYp4WDFEE2c9HEYF60Sw1rHoi5O4KLmGuc= -github.com/sei-protocol/sei-db v0.0.47-0.20250109184613-5c060631edf6/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= +github.com/sei-protocol/sei-db v0.0.47-0.20250109185538-18c578b45fcd h1:JlawEO6TSbsibVTC6AY1oFlHG0Q5aO/2Z1HuR1JG3LA= +github.com/sei-protocol/sei-db v0.0.47-0.20250109185538-18c578b45fcd/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= github.com/sei-protocol/sei-iavl v0.2.0 h1:OisPjXiDT+oe+aeckzDEFgkZCYuUjHgs/PP8DPicN+I= github.com/sei-protocol/sei-iavl v0.2.0/go.mod h1:qRf8QYUPfrAO7K6VDB2B2l/N7K5L76OorioGBcJBIbw= github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 h1:0kg1giMHiKMLXOCFLqH/9kqdl5bH+unzI8qRF6qwXzw= From c9c89dac0397d7c402b31e4abb14342ea68cfacd Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Thu, 9 Jan 2025 14:02:38 -0500 Subject: [PATCH 34/50] Update log --- tools/migration/ss/migrator.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index a8149c0686..3c6a41a255 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -72,9 +72,6 @@ func exportDistributionLeafNodes( // RawIterate will scan *all* keys in the "distribution" store. // We'll filter them by version in the callback. stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { - if version >= 121234732 { - return false - } bz, errorInner := newStateStore.Get("distribution", version, key) if errorInner != nil { panic(errorInner) @@ -101,8 +98,8 @@ func exportDistributionLeafNodes( totalExported++ // Optional progress logging every 1,000,000 keys: if totalExported%1_000_000 == 0 { - fmt.Printf("[SingleWorker][%s] Verified %d distribution keys so far mismatch %d\n", - time.Now().Format(time.RFC3339), totalExported, totalMismatch, + fmt.Printf("[SingleWorker][%s] Verified %d distribution keys so far mismatch %d currVersion %d\n", + time.Now().Format(time.RFC3339), totalExported, totalMismatch, version, ) } // Return false to continue iterating From 45c9bbbb50895cd6be2679f1e6f4927a2769ee03 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Thu, 9 Jan 2025 14:16:52 -0500 Subject: [PATCH 35/50] Less logs --- go.mod | 2 +- go.sum | 4 ++-- tools/migration/ss/migrator.go | 10 +++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 94317a5dc3..c32801fc51 100644 --- a/go.mod +++ b/go.mod @@ -352,7 +352,7 @@ replace ( github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-9.0.20241224143343-21ee50facc96 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250109185538-18c578b45fcd + github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250109191534-c427f9102b8c // Latest goleveldb is broken, we have to stick to this version github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.4.3 diff --git a/go.sum b/go.sum index 01f04f183d..8557393e32 100644 --- a/go.sum +++ b/go.sum @@ -1347,8 +1347,8 @@ github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQp github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8= github.com/sei-protocol/sei-cosmos v0.3.48 h1:kSDweeTaLZ4TByLqAD6/hmtgAhAJHwXU1beyqsVXJkQ= github.com/sei-protocol/sei-cosmos v0.3.48/go.mod h1:XC417pB6NwxP/cQ2XTSZLzVnP8dMZ//4uCXS3SxFgoM= -github.com/sei-protocol/sei-db v0.0.47-0.20250109185538-18c578b45fcd h1:JlawEO6TSbsibVTC6AY1oFlHG0Q5aO/2Z1HuR1JG3LA= -github.com/sei-protocol/sei-db v0.0.47-0.20250109185538-18c578b45fcd/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= +github.com/sei-protocol/sei-db v0.0.47-0.20250109191534-c427f9102b8c h1:Hp7hP+QnJ2kku5rFJp4MnrrPiRmM8izflG1BZb4xc4A= +github.com/sei-protocol/sei-db v0.0.47-0.20250109191534-c427f9102b8c/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= github.com/sei-protocol/sei-iavl v0.2.0 h1:OisPjXiDT+oe+aeckzDEFgkZCYuUjHgs/PP8DPicN+I= github.com/sei-protocol/sei-iavl v0.2.0/go.mod h1:qRf8QYUPfrAO7K6VDB2B2l/N7K5L76OorioGBcJBIbw= github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 h1:0kg1giMHiKMLXOCFLqH/9kqdl5bH+unzI8qRF6qwXzw= diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 3c6a41a255..c80f6f5328 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -72,6 +72,14 @@ func exportDistributionLeafNodes( // RawIterate will scan *all* keys in the "distribution" store. // We'll filter them by version in the callback. stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { + totalExported++ + if version >= 121234732 { + return false + } + + if totalExported < 475000000 { + return false + } bz, errorInner := newStateStore.Get("distribution", version, key) if errorInner != nil { panic(errorInner) @@ -99,7 +107,7 @@ func exportDistributionLeafNodes( // Optional progress logging every 1,000,000 keys: if totalExported%1_000_000 == 0 { fmt.Printf("[SingleWorker][%s] Verified %d distribution keys so far mismatch %d currVersion %d\n", - time.Now().Format(time.RFC3339), totalExported, totalMismatch, version, + time.Now().Format(time.RFC3339), totalExported, totalMismatch, ) } // Return false to continue iterating From 8fbf0de5f8c76acf0fdbfc459d5cbef8076123f8 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Thu, 9 Jan 2025 14:23:39 -0500 Subject: [PATCH 36/50] totalExported --- tools/migration/ss/migrator.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index c80f6f5328..aa2f697643 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -73,13 +73,14 @@ func exportDistributionLeafNodes( // We'll filter them by version in the callback. stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { totalExported++ - if version >= 121234732 { + if totalExported < 475000000 { return false } - if totalExported < 475000000 { + if version >= 121234732 { return false } + bz, errorInner := newStateStore.Get("distribution", version, key) if errorInner != nil { panic(errorInner) From 49f5e9e3ca5319e9780c718a395e949ba6f38662 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Thu, 9 Jan 2025 14:29:44 -0500 Subject: [PATCH 37/50] remove unncessary increment --- tools/migration/ss/migrator.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index aa2f697643..213842b805 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -104,7 +104,6 @@ func exportDistributionLeafNodes( } } - totalExported++ // Optional progress logging every 1,000,000 keys: if totalExported%1_000_000 == 0 { fmt.Printf("[SingleWorker][%s] Verified %d distribution keys so far mismatch %d currVersion %d\n", From 80be213a49742159e9f4f0d2fe09ba8b89fb443e Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Fri, 10 Jan 2025 11:32:47 -0500 Subject: [PATCH 38/50] tools --- tools/migration/ss/migrator.go | 43 ++++++++++++++-------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 213842b805..dfca3edbb5 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -66,20 +66,13 @@ func exportDistributionLeafNodes( ) var totalExported int - var totalMismatch int + // var totalMismatch int startTime := time.Now() // RawIterate will scan *all* keys in the "distribution" store. // We'll filter them by version in the callback. stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { totalExported++ - if totalExported < 475000000 { - return false - } - - if version >= 121234732 { - return false - } bz, errorInner := newStateStore.Get("distribution", version, key) if errorInner != nil { @@ -87,27 +80,27 @@ func exportDistributionLeafNodes( } if !bytes.Equal(bz, value) { - totalMismatch++ - fmt.Printf("values don't match for key %s: expected %s, got %s\n", string(key), string(value), string(bz)) - - if err := newStateStore.Set("distribution", key, value, version); err != nil { - panic(err) - } - - // Verify the write was successful - verifyBz, verifyErr := newStateStore.Get("distribution", version, key) - if verifyErr != nil { - panic(fmt.Errorf("failed to verify write: %w", verifyErr)) - } - if !bytes.Equal(verifyBz, value) { - panic(fmt.Errorf("write verification failed: value mismatch after Set")) - } + // totalMismatch++ + panic(fmt.Errorf("values don't match for key %s: expected %s, got %s\n", string(key), string(value), string(bz))) + + // if err := newStateStore.Set("distribution", key, value, version); err != nil { + // panic(err) + // } + + // // Verify the write was successful + // verifyBz, verifyErr := newStateStore.Get("distribution", version, key) + // if verifyErr != nil { + // panic(fmt.Errorf("failed to verify write: %w", verifyErr)) + // } + // if !bytes.Equal(verifyBz, value) { + // panic(fmt.Errorf("write verification failed: value mismatch after Set")) + // } } // Optional progress logging every 1,000,000 keys: if totalExported%1_000_000 == 0 { - fmt.Printf("[SingleWorker][%s] Verified %d distribution keys so far mismatch %d currVersion %d\n", - time.Now().Format(time.RFC3339), totalExported, totalMismatch, + fmt.Printf("[SingleWorker][%s] Verified %d distribution keys so far\n", + time.Now().Format(time.RFC3339), totalExported, ) } // Return false to continue iterating From ee265c075885d1ec321dec11d227461428dc187d Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Fri, 10 Jan 2025 11:33:48 -0500 Subject: [PATCH 39/50] Update sei-db --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c32801fc51..a33daf4a2f 100644 --- a/go.mod +++ b/go.mod @@ -352,7 +352,7 @@ replace ( github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-9.0.20241224143343-21ee50facc96 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250109191534-c427f9102b8c + github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250110162845-55a9817222f4 // Latest goleveldb is broken, we have to stick to this version github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.4.3 diff --git a/go.sum b/go.sum index 8557393e32..cf7fc57afb 100644 --- a/go.sum +++ b/go.sum @@ -1347,8 +1347,8 @@ github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQp github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8= github.com/sei-protocol/sei-cosmos v0.3.48 h1:kSDweeTaLZ4TByLqAD6/hmtgAhAJHwXU1beyqsVXJkQ= github.com/sei-protocol/sei-cosmos v0.3.48/go.mod h1:XC417pB6NwxP/cQ2XTSZLzVnP8dMZ//4uCXS3SxFgoM= -github.com/sei-protocol/sei-db v0.0.47-0.20250109191534-c427f9102b8c h1:Hp7hP+QnJ2kku5rFJp4MnrrPiRmM8izflG1BZb4xc4A= -github.com/sei-protocol/sei-db v0.0.47-0.20250109191534-c427f9102b8c/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= +github.com/sei-protocol/sei-db v0.0.47-0.20250110162845-55a9817222f4 h1:QTAxIhtd0AWSeZJaS4cwEaG+86gwi8G6iXldTdM+jeY= +github.com/sei-protocol/sei-db v0.0.47-0.20250110162845-55a9817222f4/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= github.com/sei-protocol/sei-iavl v0.2.0 h1:OisPjXiDT+oe+aeckzDEFgkZCYuUjHgs/PP8DPicN+I= github.com/sei-protocol/sei-iavl v0.2.0/go.mod h1:qRf8QYUPfrAO7K6VDB2B2l/N7K5L76OorioGBcJBIbw= github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 h1:0kg1giMHiKMLXOCFLqH/9kqdl5bH+unzI8qRF6qwXzw= From 19ca4a1540a5239949ae5be3bbabc95c8a4afab8 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Fri, 10 Jan 2025 12:49:21 -0500 Subject: [PATCH 40/50] Update verification --- tools/migration/ss/migrator.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index dfca3edbb5..8921211533 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -73,6 +73,9 @@ func exportDistributionLeafNodes( // We'll filter them by version in the callback. stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { totalExported++ + if totalExported < 420000000 { + return false + } bz, errorInner := newStateStore.Get("distribution", version, key) if errorInner != nil { @@ -81,20 +84,21 @@ func exportDistributionLeafNodes( if !bytes.Equal(bz, value) { // totalMismatch++ - panic(fmt.Errorf("values don't match for key %s: expected %s, got %s\n", string(key), string(value), string(bz))) - - // if err := newStateStore.Set("distribution", key, value, version); err != nil { - // panic(err) - // } - - // // Verify the write was successful - // verifyBz, verifyErr := newStateStore.Get("distribution", version, key) - // if verifyErr != nil { - // panic(fmt.Errorf("failed to verify write: %w", verifyErr)) - // } - // if !bytes.Equal(verifyBz, value) { - // panic(fmt.Errorf("write verification failed: value mismatch after Set")) - // } + // panic(fmt.Errorf("values don't match for key %s: expected %s, got %s\n", string(key), string(value), string(bz))) + fmt.Printf("values don't match for key %s: expected %s, got %s\n", string(key), string(value), string(bz)) + + if err := newStateStore.Set("distribution", key, value, version); err != nil { + panic(err) + } + + // Verify the write was successful + verifyBz, verifyErr := newStateStore.Get("distribution", version, key) + if verifyErr != nil { + panic(fmt.Errorf("failed to verify write: %w", verifyErr)) + } + if !bytes.Equal(verifyBz, value) { + panic(fmt.Errorf("write verification failed: value mismatch after Set")) + } } // Optional progress logging every 1,000,000 keys: From 10df0f26e65299ac72123a837ea2e2ddc16ace85 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Fri, 10 Jan 2025 13:13:45 -0500 Subject: [PATCH 41/50] Remove logs --- tools/migration/ss/migrator.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 8921211533..34a6d1e270 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -66,7 +66,7 @@ func exportDistributionLeafNodes( ) var totalExported int - // var totalMismatch int + var totalMismatch int startTime := time.Now() // RawIterate will scan *all* keys in the "distribution" store. @@ -83,7 +83,10 @@ func exportDistributionLeafNodes( } if !bytes.Equal(bz, value) { - // totalMismatch++ + totalMismatch++ + if totalMismatch > 3 { + panic("done with check") + } // panic(fmt.Errorf("values don't match for key %s: expected %s, got %s\n", string(key), string(value), string(bz))) fmt.Printf("values don't match for key %s: expected %s, got %s\n", string(key), string(value), string(bz)) @@ -102,11 +105,11 @@ func exportDistributionLeafNodes( } // Optional progress logging every 1,000,000 keys: - if totalExported%1_000_000 == 0 { - fmt.Printf("[SingleWorker][%s] Verified %d distribution keys so far\n", - time.Now().Format(time.RFC3339), totalExported, - ) - } + // if totalExported%1_000_000 == 0 { + // fmt.Printf("[SingleWorker][%s] Verified %d distribution keys so far\n", + // time.Now().Format(time.RFC3339), totalExported, + // ) + // } // Return false to continue iterating return false }) From 05c6504db49274374e21a831c8d0d6bd392f1439 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Fri, 10 Jan 2025 13:44:41 -0500 Subject: [PATCH 42/50] Panic --- tools/migration/ss/migrator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 34a6d1e270..5674e17aa0 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -88,7 +88,7 @@ func exportDistributionLeafNodes( panic("done with check") } // panic(fmt.Errorf("values don't match for key %s: expected %s, got %s\n", string(key), string(value), string(bz))) - fmt.Printf("values don't match for key %s: expected %s, got %s\n", string(key), string(value), string(bz)) + fmt.Printf("values don't match for key %s: expected %s, got %s\n\n", string(key), string(value), string(bz)) if err := newStateStore.Set("distribution", key, value, version); err != nil { panic(err) From fb0441274eb585ac48fa5e8c4e76e788df03e446 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Fri, 10 Jan 2025 14:11:07 -0500 Subject: [PATCH 43/50] Skip more --- tools/migration/ss/migrator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 5674e17aa0..3a914215cc 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -73,7 +73,7 @@ func exportDistributionLeafNodes( // We'll filter them by version in the callback. stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { totalExported++ - if totalExported < 420000000 { + if totalExported < 426000000 { return false } From e7a8c7ef1d19c73aa2ecfe924cd8c8a9e870bcde Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Fri, 10 Jan 2025 15:34:07 -0500 Subject: [PATCH 44/50] Sync mode --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index a33daf4a2f..8514d29efe 100644 --- a/go.mod +++ b/go.mod @@ -352,7 +352,7 @@ replace ( github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-9.0.20241224143343-21ee50facc96 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250110162845-55a9817222f4 + github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250110200519-f9adcc7607b2 // Latest goleveldb is broken, we have to stick to this version github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.4.3 diff --git a/go.sum b/go.sum index cf7fc57afb..a7c2659c7d 100644 --- a/go.sum +++ b/go.sum @@ -1347,8 +1347,8 @@ github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQp github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8= github.com/sei-protocol/sei-cosmos v0.3.48 h1:kSDweeTaLZ4TByLqAD6/hmtgAhAJHwXU1beyqsVXJkQ= github.com/sei-protocol/sei-cosmos v0.3.48/go.mod h1:XC417pB6NwxP/cQ2XTSZLzVnP8dMZ//4uCXS3SxFgoM= -github.com/sei-protocol/sei-db v0.0.47-0.20250110162845-55a9817222f4 h1:QTAxIhtd0AWSeZJaS4cwEaG+86gwi8G6iXldTdM+jeY= -github.com/sei-protocol/sei-db v0.0.47-0.20250110162845-55a9817222f4/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= +github.com/sei-protocol/sei-db v0.0.47-0.20250110200519-f9adcc7607b2 h1:HpKG/FvqQYGnGU5ypdDb7Yk0ScME1gw9Gb3nLFh8wdE= +github.com/sei-protocol/sei-db v0.0.47-0.20250110200519-f9adcc7607b2/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= github.com/sei-protocol/sei-iavl v0.2.0 h1:OisPjXiDT+oe+aeckzDEFgkZCYuUjHgs/PP8DPicN+I= github.com/sei-protocol/sei-iavl v0.2.0/go.mod h1:qRf8QYUPfrAO7K6VDB2B2l/N7K5L76OorioGBcJBIbw= github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 h1:0kg1giMHiKMLXOCFLqH/9kqdl5bH+unzI8qRF6qwXzw= From 98f2ba75ed3700ad55312cbd6736d1ae520b59d6 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Fri, 10 Jan 2025 17:32:29 -0500 Subject: [PATCH 45/50] Update --- go.mod | 2 +- go.sum | 4 +-- tools/migration/ss/migrator.go | 66 +++++++++++----------------------- 3 files changed, 23 insertions(+), 49 deletions(-) diff --git a/go.mod b/go.mod index 8514d29efe..e0d0c09360 100644 --- a/go.mod +++ b/go.mod @@ -352,7 +352,7 @@ replace ( github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 github.com/ethereum/go-ethereum => github.com/sei-protocol/go-ethereum v1.13.5-sei-9.0.20241224143343-21ee50facc96 github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1 - github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250110200519-f9adcc7607b2 + github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.47-0.20250110223130-1e7403e5d572 // Latest goleveldb is broken, we have to stick to this version github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.4.3 diff --git a/go.sum b/go.sum index a7c2659c7d..b3c0a0a9ff 100644 --- a/go.sum +++ b/go.sum @@ -1347,8 +1347,8 @@ github.com/sei-protocol/goutils v0.0.2 h1:Bfa7Sv+4CVLNM20QcpvGb81B8C5HkQC/kW1CQp github.com/sei-protocol/goutils v0.0.2/go.mod h1:iYE2DuJfEnM+APPehr2gOUXfuLuPsVxorcDO+Tzq9q8= github.com/sei-protocol/sei-cosmos v0.3.48 h1:kSDweeTaLZ4TByLqAD6/hmtgAhAJHwXU1beyqsVXJkQ= github.com/sei-protocol/sei-cosmos v0.3.48/go.mod h1:XC417pB6NwxP/cQ2XTSZLzVnP8dMZ//4uCXS3SxFgoM= -github.com/sei-protocol/sei-db v0.0.47-0.20250110200519-f9adcc7607b2 h1:HpKG/FvqQYGnGU5ypdDb7Yk0ScME1gw9Gb3nLFh8wdE= -github.com/sei-protocol/sei-db v0.0.47-0.20250110200519-f9adcc7607b2/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= +github.com/sei-protocol/sei-db v0.0.47-0.20250110223130-1e7403e5d572 h1:99T2xbVAidlaDxQhX+XjQo5ttMciuXUfKeRAMMGShLc= +github.com/sei-protocol/sei-db v0.0.47-0.20250110223130-1e7403e5d572/go.mod h1:m5g7p0QeAS3dNJHIl28zQpzOgxQmvYqPb7t4hwgIOCA= github.com/sei-protocol/sei-iavl v0.2.0 h1:OisPjXiDT+oe+aeckzDEFgkZCYuUjHgs/PP8DPicN+I= github.com/sei-protocol/sei-iavl v0.2.0/go.mod h1:qRf8QYUPfrAO7K6VDB2B2l/N7K5L76OorioGBcJBIbw= github.com/sei-protocol/sei-ibc-go/v3 v3.3.3 h1:0kg1giMHiKMLXOCFLqH/9kqdl5bH+unzI8qRF6qwXzw= diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 3a914215cc..89f2d80833 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -33,20 +33,24 @@ func NewMigrator(db dbm.DB, stateStore types.StateStore, oldStateStore types.Sta func (m *Migrator) Migrate(version int64, homeDir string) error { // Channel to send RawSnapshotNodes to the importer. - ch := make(chan types.RawSnapshotNode, 1000) + ch := make(chan types.RawSnapshotNode, 10000) // Channel to capture errors from both goroutines below. errCh := make(chan error, 2) - fmt.Printf("Starting migration for 'distribution' module from version %d to %d...\n", 100215000, 106789896) + fmt.Printf("Starting migration for 'distribution' module from version\n") // Goroutine #1: Export distribution leaf nodes into ch go func() { defer close(ch) - errCh <- exportDistributionLeafNodes(m.oldStateStore, m.stateStore, ch, 100215000, 106789896) + errCh <- exportDistributionLeafNodes(m.oldStateStore, ch) + }() + + go func() { + errCh <- m.stateStore.RawImport(ch) }() // Wait for both goroutines to complete - for i := 0; i < 1; i++ { + for i := 0; i < 2; i++ { if err := <-errCh; err != nil { return err } @@ -57,59 +61,29 @@ func (m *Migrator) Migrate(version int64, homeDir string) error { func exportDistributionLeafNodes( oldStateStore types.StateStore, - newStateStore types.StateStore, ch chan<- types.RawSnapshotNode, - startVersion, endVersion int64, ) error { - fmt.Printf("Starting export at %s for versions [%d..%d]\n", - time.Now().Format(time.RFC3339), startVersion, endVersion, - ) var totalExported int - var totalMismatch int startTime := time.Now() // RawIterate will scan *all* keys in the "distribution" store. // We'll filter them by version in the callback. stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { totalExported++ - if totalExported < 426000000 { - return false - } - - bz, errorInner := newStateStore.Get("distribution", version, key) - if errorInner != nil { - panic(errorInner) - } - - if !bytes.Equal(bz, value) { - totalMismatch++ - if totalMismatch > 3 { - panic("done with check") - } - // panic(fmt.Errorf("values don't match for key %s: expected %s, got %s\n", string(key), string(value), string(bz))) - fmt.Printf("values don't match for key %s: expected %s, got %s\n\n", string(key), string(value), string(bz)) - - if err := newStateStore.Set("distribution", key, value, version); err != nil { - panic(err) - } - - // Verify the write was successful - verifyBz, verifyErr := newStateStore.Get("distribution", version, key) - if verifyErr != nil { - panic(fmt.Errorf("failed to verify write: %w", verifyErr)) - } - if !bytes.Equal(verifyBz, value) { - panic(fmt.Errorf("write verification failed: value mismatch after Set")) - } + ch <- types.RawSnapshotNode{ + StoreKey: "distribution", + Key: key, + Value: value, + Version: version, } // Optional progress logging every 1,000,000 keys: - // if totalExported%1_000_000 == 0 { - // fmt.Printf("[SingleWorker][%s] Verified %d distribution keys so far\n", - // time.Now().Format(time.RFC3339), totalExported, - // ) - // } + if totalExported%1_000_000 == 0 { + fmt.Printf("[SingleWorker][%s] Verified %d distribution keys so far\n", + time.Now().Format(time.RFC3339), totalExported, + ) + } // Return false to continue iterating return false }) @@ -123,8 +97,8 @@ func exportDistributionLeafNodes( } fmt.Printf( - "[%s] Completed exporting distribution store for versions [%d..%d]. Total keys: %d. Duration: %s\n", - time.Now().Format(time.RFC3339), startVersion, endVersion, totalExported, time.Since(startTime), + "[%s] Completed exporting distribution store for versions. Total keys: %d. Duration: %s\n", + time.Now().Format(time.RFC3339), totalExported, time.Since(startTime), ) fmt.Printf("Finished export at %s\n", time.Now().Format(time.RFC3339)) return nil From e4433d152a1aec34f92602b26d3c8159fed989e5 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Sun, 12 Jan 2025 14:10:44 -0500 Subject: [PATCH 46/50] Verify once more --- tools/migration/ss/migrator.go | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 89f2d80833..f16fb90a62 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -42,15 +42,15 @@ func (m *Migrator) Migrate(version int64, homeDir string) error { // Goroutine #1: Export distribution leaf nodes into ch go func() { defer close(ch) - errCh <- exportDistributionLeafNodes(m.oldStateStore, ch) + errCh <- exportDistributionLeafNodes(m.oldStateStore, m.stateStore, ch) }() - go func() { - errCh <- m.stateStore.RawImport(ch) - }() + // go func() { + // errCh <- m.stateStore.RawImport(ch) + // }() // Wait for both goroutines to complete - for i := 0; i < 2; i++ { + for i := 0; i < 1; i++ { if err := <-errCh; err != nil { return err } @@ -61,6 +61,7 @@ func (m *Migrator) Migrate(version int64, homeDir string) error { func exportDistributionLeafNodes( oldStateStore types.StateStore, + newStateStore types.StateStore, ch chan<- types.RawSnapshotNode, ) error { @@ -69,14 +70,26 @@ func exportDistributionLeafNodes( // RawIterate will scan *all* keys in the "distribution" store. // We'll filter them by version in the callback. + var misMatch int stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { totalExported++ - ch <- types.RawSnapshotNode{ - StoreKey: "distribution", - Key: key, - Value: value, - Version: version, + valBz, err := newStateStore.Get("distribution", version, key) + if err != nil { + panic(err) + } + if !bytes.Equal(valBz, value) { + misMatch++ + fmt.Printf("Value mismatch for key %s: expected %s, got %s\n", string(key), string(value), string(valBz)) + } + if misMatch > 3 { + panic("3 mismatches") } + // ch <- types.RawSnapshotNode{ + // StoreKey: "distribution", + // Key: key, + // Value: value, + // Version: version, + // } // Optional progress logging every 1,000,000 keys: if totalExported%1_000_000 == 0 { From d0a884c0845603cad0c65204a5eb69252ce62c26 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Sun, 12 Jan 2025 14:15:56 -0500 Subject: [PATCH 47/50] Verification --- tools/migration/ss/migrator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index f16fb90a62..361af7c61a 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -77,7 +77,7 @@ func exportDistributionLeafNodes( if err != nil { panic(err) } - if !bytes.Equal(valBz, value) { + if value != nil && valBz != nil && !bytes.Equal(valBz, value) { misMatch++ fmt.Printf("Value mismatch for key %s: expected %s, got %s\n", string(key), string(value), string(valBz)) } From 35b7421d3038ac909a53dac5a75dced62f41a130 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Sun, 12 Jan 2025 20:30:19 -0500 Subject: [PATCH 48/50] Set --- tools/migration/ss/migrator.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 361af7c61a..3dd62bc96a 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -73,6 +73,9 @@ func exportDistributionLeafNodes( var misMatch int stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { totalExported++ + if totalExported < 45000000 { + return false + } valBz, err := newStateStore.Get("distribution", version, key) if err != nil { panic(err) @@ -80,9 +83,10 @@ func exportDistributionLeafNodes( if value != nil && valBz != nil && !bytes.Equal(valBz, value) { misMatch++ fmt.Printf("Value mismatch for key %s: expected %s, got %s\n", string(key), string(value), string(valBz)) - } - if misMatch > 3 { - panic("3 mismatches") + err := newStateStore.Set("distribution", key, value, version) + if err != nil { + panic(err) + } } // ch <- types.RawSnapshotNode{ // StoreKey: "distribution", From bc56bc721cd75e4ef6d3e40d9b23cea24479f4c1 Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Mon, 13 Jan 2025 09:22:55 -0500 Subject: [PATCH 49/50] Update new counter --- tools/migration/ss/migrator.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index 3dd62bc96a..b12e3a212f 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -73,7 +73,7 @@ func exportDistributionLeafNodes( var misMatch int stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { totalExported++ - if totalExported < 45000000 { + if totalExported < 4787000000 { return false } valBz, err := newStateStore.Get("distribution", version, key) From 87c2926d101c846092d9a13f046ba02ec14cfb7b Mon Sep 17 00:00:00 2001 From: kbhat1 Date: Mon, 13 Jan 2025 16:43:07 -0500 Subject: [PATCH 50/50] Verify --- tools/migration/ss/migrator.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/tools/migration/ss/migrator.go b/tools/migration/ss/migrator.go index b12e3a212f..ac12ec4351 100644 --- a/tools/migration/ss/migrator.go +++ b/tools/migration/ss/migrator.go @@ -70,23 +70,16 @@ func exportDistributionLeafNodes( // RawIterate will scan *all* keys in the "distribution" store. // We'll filter them by version in the callback. - var misMatch int + // var misMatch int stop, err := oldStateStore.RawIterate("distribution", func(key, value []byte, version int64) bool { totalExported++ - if totalExported < 4787000000 { - return false - } valBz, err := newStateStore.Get("distribution", version, key) if err != nil { panic(err) } if value != nil && valBz != nil && !bytes.Equal(valBz, value) { - misMatch++ - fmt.Printf("Value mismatch for key %s: expected %s, got %s\n", string(key), string(value), string(valBz)) - err := newStateStore.Set("distribution", key, value, version) - if err != nil { - panic(err) - } + // misMatch++ + panic(fmt.Errorf("Value mismatch for key %s: expected %s, got %s\n", string(key), string(value), string(valBz))) } // ch <- types.RawSnapshotNode{ // StoreKey: "distribution",