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"
|
|
|
|
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common"
|
|
|
|
"github.com/ledgerwatch/erigon/common/changeset"
|
|
|
|
"github.com/ledgerwatch/erigon/common/dbutils"
|
|
|
|
"github.com/ledgerwatch/erigon/ethdb/bitmapdb"
|
2021-06-19 08:21:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/ethdb/kv"
|
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 {
|
2021-06-19 08:21:53 +00:00
|
|
|
db := kv.MustOpen(chaindata)
|
2021-04-03 01:52:45 +00:00
|
|
|
defer db.Close()
|
2021-07-07 16:15:49 +00:00
|
|
|
tx, err := db.BeginRo(context.Background())
|
2021-04-03 01:52:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer tx.Rollback()
|
|
|
|
|
2020-04-20 10:35:33 +00:00
|
|
|
startTime := time.Now()
|
|
|
|
|
2020-12-04 21:16:51 +00:00
|
|
|
i := 0
|
2021-04-03 01:52:45 +00:00
|
|
|
if err := changeset.Walk(tx, 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
|
|
|
|
2021-04-03 01:52:45 +00:00
|
|
|
bm, innerErr := bitmapdb.Get64(tx, 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
|
|
|
|
}
|
|
|
|
|
2021-03-29 03:58:45 +00:00
|
|
|
fmt.Println("Check was successful")
|
2020-04-20 10:35:33 +00:00
|
|
|
return nil
|
|
|
|
}
|