-
Notifications
You must be signed in to change notification settings - Fork 199
/
interface.go
205 lines (174 loc) · 8.25 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
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) ([]*smartContractResult.SmartContractResult, error)
ProcessSmartContractResult(scr *smartContractResult.SmartContractResult) 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) ([]*smartContractResult.SmartContractResult, error)
DeploySmartContract(tx *transaction.Transaction, acntSrc state.AccountHandler, round uint32) ([]*smartContractResult.SmartContractResult, error)
ProcessSmartContractResult(scr *smartContractResult.SmartContractResult) error
}
type PreProcessor interface {
CreateBlockStarted()
IsDataPrepared(requestedTxs int, haveTime func() time.Duration) error
RemoveTxBlockFromPools(body block.Body, miniBlockPool storage.Cacher) error
RestoreTxBlockIntoPools(body block.Body, miniBlockHashes map[int][]byte, miniBlockPool storage.Cacher) (int, 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]*transaction.Transaction
}
// 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() (bool, uint64)
GetHighestFinalBlockNonce() uint64
ProbableHighestNonce() uint64
}
// 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)
}
// 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)
RequestSmartContractResults(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 []byte) error
CreateDataFromStorageUpdate(storageUpdates []*vmcommon.StorageUpdate) []byte
GetStorageUpdates(data []byte) ([]*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
}