erigon-pulse/cmd/state/verify/verify_headers_snapshot.go
ledgerwatch cd706d5081
Download/seed block bodies and block headers via BitTorrent (#1218)
* save state

* torrent experiments

* torrent experiment passed

* fixes after merge

* snapshot headers processing passed

* save state

* save state

* download headers works after snapshot processing

* save state

* save state

* save state

* save state

* add lazy load tx to snapshots, increase number of trackers

* save state

* speedup getting info

* change logging

* move to turbo package

* save state

* save state

* save state

* cleanup

* save state

* add test test

* save state

* lmdb debugging

* fix readonly mode

* save state

* fix build

* sync works

* save state

* save state

* save state

* allow cmd stages stageSenders use snapshots

* debugging failed hashing

* remove experimental tests

* remove torrent experimental tests

* fix lint

* extract snapshot wrapper

* metainfo checker

* add remote seeder

* add logs

* update gomod

* remove useless code

* fix lint&remove useless code

* extract verify snapshot to separated command

* skip debug test

* fix test

* change type of seedSnapshot flag

* add eth logger to torrent lib

* skip debug test

* add Close method

* review fixes

* fix lint

* tidy mods

* Fix compile

* Fix lint

* Fix rpcdaemon running in the docker

Co-authored-by: b00ris <b00ris@mail.ru>
Co-authored-by: alex.sharov <AskAlexSharov@gmail.com>
2020-10-13 13:56:16 +01:00

55 lines
1.5 KiB
Go

package verify
import (
"context"
"errors"
"github.com/ledgerwatch/turbo-geth/common/dbutils"
"github.com/ledgerwatch/turbo-geth/core/types"
"github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/ledgerwatch/turbo-geth/log"
"github.com/ledgerwatch/turbo-geth/rlp"
)
func HeadersSnapshot(snapshotPath string) error {
snKV := ethdb.NewLMDB().Path(snapshotPath).ReadOnly().WithBucketsConfig(func(defaultBuckets dbutils.BucketsCfg) dbutils.BucketsCfg {
return dbutils.BucketsCfg{
dbutils.HeaderPrefix: dbutils.BucketConfigItem{},
dbutils.SnapshotInfoBucket: dbutils.BucketConfigItem{},
}
}).MustOpen()
var prevHeader *types.Header
err := snKV.View(context.Background(), func(tx ethdb.Tx) error {
c := tx.Cursor(dbutils.HeaderPrefix)
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
}