-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
stagebuilder.go
98 lines (92 loc) · 3.54 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
// Copyright 2024 The Erigon Authors
// This file is part of Erigon.
//
// Erigon is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Erigon is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Erigon. If not, see <http://www.gnu.org/licenses/>.
package stagedsync
import (
"context"
"github.com/erigontech/erigon-lib/log/v3"
remote "github.com/erigontech/erigon-lib/gointerfaces/remoteproto"
"github.com/erigontech/erigon-lib/kv"
"github.com/erigontech/erigon-lib/wrap"
"github.com/erigontech/erigon/core/types"
"github.com/erigontech/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 txn pool",
Forward: func(badBlockUnwind bool, s *StageState, u Unwinder, txc wrap.TxContainer, logger log.Logger) error {
return SpawnMiningCreateBlockStage(s, txc, createBlockCfg, ctx.Done(), logger)
},
Unwind: func(u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
return nil
},
Prune: func(u *PruneState, tx kv.RwTx, logger log.Logger) error { return nil },
},
{
ID: stages.MiningBorHeimdall,
Description: "Download Bor-specific data from Heimdall",
Forward: func(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(u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
return BorHeimdallUnwind(u, ctx, s, txc.Tx, borHeimdallCfg)
},
Prune: func(p *PruneState, tx kv.RwTx, logger log.Logger) error {
return nil
},
},
{
ID: stages.MiningExecution,
Description: "Mining: execute new block from txn pool",
Forward: func(badBlockUnwind bool, s *StageState, u Unwinder, txc wrap.TxContainer, logger log.Logger) error {
return SpawnMiningExecStage(s, txc, execCfg, sendersCfg, executeBlockCfg, ctx, logger, nil)
},
Unwind: func(u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
return nil
},
Prune: func(u *PruneState, tx kv.RwTx, logger log.Logger) error { return nil },
},
{
ID: stages.MiningFinish,
Description: "Mining: create and propagate valid block",
Forward: func(badBlockUnwind bool, s *StageState, u Unwinder, txc wrap.TxContainer, logger log.Logger) error {
return SpawnMiningFinishStage(s, txc.Tx, finish, ctx.Done(), logger)
},
Unwind: func(u *UnwindState, s *StageState, txc wrap.TxContainer, logger log.Logger) error {
return nil
},
Prune: func(u *PruneState, tx kv.RwTx, logger log.Logger) error { return nil },
},
}
}