forked from erigontech/erigon
-
Notifications
You must be signed in to change notification settings - Fork 8
/
stagebuilder.go
109 lines (104 loc) · 4.23 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
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
package stagedsync
import (
"context"
"github.com/ledgerwatch/log/v3"
"github.com/ledgerwatch/erigon-lib/gointerfaces/remote"
"github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon-lib/wrap"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/eth/stagedsync/stages"
)
type ChainEventNotifier interface {
OnNewHeader(newHeadersRlp [][]byte)
OnNewPendingLogs(types.Logs)
OnLogs([]*remote.SubscribeLogsReply)
HasLogSubsriptions() bool
}
func MiningStages(
ctx context.Context,
createBlockCfg MiningCreateBlockCfg,
borHeimdallCfg BorHeimdallCfg,
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, txc wrap.TxContainer, logger log.Logger) error {
return SpawnMiningCreateBlockStage(s, txc.Tx, createBlockCfg, ctx.Done(), logger)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
return nil
},
Prune: func(firstCycle bool, u *PruneState, tx kv.RwTx, logger log.Logger) error { return nil },
},
{
ID: stages.MiningBorHeimdall,
Description: "Download Bor-specific data from Heimdall",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, txc wrap.TxContainer, logger log.Logger) error {
if badBlockUnwind {
return nil
}
return MiningBorHeimdallForward(ctx, borHeimdallCfg, s, u, txc.Tx, logger)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
return BorHeimdallUnwind(u, ctx, s, txc.Tx, borHeimdallCfg)
},
Prune: func(firstCycle bool, p *PruneState, tx kv.RwTx, logger log.Logger) error {
return BorHeimdallPrune(p, ctx, tx, borHeimdallCfg)
},
},
{
ID: stages.MiningExecution,
Description: "Mining: execute new block from tx pool",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, txc wrap.TxContainer, logger log.Logger) error {
return SpawnMiningExecStage(s, txc.Tx, execCfg, ctx.Done(), logger)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
return nil
},
Prune: func(firstCycle bool, u *PruneState, tx kv.RwTx, logger log.Logger) error { return nil },
},
{
ID: stages.HashState,
Description: "Hash the key in the state",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, txc wrap.TxContainer, logger log.Logger) error {
return SpawnHashStateStage(s, txc.Tx, hashStateCfg, ctx, logger)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
return nil
},
Prune: func(firstCycle bool, u *PruneState, tx kv.RwTx, logger log.Logger) error { return nil },
},
{
ID: stages.IntermediateHashes,
Description: "Generate intermediate hashes and computing state root",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, txc wrap.TxContainer, logger log.Logger) error {
stateRoot, err := SpawnIntermediateHashesStage(s, u, txc.Tx, trieCfg, ctx, logger)
if err != nil {
return err
}
createBlockCfg.miner.MiningBlock.Header.Root = stateRoot
return nil
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
return nil
},
Prune: func(firstCycle bool, u *PruneState, tx kv.RwTx, logger log.Logger) error { return nil },
},
{
ID: stages.MiningFinish,
Description: "Mining: create and propagate valid block",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, txc wrap.TxContainer, logger log.Logger) error {
return SpawnMiningFinishStage(s, txc.Tx, finish, ctx.Done(), logger)
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
return nil
},
Prune: func(firstCycle bool, u *PruneState, tx kv.RwTx, logger log.Logger) error { return nil },
},
}
}