Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

eth: Migrate transaction DB to Lexi #3213

Merged
merged 2 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion client/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,33 @@ func getWalletDir(dataDir string, network dex.Network) string {
return filepath.Join(dataDir, network.String())
}

func migrateLegacyTxDB(legacyDBPath string, newDB txDB, log dex.Logger) error {
if _, err := os.Stat(legacyDBPath); err != nil {
return nil
}

legacyDB, err := newBadgerTxDB(legacyDBPath, log.SubLogger("LEGACYDB"))
if err != nil {
return fmt.Errorf("error opening legacy db: %w", err)
}

entries, err := legacyDB.getAllEntries()
if err != nil {
return fmt.Errorf("error getting legacy entries: %w", err)
}

for _, tx := range entries {
if err := newDB.storeTx(tx); err != nil {
return fmt.Errorf("error storing legacy tx: %w", err)
}
}

log.Infof("Successfully migrated %d transactions from legacy database", len(entries))

legacyDB.Close()
return os.RemoveAll(legacyDBPath)
}

// Connect connects to the node RPC server. Satisfies dex.Connector.
func (w *ETHWallet) Connect(ctx context.Context) (_ *sync.WaitGroup, err error) {
var cl ethFetcher
Expand Down Expand Up @@ -889,7 +916,13 @@ func (w *ETHWallet) Connect(ctx context.Context) (_ *sync.WaitGroup, err error)
}
}

w.txDB, err = newBadgerTxDB(filepath.Join(w.dir, "txhistorydb"), w.log.SubLogger("TXDB"))
w.txDB, err = NewTxDB(filepath.Join(w.dir, "txhistorydb-lexi"), w.log.SubLogger("TXDB"), w.baseChainID)
if err != nil {
return nil, err
}

legacyDBPath := filepath.Join(w.dir, "txhistorydb")
err = migrateLegacyTxDB(legacyDBPath, w.txDB, w.log)
if err != nil {
return nil, err
}
Expand Down
Loading
Loading