Skip to content

Commit 93a1be2

Browse files
Integration check history (#1040)
* integration check history * reset tx pool * reset tx pool * reset tx pool
1 parent 136ecb4 commit 93a1be2

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

cmd/integration/commands/reset_state.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ func resetState(_ context.Context) error {
102102
if err := resetTxLookup(db); err != nil {
103103
return err
104104
}
105+
if err := resetTxPool(db); err != nil {
106+
return err
107+
}
105108

106109
// set genesis after reset all buckets
107110
if _, _, err := core.DefaultGenesisBlock().CommitGenesisState(db, false); err != nil {
@@ -193,6 +196,18 @@ func resetTxLookup(db *ethdb.ObjectDatabase) error {
193196

194197
return nil
195198
}
199+
200+
func resetTxPool(db ethdb.Putter) error {
201+
if err := stages.SaveStageProgress(db, stages.TxPool, 0, nil); err != nil {
202+
return err
203+
}
204+
if err := stages.SaveStageUnwind(db, stages.TxPool, 0, nil); err != nil {
205+
return err
206+
}
207+
208+
return nil
209+
}
210+
196211
func printStages(db *ethdb.ObjectDatabase) error {
197212
var err error
198213
var progress uint64

cmd/integration/commands/state_stages.go

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package commands
33
import (
44
"bytes"
55
"context"
6+
"errors"
67
"fmt"
7-
88
"github.com/ledgerwatch/turbo-geth/cmd/utils"
9+
"github.com/ledgerwatch/turbo-geth/common/dbutils"
910

1011
"github.com/ledgerwatch/turbo-geth/common"
1112
"github.com/ledgerwatch/turbo-geth/common/changeset"
@@ -120,7 +121,8 @@ func syncBySmallSteps(ctx context.Context, chaindata string) error {
120121
}
121122

122123
// All stages forward to `execStage + unwindEvery` block
123-
execToBlock := progress(stages.Execution).BlockNumber + unwindEvery
124+
execAtBlock := progress(stages.Execution).BlockNumber
125+
execToBlock := execAtBlock + unwindEvery
124126
if execToBlock > stopAt {
125127
execToBlock = stopAt + 1
126128
unwind = 0
@@ -146,6 +148,13 @@ func syncBySmallSteps(ctx context.Context, chaindata string) error {
146148
delete(expectedStorageChanges, blockN)
147149
}
148150

151+
if err := checkHistory(tx, dbutils.AccountChangeSetBucket, execAtBlock); err != nil {
152+
return err
153+
}
154+
if err := checkHistory(tx, dbutils.StorageChangeSetBucket, execAtBlock); err != nil {
155+
return err
156+
}
157+
149158
// Unwind all stages to `execStage - unwind` block
150159
if unwind == 0 {
151160
continue
@@ -249,3 +258,47 @@ func checkChangeSet(db ethdb.Getter, blockNum uint64, expectedAccountChanges []b
249258
}
250259
return nil
251260
}
261+
262+
func checkHistory(db ethdb.Getter, changeSetBucket string, blockNum uint64) error {
263+
currentKey := dbutils.EncodeTimestamp(blockNum)
264+
265+
var walker func([]byte) changeset.Walker
266+
if dbutils.AccountChangeSetBucket == changeSetBucket {
267+
walker = func(cs []byte) changeset.Walker {
268+
return changeset.AccountChangeSetBytes(cs)
269+
}
270+
}
271+
272+
if dbutils.StorageChangeSetBucket == changeSetBucket {
273+
walker = func(cs []byte) changeset.Walker {
274+
return changeset.StorageChangeSetBytes(cs)
275+
}
276+
}
277+
278+
vv, ok := changeset.Mapper[changeSetBucket]
279+
if !ok {
280+
return errors.New("unknown bucket type")
281+
}
282+
283+
if err := db.Walk(changeSetBucket, currentKey, 0, func(k, v []byte) (b bool, e error) {
284+
blockNum, _ := dbutils.DecodeTimestamp(k)
285+
if err := walker(v).Walk(func(key, val []byte) error {
286+
indexBytes, innerErr := db.GetIndexChunk(vv.IndexBucket, key, blockNum)
287+
if innerErr != nil {
288+
return innerErr
289+
}
290+
291+
index := dbutils.WrapHistoryIndex(indexBytes)
292+
if findVal, _, ok := index.Search(blockNum); !ok {
293+
return fmt.Errorf("%v,%v,%v", blockNum, findVal, common.Bytes2Hex(key))
294+
}
295+
return nil
296+
}); err != nil {
297+
return false, err
298+
}
299+
return true, nil
300+
}); err != nil {
301+
return err
302+
}
303+
return nil
304+
}

0 commit comments

Comments
 (0)