/
types.go
108 lines (99 loc) · 3.85 KB
/
types.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
package syncer
import (
"context"
"math/big"
"time"
rawGrpc "google.golang.org/grpc"
"github.com/0xDaoChain/dao-chain/blockchain"
"github.com/0xDaoChain/dao-chain/helper/progress"
"github.com/0xDaoChain/dao-chain/network"
"github.com/0xDaoChain/dao-chain/network/event"
"github.com/0xDaoChain/dao-chain/types"
"github.com/libp2p/go-libp2p/core/peer"
"google.golang.org/protobuf/proto"
)
type Blockchain interface {
// SubscribeEvents subscribes new blockchain event
SubscribeEvents() blockchain.Subscription
// Header returns get latest header
Header() *types.Header
// GetBlockByNumber returns block by number
GetBlockByNumber(uint64, bool) (*types.Block, bool)
// VerifyFinalizedBlock verifies finalized block
VerifyFinalizedBlock(*types.Block) error
// WriteBlock writes a given block to chain
WriteBlock(*types.Block, string) error
}
type Network interface {
// AddrInfo returns Network Info
AddrInfo() *peer.AddrInfo
// RegisterProtocol registers gRPC service
RegisterProtocol(string, network.Protocol)
// Peers returns current connected peers
Peers() []*network.PeerConnInfo
// SubscribeCh returns a channel of peer event
SubscribeCh(context.Context) (<-chan *event.PeerEvent, error)
// GetPeerDistance returns the distance between the node and given peer
GetPeerDistance(peer.ID) *big.Int
// NewProtoConnection opens up a new stream on the set protocol to the peer,
// and returns a reference to the connection
NewProtoConnection(protocol string, peerID peer.ID) (*rawGrpc.ClientConn, error)
// NewTopic Creates New Topic for gossip
NewTopic(protoID string, obj proto.Message) (*network.Topic, error)
// IsConnected returns the node is connecting to the peer associated with the given ID
IsConnected(peerID peer.ID) bool
// SaveProtocolStream saves stream
SaveProtocolStream(protocol string, stream *rawGrpc.ClientConn, peerID peer.ID)
// CloseProtocolStream closes stream
CloseProtocolStream(protocol string, peerID peer.ID) error
}
type Syncer interface {
// Start starts syncer processes
Start() error
// Close terminates syncer process
Close() error
// GetSyncProgression returns sync progression
GetSyncProgression() *progress.Progression
// HasSyncPeer returns whether syncer has the peer syncer can sync with
HasSyncPeer() bool
// Sync starts routine to sync blocks
Sync(func(*types.Block) bool) error
}
type Progression interface {
// StartProgression starts progression
StartProgression(startingBlock uint64, subscription blockchain.Subscription)
// UpdateHighestProgression updates highest block number
UpdateHighestProgression(highestBlock uint64)
// GetProgression returns Progression
GetProgression() *progress.Progression
// StopProgression finishes progression
StopProgression()
}
type SyncPeerService interface {
// Start starts server
Start()
// Close terminates running processes for SyncPeerService
Close() error
}
type SyncPeerClient interface {
// Start processes for SyncPeerClient
Start() error
// Close terminates running processes for SyncPeerClient
Close()
// GetPeerStatus fetches peer status
GetPeerStatus(id peer.ID) (*NoForkPeer, error)
// GetConnectedPeerStatuses fetches the statuses of all connecting peers
GetConnectedPeerStatuses() []*NoForkPeer
// GetBlocks returns a stream of blocks from given height to peer's latest
GetBlocks(peer.ID, uint64, time.Duration) (<-chan *types.Block, error)
// GetPeerStatusUpdateCh returns a channel of peer's status update
GetPeerStatusUpdateCh() <-chan *NoForkPeer
// GetPeerConnectionUpdateEventCh returns peer's connection change event
GetPeerConnectionUpdateEventCh() <-chan *event.PeerEvent
// CloseStream close a stream
CloseStream(peerID peer.ID) error
// DisablePublishingPeerStatus disables publishing status in syncer topic
DisablePublishingPeerStatus()
// EnablePublishingPeerStatus enables publishing status in syncer topic
EnablePublishingPeerStatus()
}