forked from erigontech/erigon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stagebuilder.go
82 lines (77 loc) · 3.07 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
package stagedsync
import (
"context"
"github.com/ledgerwatch/log/v3"
remote "github.com/ledgerwatch/erigon-lib/gointerfaces/remoteproto"
"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,
executeBlockCfg ExecuteBlockCfg,
sendersCfg SendersCfg,
execCfg MiningExecCfg,
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, execCfg, sendersCfg, executeBlockCfg, 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.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 },
},
}
}