-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathinterface.go
More file actions
512 lines (443 loc) · 16.4 KB
/
interface.go
File metadata and controls
512 lines (443 loc) · 16.4 KB
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
package common
import (
"context"
"math/big"
"time"
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
crypto "github.com/multiversx/mx-chain-crypto-go"
"github.com/multiversx/mx-chain-go/common/configs/dto"
logger "github.com/multiversx/mx-chain-logger-go"
"github.com/multiversx/mx-chain-go/config"
)
// TrieIteratorChannels defines the channels that are being used when iterating the trie nodes
type TrieIteratorChannels struct {
LeavesChan chan core.KeyValueHolder
ErrChan BufferedErrChan
}
// TrieType defines the type of the trie
type TrieType string
const (
// MainTrie represents the main trie in which all the accounts and SC code are stored
MainTrie TrieType = "mainTrie"
// DataTrie represents a data trie in which all the data related to an account is stored
DataTrie TrieType = "dataTrie"
)
// BufferedErrChan is an interface that defines the methods for a buffered error channel
type BufferedErrChan interface {
WriteInChanNonBlocking(err error)
ReadFromChanNonBlocking() error
Close()
IsInterfaceNil() bool
}
// Trie is an interface for Merkle Trees implementations
type Trie interface {
Get(key []byte) ([]byte, uint32, error)
Update(key, value []byte) error
Delete(key []byte) error
RootHash() ([]byte, error)
Commit() error
Recreate(options RootHashHolder) (Trie, error)
String() string
GetObsoleteHashes() [][]byte
GetDirtyHashes() (ModifiedHashes, error)
GetOldRoot() []byte
GetSerializedNodes([]byte, uint64) ([][]byte, uint64, error)
GetSerializedNode([]byte) ([]byte, error)
GetAllLeavesOnChannel(allLeavesChan *TrieIteratorChannels, ctx context.Context, rootHash []byte, keyBuilder KeyBuilder, trieLeafParser TrieLeafParser) error
GetAllHashes() ([][]byte, error)
GetProof(key []byte) ([][]byte, []byte, error)
VerifyProof(rootHash []byte, key []byte, proof [][]byte) (bool, error)
GetStorageManager() StorageManager
IsMigratedToLatestVersion() (bool, error)
Close() error
IsInterfaceNil() bool
}
// TrieLeafParser is used to parse trie leaves
type TrieLeafParser interface {
ParseLeaf(key []byte, val []byte, version core.TrieNodeVersion) (core.KeyValueHolder, error)
IsInterfaceNil() bool
}
// TrieStats is used to collect the trie statistics for the given rootHash
type TrieStats interface {
GetTrieStats(address string, rootHash []byte) (TrieStatisticsHandler, error)
}
// StorageMarker is used to mark the given storer as synced and active
type StorageMarker interface {
MarkStorerAsSyncedAndActive(storer StorageManager)
IsInterfaceNil() bool
}
// KeyBuilder is used for building trie keys as you traverse the trie
type KeyBuilder interface {
BuildKey(keyPart []byte)
GetKey() ([]byte, error)
GetRawKey() []byte
DeepClone() KeyBuilder
ShallowClone() KeyBuilder
Size() uint
IsInterfaceNil() bool
}
// DataTrieHandler is an interface that declares the methods used for dataTries
type DataTrieHandler interface {
RootHash() ([]byte, error)
GetAllLeavesOnChannel(leavesChannels *TrieIteratorChannels, ctx context.Context, rootHash []byte, keyBuilder KeyBuilder, trieLeafParser TrieLeafParser) error
IsMigratedToLatestVersion() (bool, error)
IsInterfaceNil() bool
}
// StorageManager manages all trie storage operations
type StorageManager interface {
TrieStorageInteractor
GetFromCurrentEpoch(key []byte) ([]byte, error)
PutInEpoch(key []byte, val []byte, epoch uint32) error
PutInEpochWithoutCache(key []byte, val []byte, epoch uint32) error
TakeSnapshot(address string, rootHash []byte, mainTrieRootHash []byte, iteratorChannels *TrieIteratorChannels, missingNodesChan chan []byte, stats SnapshotStatisticsHandler, epoch uint32)
GetLatestStorageEpoch() (uint32, error)
IsPruningEnabled() bool
IsPruningBlocked() bool
EnterPruningBufferingMode()
ExitPruningBufferingMode()
RemoveFromAllActiveEpochs(hash []byte) error
SetEpochForPutOperation(uint32)
ShouldTakeSnapshot() bool
IsSnapshotSupported() bool
GetBaseTrieStorageManager() StorageManager
IsClosed() bool
Close() error
IsInterfaceNil() bool
}
// TrieStorageInteractor defines the methods used for interacting with the trie storage
type TrieStorageInteractor interface {
BaseStorer
GetIdentifier() string
GetStateStatsHandler() StateStatisticsHandler
}
// BaseStorer define the base methods needed for a storer
type BaseStorer interface {
Put(key, val []byte) error
Get(key []byte) ([]byte, error)
Remove(key []byte) error
Close() error
IsInterfaceNil() bool
}
// SnapshotDbHandler is used to keep track of how many references a snapshot db has
type SnapshotDbHandler interface {
BaseStorer
IsInUse() bool
DecreaseNumReferences()
IncreaseNumReferences()
MarkForRemoval()
MarkForDisconnection()
SetPath(string)
}
// TriesHolder is used to store multiple tries
type TriesHolder interface {
Put([]byte, Trie)
Replace(key []byte, tr Trie)
Get([]byte) Trie
GetAll() []Trie
Reset()
IsInterfaceNil() bool
}
// Locker defines the operations used to lock different critical areas. Implemented by the RWMutex.
type Locker interface {
Lock()
Unlock()
RLock()
RUnlock()
}
// MerkleProofVerifier is used to verify merkle proofs
type MerkleProofVerifier interface {
VerifyProof(rootHash []byte, key []byte, proof [][]byte) (bool, error)
}
// SizeSyncStatisticsHandler extends the SyncStatisticsHandler interface by allowing setting up the trie node size
type SizeSyncStatisticsHandler interface {
data.SyncStatisticsHandler
AddNumBytesReceived(bytes uint64)
NumBytesReceived() uint64
NumTries() int
AddProcessingTime(duration time.Duration)
IncrementIteration()
ProcessingTime() time.Duration
NumIterations() int
}
// SnapshotStatisticsHandler is used to measure different statistics for the trie snapshot
type SnapshotStatisticsHandler interface {
SnapshotFinished()
NewSnapshotStarted()
WaitForSnapshotsToFinish()
AddTrieStats(handler TrieStatisticsHandler, trieType TrieType)
GetSnapshotDuration() int64
GetSnapshotNumNodes() uint64
IsInterfaceNil() bool
}
// TrieStatisticsHandler is used to collect different statistics about a single trie
type TrieStatisticsHandler interface {
AddBranchNode(level int, size uint64)
AddExtensionNode(level int, size uint64)
AddLeafNode(level int, size uint64, version core.TrieNodeVersion)
AddAccountInfo(address string, rootHash []byte)
GetTotalNodesSize() uint64
GetTotalNumNodes() uint64
GetMaxTrieDepth() uint32
GetBranchNodesSize() uint64
GetNumBranchNodes() uint64
GetExtensionNodesSize() uint64
GetNumExtensionNodes() uint64
GetLeafNodesSize() uint64
GetNumLeafNodes() uint64
GetLeavesMigrationStats() map[core.TrieNodeVersion]uint64
MergeTriesStatistics(statsToBeMerged TrieStatisticsHandler)
ToString() []string
IsInterfaceNil() bool
}
// TriesStatisticsCollector is used to merge the statistics for multiple tries
type TriesStatisticsCollector interface {
Add(trieStats TrieStatisticsHandler, trieType TrieType)
Print()
GetNumNodes() uint64
}
// StateStatisticsHandler defines the behaviour of a storage statistics handler
type StateStatisticsHandler interface {
Reset()
ResetSnapshot()
IncrCache()
Cache() uint64
IncrSnapshotCache()
SnapshotCache() uint64
IncrPersister(epoch uint32)
Persister(epoch uint32) uint64
IncrWritePersister(epoch uint32)
WritePersister(epoch uint32) uint64
IncrSnapshotPersister(epoch uint32)
SnapshotPersister(epoch uint32) uint64
IncrTrie()
Trie() uint64
ProcessingStats() []string
SnapshotStats() []string
IsInterfaceNil() bool
}
// ProcessStatusHandler defines the behavior of a component able to hold the current status of the node and
// able to tell if the node is idle or processing/committing a block
type ProcessStatusHandler interface {
SetBusy(reason string)
SetIdle()
IsIdle() bool
IsInterfaceNil() bool
}
// BlockInfo provides a block information such as nonce, hash, roothash and so on
type BlockInfo interface {
GetNonce() uint64
GetHash() []byte
GetRootHash() []byte
Equal(blockInfo BlockInfo) bool
IsInterfaceNil() bool
}
// ReceiptsHolder holds receipts content (e.g. miniblocks)
type ReceiptsHolder interface {
GetMiniblocks() []*block.MiniBlock
IsInterfaceNil() bool
}
// RootHashHolder holds a rootHash and the corresponding epoch
type RootHashHolder interface {
GetRootHash() []byte
GetEpoch() core.OptionalUint32
String() string
IsInterfaceNil() bool
}
// TxSelectionOptions holds transactions selection options (parameters)
type TxSelectionOptions interface {
GetGasRequested() uint64
GetMaxNumTxs() int
GetLoopMaximumDurationMs() int
GetLoopDurationCheckInterval() int
IsInterfaceNil() bool
}
// TxSelectionOptionsAPI holds transactions selection options (parameters) for the API call
type TxSelectionOptionsAPI interface {
TxSelectionOptions
GetRequestedFields() string
}
// GasScheduleNotifierAPI defines the behavior of the gas schedule notifier components that is used for api
type GasScheduleNotifierAPI interface {
core.GasScheduleNotifier
LatestGasScheduleCopy() map[string]map[string]uint64
}
// PidQueueHandler defines the behavior of a queue of pids
type PidQueueHandler interface {
Push(pid core.PeerID)
Pop() core.PeerID
IndexOf(pid core.PeerID) int
Promote(idx int)
Remove(pid core.PeerID)
DataSizeInBytes() int
Get(idx int) core.PeerID
Len() int
IsInterfaceNil() bool
}
// EnableEpochsHandler is used to verify which flags are set in a specific epoch based on EnableEpochs config
type EnableEpochsHandler interface {
GetCurrentEpoch() uint32
IsFlagDefined(flag core.EnableEpochFlag) bool
IsFlagEnabled(flag core.EnableEpochFlag) bool
IsFlagEnabledInEpoch(flag core.EnableEpochFlag, epoch uint32) bool
GetActivationEpoch(flag core.EnableEpochFlag) uint32
IsInterfaceNil() bool
}
// EnableRoundsHandler defines the operations of an entity that manages round activation flags
type EnableRoundsHandler interface {
RoundConfirmed(round uint64, timestamp uint64)
GetCurrentRound() uint64
IsFlagDefined(flag EnableRoundFlag) bool
IsFlagEnabled(flag EnableRoundFlag) bool
IsFlagEnabledInRound(flag EnableRoundFlag, round uint64) bool
GetActivationRound(flag EnableRoundFlag) uint64
IsInterfaceNil() bool
}
// ManagedPeersHolder defines the operations of an entity that holds managed identities for a node
type ManagedPeersHolder interface {
AddManagedPeer(privateKeyBytes []byte) error
GetPrivateKey(pkBytes []byte) (crypto.PrivateKey, error)
GetP2PIdentity(pkBytes []byte) ([]byte, core.PeerID, error)
GetMachineID(pkBytes []byte) (string, error)
GetNameAndIdentity(pkBytes []byte) (string, string, error)
IncrementRoundsWithoutReceivedMessages(pkBytes []byte)
ResetRoundsWithoutReceivedMessages(pkBytes []byte, pid core.PeerID)
GetManagedKeysByCurrentNode() map[string]crypto.PrivateKey
GetLoadedKeysByCurrentNode() [][]byte
IsKeyManagedByCurrentNode(pkBytes []byte) bool
IsKeyRegistered(pkBytes []byte) bool
IsPidManagedByCurrentNode(pid core.PeerID) bool
IsKeyValidator(pkBytes []byte) bool
SetValidatorState(pkBytes []byte, state bool)
GetNextPeerAuthenticationTime(pkBytes []byte) (time.Time, error)
SetNextPeerAuthenticationTime(pkBytes []byte, nextTime time.Time)
IsMultiKeyMode() bool
GetRedundancyStepInReason() string
IsInterfaceNil() bool
}
// MissingTrieNodesNotifier defines the operations of an entity that notifies about missing trie nodes
type MissingTrieNodesNotifier interface {
RegisterHandler(handler StateSyncNotifierSubscriber) error
AsyncNotifyMissingTrieNode(hash []byte)
IsInterfaceNil() bool
}
// StateSyncNotifierSubscriber defines the operations of an entity that subscribes to a missing trie nodes notifier
type StateSyncNotifierSubscriber interface {
MissingDataTrieNodeFound(hash []byte)
IsInterfaceNil() bool
}
// ManagedPeersMonitor defines the operations of an entity that monitors the managed peers holder
type ManagedPeersMonitor interface {
GetManagedKeysCount() int
GetManagedKeys() [][]byte
GetLoadedKeys() [][]byte
GetEligibleManagedKeys() ([][]byte, error)
GetWaitingManagedKeys() ([][]byte, error)
IsInterfaceNil() bool
}
// TxExecutionOrderHandler is used to collect and provide the order of transactions execution
type TxExecutionOrderHandler interface {
Add(txHash []byte)
GetItemAtIndex(index uint32) ([]byte, error)
GetOrder(txHash []byte) (int, error)
Remove(txHash []byte)
RemoveMultiple(txHashes [][]byte)
GetItems() [][]byte
Contains(txHash []byte) bool
Clear()
Len() int
IsInterfaceNil() bool
}
// ExecutionOrderGetter defines the functionality of a component that can return the execution order of a block transactions
type ExecutionOrderGetter interface {
GetItemAtIndex(index uint32) ([]byte, error)
GetOrder(txHash []byte) (int, error)
GetItems() [][]byte
Contains(txHash []byte) bool
Len() int
IsInterfaceNil() bool
}
// ChainParametersSubscriptionHandler defines the behavior of a chain parameters subscription handler
type ChainParametersSubscriptionHandler interface {
ChainParametersChanged(chainParameters config.ChainParametersByEpochConfig)
IsInterfaceNil() bool
}
// HeadersPool defines what a headers pool structure can perform
type HeadersPool interface {
GetHeaderByHash(hash []byte) (data.HeaderHandler, error)
IsInterfaceNil() bool
}
// FieldsSizeChecker defines the behavior of a fields size checker common component
type FieldsSizeChecker interface {
IsProofSizeValid(proof data.HeaderProofHandler) bool
IsInterfaceNil() bool
}
// EpochChangeGracePeriodHandler defines the behavior of a component that can return the grace period for a specific epoch
type EpochChangeGracePeriodHandler interface {
GetGracePeriodForEpoch(epoch uint32) (uint32, error)
IsInterfaceNil() bool
}
// TrieNodeData is used to retrieve the data of a trie node
type TrieNodeData interface {
GetKeyBuilder() KeyBuilder
GetData() []byte
Size() uint64
IsLeaf() bool
GetVersion() core.TrieNodeVersion
}
// DfsIterator is used to iterate the trie nodes in a depth-first search manner
type DfsIterator interface {
GetLeaves(numLeaves int, maxSize uint64, leavesParser TrieLeafParser, ctx context.Context) (map[string]string, error)
GetIteratorState() [][]byte
IsInterfaceNil() bool
}
// TrieLeavesRetriever is used to retrieve the leaves from the trie. If there is a saved checkpoint for the iterator id,
// it will continue to iterate from the checkpoint.
type TrieLeavesRetriever interface {
GetLeaves(numLeaves int, iteratorState [][]byte, leavesParser TrieLeafParser, ctx context.Context) (map[string]string, [][]byte, error)
IsInterfaceNil() bool
}
// AccountNonceAndBalanceProvider provides the nonce and balance of accounts
type AccountNonceAndBalanceProvider interface {
GetAccountNonceAndBalance(accountKey []byte) (uint64, *big.Int, bool, error)
GetRootHash() ([]byte, error)
IsInterfaceNil() bool
}
// AccountNonceProvider provides the nonce of accounts
type AccountNonceProvider interface {
GetAccountNonce(accountKey []byte) (uint64, bool, error)
GetRootHash() ([]byte, error)
IsInterfaceNil() bool
}
// ChainParametersHandler defines the actions that need to be done by a component that can handle chain parameters
type ChainParametersHandler interface {
CurrentChainParameters() config.ChainParametersByEpochConfig
AllChainParameters() []config.ChainParametersByEpochConfig
ChainParametersForEpoch(epoch uint32) (config.ChainParametersByEpochConfig, error)
IsInterfaceNil() bool
}
// ProcessConfigsHandler defines the behavior of a component that can return the process configs for a specific epoch or round
type ProcessConfigsHandler interface {
GetMaxMetaNoncesBehindByEpoch(epoch uint32) uint32
GetMaxMetaNoncesBehindForGlobalStuckByEpoch(epoch uint32) uint32
GetMaxShardNoncesBehindByEpoch(epoch uint32) uint32
GetMaxRoundsWithoutNewBlockReceivedByRound(round uint64) uint32
GetMaxRoundsWithoutCommittedBlock(round uint64) uint32
GetRoundModulusTriggerWhenSyncIsStuck(round uint64) uint32
GetMaxSyncWithErrorsAllowed(round uint64) uint32
GetMaxRoundsToKeepUnprocessedTransactions(round uint64) uint64
GetMaxRoundsToKeepUnprocessedMiniBlocks(round uint64) uint64
GetValue(variable dto.ConfigVariable) uint64
SetActivationRound(round uint64, log logger.Logger)
IsInterfaceNil() bool
}
// CommonConfigsHandler defines the behavior of a component that can return epoch start configurations by epoch or by round
type CommonConfigsHandler interface {
GetGracePeriodRoundsByEpoch(epoch uint32) uint32
GetExtraDelayForRequestBlockInfoInMs(epoch uint32) uint32
GetMaxRoundsWithoutCommittedStartInEpochBlockInRound(round uint64) uint32
GetNumRoundsToWaitBeforeSignalingChronologyStuck(epoch uint32) uint32
SetActivationRound(round uint64, log logger.Logger)
IsInterfaceNil() bool
}