-
Notifications
You must be signed in to change notification settings - Fork 199
/
consensusCore.go
152 lines (131 loc) · 4.42 KB
/
consensusCore.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
package spos
import (
"github.com/ElrondNetwork/elrond-go/consensus"
"github.com/ElrondNetwork/elrond-go/crypto"
"github.com/ElrondNetwork/elrond-go/data"
"github.com/ElrondNetwork/elrond-go/hashing"
"github.com/ElrondNetwork/elrond-go/marshal"
"github.com/ElrondNetwork/elrond-go/ntp"
"github.com/ElrondNetwork/elrond-go/process"
"github.com/ElrondNetwork/elrond-go/sharding"
)
// ConsensusCore implements ConsensusCoreHandler and provides access to common functionalities
// for the rest of the consensus structures
type ConsensusCore struct {
blockChain data.ChainHandler
blockProcessor process.BlockProcessor
bootstrapper process.Bootstrapper
broadcastMessenger consensus.BroadcastMessenger
chronologyHandler consensus.ChronologyHandler
hasher hashing.Hasher
marshalizer marshal.Marshalizer
blsPrivateKey crypto.PrivateKey
blsSingleSigner crypto.SingleSigner
multiSigner crypto.MultiSigner
rounder consensus.Rounder
shardCoordinator sharding.Coordinator
nodesCoordinator sharding.NodesCoordinator
syncTimer ntp.SyncTimer
}
// NewConsensusCore creates a new ConsensusCore instance
func NewConsensusCore(
blockChain data.ChainHandler,
blockProcessor process.BlockProcessor,
bootstrapper process.Bootstrapper,
broadcastMessenger consensus.BroadcastMessenger,
chronologyHandler consensus.ChronologyHandler,
hasher hashing.Hasher,
marshalizer marshal.Marshalizer,
blsPrivateKey crypto.PrivateKey,
blsSingleSigner crypto.SingleSigner,
multiSigner crypto.MultiSigner,
rounder consensus.Rounder,
shardCoordinator sharding.Coordinator,
nodesCoordinator sharding.NodesCoordinator,
syncTimer ntp.SyncTimer,
) (*ConsensusCore, error) {
consensusCore := &ConsensusCore{
blockChain,
blockProcessor,
bootstrapper,
broadcastMessenger,
chronologyHandler,
hasher,
marshalizer,
blsPrivateKey,
blsSingleSigner,
multiSigner,
rounder,
shardCoordinator,
nodesCoordinator,
syncTimer,
}
err := ValidateConsensusCore(consensusCore)
if err != nil {
return nil, err
}
return consensusCore, nil
}
// Blockchain gets the ChainHandler stored in the ConsensusCore
func (cc *ConsensusCore) Blockchain() data.ChainHandler {
return cc.blockChain
}
// BlockProcessor gets the BlockProcessor stored in the ConsensusCore
func (cc *ConsensusCore) BlockProcessor() process.BlockProcessor {
return cc.blockProcessor
}
// BootStrapper gets the Bootstrapper stored in the ConsensusCore
func (cc *ConsensusCore) BootStrapper() process.Bootstrapper {
return cc.bootstrapper
}
// BroadcastMessenger gets the BroadcastMessenger stored in the ConsensusCore
func (cc *ConsensusCore) BroadcastMessenger() consensus.BroadcastMessenger {
return cc.broadcastMessenger
}
// Chronology gets the ChronologyHandler stored in the ConsensusCore
func (cc *ConsensusCore) Chronology() consensus.ChronologyHandler {
return cc.chronologyHandler
}
// Hasher gets the Hasher stored in the ConsensusCore
func (cc *ConsensusCore) Hasher() hashing.Hasher {
return cc.hasher
}
// Marshalizer gets the Marshalizer stored in the ConsensusCore
func (cc *ConsensusCore) Marshalizer() marshal.Marshalizer {
return cc.marshalizer
}
// MultiSigner gets the MultiSigner stored in the ConsensusCore
func (cc *ConsensusCore) MultiSigner() crypto.MultiSigner {
return cc.multiSigner
}
//Rounder gets the Rounder stored in the ConsensusCore
func (cc *ConsensusCore) Rounder() consensus.Rounder {
return cc.rounder
}
// ShardCoordinator gets the Coordinator stored in the ConsensusCore
func (cc *ConsensusCore) ShardCoordinator() sharding.Coordinator {
return cc.shardCoordinator
}
//SyncTimer gets the SyncTimer stored in the ConsensusCore
func (cc *ConsensusCore) SyncTimer() ntp.SyncTimer {
return cc.syncTimer
}
// NodesCoordinator gets the NodesCoordinator stored in the ConsensusCore
func (cc *ConsensusCore) NodesCoordinator() sharding.NodesCoordinator {
return cc.nodesCoordinator
}
// RandomnessPrivateKey returns the BLS private key stored in the ConsensusStore
func (cc *ConsensusCore) RandomnessPrivateKey() crypto.PrivateKey {
return cc.blsPrivateKey
}
// RandomnessSingleSigner returns the bls single signer stored in the ConsensusStore
func (cc *ConsensusCore) RandomnessSingleSigner() crypto.SingleSigner {
return cc.blsSingleSigner
}
// IsInterfaceNil returns true if there is no value under the interface
func (cc *ConsensusCore) IsInterfaceNil() bool {
if cc == nil {
return true
}
return false
}