-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdefault_stages.go
287 lines (272 loc) · 10.3 KB
/
default_stages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
package stagedsync
import (
"context"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/eth/stagedsync/stages"
"github.com/ledgerwatch/erigon/ethdb/prune"
)
func DefaultStages(ctx context.Context, sm prune.Mode, headers HeadersCfg, blockHashCfg BlockHashesCfg, bodies BodiesCfg, difficulty DifficultyCfg, senders SendersCfg, exec ExecuteBlockCfg, trans TranspileCfg, hashState HashStateCfg, trieCfg TrieCfg, history HistoryCfg, logIndex LogIndexCfg, callTraces CallTracesCfg, txLookup TxLookupCfg, finish FinishCfg, test bool) []*Stage {
return []*Stage{
{
ID: stages.Headers,
Description: "Download headers",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
if badBlockUnwind {
return nil
}
return SpawnStageHeaders(s, u, ctx, tx, headers, firstCycle, test)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error {
return HeadersUnwind(u, s, tx, headers, test)
},
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx) error {
return HeadersPrune(p, tx, headers, ctx)
},
},
{
ID: stages.BlockHashes,
Description: "Write block hashes",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
return SpawnBlockHashStage(s, tx, blockHashCfg, ctx)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error {
return UnwindBlockHashStage(u, tx, blockHashCfg, ctx)
},
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx) error {
return PruneBlockHashStage(p, tx, blockHashCfg, ctx)
},
},
{
ID: stages.Bodies,
Description: "Download block bodies",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
return BodiesForward(s, u, ctx, tx, bodies, test)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error {
return UnwindBodiesStage(u, tx, bodies, ctx)
},
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx) error {
return PruneBodiesStage(p, tx, bodies, ctx)
},
},
{
ID: stages.TotalDifficulty,
Description: "Compute total difficulty",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
return SpawnDifficultyStage(s, tx, difficulty, ctx)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error {
return UnwindDifficultyStage(u, tx, ctx)
},
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx) error {
return PruneDifficultyStage(p, tx, ctx)
},
},
{
ID: stages.Senders,
Description: "Recover senders from tx signatures",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
return SpawnRecoverSendersStage(senders, s, u, tx, 0, ctx)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error {
return UnwindSendersStage(u, tx, senders, ctx)
},
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx) error {
return PruneSendersStage(p, tx, senders, ctx)
},
},
{
ID: stages.Execution,
Description: "Execute blocks w/o hash checks",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
return SpawnExecuteBlocksStage(s, u, tx, 0, ctx, exec, firstCycle)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error {
return UnwindExecutionStage(u, s, tx, ctx, exec, firstCycle)
},
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx) error {
return PruneExecutionStage(p, tx, exec, ctx, firstCycle)
},
},
{
ID: stages.Translation,
Description: "Transpile marked EVM contracts to TEVM",
Disabled: !sm.Experiments.TEVM,
DisabledDescription: "Enable by adding `tevm` to --experiments",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
return SpawnTranspileStage(s, tx, 0, trans, ctx)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error {
return UnwindTranspileStage(u, s, tx, trans, ctx)
},
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx) error {
return PruneTranspileStage(p, tx, trans, firstCycle, ctx)
},
},
{
ID: stages.HashState,
Description: "Hash the key in the state",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
return SpawnHashStateStage(s, tx, hashState, ctx)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error {
return UnwindHashStateStage(u, s, tx, hashState, ctx)
},
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx) error {
return PruneHashStateStage(p, tx, hashState, ctx)
},
},
{
ID: stages.IntermediateHashes,
Description: "Generate intermediate hashes and computing state root",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
_, err := SpawnIntermediateHashesStage(s, u, tx, trieCfg, ctx)
return err
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error {
return UnwindIntermediateHashesStage(u, s, tx, trieCfg, ctx)
},
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx) error {
return PruneIntermediateHashesStage(p, tx, trieCfg, ctx)
},
},
{
ID: stages.CallTraces,
Description: "Generate call traces index",
DisabledDescription: "Work In Progress",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
return SpawnCallTraces(s, tx, callTraces, ctx)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error {
return UnwindCallTraces(u, s, tx, callTraces, ctx)
},
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx) error {
return PruneCallTraces(p, tx, callTraces, ctx)
},
},
{
ID: stages.AccountHistoryIndex,
Description: "Generate account history index",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
return SpawnAccountHistoryIndex(s, tx, history, ctx)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error {
return UnwindAccountHistoryIndex(u, s, tx, history, ctx)
},
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx) error {
return PruneAccountHistoryIndex(p, tx, history, ctx)
},
},
{
ID: stages.StorageHistoryIndex,
Description: "Generate storage history index",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
return SpawnStorageHistoryIndex(s, tx, history, ctx)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error {
return UnwindStorageHistoryIndex(u, s, tx, history, ctx)
},
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx) error {
return PruneStorageHistoryIndex(p, tx, history, ctx)
},
},
{
ID: stages.LogIndex,
Description: "Generate receipt logs index",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
return SpawnLogIndex(s, tx, logIndex, ctx)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error {
return UnwindLogIndex(u, s, tx, logIndex, ctx)
},
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx) error {
return PruneLogIndex(p, tx, logIndex, ctx)
},
},
{
ID: stages.TxLookup,
Description: "Generate tx lookup index",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
return SpawnTxLookup(s, tx, txLookup, ctx)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error {
return UnwindTxLookup(u, s, tx, txLookup, ctx)
},
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx) error {
return PruneTxLookup(p, tx, txLookup, ctx)
},
},
{
ID: stages.Finish,
Description: "Final: update current block for the RPC API",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, _ Unwinder, tx kv.RwTx) error {
return FinishForward(s, tx, finish, firstCycle)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error {
return UnwindFinish(u, tx, finish, ctx)
},
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx) error {
return PruneFinish(p, tx, finish, ctx)
},
},
}
}
var DefaultForwardOrder = UnwindOrder{
stages.Headers,
stages.BlockHashes,
stages.Bodies,
// Stages below don't use Internet
stages.Senders,
stages.Execution,
stages.Translation,
stages.HashState,
stages.IntermediateHashes,
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.Finish,
stages.TxLookup,
stages.LogIndex,
stages.StorageHistoryIndex,
stages.AccountHistoryIndex,
stages.CallTraces,
// Unwinding of IHashes needs to happen after unwinding HashState
stages.HashState,
stages.IntermediateHashes,
stages.Translation,
stages.Execution,
stages.Senders,
stages.Bodies,
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.HashState,
stages.IntermediateHashes,
stages.Translation,
stages.Execution,
stages.Senders,
stages.Bodies,
stages.BlockHashes,
stages.Headers,
}
var MiningUnwindOrder = UnwindOrder{} // nothing to unwind in mining - because mining does not commit db changes
var MiningPruneOrder = PruneOrder{} // nothing to unwind in mining - because mining does not commit db changes