diff --git a/eth/stagedsync/default_stages.go b/eth/stagedsync/default_stages.go index 7d8d5762fb839dfee073cd1b81d7d1f686b4edb9..f881db0e2fc25ac40a9db18c18b35c228719ba9a 100644 --- a/eth/stagedsync/default_stages.go +++ b/eth/stagedsync/default_stages.go @@ -291,6 +291,8 @@ var DefaultForwardOrder = UnwindOrder{ stages.CreateHeadersSnapshot, stages.Bodies, stages.CreateBodiesSnapshot, + + // Stages below don't use Internet stages.Senders, stages.Execution, stages.Translation, @@ -306,66 +308,67 @@ var DefaultForwardOrder = UnwindOrder{ stages.Finish, } -var DefaultPruneOrder = PruneOrder{ - stages.Headers, - stages.BlockHashes, - stages.CreateHeadersSnapshot, - stages.Bodies, - stages.CreateBodiesSnapshot, - - // Unwinding of tx pool (reinjecting transactions into the pool needs to happen after unwinding execution) - // also tx pool is before senders because senders unwind is inside cycle transaction - stages.TxPool, - - stages.Senders, - stages.Execution, - stages.Translation, - stages.CreateStateSnapshot, - - // Unwinding of IHashes needs to happen after unwinding HashState - stages.IntermediateHashes, - stages.HashState, - - stages.CallTraces, - stages.AccountHistoryIndex, - stages.StorageHistoryIndex, - stages.LogIndex, - stages.TxLookup, - stages.Finish, -} - // UnwindOrder represents the order in which the stages needs to be unwound. // The unwind order is important and not always just stages going backwards. // Let's say, there is tx pool can be unwound only after execution. +// It's ok to remove some stage from here to disable only unwind of stage type UnwindOrder []stages.SyncStage type PruneOrder []stages.SyncStage var DefaultUnwindOrder = UnwindOrder{ - stages.Headers, - stages.BlockHashes, - stages.CreateHeadersSnapshot, - stages.Bodies, - stages.CreateBodiesSnapshot, + stages.Finish, + stages.TxLookup, + stages.LogIndex, + stages.StorageHistoryIndex, + stages.AccountHistoryIndex, + stages.CallTraces, - // Unwinding of tx pool (reinjecting transactions into the pool needs to happen after unwinding execution) + // Unwinding of IHashes needs to happen after unwinding HashState + stages.HashState, + stages.IntermediateHashes, + + stages.CreateStateSnapshot, + stages.Translation, + stages.Execution, + stages.Senders, + + // Unwinding of tx pool (re-injecting transactions into the pool needs to happen after unwinding execution) // also tx pool is before senders because senders unwind is inside cycle transaction stages.TxPool, - stages.Senders, - stages.Execution, - stages.Translation, - stages.CreateStateSnapshot, + stages.CreateBodiesSnapshot, + stages.Bodies, + stages.CreateHeadersSnapshot, + stages.BlockHashes, + stages.Headers, +} + +var DefaultPruneOrder = PruneOrder{ + stages.Finish, + stages.TxLookup, + stages.LogIndex, + stages.StorageHistoryIndex, + stages.AccountHistoryIndex, + stages.CallTraces, // Unwinding of IHashes needs to happen after unwinding HashState - stages.IntermediateHashes, stages.HashState, + stages.IntermediateHashes, - stages.CallTraces, - stages.AccountHistoryIndex, - stages.StorageHistoryIndex, - stages.LogIndex, - stages.TxLookup, - stages.Finish, + stages.CreateStateSnapshot, + stages.Translation, + stages.Execution, + stages.Senders, + + // Unwinding of tx pool (reinjecting transactions into the pool needs to happen after unwinding execution) + // also tx pool is before senders because senders unwind is inside cycle transaction + stages.TxPool, + + stages.CreateBodiesSnapshot, + stages.Bodies, + stages.CreateHeadersSnapshot, + stages.BlockHashes, + stages.Headers, } var MiningUnwindOrder = UnwindOrder{} // nothing to unwind in mining - because mining does not commit db changes diff --git a/eth/stagedsync/sync.go b/eth/stagedsync/sync.go index 02203feff8c3f7a94c9b125fecb6d7bfc1828a0e..fbbfc593c3f93b4a0a1c855a51e9c1c39361efe1 100644 --- a/eth/stagedsync/sync.go +++ b/eth/stagedsync/sync.go @@ -162,15 +162,15 @@ func (s *Sync) Run(db ethdb.RwKV, tx ethdb.RwTx, firstCycle bool) error { var timings []interface{} for !s.IsDone() { if s.unwindPoint != nil { - for i := len(s.unwindOrder) - 1; i >= 0; i-- { - if s.unwindOrder[i].Disabled || s.unwindOrder[i].Unwind == nil { + for j := 0; j < len(s.unwindOrder); j++ { + if s.unwindOrder[j].Disabled || s.unwindOrder[j].Unwind == nil { continue } t := time.Now() - if err := s.unwindStage(firstCycle, s.unwindOrder[i], db, tx); err != nil { + if err := s.unwindStage(firstCycle, s.unwindOrder[j], db, tx); err != nil { return err } - timings = append(timings, "Unwind "+string(s.unwindOrder[i].ID), time.Since(t)) + timings = append(timings, "Unwind "+string(s.unwindOrder[j].ID), time.Since(t)) } s.prevUnwindPoint = s.unwindPoint s.unwindPoint = nil @@ -204,7 +204,7 @@ func (s *Sync) Run(db ethdb.RwKV, tx ethdb.RwTx, firstCycle bool) error { s.NextStage() } - for i := len(s.pruningOrder) - 1; i >= 0; i-- { + for i := 0; i < len(s.pruningOrder); i++ { if s.pruningOrder[i].Disabled || s.pruningOrder[i].Prune == nil { continue } diff --git a/eth/stagedsync/sync_test.go b/eth/stagedsync/sync_test.go index 7bfb669a3088d7ffd1207d5e98f1ac807cc94f07..9ccbe630e5e233dd77d31f3c6467e79135bab2fd 100644 --- a/eth/stagedsync/sync_test.go +++ b/eth/stagedsync/sync_test.go @@ -119,7 +119,7 @@ func TestErroredStage(t *testing.T) { }, }, } - state := New(s, []stages.SyncStage{s[0].ID, s[1].ID, s[2].ID}, nil) + state := New(s, []stages.SyncStage{s[2].ID, s[1].ID, s[0].ID}, nil) db, tx := kv.NewTestTx(t) err := state.Run(db, tx, true) assert.Equal(t, expectedErr, err) @@ -202,7 +202,7 @@ func TestUnwindSomeStagesBehindUnwindPoint(t *testing.T) { }, }, } - state := New(s, []stages.SyncStage{s[0].ID, s[1].ID, s[2].ID, s[3].ID}, nil) + state := New(s, []stages.SyncStage{s[3].ID, s[2].ID, s[1].ID, s[0].ID}, nil) db, tx := kv.NewTestTx(t) err := state.Run(db, tx, true) assert.NoError(t, err) @@ -295,7 +295,7 @@ func TestUnwind(t *testing.T) { }, }, } - state := New(s, []stages.SyncStage{s[0].ID, s[1].ID, s[2].ID, s[3].ID}, nil) + state := New(s, []stages.SyncStage{s[3].ID, s[2].ID, s[1].ID, s[0].ID}, nil) db, tx := kv.NewTestTx(t) err := state.Run(db, tx, true) assert.NoError(t, err) @@ -322,7 +322,7 @@ func TestUnwind(t *testing.T) { //check that at unwind disabled stage not appear flow = flow[:0] - state.unwindOrder = []*Stage{s[0], s[1], s[2], s[3]} + state.unwindOrder = []*Stage{s[3], s[2], s[1], s[0]} state.UnwindTo(100, common.Hash{}) err = state.Run(db, tx, true) assert.NoError(t, err) @@ -384,7 +384,7 @@ func TestUnwindEmptyUnwinder(t *testing.T) { }, }, } - state := New(s, []stages.SyncStage{s[0].ID, s[1].ID, s[2].ID}, nil) + state := New(s, []stages.SyncStage{s[2].ID, s[1].ID, s[0].ID}, nil) db, tx := kv.NewTestTx(t) err := state.Run(db, tx, true) assert.NoError(t, err) @@ -577,7 +577,7 @@ func TestSyncInterruptLongUnwind(t *testing.T) { }, }, } - state := New(s, []stages.SyncStage{s[0].ID, s[1].ID, s[2].ID}, nil) + state := New(s, []stages.SyncStage{s[2].ID, s[1].ID, s[0].ID}, nil) db, tx := kv.NewTestTx(t) err := state.Run(db, tx, true) assert.Error(t, errInterrupted, err)