mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 13:07:17 +00:00
f06db2f37b
* save state * add current index feature * fix test * remove logs * Only execute 1000 blocks * Reset history index * Correct action * Increase batch size * Increase chunk size, print memory stats * Fix linter * Remove unused from * Split into 2 staged * Use storage history gen * remove log * Not to run tx_cacher in staged mode * Not to recover during stage 2 * Not to recover during stage 2 * Remove counter Co-authored-by: b00ris <b00ris@mail.ru>
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package migrations
|
|
|
|
import (
|
|
"github.com/ledgerwatch/turbo-geth/common/dbutils"
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
|
"github.com/ledgerwatch/turbo-geth/log"
|
|
)
|
|
|
|
type Migration struct {
|
|
Name string
|
|
Up func(db ethdb.Database, history, receipts, txIndex, preImages bool) error
|
|
}
|
|
|
|
func NewMigrator() *Migrator {
|
|
return &Migrator{
|
|
Migrations: migrations,
|
|
}
|
|
}
|
|
|
|
type Migrator struct {
|
|
Migrations []Migration
|
|
}
|
|
|
|
func (m *Migrator) Apply(db ethdb.Database, history, receipts, txIndex, preImages bool) error {
|
|
if len(m.Migrations) == 0 {
|
|
return nil
|
|
}
|
|
|
|
lastApplied, err := db.Get(dbutils.DatabaseInfoBucket, dbutils.LastAppliedMigration)
|
|
if err != nil && err != ethdb.ErrKeyNotFound {
|
|
return err
|
|
}
|
|
|
|
i := len(m.Migrations) - 1
|
|
for ; i >= 0; i-- {
|
|
if m.Migrations[i].Name == string(lastApplied) {
|
|
break
|
|
}
|
|
}
|
|
|
|
m.Migrations = m.Migrations[i+1:]
|
|
for _, v := range m.Migrations {
|
|
log.Warn("Apply migration", "name", v.Name)
|
|
err := v.Up(db, history, receipts, txIndex, preImages)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = db.Put(dbutils.DatabaseInfoBucket, dbutils.LastAppliedMigration, []byte(v.Name))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
log.Warn("Applied migration", "name", v.Name)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var migrations = []Migration{}
|