-
Notifications
You must be signed in to change notification settings - Fork 199
/
interface.go
228 lines (202 loc) · 6.48 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
package data
import (
"context"
"math/big"
"github.com/ElrondNetwork/elrond-go/config"
)
// TriePruningIdentifier is the type for trie pruning identifiers
type TriePruningIdentifier byte
const (
// OldRoot is appended to the key when oldHashes are added to the evictionWaitingList
OldRoot TriePruningIdentifier = 0
// NewRoot is appended to the key when newHashes are added to the evictionWaitingList
NewRoot TriePruningIdentifier = 1
)
// ModifiedHashes is used to memorize all old hashes and new hashes from when a trie is committed
type ModifiedHashes map[string]struct{}
// HeaderHandler defines getters and setters for header data holder
type HeaderHandler interface {
GetShardID() uint32
GetNonce() uint64
GetEpoch() uint32
GetRound() uint64
GetRootHash() []byte
GetValidatorStatsRootHash() []byte
GetPrevHash() []byte
GetPrevRandSeed() []byte
GetRandSeed() []byte
GetPubKeysBitmap() []byte
GetSignature() []byte
GetLeaderSignature() []byte
GetChainID() []byte
GetTimeStamp() uint64
GetTxCount() uint32
GetReceiptsHash() []byte
GetAccumulatedFees() *big.Int
GetEpochStartMetaHash() []byte
SetAccumulatedFees(value *big.Int)
SetShardID(shId uint32)
SetNonce(n uint64)
SetEpoch(e uint32)
SetRound(r uint64)
SetTimeStamp(ts uint64)
SetRootHash(rHash []byte)
SetValidatorStatsRootHash(rHash []byte)
SetPrevHash(pvHash []byte)
SetPrevRandSeed(pvRandSeed []byte)
SetRandSeed(randSeed []byte)
SetPubKeysBitmap(pkbm []byte)
SetSignature(sg []byte)
SetLeaderSignature(sg []byte)
SetChainID(chainID []byte)
SetTxCount(txCount uint32)
IsStartOfEpochBlock() bool
GetMiniBlockHeadersWithDst(destId uint32) map[string]uint32
IsInterfaceNil() bool
Clone() HeaderHandler
CheckChainID(reference []byte) error
}
// BodyHandler interface for a block body
type BodyHandler interface {
Clone() BodyHandler
// IntegrityAndValidity checks the integrity and validity of the block
IntegrityAndValidity() error
// IsInterfaceNil returns true if there is no value under the interface
IsInterfaceNil() bool
}
// ChainHandler is the interface defining the functionality a blockchain should implement
type ChainHandler interface {
GetGenesisHeader() HeaderHandler
SetGenesisHeader(gb HeaderHandler) error
GetGenesisHeaderHash() []byte
SetGenesisHeaderHash(hash []byte)
GetCurrentBlockHeader() HeaderHandler
SetCurrentBlockHeader(bh HeaderHandler) error
GetCurrentBlockHeaderHash() []byte
SetCurrentBlockHeaderHash(hash []byte)
IsInterfaceNil() bool
CreateNewHeader() HeaderHandler
}
// TransactionHandler defines the type of executable transaction
type TransactionHandler interface {
IsInterfaceNil() bool
GetValue() *big.Int
GetNonce() uint64
GetData() []byte
GetRcvAddr() []byte
GetSndAddr() []byte
GetGasLimit() uint64
GetGasPrice() uint64
SetValue(*big.Int)
SetData([]byte)
SetRcvAddr([]byte)
SetSndAddr([]byte)
}
// LogHandler defines the type for a log resulted from executing a transaction or smart contract call
type LogHandler interface {
// GetAddress returns the address of the sc that was originally called by the user
GetAddress() []byte
// GetLogEvents returns the events from a transaction log entry
GetLogEvents() []EventHandler
IsInterfaceNil() bool
}
// EventHandler defines the type for an event resulted from a smart contract call contained in a log
type EventHandler interface {
// GetAddress returns the address of the contract that generated this event
// - in sc calling another sc situation this will differ from the
// LogHandler's GetAddress, whereas in the single sc situation
// they will be the same
GetAddress() []byte
// GetIdentifier returns identifier of the event, that together with the ABI can
// be used to understand the type of the event by other applications
GetIdentifier() []byte
// GetTopics returns the data that can be indexed so that it would be searchable
// by other applications
GetTopics() [][]byte
// GetData returns the rest of the event data, which will not be indexed, so storing
// information here should be cheaper
GetData() []byte
IsInterfaceNil() bool
}
//Trie is an interface for Merkle Trees implementations
type Trie interface {
Get(key []byte) ([]byte, error)
Update(key, value []byte) error
Delete(key []byte) error
Root() ([]byte, error)
Commit() error
Recreate(root []byte) (Trie, error)
String() string
CancelPrune(rootHash []byte, identifier TriePruningIdentifier)
Prune(rootHash []byte, identifier TriePruningIdentifier)
TakeSnapshot(rootHash []byte)
SetCheckpoint(rootHash []byte)
ResetOldHashes() [][]byte
AppendToOldHashes([][]byte)
Database() DBWriteCacher
GetSerializedNodes([]byte, uint64) ([][]byte, error)
GetAllLeaves() (map[string][]byte, error)
IsPruningEnabled() bool
EnterSnapshotMode()
ExitSnapshotMode()
IsInterfaceNil() bool
ClosePersister() error
}
// DBWriteCacher is used to cache changes made to the trie, and only write to the database when it's needed
type DBWriteCacher interface {
Put(key, val []byte) error
Get(key []byte) ([]byte, error)
Remove(key []byte) error
Close() error
IsInterfaceNil() bool
}
// DBRemoveCacher is used to cache keys that will be deleted from the database
type DBRemoveCacher interface {
Put([]byte, ModifiedHashes) error
Evict([]byte) (ModifiedHashes, error)
PresentInNewHashes(hash string) (bool, error)
IsInterfaceNil() bool
}
// TrieSyncer synchronizes the trie, asking on the network for the missing nodes
type TrieSyncer interface {
StartSyncing(rootHash []byte, ctx context.Context) error
Trie() Trie
IsInterfaceNil() bool
}
// StorageManager manages all trie storage operations
type StorageManager interface {
Database() DBWriteCacher
TakeSnapshot([]byte)
SetCheckpoint([]byte)
Prune([]byte)
CancelPrune([]byte)
MarkForEviction([]byte, ModifiedHashes) error
GetDbThatContainsHash([]byte) DBWriteCacher
IsPruningEnabled() bool
EnterSnapshotMode()
ExitSnapshotMode()
IsInterfaceNil() bool
}
// TrieFactory creates new tries
type TrieFactory interface {
Create(config.StorageConfig, bool) (StorageManager, Trie, error)
IsInterfaceNil() bool
}
// ValidatorInfoHandler is used to store multiple validatorInfo properties
type ValidatorInfoHandler interface {
GetPublicKey() []byte
GetShardId() uint32
GetList() string
GetIndex() uint32
GetTempRating() uint32
GetRating() uint32
String() string
IsInterfaceNil() bool
}
// ShardValidatorInfoHandler is used to store multiple validatorInfo properties required in shards
type ShardValidatorInfoHandler interface {
GetPublicKey() []byte
GetTempRating() uint32
String() string
IsInterfaceNil() bool
}