mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-03 17:44:29 +00:00
57473175ff
* fix test * get rid of ObjectDatabase * sn_builder_prototype2 * save state * save state * integration step1 * fix lint * fix * fix test * integrate migrator.finish * fix lint * fix build * fix typo * save state * body snapshot test * unique tx * body snapshot generation using walk * move methods out of test * block data verification added * fix lint * test with remove works correctly * fix lint * remove experiment test * fix test * add comment * add second layer of remove test * rename test * fix typos * fix lint * revert testdata * body snapshot migration save state * fix body snapshot migration * fix after merge * remove debug test * debug windows build * fix build * fix * fix lint * debug * fix * fix windows build * simplify snapshot management&&get rid of lazy tx * fix lint * fix windows path * debug * debug * debug * debug * remove geometry experiments * skip windows tests * clean * fix * fix ;int
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package verify
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/ledgerwatch/erigon/common/dbutils"
|
|
"github.com/ledgerwatch/erigon/core/types"
|
|
"github.com/ledgerwatch/erigon/ethdb"
|
|
"github.com/ledgerwatch/erigon/ethdb/kv"
|
|
"github.com/ledgerwatch/erigon/log"
|
|
"github.com/ledgerwatch/erigon/rlp"
|
|
)
|
|
|
|
func HeadersSnapshot(snapshotPath string) error {
|
|
snKV := kv.NewMDBX().Path(snapshotPath).Readonly().WithBucketsConfig(func(defaultBuckets dbutils.BucketsCfg) dbutils.BucketsCfg {
|
|
return dbutils.BucketsCfg{
|
|
dbutils.HeadersBucket: dbutils.BucketConfigItem{},
|
|
}
|
|
}).MustOpen()
|
|
var prevHeader *types.Header
|
|
err := snKV.View(context.Background(), func(tx ethdb.Tx) error {
|
|
c, err := tx.Cursor(dbutils.HeadersBucket)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
k, v, innerErr := c.First()
|
|
for {
|
|
if len(k) == 0 && len(v) == 0 {
|
|
break
|
|
}
|
|
if innerErr != nil {
|
|
return innerErr
|
|
}
|
|
|
|
header := new(types.Header)
|
|
innerErr := rlp.DecodeBytes(v, header)
|
|
if innerErr != nil {
|
|
return innerErr
|
|
}
|
|
|
|
if prevHeader != nil {
|
|
if prevHeader.Number.Uint64()+1 != header.Number.Uint64() {
|
|
log.Error("invalid header number", "p", prevHeader.Number.Uint64(), "c", header.Number.Uint64())
|
|
return errors.New("invalid header number")
|
|
}
|
|
if prevHeader.Hash() != header.ParentHash {
|
|
log.Error("invalid parent hash", "p", prevHeader.Hash(), "c", header.ParentHash)
|
|
return errors.New("invalid parent hash")
|
|
}
|
|
}
|
|
k, v, innerErr = c.Next() //nolint
|
|
prevHeader = header
|
|
}
|
|
return nil
|
|
})
|
|
return err
|
|
}
|