-
Notifications
You must be signed in to change notification settings - Fork 202
/
interface.go
214 lines (196 loc) · 7.13 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
package state
import (
"context"
"math/big"
"github.com/ElrondNetwork/elrond-go-core/core"
"github.com/ElrondNetwork/elrond-go-core/data/api"
"github.com/ElrondNetwork/elrond-go/common"
vmcommon "github.com/ElrondNetwork/elrond-vm-common"
)
// AccountFactory creates an account of different types
type AccountFactory interface {
CreateAccount(address []byte) (vmcommon.AccountHandler, error)
IsInterfaceNil() bool
}
// Updater set a new value for a key, implemented by trie
type Updater interface {
Get(key []byte) ([]byte, error)
Update(key, value []byte) error
IsInterfaceNil() bool
}
// PeerAccountHandler models a peer state account, which can journalize a normal account's data
// with some extra features like signing statistics or rating information
type PeerAccountHandler interface {
GetBLSPublicKey() []byte
SetBLSPublicKey([]byte) error
GetRewardAddress() []byte
SetRewardAddress([]byte) error
GetAccumulatedFees() *big.Int
AddToAccumulatedFees(*big.Int)
GetList() string
GetIndexInList() uint32
GetShardId() uint32
SetUnStakedEpoch(epoch uint32)
GetUnStakedEpoch() uint32
IncreaseLeaderSuccessRate(uint32)
DecreaseLeaderSuccessRate(uint32)
IncreaseValidatorSuccessRate(uint32)
DecreaseValidatorSuccessRate(uint32)
IncreaseValidatorIgnoredSignaturesRate(uint32)
GetNumSelectedInSuccessBlocks() uint32
IncreaseNumSelectedInSuccessBlocks()
GetLeaderSuccessRate() SignRate
GetValidatorSuccessRate() SignRate
GetValidatorIgnoredSignaturesRate() uint32
GetTotalLeaderSuccessRate() SignRate
GetTotalValidatorSuccessRate() SignRate
GetTotalValidatorIgnoredSignaturesRate() uint32
SetListAndIndex(shardID uint32, list string, index uint32)
GetRating() uint32
SetRating(uint32)
GetTempRating() uint32
SetTempRating(uint32)
GetConsecutiveProposerMisses() uint32
SetConsecutiveProposerMisses(uint322 uint32)
ResetAtNewEpoch()
vmcommon.AccountHandler
}
// UserAccountHandler models a user account, which can journalize account's data with some extra features
// like balance, developer rewards, owner
type UserAccountHandler interface {
SetCode(code []byte)
SetCodeMetadata(codeMetadata []byte)
GetCodeMetadata() []byte
SetCodeHash([]byte)
GetCodeHash() []byte
SetRootHash([]byte)
GetRootHash() []byte
SetDataTrie(trie common.Trie)
DataTrie() common.Trie
DataTrieTracker() DataTrieTracker
RetrieveValueFromDataTrieTracker(key []byte) ([]byte, error)
AddToBalance(value *big.Int) error
SubFromBalance(value *big.Int) error
GetBalance() *big.Int
ClaimDeveloperRewards([]byte) (*big.Int, error)
AddToDeveloperReward(*big.Int)
GetDeveloperReward() *big.Int
ChangeOwnerAddress([]byte, []byte) error
SetOwnerAddress([]byte)
GetOwnerAddress() []byte
SetUserName(userName []byte)
GetUserName() []byte
vmcommon.AccountHandler
}
// DataTrieTracker models what how to manipulate data held by a SC account
type DataTrieTracker interface {
ClearDataCaches()
DirtyData() map[string][]byte
RetrieveValue(key []byte) ([]byte, error)
SaveKeyValue(key []byte, value []byte) error
SetDataTrie(tr common.Trie)
DataTrie() common.Trie
IsInterfaceNil() bool
}
// AccountsAdapter is used for the structure that manages the accounts on top of a trie.PatriciaMerkleTrie
// implementation
type AccountsAdapter interface {
GetExistingAccount(address []byte) (vmcommon.AccountHandler, error)
GetAccountFromBytes(address []byte, accountBytes []byte) (vmcommon.AccountHandler, error)
LoadAccount(address []byte) (vmcommon.AccountHandler, error)
SaveAccount(account vmcommon.AccountHandler) error
RemoveAccount(address []byte) error
CommitInEpoch(currentEpoch uint32, epochToCommit uint32) ([]byte, error)
Commit() ([]byte, error)
JournalLen() int
RevertToSnapshot(snapshot int) error
GetCode(codeHash []byte) []byte
RootHash() ([]byte, error)
RecreateTrie(rootHash []byte) error
RecreateTrieFromEpoch(options common.RootHashHolder) error
PruneTrie(rootHash []byte, identifier TriePruningIdentifier, handler PruningHandler)
CancelPrune(rootHash []byte, identifier TriePruningIdentifier)
SnapshotState(rootHash []byte)
SetStateCheckpoint(rootHash []byte)
IsPruningEnabled() bool
GetAllLeaves(leavesChannel chan core.KeyValueHolder, ctx context.Context, rootHash []byte) error
RecreateAllTries(rootHash []byte) (map[string]common.Trie, error)
GetTrie(rootHash []byte) (common.Trie, error)
GetStackDebugFirstEntry() []byte
StartSnapshotIfNeeded()
Close() error
IsInterfaceNil() bool
}
// AccountsRepository handles the defined execution based on the query options
type AccountsRepository interface {
GetAccountWithBlockInfo(address []byte, options api.AccountQueryOptions) (vmcommon.AccountHandler, common.BlockInfo, error)
GetCodeWithBlockInfo(codeHash []byte, options api.AccountQueryOptions) ([]byte, common.BlockInfo, error)
GetCurrentStateAccountsWrapper() AccountsAdapterAPI
Close() error
IsInterfaceNil() bool
}
// JournalEntry will be used to implement different state changes to be able to easily revert them
type JournalEntry interface {
Revert() (vmcommon.AccountHandler, error)
IsInterfaceNil() bool
}
type baseAccountHandler interface {
AddressBytes() []byte
IncreaseNonce(nonce uint64)
GetNonce() uint64
SetCode(code []byte)
HasNewCode() bool
SetCodeMetadata(codeMetadata []byte)
GetCodeMetadata() []byte
SetCodeHash([]byte)
GetCodeHash() []byte
SetRootHash([]byte)
GetRootHash() []byte
SetDataTrie(trie common.Trie)
DataTrie() common.Trie
DataTrieTracker() DataTrieTracker
IsInterfaceNil() bool
}
// AccountsDBImporter is used in importing accounts
type AccountsDBImporter interface {
ImportAccount(account vmcommon.AccountHandler) error
Commit() ([]byte, error)
IsInterfaceNil() bool
}
// DBRemoveCacher is used to cache keys that will be deleted from the database
type DBRemoveCacher interface {
Put([]byte, common.ModifiedHashes) error
Evict([]byte) (common.ModifiedHashes, error)
ShouldKeepHash(hash string, identifier TriePruningIdentifier) (bool, error)
IsInterfaceNil() bool
Close() error
}
// AtomicBuffer is used to buffer byteArrays
type AtomicBuffer interface {
Add(rootHash []byte)
RemoveAll() [][]byte
Len() int
}
// StoragePruningManager is used to manage all state pruning operations
type StoragePruningManager interface {
MarkForEviction([]byte, []byte, common.ModifiedHashes, common.ModifiedHashes) error
PruneTrie(rootHash []byte, identifier TriePruningIdentifier, tsm common.StorageManager, handler PruningHandler)
CancelPrune(rootHash []byte, identifier TriePruningIdentifier, tsm common.StorageManager)
Close() error
IsInterfaceNil() bool
}
// PruningHandler defines different options for pruning
type PruningHandler interface {
IsPruningEnabled() bool
}
// BlockInfoProvider defines the behavior of a struct able to provide the block information used in state tries
type BlockInfoProvider interface {
GetBlockInfo() common.BlockInfo
IsInterfaceNil() bool
}
// AccountsAdapterAPI defines the extension of the AccountsAdapter that should be used in API calls
type AccountsAdapterAPI interface {
AccountsAdapter
GetAccountWithBlockInfo(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error)
GetCodeWithBlockInfo(codeHash []byte, options common.RootHashHolder) ([]byte, common.BlockInfo, error)
}