-
Notifications
You must be signed in to change notification settings - Fork 9
/
blockprocessor.go
172 lines (153 loc) · 6.73 KB
/
blockprocessor.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
package blockprocessor
import (
"time"
"github.com/sedracoin/sedrad/domain/consensus/model"
"github.com/sedracoin/sedrad/domain/consensus/model/externalapi"
"github.com/sedracoin/sedrad/domain/consensus/processes/blockprocessor/blocklogger"
"github.com/sedracoin/sedrad/infrastructure/logger"
)
// blockProcessor is responsible for processing incoming blocks
// and creating blocks from the current state
type blockProcessor struct {
genesisHash *externalapi.DomainHash
targetTimePerBlock time.Duration
maxBlockLevel int
databaseContext model.DBManager
blockLogger *blocklogger.BlockLogger
consensusStateManager model.ConsensusStateManager
pruningManager model.PruningManager
blockValidator model.BlockValidator
dagTopologyManager model.DAGTopologyManager
reachabilityManager model.ReachabilityManager
difficultyManager model.DifficultyManager
pastMedianTimeManager model.PastMedianTimeManager
coinbaseManager model.CoinbaseManager
headerTipsManager model.HeadersSelectedTipManager
syncManager model.SyncManager
finalityManager model.FinalityManager
acceptanceDataStore model.AcceptanceDataStore
blockStore model.BlockStore
blockStatusStore model.BlockStatusStore
blockRelationStore model.BlockRelationStore
multisetStore model.MultisetStore
ghostdagDataStore model.GHOSTDAGDataStore
consensusStateStore model.ConsensusStateStore
pruningStore model.PruningStore
reachabilityDataStore model.ReachabilityDataStore
utxoDiffStore model.UTXODiffStore
blockHeaderStore model.BlockHeaderStore
headersSelectedTipStore model.HeaderSelectedTipStore
finalityStore model.FinalityStore
headersSelectedChainStore model.HeadersSelectedChainStore
daaBlocksStore model.DAABlocksStore
blocksWithTrustedDataDAAWindowStore model.BlocksWithTrustedDataDAAWindowStore
stores []model.Store
}
// New instantiates a new BlockProcessor
func New(
genesisHash *externalapi.DomainHash,
targetTimePerBlock time.Duration,
maxBlockLevel int,
databaseContext model.DBManager,
consensusStateManager model.ConsensusStateManager,
pruningManager model.PruningManager,
blockValidator model.BlockValidator,
dagTopologyManager model.DAGTopologyManager,
reachabilityManager model.ReachabilityManager,
difficultyManager model.DifficultyManager,
pastMedianTimeManager model.PastMedianTimeManager,
coinbaseManager model.CoinbaseManager,
headerTipsManager model.HeadersSelectedTipManager,
syncManager model.SyncManager,
acceptanceDataStore model.AcceptanceDataStore,
blockStore model.BlockStore,
blockStatusStore model.BlockStatusStore,
blockRelationStore model.BlockRelationStore,
multisetStore model.MultisetStore,
ghostdagDataStore model.GHOSTDAGDataStore,
consensusStateStore model.ConsensusStateStore,
pruningStore model.PruningStore,
reachabilityDataStore model.ReachabilityDataStore,
utxoDiffStore model.UTXODiffStore,
blockHeaderStore model.BlockHeaderStore,
headersSelectedTipStore model.HeaderSelectedTipStore,
finalityStore model.FinalityStore,
headersSelectedChainStore model.HeadersSelectedChainStore,
daaBlocksStore model.DAABlocksStore,
blocksWithTrustedDataDAAWindowStore model.BlocksWithTrustedDataDAAWindowStore,
) model.BlockProcessor {
return &blockProcessor{
genesisHash: genesisHash,
targetTimePerBlock: targetTimePerBlock,
maxBlockLevel: maxBlockLevel,
databaseContext: databaseContext,
blockLogger: blocklogger.NewBlockLogger(),
pruningManager: pruningManager,
blockValidator: blockValidator,
dagTopologyManager: dagTopologyManager,
reachabilityManager: reachabilityManager,
difficultyManager: difficultyManager,
pastMedianTimeManager: pastMedianTimeManager,
coinbaseManager: coinbaseManager,
headerTipsManager: headerTipsManager,
syncManager: syncManager,
consensusStateManager: consensusStateManager,
acceptanceDataStore: acceptanceDataStore,
blockStore: blockStore,
blockStatusStore: blockStatusStore,
blockRelationStore: blockRelationStore,
multisetStore: multisetStore,
ghostdagDataStore: ghostdagDataStore,
consensusStateStore: consensusStateStore,
pruningStore: pruningStore,
reachabilityDataStore: reachabilityDataStore,
utxoDiffStore: utxoDiffStore,
blockHeaderStore: blockHeaderStore,
headersSelectedTipStore: headersSelectedTipStore,
finalityStore: finalityStore,
headersSelectedChainStore: headersSelectedChainStore,
daaBlocksStore: daaBlocksStore,
blocksWithTrustedDataDAAWindowStore: blocksWithTrustedDataDAAWindowStore,
stores: []model.Store{
consensusStateStore,
acceptanceDataStore,
blockStore,
blockStatusStore,
blockRelationStore,
multisetStore,
ghostdagDataStore,
consensusStateStore,
pruningStore,
reachabilityDataStore,
utxoDiffStore,
blockHeaderStore,
headersSelectedTipStore,
finalityStore,
headersSelectedChainStore,
daaBlocksStore,
blocksWithTrustedDataDAAWindowStore,
},
}
}
// ValidateAndInsertBlock validates the given block and, if valid, applies it
// to the current state
func (bp *blockProcessor) ValidateAndInsertBlock(block *externalapi.DomainBlock,
shouldValidateAgainstUTXO bool) (*externalapi.VirtualChangeSet, externalapi.BlockStatus, error) {
onEnd := logger.LogAndMeasureExecutionTime(log, "ValidateAndInsertBlock")
defer onEnd()
stagingArea := model.NewStagingArea()
return bp.validateAndInsertBlock(stagingArea, block, false, shouldValidateAgainstUTXO, false)
}
func (bp *blockProcessor) ValidateAndInsertImportedPruningPoint(newPruningPoint *externalapi.DomainHash) error {
onEnd := logger.LogAndMeasureExecutionTime(log, "ValidateAndInsertImportedPruningPoint")
defer onEnd()
stagingArea := model.NewStagingArea()
return bp.validateAndInsertImportedPruningPoint(stagingArea, newPruningPoint)
}
func (bp *blockProcessor) ValidateAndInsertBlockWithTrustedData(block *externalapi.BlockWithTrustedData,
shouldValidateAgainstUTXO bool) (*externalapi.VirtualChangeSet, externalapi.BlockStatus, error) {
onEnd := logger.LogAndMeasureExecutionTime(log, "ValidateAndInsertBlockWithTrustedData")
defer onEnd()
stagingArea := model.NewStagingArea()
return bp.validateAndInsertBlockWithTrustedData(stagingArea, block, shouldValidateAgainstUTXO)
}