-
Notifications
You must be signed in to change notification settings - Fork 202
/
interface.go
222 lines (197 loc) · 7.9 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
package epochStart
import (
"context"
"math/big"
"time"
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-go/state"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
)
// TriggerHandler defines the functionalities for an start of epoch trigger
type TriggerHandler interface {
Close() error
ForceEpochStart(round uint64)
IsEpochStart() bool
Epoch() uint32
MetaEpoch() uint32
Update(round uint64, nonce uint64)
EpochStartRound() uint64
EpochStartMetaHdrHash() []byte
GetSavedStateKey() []byte
LoadState(key []byte) error
SetProcessed(header data.HeaderHandler, body data.BodyHandler)
SetFinalityAttestingRound(round uint64)
EpochFinalityAttestingRound() uint64
RevertStateToBlock(header data.HeaderHandler) error
SetCurrentEpochStartRound(round uint64)
RequestEpochStartIfNeeded(interceptedHeader data.HeaderHandler)
IsInterfaceNil() bool
}
// RoundHandler defines the actions which should be handled by a round implementation
type RoundHandler interface {
// Index returns the current round
Index() int64
// TimeStamp returns the time stamp of the round
TimeStamp() time.Time
IsInterfaceNil() bool
}
// HeaderValidator defines the actions needed to validate a header
type HeaderValidator interface {
IsHeaderConstructionValid(currHdr, prevHdr data.HeaderHandler) error
IsInterfaceNil() bool
}
// RequestHandler defines the methods through which request to data can be made
type RequestHandler interface {
RequestShardHeader(shardId uint32, hash []byte)
RequestMetaHeader(hash []byte)
RequestMetaHeaderByNonce(nonce uint64)
RequestShardHeaderByNonce(shardId uint32, nonce uint64)
RequestStartOfEpochMetaBlock(epoch uint32)
RequestMiniBlocks(destShardID uint32, miniblocksHashes [][]byte)
RequestInterval() time.Duration
SetNumPeersToQuery(key string, intra int, cross int) error
GetNumPeersToQuery(key string) (int, int, error)
RequestValidatorInfo(hash []byte)
RequestValidatorsInfo(hashes [][]byte)
IsInterfaceNil() bool
}
// ActionHandler defines the action taken on epoch start event
type ActionHandler interface {
EpochStartAction(hdr data.HeaderHandler)
EpochStartPrepare(metaHdr data.HeaderHandler, body data.BodyHandler)
NotifyOrder() uint32
}
// RegistrationHandler provides Register and Unregister functionality for the end of epoch events
type RegistrationHandler interface {
RegisterHandler(handler ActionHandler)
UnregisterHandler(handler ActionHandler)
IsInterfaceNil() bool
}
// Notifier defines which actions should be done for handling new epoch's events
type Notifier interface {
NotifyAll(hdr data.HeaderHandler)
NotifyAllPrepare(metaHdr data.HeaderHandler, body data.BodyHandler)
NotifyEpochChangeConfirmed(epoch uint32)
IsInterfaceNil() bool
}
// ValidatorStatisticsProcessorHandler defines the actions for processing validator statistics
// needed in the epoch events
type ValidatorStatisticsProcessorHandler interface {
Process(info data.ShardValidatorInfoHandler) error
Commit() ([]byte, error)
IsInterfaceNil() bool
}
// ValidatorInfoCreator defines the methods to create a validator info
type ValidatorInfoCreator interface {
PeerAccountToValidatorInfo(peerAccount state.PeerAccountHandler) *state.ValidatorInfo
IsInterfaceNil() bool
}
// HeadersByHashSyncer defines the methods to sync all missing headers by hash
type HeadersByHashSyncer interface {
SyncMissingHeadersByHash(shardIDs []uint32, headersHashes [][]byte, ctx context.Context) error
GetHeaders() (map[string]data.HeaderHandler, error)
ClearFields()
IsInterfaceNil() bool
}
// PendingMiniBlocksSyncHandler defines the methods to sync all pending miniblocks
type PendingMiniBlocksSyncHandler interface {
SyncPendingMiniBlocks(miniBlockHeaders []data.MiniBlockHeaderHandler, ctx context.Context) error
GetMiniBlocks() (map[string]*block.MiniBlock, error)
ClearFields()
IsInterfaceNil() bool
}
// AccountsDBSyncer defines the methods for the accounts db syncer
type AccountsDBSyncer interface {
SyncAccounts(rootHash []byte) error
IsInterfaceNil() bool
}
// StartOfEpochMetaSyncer defines the methods to synchronize epoch start meta block from the network when nothing is known
type StartOfEpochMetaSyncer interface {
SyncEpochStartMeta(waitTime time.Duration) (data.MetaHeaderHandler, error)
IsInterfaceNil() bool
}
// NodesConfigProvider will provide the necessary information for start in epoch economics block creation
type NodesConfigProvider interface {
ConsensusGroupSize(shardID uint32) int
IsInterfaceNil() bool
}
// ImportStartHandler can manage the process of starting the import after the hardfork event
type ImportStartHandler interface {
ShouldStartImport() bool
IsAfterExportBeforeImport() bool
IsInterfaceNil() bool
}
// ManualEpochStartNotifier represents a notifier that can be triggered manually for an epoch change event.
// Useful in storage resolvers (import-db process)
type ManualEpochStartNotifier interface {
RegisterHandler(handler ActionHandler)
NewEpoch(epoch uint32)
CurrentEpoch() uint32
IsInterfaceNil() bool
}
// TransactionCacher defines the methods for the local transaction cacher, needed for the current block
type TransactionCacher interface {
GetTx(txHash []byte) (data.TransactionHandler, error)
IsInterfaceNil() bool
}
// ValidatorInfoCacher defines the methods for the local validator info cacher, needed for the current epoch
type ValidatorInfoCacher interface {
GetValidatorInfo(validatorInfoHash []byte) (*state.ShardValidatorInfo, error)
AddValidatorInfo(validatorInfoHash []byte, validatorInfo *state.ShardValidatorInfo)
IsInterfaceNil() bool
}
// StakingDataProvider is able to provide staking data from the system smart contracts
type StakingDataProvider interface {
GetTotalStakeEligibleNodes() *big.Int
GetTotalTopUpStakeEligibleNodes() *big.Int
GetNodeStakedTopUp(blsKey []byte) (*big.Int, error)
PrepareStakingDataForRewards(keys map[uint32][][]byte) error
FillValidatorInfo(blsKey []byte) error
ComputeUnQualifiedNodes(validatorInfos map[uint32][]*state.ValidatorInfo) ([][]byte, map[string][][]byte, error)
Clean()
IsInterfaceNil() bool
}
// EpochEconomicsDataProvider provides end of epoch economics data
type EpochEconomicsDataProvider interface {
SetNumberOfBlocks(nbBlocks uint64)
SetNumberOfBlocksPerShard(blocksPerShard map[uint32]uint64)
SetLeadersFees(fees *big.Int)
SetRewardsToBeDistributed(rewards *big.Int)
SetRewardsToBeDistributedForBlocks(rewards *big.Int)
NumberOfBlocks() uint64
NumberOfBlocksPerShard() map[uint32]uint64
LeaderFees() *big.Int
RewardsToBeDistributed() *big.Int
RewardsToBeDistributedForBlocks() *big.Int
IsInterfaceNil() bool
}
// RewardsCreator defines the functionality for the metachain to create rewards at end of epoch
type RewardsCreator interface {
CreateRewardsMiniBlocks(
metaBlock data.MetaHeaderHandler, validatorsInfo map[uint32][]*state.ValidatorInfo, computedEconomics *block.Economics,
) (block.MiniBlockSlice, error)
VerifyRewardsMiniBlocks(
metaBlock data.MetaHeaderHandler, validatorsInfo map[uint32][]*state.ValidatorInfo, computedEconomics *block.Economics,
) error
GetProtocolSustainabilityRewards() *big.Int
GetLocalTxCache() TransactionCacher
CreateMarshalledData(body *block.Body) map[string][][]byte
GetRewardsTxs(body *block.Body) map[string]data.TransactionHandler
SaveBlockDataToStorage(metaBlock data.MetaHeaderHandler, body *block.Body)
DeleteBlockDataFromStorage(metaBlock data.MetaHeaderHandler, body *block.Body)
RemoveBlockDataFromPools(metaBlock data.MetaHeaderHandler, body *block.Body)
IsInterfaceNil() bool
}
// EpochNotifier can notify upon an epoch change and provide the current epoch
type EpochNotifier interface {
RegisterNotifyHandler(handler vmcommon.EpochSubscriberHandler)
CurrentEpoch() uint32
CheckEpoch(epoch uint32)
IsInterfaceNil() bool
}
// EpochStartNotifier defines which actions should be done for handling new epoch's events
type EpochStartNotifier interface {
RegisterHandler(handler ActionHandler)
IsInterfaceNil() bool
}