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-12-04 21:16:51 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/ethdb/bitmapdb"
|
2020-04-20 10:35:33 +00:00
|
|
|
)
|
|
|
|
|
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-12-04 21:16:51 +00:00
|
|
|
i := 0
|
2020-11-16 12:08:28 +00:00
|
|
|
if err := changeset.Walk(db, changeSetBucket, nil, 0, func(blockN uint64, k, v []byte) (bool, error) {
|
2020-12-04 21:16:51 +00:00
|
|
|
i++
|
|
|
|
if i%100_000 == 0 {
|
2020-11-16 12:08:28 +00:00
|
|
|
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-12-26 02:01:00 +00:00
|
|
|
bm, innerErr := bitmapdb.Get64(db, indexBucket, dbutils.CompositeKeyWithoutIncarnation(k), blockN-1, blockN+1)
|
2020-11-16 12:08:28 +00:00
|
|
|
if innerErr != nil {
|
|
|
|
return false, innerErr
|
2020-04-20 10:35:33 +00:00
|
|
|
}
|
2020-12-26 02:01:00 +00:00
|
|
|
if !bm.Contains(blockN) {
|
2020-12-04 21:16:51 +00:00
|
|
|
return false, fmt.Errorf("%v,%v", blockN, 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
|
|
|
|
}
|