-
Notifications
You must be signed in to change notification settings - Fork 534
/
dummy.go
86 lines (68 loc) · 1.8 KB
/
dummy.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
package dummy
import (
"github.com/0xPolygon/polygon-edge/blockchain"
"github.com/0xPolygon/polygon-edge/consensus"
"github.com/0xPolygon/polygon-edge/helper/progress"
"github.com/0xPolygon/polygon-edge/state"
"github.com/0xPolygon/polygon-edge/txpool"
"github.com/0xPolygon/polygon-edge/types"
"github.com/hashicorp/go-hclog"
)
type Dummy struct {
logger hclog.Logger
notifyCh chan struct{}
closeCh chan struct{}
txpool *txpool.TxPool
blockchain *blockchain.Blockchain
executor *state.Executor
}
func Factory(params *consensus.Params) (consensus.Consensus, error) {
logger := params.Logger.Named("dummy")
d := &Dummy{
logger: logger,
notifyCh: make(chan struct{}),
closeCh: make(chan struct{}),
blockchain: params.Blockchain,
executor: params.Executor,
txpool: params.TxPool,
}
return d, nil
}
// Initialize initializes the consensus
func (d *Dummy) Initialize() error {
d.txpool.SetSealing(true)
return nil
}
func (d *Dummy) Start() error {
go d.run()
return nil
}
func (d *Dummy) VerifyHeader(header *types.Header) error {
// All blocks are valid
return nil
}
func (d *Dummy) ProcessHeaders(headers []*types.Header) error {
return nil
}
func (d *Dummy) GetBlockCreator(header *types.Header) (types.Address, error) {
return types.BytesToAddress(header.Miner), nil
}
// PreCommitState a hook to be called before finalizing state transition on inserting block
func (d *Dummy) PreCommitState(_header *types.Header, _txn *state.Transition) error {
return nil
}
func (d *Dummy) GetSyncProgression() *progress.Progression {
return nil
}
func (d *Dummy) Close() error {
close(d.closeCh)
return nil
}
func (d *Dummy) GetBridgeProvider() consensus.BridgeDataProvider {
return nil
}
func (d *Dummy) run() {
d.logger.Info("started")
// do nothing
<-d.closeCh
}