mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-25 21:17:16 +00:00
bf596c26f3
* dupsort of plain state * rebase master
78 lines
2.0 KiB
Go
78 lines
2.0 KiB
Go
package migrations
|
|
|
|
import (
|
|
"github.com/ledgerwatch/turbo-geth/common/dbutils"
|
|
"github.com/ledgerwatch/turbo-geth/common/etl"
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
|
)
|
|
|
|
var dupSortHashState = Migration{
|
|
Name: "dupsort_hash_state",
|
|
Up: func(db ethdb.Database, datadir string, OnLoadCommit etl.LoadCommitHandler) error {
|
|
if exists, err := db.(ethdb.NonTransactional).BucketExists(dbutils.CurrentStateBucketOld1); err != nil {
|
|
return err
|
|
} else if !exists {
|
|
return OnLoadCommit(db, nil, true)
|
|
}
|
|
|
|
if err := db.(ethdb.NonTransactional).ClearBuckets(dbutils.CurrentStateBucket); err != nil {
|
|
return err
|
|
}
|
|
extractFunc := func(k []byte, v []byte, next etl.ExtractNextFunc) error {
|
|
return next(k, k, v)
|
|
}
|
|
|
|
if err := etl.Transform(
|
|
db,
|
|
dbutils.CurrentStateBucketOld1,
|
|
dbutils.CurrentStateBucket,
|
|
datadir,
|
|
extractFunc,
|
|
etl.IdentityLoadFunc,
|
|
etl.TransformArgs{OnLoadCommit: OnLoadCommit},
|
|
); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := db.(ethdb.NonTransactional).DropBuckets(dbutils.CurrentStateBucketOld1); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
var dupSortPlainState = Migration{
|
|
Name: "dupsort_plain_state",
|
|
Up: func(db ethdb.Database, datadir string, OnLoadCommit etl.LoadCommitHandler) error {
|
|
if exists, err := db.(ethdb.NonTransactional).BucketExists(dbutils.PlainStateBucketOld1); err != nil {
|
|
return err
|
|
} else if !exists {
|
|
return OnLoadCommit(db, nil, true)
|
|
}
|
|
|
|
if err := db.(ethdb.NonTransactional).ClearBuckets(dbutils.PlainStateBucket); err != nil {
|
|
return err
|
|
}
|
|
extractFunc := func(k []byte, v []byte, next etl.ExtractNextFunc) error {
|
|
return next(k, k, v)
|
|
}
|
|
|
|
if err := etl.Transform(
|
|
db,
|
|
dbutils.PlainStateBucketOld1,
|
|
dbutils.PlainStateBucket,
|
|
datadir,
|
|
extractFunc,
|
|
etl.IdentityLoadFunc,
|
|
etl.TransformArgs{OnLoadCommit: OnLoadCommit},
|
|
); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := db.(ethdb.NonTransactional).DropBuckets(dbutils.PlainStateBucketOld1); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
},
|
|
}
|