-
Notifications
You must be signed in to change notification settings - Fork 197
/
interface.go
279 lines (234 loc) · 11.2 KB
/
interface.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
package process
import (
"math/big"
"time"
"github.com/ElrondNetwork/elrond-go/data"
"github.com/ElrondNetwork/elrond-go/data/block"
"github.com/ElrondNetwork/elrond-go/data/smartContractResult"
"github.com/ElrondNetwork/elrond-go/data/state"
"github.com/ElrondNetwork/elrond-go/data/transaction"
"github.com/ElrondNetwork/elrond-go/p2p"
"github.com/ElrondNetwork/elrond-go/sharding"
"github.com/ElrondNetwork/elrond-go/storage"
"github.com/ElrondNetwork/elrond-vm-common"
)
// TransactionProcessor is the main interface for transaction execution engine
type TransactionProcessor interface {
ProcessTransaction(transaction *transaction.Transaction, round uint32) error
}
// SmartContractResultProcessor is the main interface for smart contract result execution engine
type SmartContractResultProcessor interface {
ProcessSmartContractResult(scr *smartContractResult.SmartContractResult) error
}
// TxTypeHandler is an interface to calculate the transaction type
type TxTypeHandler interface {
ComputeTransactionType(tx data.TransactionHandler) (TransactionType, error)
}
// TransactionCoordinator is an interface to coordinate transaction processing using multiple processors
type TransactionCoordinator interface {
RequestMiniBlocks(header data.HeaderHandler)
RequestBlockTransactions(body block.Body)
IsDataPreparedForProcessing(haveTime func() time.Duration) error
SaveBlockDataToStorage(body block.Body) error
RestoreBlockDataFromStorage(body block.Body) (int, map[int][][]byte, error)
RemoveBlockDataFromPool(body block.Body) error
ProcessBlockTransaction(body block.Body, round uint32, haveTime func() time.Duration) error
CreateBlockStarted()
CreateMbsAndProcessCrossShardTransactionsDstMe(header data.HeaderHandler, maxTxRemaining uint32, round uint32, haveTime func() bool) (block.MiniBlockSlice, uint32, bool)
CreateMbsAndProcessTransactionsFromMe(maxTxRemaining uint32, round uint32, haveTime func() bool) block.MiniBlockSlice
CreateMarshalizedData(body block.Body) (map[uint32]block.MiniBlockSlice, map[uint32][][]byte)
GetAllCurrentUsedTxs(blockType block.Type) map[string]data.TransactionHandler
VerifyCreatedBlockTransactions(body block.Body) error
}
// SmartContractProcessor is the main interface for the smart contract caller engine
type SmartContractProcessor interface {
ComputeTransactionType(tx *transaction.Transaction) (TransactionType, error)
ExecuteSmartContractTransaction(tx *transaction.Transaction, acntSrc, acntDst state.AccountHandler, round uint32) error
DeploySmartContract(tx *transaction.Transaction, acntSrc state.AccountHandler, round uint32) error
}
// IntermediateTransactionHandler handles transactions which are not resolved in only one step
type IntermediateTransactionHandler interface {
AddIntermediateTransactions(txs []data.TransactionHandler) error
CreateAllInterMiniBlocks() map[uint32]*block.MiniBlock
VerifyInterMiniBlocks(body block.Body) error
SaveCurrentIntermediateTxToStorage() error
CreateBlockStarted()
}
// PreProcessor is an interface used to prepare and process transaction data
type PreProcessor interface {
CreateBlockStarted()
IsDataPrepared(requestedTxs int, haveTime func() time.Duration) error
RemoveTxBlockFromPools(body block.Body, miniBlockPool storage.Cacher) error
RestoreTxBlockIntoPools(body block.Body, miniBlockPool storage.Cacher) (int, map[int][]byte, error)
SaveTxBlockToStorage(body block.Body) error
ProcessBlockTransactions(body block.Body, round uint32, haveTime func() time.Duration) error
RequestBlockTransactions(body block.Body) int
CreateMarshalizedData(txHashes [][]byte) ([][]byte, error)
RequestTransactionsForMiniBlock(mb block.MiniBlock) int
ProcessMiniBlock(miniBlock *block.MiniBlock, haveTime func() bool, round uint32) error
CreateAndProcessMiniBlock(sndShardId, dstShardId uint32, spaceRemained int, haveTime func() bool, round uint32) (*block.MiniBlock, error)
GetAllCurrentUsedTxs() map[string]data.TransactionHandler
}
// BlockProcessor is the main interface for block execution engine
type BlockProcessor interface {
ProcessBlock(blockChain data.ChainHandler, header data.HeaderHandler, body data.BodyHandler, haveTime func() time.Duration) error
CommitBlock(blockChain data.ChainHandler, header data.HeaderHandler, body data.BodyHandler) error
RevertAccountState()
CreateBlockBody(round uint32, haveTime func() bool) (data.BodyHandler, error)
RestoreBlockIntoPools(header data.HeaderHandler, body data.BodyHandler) error
CreateBlockHeader(body data.BodyHandler, round uint32, haveTime func() bool) (data.HeaderHandler, error)
MarshalizedDataToBroadcast(header data.HeaderHandler, body data.BodyHandler) (map[uint32][]byte, map[uint32][][]byte, error)
DecodeBlockBody(dta []byte) data.BodyHandler
DecodeBlockHeader(dta []byte) data.HeaderHandler
SetLastNotarizedHdr(shardId uint32, processedHdr data.HeaderHandler)
}
// Checker provides functionality to checks the integrity and validity of a data structure
type Checker interface {
// IntegrityAndValidity does both validity and integrity checks on the data structure
IntegrityAndValidity(coordinator sharding.Coordinator) error
// Integrity checks only the integrity of the data
Integrity(coordinator sharding.Coordinator) error
}
// SigVerifier provides functionality to verify a signature of a signed data structure that holds also the verifying parameters
type SigVerifier interface {
VerifySig() error
}
// SignedDataValidator provides functionality to check the validity and signature of a data structure
type SignedDataValidator interface {
SigVerifier
Checker
}
// HashAccesser interface provides functionality over hashable objects
type HashAccesser interface {
SetHash([]byte)
Hash() []byte
}
// InterceptedBlockBody interface provides functionality over intercepted blocks
type InterceptedBlockBody interface {
Checker
HashAccesser
GetUnderlyingObject() interface{}
}
// Bootstrapper is an interface that defines the behaviour of a struct that is able
// to synchronize the node
type Bootstrapper interface {
AddSyncStateListener(func(bool))
ShouldSync() bool
StopSync()
StartSync()
}
// ForkDetector is an interface that defines the behaviour of a struct that is able
// to detect forks
type ForkDetector interface {
AddHeader(header data.HeaderHandler, hash []byte, state BlockHeaderState) error
RemoveHeaders(nonce uint64, hash []byte)
CheckFork() (forkDetected bool, nonce uint64, hash []byte)
GetHighestFinalBlockNonce() uint64
ProbableHighestNonce() uint64
ResetProbableHighestNonceIfNeeded()
}
// InterceptorsContainer defines an interceptors holder data type with basic functionality
type InterceptorsContainer interface {
Get(key string) (Interceptor, error)
Add(key string, val Interceptor) error
AddMultiple(keys []string, interceptors []Interceptor) error
Replace(key string, val Interceptor) error
Remove(key string)
Len() int
}
// InterceptorsContainerFactory defines the functionality to create an interceptors container
type InterceptorsContainerFactory interface {
Create() (InterceptorsContainer, error)
}
// PreProcessorsContainer defines an PreProcessors holder data type with basic functionality
type PreProcessorsContainer interface {
Get(key block.Type) (PreProcessor, error)
Add(key block.Type, val PreProcessor) error
AddMultiple(keys []block.Type, preprocessors []PreProcessor) error
Replace(key block.Type, val PreProcessor) error
Remove(key block.Type)
Len() int
Keys() []block.Type
}
// PreProcessorsContainerFactory defines the functionality to create an PreProcessors container
type PreProcessorsContainerFactory interface {
Create() (PreProcessorsContainer, error)
}
// IntermediateProcessorContainer defines an IntermediateProcessor holder data type with basic functionality
type IntermediateProcessorContainer interface {
Get(key block.Type) (IntermediateTransactionHandler, error)
Add(key block.Type, val IntermediateTransactionHandler) error
AddMultiple(keys []block.Type, preprocessors []IntermediateTransactionHandler) error
Replace(key block.Type, val IntermediateTransactionHandler) error
Remove(key block.Type)
Len() int
Keys() []block.Type
}
// IntermediateProcessorsContainerFactory defines the functionality to create an IntermediateProcessors container
type IntermediateProcessorsContainerFactory interface {
Create() (IntermediateProcessorContainer, error)
}
// Interceptor defines what a data interceptor should do
// It should also adhere to the p2p.MessageProcessor interface so it can wire to a p2p.Messenger
type Interceptor interface {
ProcessReceivedMessage(message p2p.MessageP2P) error
}
// MessageHandler defines the functionality needed by structs to send data to other peers
type MessageHandler interface {
ConnectedPeersOnTopic(topic string) []p2p.PeerID
SendToConnectedPeer(topic string, buff []byte, peerID p2p.PeerID) error
}
// TopicHandler defines the functionality needed by structs to manage topics and message processors
type TopicHandler interface {
HasTopic(name string) bool
CreateTopic(name string, createChannelForTopic bool) error
RegisterMessageProcessor(topic string, handler p2p.MessageProcessor) error
}
// TopicMessageHandler defines the functionality needed by structs to manage topics, message processors and to send data
// to other peers
type TopicMessageHandler interface {
MessageHandler
TopicHandler
}
// ChronologyValidator defines the functionality needed to validate a received header block (shard or metachain)
// from chronology point of view
type ChronologyValidator interface {
ValidateReceivedBlock(shardID uint32, epoch uint32, nonce uint64, round uint32) error
}
// DataPacker can split a large slice of byte slices in smaller packets
type DataPacker interface {
PackDataInChunks(data [][]byte, limit int) ([][]byte, error)
}
// BlocksTracker defines the functionality to track all the notarised blocks
type BlocksTracker interface {
UnnotarisedBlocks() []data.HeaderHandler
RemoveNotarisedBlocks(headerHandler data.HeaderHandler) error
AddBlock(headerHandler data.HeaderHandler)
SetBlockBroadcastRound(nonce uint64, round int32)
BlockBroadcastRound(nonce uint64) int32
}
// RequestHandler defines the methods through which request to data can be made
type RequestHandler interface {
RequestHeaderByNonce(shardId uint32, nonce uint64)
RequestTransaction(shardId uint32, txHashes [][]byte)
RequestUnsignedTransactions(destShardID uint32, scrHashes [][]byte)
RequestMiniBlock(shardId uint32, miniblockHash []byte)
RequestHeader(shardId uint32, hash []byte)
}
// ArgumentsParser defines the functionality to parse transaction data into arguments and code for smart contracts
type ArgumentsParser interface {
GetArguments() ([]*big.Int, error)
GetCode() ([]byte, error)
GetFunction() (string, error)
ParseData(data string) error
CreateDataFromStorageUpdate(storageUpdates []*vmcommon.StorageUpdate) string
GetStorageUpdates(data string) ([]*vmcommon.StorageUpdate, error)
}
// TemporaryAccountsHandler defines the functionality to create temporary accounts and pass to VM.
// This holder will contain usually one account from shard X that calls a SC in shard Y
// so when executing the code in shard Y, this impl will hold an ephemeral copy of the sender account from shard X
type TemporaryAccountsHandler interface {
AddTempAccount(address []byte, balance *big.Int, nonce uint64)
CleanTempAccounts()
TempAccount(address []byte) state.AccountHandler
}