-
Notifications
You must be signed in to change notification settings - Fork 48
/
cuckoo_faker.go
106 lines (87 loc) · 2.71 KB
/
cuckoo_faker.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
package cuckoo
import (
"github.com/CortexFoundation/CortexTheseus/common"
"github.com/CortexFoundation/CortexTheseus/consensus"
"github.com/CortexFoundation/CortexTheseus/core/state"
"github.com/CortexFoundation/CortexTheseus/core/types"
"github.com/CortexFoundation/CortexTheseus/rpc"
"math/big"
"time"
)
func NewFaker() *Cuckoo {
return &Cuckoo{
config: Config{
PowMode: ModeFake,
},
}
}
func NewFakeFailer(number uint64) *Cuckoo {
return &Cuckoo{
config: Config{
PowMode: ModeFake,
},
fakeFail: number,
}
}
func NewFakeDelayer(seconds time.Duration) *Cuckoo {
return &Cuckoo{
config: Config{
PowMode: ModeFake,
},
}
}
func NewFullFaker() *Cuckoo {
return &Cuckoo{
config: Config{
PowMode: ModeFullFake,
},
}
}
type CuckooFake struct {
}
func (cuckoo *CuckooFake) APIs(chain consensus.ChainReader) []rpc.API {
return []rpc.API{}
}
func (cuckoo *CuckooFake) Author(header *types.Header) (common.Address, error) {
return header.Coinbase, nil
}
func (cuckoo *CuckooFake) CalcDifficulty(chain consensus.ChainReader, time uint64, parent *types.Header) *big.Int {
return big.NewInt(0)
}
func (cuckoo *CuckooFake) Close() error {
return nil
}
func (cuckoo *CuckooFake) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
return types.NewBlock(header, txs, uncles, receipts), nil
}
func (cuckoo *CuckooFake) FinalizeWithoutParent(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
return types.NewBlock(header, txs, uncles, receipts), nil
}
func (cuckoo *CuckooFake) Prepare(chain consensus.ChainReader, header *types.Header) error {
return nil
}
func (cuckoo *CuckooFake) Seal(chain consensus.ChainReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error {
return nil
}
func (cuckoo *CuckooFake) SealHash(header *types.Header) (hash common.Hash) {
return common.Hash{}
}
func (cuckoo *CuckooFake) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error {
return nil
}
func (cuckoo *CuckooFake) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error) {
abort := make(chan struct{})
errorsOut := make(chan error, len(headers))
go func() {
for _, _ = range headers {
errorsOut <- nil
}
}()
return abort, errorsOut
}
func (cuckoo *CuckooFake) VerifySeal(chain consensus.ChainReader, header *types.Header) error {
return nil
}
func (cuckoo *CuckooFake) VerifyUncles(chain consensus.ChainReader, block *types.Block) error {
return nil
}