forked from erigontech/erigon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stagebuilder.go
84 lines (79 loc) · 3.1 KB
/
stagebuilder.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
package stagedsync
import (
"context"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/eth/stagedsync/stages"
"github.com/ledgerwatch/erigon/ethdb/privateapi"
"github.com/ledgerwatch/erigon/turbo/shards"
)
type ChainEventNotifier interface {
OnNewHeader(*types.Header)
OnNewPendingLogs(types.Logs)
}
type Notifications struct {
Events *privateapi.Events
Accumulator *shards.Accumulator
StateChangesConsumer shards.StateChangeConsumer
}
func MiningStages(
ctx context.Context,
createBlockCfg MiningCreateBlockCfg,
execCfg MiningExecCfg,
hashStateCfg HashStateCfg,
trieCfg TrieCfg,
finish MiningFinishCfg,
) []*Stage {
return []*Stage{
{
ID: stages.MiningCreateBlock,
Description: "Mining: construct new block from tx pool",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
return SpawnMiningCreateBlockStage(s, tx, createBlockCfg, ctx.Done())
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error { return nil },
Prune: func(firstCycle bool, u *PruneState, tx kv.RwTx) error { return nil },
},
{
ID: stages.MiningExecution,
Description: "Mining: construct new block from tx pool",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
return SpawnMiningExecStage(s, tx, execCfg, ctx.Done())
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error { return nil },
Prune: func(firstCycle bool, u *PruneState, tx kv.RwTx) error { return nil },
},
{
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, hashStateCfg, ctx)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error { return nil },
Prune: func(firstCycle bool, u *PruneState, tx kv.RwTx) error { return nil },
},
{
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 {
stateRoot, err := SpawnIntermediateHashesStage(s, u, tx, trieCfg, ctx)
if err != nil {
return err
}
createBlockCfg.miner.MiningBlock.Header.Root = stateRoot
return nil
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error { return nil },
Prune: func(firstCycle bool, u *PruneState, tx kv.RwTx) error { return nil },
},
{
ID: stages.MiningFinish,
Description: "Mining: create and propagate valid block",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx) error {
return SpawnMiningFinishStage(s, tx, finish, ctx.Done())
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error { return nil },
Prune: func(firstCycle bool, u *PruneState, tx kv.RwTx) error { return nil },
},
}
}