-
Notifications
You must be signed in to change notification settings - Fork 2
/
blockchain_stub.go
420 lines (318 loc) · 14.2 KB
/
blockchain_stub.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
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
package core
import (
"math/big"
"github.com/PositionExchange/posichain/block"
"github.com/PositionExchange/posichain/consensus/engine"
"github.com/PositionExchange/posichain/consensus/reward"
"github.com/PositionExchange/posichain/core/rawdb"
"github.com/PositionExchange/posichain/core/state"
"github.com/PositionExchange/posichain/core/types"
"github.com/PositionExchange/posichain/core/vm"
harmonyconfig "github.com/PositionExchange/posichain/internal/configs/harmony"
"github.com/PositionExchange/posichain/internal/params"
"github.com/PositionExchange/posichain/internal/tikv/redis_helper"
"github.com/PositionExchange/posichain/shard"
"github.com/PositionExchange/posichain/staking/slash"
staking "github.com/PositionExchange/posichain/staking/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/pkg/errors"
)
// Smoke test.
var _ BlockChain = Stub{}
type Stub struct {
Name string
}
func (a Stub) ValidateNewBlock(block *types.Block, beaconChain BlockChain) error {
return errors.Errorf("method ValidateNewBlock not implemented for %s", a.Name)
}
func (a Stub) SetHead(head uint64) error {
return errors.Errorf("method SetHead not implemented for %s", a.Name)
}
func (a Stub) ShardID() uint32 {
return 0
}
func (a Stub) CurrentBlock() *types.Block {
return nil
}
func (a Stub) Validator() Validator {
return nil
}
func (a Stub) Processor() Processor {
return nil
}
func (a Stub) State() (*state.DB, error) {
return nil, errors.Errorf("method State not implemented for %s", a.Name)
}
func (a Stub) StateAt(common.Hash) (*state.DB, error) {
return nil, errors.Errorf("method StateAt not implemented for %s", a.Name)
}
func (a Stub) HasBlock(hash common.Hash, number uint64) bool {
return false
}
func (a Stub) HasState(hash common.Hash) bool {
return false
}
func (a Stub) HasBlockAndState(hash common.Hash, number uint64) bool {
return false
}
func (a Stub) GetBlock(hash common.Hash, number uint64) *types.Block {
return nil
}
func (a Stub) GetBlockByHash(hash common.Hash) *types.Block {
return nil
}
func (a Stub) GetBlockByNumber(number uint64) *types.Block {
return nil
}
func (a Stub) GetReceiptsByHash(hash common.Hash) types.Receipts {
return nil
}
func (a Stub) Stop() {
}
func (a Stub) Rollback(chain []common.Hash) error {
return errors.Errorf("method Rollback not implemented for %s", a.Name)
}
func (a Stub) WriteBlockWithoutState(block *types.Block, td *big.Int) (err error) {
return errors.Errorf("method WriteBlockWithoutState not implemented for %s", a.Name)
}
func (a Stub) WriteBlockWithState(block *types.Block, receipts []*types.Receipt, cxReceipts []*types.CXReceipt, stakeMsgs []staking.StakeMsg, paid reward.Reader, state *state.DB) (status WriteStatus, err error) {
return 0, errors.Errorf("method WriteBlockWithState not implemented for %s", a.Name)
}
func (a Stub) GetMaxGarbageCollectedBlockNumber() int64 {
return 0
}
func (a Stub) InsertChain(chain types.Blocks, verifyHeaders bool) (int, error) {
return 0, errors.Errorf("method InsertChain not implemented for %s", a.Name)
}
func (a Stub) BadBlocks() []BadBlock {
return nil
}
func (a Stub) CurrentHeader() *block.Header {
return nil
}
func (a Stub) GetHeader(hash common.Hash, number uint64) *block.Header {
return nil
}
func (a Stub) GetHeaderByHash(hash common.Hash) *block.Header {
return nil
}
func (a Stub) GetCanonicalHash(number uint64) common.Hash {
return common.Hash{}
}
func (a Stub) GetHeaderByNumber(number uint64) *block.Header {
return nil
}
func (a Stub) Config() *params.ChainConfig {
return nil
}
func (a Stub) Engine() engine.Engine {
return nil
}
func (a Stub) SubscribeRemovedLogsEvent(ch chan<- RemovedLogsEvent) event.Subscription {
return nil
}
func (a Stub) SubscribeTraceEvent(ch chan<- TraceEvent) event.Subscription {
return nil
}
func (a Stub) SubscribeChainEvent(ch chan<- ChainEvent) event.Subscription {
return nil
}
func (a Stub) SubscribeChainHeadEvent(ch chan<- ChainHeadEvent) event.Subscription {
return nil
}
func (a Stub) SubscribeChainSideEvent(ch chan<- ChainSideEvent) event.Subscription {
return nil
}
func (a Stub) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription {
return nil
}
func (a Stub) ReadShardState(epoch *big.Int) (*shard.State, error) {
return nil, errors.Errorf("method ReadShardState not implemented for %s", a.Name)
}
func (a Stub) WriteShardStateBytes(db rawdb.DatabaseWriter, epoch *big.Int, shardState []byte) (*shard.State, error) {
return nil, errors.Errorf("method WriteShardStateBytes not implemented for %s", a.Name)
}
func (a Stub) WriteHeadBlock(block *types.Block) error {
return errors.Errorf("method WriteHeadBlock not implemented for %s", a.Name)
}
func (a Stub) ReadCommitSig(blockNum uint64) ([]byte, error) {
return nil, errors.Errorf("method ReadCommitSig not implemented for %s", a.Name)
}
func (a Stub) WriteCommitSig(blockNum uint64, lastCommits []byte) error {
return errors.Errorf("method WriteCommitSig not implemented for %s", a.Name)
}
func (a Stub) GetVdfByNumber(number uint64) []byte {
return nil
}
func (a Stub) GetVrfByNumber(number uint64) []byte {
return nil
}
func (a Stub) ChainDb() ethdb.Database {
return nil
}
func (a Stub) GetEpochBlockNumber(epoch *big.Int) (*big.Int, error) {
return nil, errors.Errorf("method GetEpochBlockNumber not implemented for %s", a.Name)
}
func (a Stub) StoreEpochBlockNumber(epoch *big.Int, blockNum *big.Int) error {
return errors.Errorf("method StoreEpochBlockNumber not implemented for %s", a.Name)
}
func (a Stub) ReadEpochVrfBlockNums(epoch *big.Int) ([]uint64, error) {
return nil, errors.Errorf("method ReadEpochVrfBlockNums not implemented for %s", a.Name)
}
func (a Stub) WriteEpochVrfBlockNums(epoch *big.Int, vrfNumbers []uint64) error {
return errors.Errorf("method WriteEpochVrfBlockNums not implemented for %s", a.Name)
}
func (a Stub) ReadEpochVdfBlockNum(epoch *big.Int) (*big.Int, error) {
return nil, errors.Errorf("method ReadEpochVdfBlockNum not implemented for %s", a.Name)
}
func (a Stub) WriteEpochVdfBlockNum(epoch *big.Int, blockNum *big.Int) error {
return errors.Errorf("method WriteEpochVdfBlockNum not implemented for %s", a.Name)
}
func (a Stub) WriteCrossLinks(batch rawdb.DatabaseWriter, cls []types.CrossLink) error {
return errors.Errorf("method WriteCrossLinks not implemented for %s", a.Name)
}
func (a Stub) DeleteCrossLinks(cls []types.CrossLink) error {
return errors.Errorf("method DeleteCrossLinks not implemented for %s", a.Name)
}
func (a Stub) ReadCrossLink(shardID uint32, blockNum uint64) (*types.CrossLink, error) {
return nil, errors.Errorf("method ReadCrossLink not implemented for %s", a.Name)
}
func (a Stub) LastContinuousCrossLink(batch rawdb.DatabaseWriter, shardID uint32) error {
return errors.Errorf("method LastContinuousCrossLink not implemented for %s", a.Name)
}
func (a Stub) ReadShardLastCrossLink(shardID uint32) (*types.CrossLink, error) {
return nil, errors.Errorf("method ReadShardLastCrossLink not implemented for %s", a.Name)
}
func (a Stub) DeleteFromPendingSlashingCandidates(processed slash.Records) error {
return errors.Errorf("method DeleteFromPendingSlashingCandidates not implemented for %s", a.Name)
}
func (a Stub) ReadPendingSlashingCandidates() slash.Records {
return nil
}
func (a Stub) ReadPendingCrossLinks() ([]types.CrossLink, error) {
return nil, errors.Errorf("method ReadPendingCrossLinks not implemented for %s", a.Name)
}
func (a Stub) CachePendingCrossLinks(crossLinks []types.CrossLink) error {
return errors.Errorf("method CachePendingCrossLinks not implemented for %s", a.Name)
}
func (a Stub) SavePendingCrossLinks() error {
return errors.Errorf("method SavePendingCrossLinks not implemented for %s", a.Name)
}
func (a Stub) AddPendingSlashingCandidates(candidates slash.Records) error {
return errors.Errorf("method AddPendingSlashingCandidates not implemented for %s", a.Name)
}
func (a Stub) AddPendingCrossLinks(pendingCLs []types.CrossLink) (int, error) {
return 0, errors.Errorf("method AddPendingCrossLinks not implemented for %s", a.Name)
}
func (a Stub) DeleteFromPendingCrossLinks(crossLinks []types.CrossLink) (int, error) {
return 0, errors.Errorf("method DeleteFromPendingCrossLinks not implemented for %s", a.Name)
}
func (a Stub) IsSameLeaderAsPreviousBlock(block *types.Block) bool {
return false
}
func (a Stub) GetVMConfig() *vm.Config {
return nil
}
func (a Stub) ReadCXReceipts(shardID uint32, blockNum uint64, blockHash common.Hash) (types.CXReceipts, error) {
return nil, errors.Errorf("method ReadCXReceipts not implemented for %s", a.Name)
}
func (a Stub) CXMerkleProof(toShardID uint32, block *types.Block) (*types.CXMerkleProof, error) {
return nil, errors.Errorf("method CXMerkleProof not implemented for %s", a.Name)
}
func (a Stub) WriteCXReceiptsProofSpent(db rawdb.DatabaseWriter, cxps []*types.CXReceiptsProof) error {
return errors.Errorf("method WriteCXReceiptsProofSpent not implemented for %s", a.Name)
}
func (a Stub) IsSpent(cxp *types.CXReceiptsProof) bool {
return false
}
func (a Stub) ReadTxLookupEntry(txID common.Hash) (common.Hash, uint64, uint64) {
return common.Hash{}, 0, 0
}
func (a Stub) ReadValidatorInformationAtRoot(addr common.Address, root common.Hash) (*staking.ValidatorWrapper, error) {
return nil, errors.Errorf("method ReadValidatorInformationAtRoot not implemented for %s", a.Name)
}
func (a Stub) ReadValidatorInformationAtState(addr common.Address, state *state.DB) (*staking.ValidatorWrapper, error) {
return nil, errors.Errorf("method ReadValidatorInformationAtState not implemented for %s", a.Name)
}
func (a Stub) ReadValidatorInformation(addr common.Address) (*staking.ValidatorWrapper, error) {
return nil, errors.Errorf("method ReadValidatorInformation not implemented for %s", a.Name)
}
func (a Stub) ReadValidatorSnapshotAtEpoch(epoch *big.Int, addr common.Address) (*staking.ValidatorSnapshot, error) {
return nil, errors.Errorf("method ReadValidatorSnapshotAtEpoch not implemented for %s", a.Name)
}
func (a Stub) ReadValidatorSnapshot(addr common.Address) (*staking.ValidatorSnapshot, error) {
return nil, errors.Errorf("method ReadValidatorSnapshot not implemented for %s", a.Name)
}
func (a Stub) WriteValidatorSnapshot(batch rawdb.DatabaseWriter, snapshot *staking.ValidatorSnapshot) error {
return errors.Errorf("method WriteValidatorSnapshot not implemented for %s", a.Name)
}
func (a Stub) ReadValidatorStats(addr common.Address) (*staking.ValidatorStats, error) {
return nil, errors.Errorf("method ReadValidatorStats not implemented for %s", a.Name)
}
func (a Stub) UpdateValidatorVotingPower(batch rawdb.DatabaseWriter, block *types.Block, newEpochSuperCommittee, currentEpochSuperCommittee *shard.State, state *state.DB) (map[common.Address]*staking.ValidatorStats, error) {
return nil, errors.Errorf("method UpdateValidatorVotingPower not implemented for %s", a.Name)
}
func (a Stub) ComputeAndUpdateAPR(block *types.Block, now *big.Int, wrapper *staking.ValidatorWrapper, stats *staking.ValidatorStats) error {
return errors.Errorf("method ComputeAndUpdateAPR not implemented for %s", a.Name)
}
func (a Stub) UpdateValidatorSnapshots(batch rawdb.DatabaseWriter, epoch *big.Int, state *state.DB, newValidators []common.Address) error {
return errors.Errorf("method UpdateValidatorSnapshots not implemented for %s", a.Name)
}
func (a Stub) ReadValidatorList() ([]common.Address, error) {
return nil, errors.Errorf("method ReadValidatorList not implemented for %s", a.Name)
}
func (a Stub) WriteValidatorList(db rawdb.DatabaseWriter, addrs []common.Address) error {
return errors.Errorf("method WriteValidatorList not implemented for %s", a.Name)
}
func (a Stub) ReadDelegationsByDelegator(delegator common.Address) (m staking.DelegationIndexes, err error) {
return nil, errors.Errorf("method ReadDelegationsByDelegator not implemented for %s", a.Name)
}
func (a Stub) ReadDelegationsByDelegatorAt(delegator common.Address, blockNum *big.Int) (m staking.DelegationIndexes, err error) {
return nil, errors.Errorf("method ReadDelegationsByDelegatorAt not implemented for %s", a.Name)
}
func (a Stub) UpdateStakingMetaData(batch rawdb.DatabaseWriter, block *types.Block, stakeMsgs []staking.StakeMsg, state *state.DB, epoch, newEpoch *big.Int) (newValidators []common.Address, err error) {
return nil, errors.Errorf("method UpdateStakingMetaData not implemented for %s", a.Name)
}
func (a Stub) ReadBlockRewardAccumulator(number uint64) (*big.Int, error) {
return nil, errors.Errorf("method ReadBlockRewardAccumulator not implemented for %s", a.Name)
}
func (a Stub) WriteBlockRewardAccumulator(batch rawdb.DatabaseWriter, reward *big.Int, number uint64) error {
return errors.Errorf("method WriteBlockRewardAccumulator not implemented for %s", a.Name)
}
func (a Stub) UpdateBlockRewardAccumulator(batch rawdb.DatabaseWriter, diff *big.Int, number uint64) error {
return errors.Errorf("method UpdateBlockRewardAccumulator not implemented for %s", a.Name)
}
func (a Stub) ValidatorCandidates() []common.Address {
return nil
}
func (a Stub) DelegatorsInformation(addr common.Address) []*staking.Delegation {
return nil
}
func (a Stub) GetECDSAFromCoinbase(header *block.Header) (common.Address, error) {
return common.Address{}, errors.Errorf("method GetECDSAFromCoinbase not implemented for %s", a.Name)
}
func (a Stub) SuperCommitteeForNextEpoch(beacon engine.ChainReader, header *block.Header, isVerify bool) (*shard.State, error) {
return nil, errors.Errorf("method SuperCommitteeForNextEpoch not implemented for %s", a.Name)
}
func (a Stub) EnablePruneBeaconChainFeature() {
}
func (a Stub) IsEnablePruneBeaconChainFeature() bool {
return false
}
func (a Stub) CommitOffChainData(batch rawdb.DatabaseWriter, block *types.Block, receipts []*types.Receipt, cxReceipts []*types.CXReceipt, stakeMsgs []staking.StakeMsg, payout reward.Reader, state *state.DB) (status WriteStatus, err error) {
return 0, errors.Errorf("method CommitOffChainData not implemented for %s", a.Name)
}
func (a Stub) IsTikvWriterMaster() bool {
return false
}
func (a Stub) RedisPreempt() *redis_helper.RedisPreempt {
return nil
}
func (a Stub) SyncFromTiKVWriter(newBlkNum uint64, logs []*types.Log) error {
return errors.Errorf("method SyncFromTiKVWriter not implemented for %s", a.Name)
}
func (a Stub) InitTiKV(conf *harmonyconfig.TiKVConfig) {
return
}