erigon-pulse/cmd/state/verify/check_indexes.go
Alex Sharov 98b36126b2
History bitmap 64 (#1374)
* squash

* squash

* squash

* squash

* squash

* squash

* subscription_doesnt_preserve_shutdown
2020-12-04 21:16:51 +00:00

46 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"
"github.com/ledgerwatch/turbo-geth/ethdb/bitmapdb"
)
func CheckIndex(ctx context.Context, chaindata string, changeSetBucket string, indexBucket string) error {
db := ethdb.MustOpen(chaindata)
startTime := time.Now()
i := 0
if err := changeset.Walk(db, changeSetBucket, nil, 0, func(blockN uint64, k, v []byte) (bool, error) {
i++
if i%100_000 == 0 {
fmt.Printf("Processed %dK, %s\n", blockN/1000, time.Since(startTime))
}
select {
default:
case <-ctx.Done():
return false, ctx.Err()
}
bm, innerErr := bitmapdb.Get(db, indexBucket, dbutils.CompositeKeyWithoutIncarnation(k), uint32(blockN-1), uint32(blockN+1))
if innerErr != nil {
return false, innerErr
}
if !bm.Contains(uint32(blockN)) {
return false, fmt.Errorf("%v,%v", blockN, common.Bytes2Hex(k))
}
return true, nil
}); err != nil {
return err
}
fmt.Println("Check was succesful")
return nil
}