-
Notifications
You must be signed in to change notification settings - Fork 199
/
interface.go
140 lines (124 loc) · 5.6 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
package consensus
import (
"time"
"github.com/ElrondNetwork/elrond-go-core/core"
"github.com/ElrondNetwork/elrond-go-core/data"
"github.com/ElrondNetwork/elrond-go-crypto"
"github.com/ElrondNetwork/elrond-go/p2p"
)
// BlsConsensusType specifies the signature scheme used in the consensus
const BlsConsensusType = "bls"
// RoundHandler defines the actions which should be handled by a round implementation
type RoundHandler interface {
Index() int64
BeforeGenesis() bool
// UpdateRound updates the index and the time stamp of the round depending of the genesis time and the current time given
UpdateRound(time.Time, time.Time)
TimeStamp() time.Time
TimeDuration() time.Duration
RemainingTime(startTime time.Time, maxTime time.Duration) time.Duration
IsInterfaceNil() bool
}
// SubroundHandler defines the actions which should be handled by a subround implementation
type SubroundHandler interface {
// DoWork implements of the subround's job
DoWork(roundHandler RoundHandler) bool
// Previous returns the ID of the previous subround
Previous() int
// Next returns the ID of the next subround
Next() int
// Current returns the ID of the current subround
Current() int
// StartTime returns the start time, in the roundHandler time, of the current subround
StartTime() int64
// EndTime returns the top limit time, in the roundHandler time, of the current subround
EndTime() int64
// Name returns the name of the current roundHandler
Name() string
// ConsensusChannel returns the consensus channel
ConsensusChannel() chan bool
// IsInterfaceNil returns true if there is no value under the interface
IsInterfaceNil() bool
}
// ChronologyHandler defines the actions which should be handled by a chronology implementation
type ChronologyHandler interface {
Close() error
AddSubround(SubroundHandler)
RemoveAllSubrounds()
// StartRounds starts rounds in a sequential manner, one after the other
StartRounds()
IsInterfaceNil() bool
}
// BroadcastMessenger defines the behaviour of the broadcast messages by the consensus group
type BroadcastMessenger interface {
BroadcastBlock(data.BodyHandler, data.HeaderHandler) error
BroadcastHeader(data.HeaderHandler) error
BroadcastMiniBlocks(map[uint32][]byte) error
BroadcastTransactions(map[string][][]byte) error
BroadcastConsensusMessage(*Message) error
BroadcastBlockDataLeader(header data.HeaderHandler, miniBlocks map[uint32][]byte, transactions map[string][][]byte) error
PrepareBroadcastHeaderValidator(header data.HeaderHandler, miniBlocks map[uint32][]byte, transactions map[string][][]byte, order int)
PrepareBroadcastBlockDataValidator(header data.HeaderHandler, miniBlocks map[uint32][]byte, transactions map[string][][]byte, idx int)
IsInterfaceNil() bool
}
// P2PMessenger defines a subset of the p2p.Messenger interface
type P2PMessenger interface {
Broadcast(topic string, buff []byte)
IsInterfaceNil() bool
}
// NetworkShardingCollector defines the updating methods used by the network sharding component
// The interface assures that the collected data will be used by the p2p network sharding components
type NetworkShardingCollector interface {
UpdatePeerIDInfo(pid core.PeerID, pk []byte, shardID uint32)
UpdatePeerIdSubType(pid core.PeerID, peerSubType core.P2PPeerSubType)
GetPeerInfo(pid core.PeerID) core.P2PPeerInfo
IsInterfaceNil() bool
}
// P2PAntifloodHandler defines the behavior of a component able to signal that the system is too busy (or flooded) processing
// p2p messages
type P2PAntifloodHandler interface {
CanProcessMessage(message p2p.MessageP2P, fromConnectedPeer core.PeerID) error
CanProcessMessagesOnTopic(peer core.PeerID, topic string, numMessages uint32, totalSize uint64, sequence []byte) error
ResetForTopic(topic string)
SetMaxMessagesForTopic(topic string, maxNum uint32)
BlacklistPeer(peer core.PeerID, reason string, duration time.Duration)
IsInterfaceNil() bool
}
// HeadersPoolSubscriber can subscribe for notifications when a new block header is added to the headers pool
type HeadersPoolSubscriber interface {
RegisterHandler(handler func(headerHandler data.HeaderHandler, headerHash []byte))
IsInterfaceNil() bool
}
// PeerHonestyHandler defines the behaivour of a component able to handle/monitor the peer honesty of nodes which are
// participating in consensus
type PeerHonestyHandler interface {
ChangeScore(pk string, topic string, units int)
IsInterfaceNil() bool
Close() error
}
// InterceptorSubscriber can subscribe for notifications when data is received by an interceptor
type InterceptorSubscriber interface {
RegisterHandler(handler func(toShard uint32, data []byte))
IsInterfaceNil() bool
}
// HeaderSigVerifier encapsulates methods that are check if header rand seed, leader signature and aggregate signature are correct
type HeaderSigVerifier interface {
VerifyRandSeed(header data.HeaderHandler) error
VerifyLeaderSignature(header data.HeaderHandler) error
VerifySignature(header data.HeaderHandler) error
IsInterfaceNil() bool
}
// FallbackHeaderValidator defines the behaviour of a component able to signal when a fallback header validation could be applied
type FallbackHeaderValidator interface {
ShouldApplyFallbackValidation(headerHandler data.HeaderHandler) bool
IsInterfaceNil() bool
}
// NodeRedundancyHandler provides functionality to handle the redundancy mechanism for a node
type NodeRedundancyHandler interface {
IsRedundancyNode() bool
IsMainMachineActive() bool
AdjustInactivityIfNeeded(selfPubKey string, consensusPubKeys []string, roundIndex int64)
ResetInactivityIfNeeded(selfPubKey string, consensusMsgPubKey string, consensusMsgPeerID core.PeerID)
ObserverPrivateKey() crypto.PrivateKey
IsInterfaceNil() bool
}