2020-05-23 09:19:56 +00:00
|
|
|
package verify
|
2020-04-20 10:35:33 +00:00
|
|
|
|
|
|
|
import (
|
2020-11-22 21:25:26 +00:00
|
|
|
"context"
|
2020-04-20 10:35:33 +00:00
|
|
|
"fmt"
|
2020-05-30 07:00:35 +00:00
|
|
|
"time"
|
|
|
|
|
2020-04-20 10:35:33 +00:00
|
|
|
"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"
|
|
|
|
)
|
|
|
|
|
2020-11-22 21:25:26 +00:00
|
|
|
func CheckIndex(ctx context.Context, chaindata string, changeSetBucket string, indexBucket string) error {
|
2020-06-16 13:36:16 +00:00
|
|
|
db := ethdb.MustOpen(chaindata)
|
2020-04-20 10:35:33 +00:00
|
|
|
startTime := time.Now()
|
|
|
|
|
2020-11-16 12:08:28 +00:00
|
|
|
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))
|
2020-04-20 10:35:33 +00:00
|
|
|
}
|
2020-11-22 21:25:26 +00:00
|
|
|
select {
|
|
|
|
default:
|
|
|
|
case <-ctx.Done():
|
|
|
|
return false, ctx.Err()
|
|
|
|
}
|
2020-04-20 10:35:33 +00:00
|
|
|
|
2020-11-16 12:08:28 +00:00
|
|
|
indexBytes, innerErr := db.GetIndexChunk(indexBucket, k, blockN)
|
|
|
|
if innerErr != nil {
|
|
|
|
return false, innerErr
|
2020-04-20 10:35:33 +00:00
|
|
|
}
|
|
|
|
|
2020-11-16 12:08:28 +00:00
|
|
|
index := dbutils.WrapHistoryIndex(indexBytes)
|
|
|
|
if findVal, _, ok := index.Search(blockN); !ok {
|
|
|
|
return false, fmt.Errorf("%v,%v,%v", blockN, findVal, common.Bytes2Hex(k))
|
2020-04-20 10:35:33 +00:00
|
|
|
}
|
|
|
|
return true, nil
|
2020-06-16 13:36:16 +00:00
|
|
|
}); err != nil {
|
2020-04-20 10:35:33 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Check was succesful")
|
|
|
|
return nil
|
|
|
|
}
|