-
Notifications
You must be signed in to change notification settings - Fork 199
/
intermediateProcessorsContainerFactory.go
149 lines (133 loc) · 5.1 KB
/
intermediateProcessorsContainerFactory.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
package metachain
import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-core-go/hashing"
"github.com/multiversx/mx-chain-core-go/marshal"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/dataRetriever"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/process/block/postprocess"
"github.com/multiversx/mx-chain-go/process/factory/containers"
"github.com/multiversx/mx-chain-go/sharding"
)
type intermediateProcessorsContainerFactory struct {
shardCoordinator sharding.Coordinator
marshalizer marshal.Marshalizer
hasher hashing.Hasher
pubkeyConverter core.PubkeyConverter
store dataRetriever.StorageService
poolsHolder dataRetriever.PoolsHolder
economicsFee process.FeeHandler
enableEpochsHandler common.EnableEpochsHandler
executionOrderHandler common.TxExecutionOrderHandler
}
// ArgsNewIntermediateProcessorsContainerFactory defines the argument list to create a new container factory
type ArgsNewIntermediateProcessorsContainerFactory struct {
ShardCoordinator sharding.Coordinator
Marshalizer marshal.Marshalizer
Hasher hashing.Hasher
PubkeyConverter core.PubkeyConverter
Store dataRetriever.StorageService
PoolsHolder dataRetriever.PoolsHolder
EconomicsFee process.FeeHandler
EnableEpochsHandler common.EnableEpochsHandler
TxExecutionOrderHandler common.TxExecutionOrderHandler
}
// NewIntermediateProcessorsContainerFactory is responsible for creating a new intermediate processors factory object
func NewIntermediateProcessorsContainerFactory(
args ArgsNewIntermediateProcessorsContainerFactory,
) (*intermediateProcessorsContainerFactory, error) {
if check.IfNil(args.ShardCoordinator) {
return nil, process.ErrNilShardCoordinator
}
if check.IfNil(args.Marshalizer) {
return nil, process.ErrNilMarshalizer
}
if check.IfNil(args.Hasher) {
return nil, process.ErrNilHasher
}
if check.IfNil(args.PubkeyConverter) {
return nil, process.ErrNilPubkeyConverter
}
if check.IfNil(args.Store) {
return nil, process.ErrNilStorage
}
if check.IfNil(args.PoolsHolder) {
return nil, process.ErrNilPoolsHolder
}
if check.IfNil(args.EconomicsFee) {
return nil, process.ErrNilEconomicsFeeHandler
}
if check.IfNil(args.EnableEpochsHandler) {
return nil, process.ErrNilEnableEpochsHandler
}
if check.IfNil(args.TxExecutionOrderHandler) {
return nil, process.ErrNilTxExecutionOrderHandler
}
return &intermediateProcessorsContainerFactory{
shardCoordinator: args.ShardCoordinator,
marshalizer: args.Marshalizer,
hasher: args.Hasher,
pubkeyConverter: args.PubkeyConverter,
store: args.Store,
poolsHolder: args.PoolsHolder,
economicsFee: args.EconomicsFee,
enableEpochsHandler: args.EnableEpochsHandler,
executionOrderHandler: args.TxExecutionOrderHandler,
}, nil
}
// Create returns a preprocessor container that will hold all preprocessors in the system
func (ppcm *intermediateProcessorsContainerFactory) Create() (process.IntermediateProcessorContainer, error) {
container := containers.NewIntermediateTransactionHandlersContainer()
interproc, err := ppcm.createSmartContractResultsIntermediateProcessor()
if err != nil {
return nil, err
}
err = container.Add(block.SmartContractResultBlock, interproc)
if err != nil {
return nil, err
}
interproc, err = ppcm.createBadTransactionsIntermediateProcessor()
if err != nil {
return nil, err
}
err = container.Add(block.InvalidBlock, interproc)
if err != nil {
return nil, err
}
return container, nil
}
func (ppcm *intermediateProcessorsContainerFactory) createSmartContractResultsIntermediateProcessor() (process.IntermediateTransactionHandler, error) {
args := postprocess.ArgsNewIntermediateResultsProcessor{
Hasher: ppcm.hasher,
Marshalizer: ppcm.marshalizer,
Coordinator: ppcm.shardCoordinator,
PubkeyConv: ppcm.pubkeyConverter,
Store: ppcm.store,
BlockType: block.SmartContractResultBlock,
CurrTxs: ppcm.poolsHolder.CurrentBlockTxs(),
EconomicsFee: ppcm.economicsFee,
EnableEpochsHandler: ppcm.enableEpochsHandler,
TxExecutionOrderHandler: ppcm.executionOrderHandler,
}
irp, err := postprocess.NewIntermediateResultsProcessor(args)
return irp, err
}
func (ppcm *intermediateProcessorsContainerFactory) createBadTransactionsIntermediateProcessor() (process.IntermediateTransactionHandler, error) {
irp, err := postprocess.NewOneMiniBlockPostProcessor(
ppcm.hasher,
ppcm.marshalizer,
ppcm.shardCoordinator,
ppcm.store,
block.InvalidBlock,
dataRetriever.TransactionUnit,
ppcm.economicsFee,
)
return irp, err
}
// IsInterfaceNil returns true if there is no value under the interface
func (ppcm *intermediateProcessorsContainerFactory) IsInterfaceNil() bool {
return ppcm == nil
}