TxLookup unwind: Remove entries for blocks between unwindPoint+1 and stage.BlockNumber (#723)

This commit is contained in:
Alex Sharov 2020-07-08 11:46:04 +07:00 committed by GitHub
parent 9881a2ccb3
commit 2689b35da9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 6 deletions

View File

@ -307,7 +307,8 @@ func stage9(ctx context.Context) error {
if unwind > 0 {
u := &stagedsync.UnwindState{Stage: stages.TxLookup, UnwindPoint: stage9.BlockNumber - unwind}
return stagedsync.UnwindTxLookup(u, db, "", ch)
s := progress(db, stages.TxLookup)
return stagedsync.UnwindTxLookup(u, s, db, "", ch)
}
return stagedsync.SpawnTxLookup(stage9, db, "", ch)

View File

@ -120,7 +120,8 @@ func syncBySmallSteps(ctx context.Context, chaindata string) error {
to := execStage.BlockNumber - unwind
{
u := &stagedsync.UnwindState{Stage: stages.TxLookup, UnwindPoint: to}
if err = stagedsync.UnwindTxLookup(u, db, "", ch); err != nil {
stage9 := progress(db, stages.TxLookup)
if err = stagedsync.UnwindTxLookup(u, stage9, db, "", ch); err != nil {
return fmt.Errorf("unwindTxLookup: %w", err)
}
}

View File

@ -64,10 +64,16 @@ func TxLookupTransform(db ethdb.Database, startKey, endKey []byte, quitCh <-chan
})
}
func UnwindTxLookup(u *UnwindState, db ethdb.Database, datadir string, quitCh <-chan struct{}) error {
func UnwindTxLookup(u *UnwindState, s *StageState, db ethdb.Database, datadir string, quitCh <-chan struct{}) error {
collector := etl.NewCollector(datadir, etl.NewSortableBuffer(etl.BufferOptimalSize))
// Remove lookup entries for all blocks above unwindPoint
if err := db.Walk(dbutils.BlockBodyPrefix, dbutils.EncodeBlockNumber(u.UnwindPoint+1), 8*8, func(k, v []byte) (b bool, e error) {
// Remove lookup entries for blocks between unwindPoint+1 and stage.BlockNumber
if err := db.Walk(dbutils.BlockBodyPrefix, dbutils.EncodeBlockNumber(u.UnwindPoint+1), 0, func(k, v []byte) (b bool, e error) {
blockNumber := binary.BigEndian.Uint64(k[:8])
if blockNumber > s.BlockNumber {
return false, nil
}
if err := common.Stopped(quitCh); err != nil {
return false, err
}

View File

@ -133,7 +133,7 @@ func PrepareStagedSync(
return SpawnTxLookup(s, stateDB, datadir, quitCh)
},
UnwindFunc: func(u *UnwindState, s *StageState) error {
return UnwindTxLookup(u, stateDB, datadir, quitCh)
return UnwindTxLookup(u, s, stateDB, datadir, quitCh)
},
},
}