erigon-pulse/cmd/state/verify/check_indexes.go
Alex Sharov 068463dff4
Store transactions individually (#1358)
* Store transactions individually

* Store transactions individually

* save progress

* checkIndex

* merge
2020-11-22 21:25:26 +00:00

45 lines
1.1 KiB
Go

package verify
import (
"context"
"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(ctx context.Context, chaindata string, changeSetBucket string, indexBucket string) error {
db := ethdb.MustOpen(chaindata)
startTime := time.Now()
if err := changeset.Walk(db, changeSetBucket, nil, 0, func(blockN uint64, k, v []byte) (bool, error) {
if blockN%100_000 == 0 {
fmt.Printf("Processed %dK, %s\n", blockN/1000, time.Since(startTime))
}
select {
default:
case <-ctx.Done():
return false, ctx.Err()
}
indexBytes, innerErr := db.GetIndexChunk(indexBucket, k, blockN)
if innerErr != nil {
return false, innerErr
}
index := dbutils.WrapHistoryIndex(indexBytes)
if findVal, _, ok := index.Search(blockN); !ok {
return false, fmt.Errorf("%v,%v,%v", blockN, findVal, common.Bytes2Hex(k))
}
return true, nil
}); err != nil {
return err
}
fmt.Println("Check was succesful")
return nil
}