-
Notifications
You must be signed in to change notification settings - Fork 199
/
interface.go
105 lines (92 loc) · 3.58 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
package heartbeat
import (
"io"
"time"
"github.com/ElrondNetwork/elrond-go/core"
"github.com/ElrondNetwork/elrond-go/data/state"
"github.com/ElrondNetwork/elrond-go/heartbeat/data"
"github.com/ElrondNetwork/elrond-go/p2p"
)
// P2PMessenger defines a subset of the p2p.Messenger interface
type P2PMessenger interface {
io.Closer
Bootstrap() error
Broadcast(topic string, buff []byte)
BroadcastOnChannel(channel string, topic string, buff []byte)
BroadcastOnChannelBlocking(channel string, topic string, buff []byte) error
CreateTopic(name string, createChannelForTopic bool) error
HasTopic(name string) bool
HasTopicValidator(name string) bool
RegisterMessageProcessor(topic string, handler p2p.MessageProcessor) error
PeerAddress(pid p2p.PeerID) string
IsConnectedToTheNetwork() bool
ID() p2p.PeerID
IsInterfaceNil() bool
}
// MessageHandler defines what a message processor for heartbeat should do
type MessageHandler interface {
CreateHeartbeatFromP2PMessage(message p2p.MessageP2P) (*data.Heartbeat, error)
IsInterfaceNil() bool
}
// EligibleListProvider defines what an eligible list provider should do
type EligibleListProvider interface {
GetAllEligibleValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error)
GetAllWaitingValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error)
IsInterfaceNil() bool
}
//Timer defines an interface for tracking time
type Timer interface {
Now() time.Time
IsInterfaceNil() bool
}
// HeartbeatStorageHandler defines what a heartbeat's storer should do
type HeartbeatStorageHandler interface {
LoadGenesisTime() (time.Time, error)
UpdateGenesisTime(genesisTime time.Time) error
LoadHeartBeatDTO(pubKey string) (*data.HeartbeatDTO, error)
SavePubkeyData(pubkey []byte, heartbeat *data.HeartbeatDTO) error
LoadKeys() ([][]byte, error)
SaveKeys(peersSlice [][]byte) error
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 {
UpdatePeerIdPublicKey(pid p2p.PeerID, pk []byte)
UpdatePublicKeyShardId(pk []byte, shardId uint32)
UpdatePeerIdShardId(pid p2p.PeerID, shardId uint32)
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 p2p.PeerID) error
CanProcessMessagesOnTopic(peer p2p.PeerID, topic string, numMessages uint32) error
IsInterfaceNil() bool
}
// PeerTypeProviderHandler defines what a component which computes the type of a peer should do
type PeerTypeProviderHandler interface {
ComputeForPubKey(pubKey []byte) (core.PeerType, uint32, error)
GetAllPeerTypeInfos() []*state.PeerTypeInfo
IsInterfaceNil() bool
}
// HardforkTrigger defines the behavior of a hardfork trigger
type HardforkTrigger interface {
TriggerReceived(payload []byte, data []byte, pkBytes []byte) (bool, error)
RecordedTriggerMessage() ([]byte, bool)
CreateData() []byte
IsInterfaceNil() bool
}
// BlackListHandler can determine if a certain key is or not blacklisted
type BlackListHandler interface {
Add(key string) error
Has(key string) bool
Sweep()
IsInterfaceNil() bool
}
// ValidatorStatisticsProcessor is the interface for consensus participation statistics
type ValidatorStatisticsProcessor interface {
RootHash() ([]byte, error)
GetValidatorInfoForRootHash(rootHash []byte) (map[uint32][]*state.ValidatorInfo, error)
IsInterfaceNil() bool
}