mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-24 20:47:16 +00:00
57777e7c60
* Add kv.tx.bucket.Clear() and db.ClearBuckets() methods * Add kv.tx.bucket.Clear() and db.ClearBuckets() methods * choose db based on file suffix * implement db.id method * implement db.id method * use ethdb.NewDatabase method * use ethb.MustOpen method * cleanup * support TEST_DB env flag * create db path automatically needed * bolt - don't change prefix on happy path
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package verify
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
"github.com/ledgerwatch/turbo-geth/common/changeset"
|
|
"github.com/ledgerwatch/turbo-geth/common/dbutils"
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
|
)
|
|
|
|
func CheckIndex(chaindata string, changeSetBucket []byte, indexBucket []byte) error {
|
|
db := ethdb.MustOpen(chaindata)
|
|
startTime := time.Now()
|
|
|
|
var walker func([]byte) changeset.Walker
|
|
if bytes.Equal(dbutils.AccountChangeSetBucket, changeSetBucket) {
|
|
walker = func(cs []byte) changeset.Walker {
|
|
return changeset.AccountChangeSetBytes(cs)
|
|
}
|
|
}
|
|
|
|
if bytes.Equal(dbutils.StorageChangeSetBucket, changeSetBucket) {
|
|
walker = func(cs []byte) changeset.Walker {
|
|
return changeset.StorageChangeSetBytes(cs)
|
|
}
|
|
}
|
|
|
|
if err := db.Walk(changeSetBucket, []byte{}, 0, func(k, v []byte) (b bool, e error) {
|
|
blockNum, _ := dbutils.DecodeTimestamp(k)
|
|
if blockNum%100_000 == 0 {
|
|
fmt.Printf("Processed %dK, %s\n", blockNum/1000, time.Since(startTime))
|
|
}
|
|
|
|
if err := walker(v).Walk(func(key, val []byte) error {
|
|
indexBytes, innerErr := db.GetIndexChunk(indexBucket, key, blockNum)
|
|
if innerErr != nil {
|
|
return innerErr
|
|
}
|
|
|
|
index := dbutils.WrapHistoryIndex(indexBytes)
|
|
if findVal, _, ok := index.Search(blockNum); !ok {
|
|
return fmt.Errorf("%v,%v,%v", blockNum, findVal, common.Bytes2Hex(key))
|
|
}
|
|
return nil
|
|
}); err != nil {
|
|
return false, err
|
|
}
|
|
return true, nil
|
|
}); err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Println("Check was succesful")
|
|
return nil
|
|
}
|