/
protocol.go
132 lines (107 loc) · 3.78 KB
/
protocol.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
package gossip
import (
"github.com/Fantom-foundation/lachesis-base/hash"
"github.com/Fantom-foundation/lachesis-base/inter/idx"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
notify "github.com/ethereum/go-ethereum/event"
"github.com/Ecosystem-Knowledge/go-ecoterium/evmcore"
"github.com/Ecosystem-Knowledge/go-ecoterium/inter"
)
// Constants to match up protocol versions and messages
const (
ProtocolVersion = 62 // derived from eth62
)
// ProtocolName is the official short name of the protocol used during capability negotiation.
const ProtocolName = "opera"
// ProtocolVersions are the supported versions of the protocol (first is primary).
var ProtocolVersions = []uint{ProtocolVersion}
// protocolLengths are the number of implemented message corresponding to different protocol versions.
var protocolLengths = map[uint]uint64{ProtocolVersion: EventsStreamResponse + 1}
const protocolMaxMsgSize = 10 * 1024 * 1024 // Maximum cap on the size of a protocol message
// protocol message codes
const (
HandshakeMsg = 0
// Signals about the current synchronization status.
// The current peer's status is used during packs downloading,
// and to estimate may peer be interested in the new event or not
// (based on peer's epoch).
ProgressMsg = 1
EvmTxsMsg = 2
NewEvmTxHashesMsg = 3
GetEvmTxsMsg = 4
// Non-aggressive events propagation. Signals about newly-connected
// batch of events, sending only their IDs.
NewEventIDsMsg = 5
// Request the batch of events by IDs
GetEventsMsg = 6
// Contains the batch of events.
// May be an answer to GetEventsMsg, or be sent during aggressive events propagation.
EventsMsg = 7
// Request a range of events by a selector
RequestEventsStream = 8
// Contains the requested events by RequestEventsStream
EventsStreamResponse = 9
)
type errCode int
const (
ErrMsgTooLarge = iota
ErrDecode
ErrInvalidMsgCode
ErrProtocolVersionMismatch
ErrNetworkIDMismatch
ErrGenesisMismatch
ErrNoStatusMsg
ErrExtraStatusMsg
ErrSuspendedPeer
ErrEmptyMessage = 0xf00
)
func (e errCode) String() string {
return errorToString[int(e)]
}
// XXX change once legacy code is out
var errorToString = map[int]string{
ErrMsgTooLarge: "Message too long",
ErrDecode: "Invalid message",
ErrInvalidMsgCode: "Invalid message code",
ErrProtocolVersionMismatch: "Protocol version mismatch",
ErrNetworkIDMismatch: "NetworkId mismatch",
ErrGenesisMismatch: "Genesis object mismatch",
ErrNoStatusMsg: "No status message",
ErrExtraStatusMsg: "Extra status message",
ErrSuspendedPeer: "Suspended peer",
ErrEmptyMessage: "Empty message",
}
type txPool interface {
// AddRemotes should add the given transactions to the pool.
AddRemotes([]*types.Transaction) []error
// Pending should return pending transactions.
// The slice should be modifiable by the caller.
Pending() (map[common.Address]types.Transactions, error)
// SubscribeNewTxsNotify should return an event subscription of
// NewTxsNotify and send events to the given channel.
SubscribeNewTxsNotify(chan<- evmcore.NewTxsNotify) notify.Subscription
Get(common.Hash) *types.Transaction
OnlyNotExisting(hashes []common.Hash) []common.Hash
SampleHashes(max int) []common.Hash
}
// handshakeData is the network packet for the initial handshake message
type handshakeData struct {
ProtocolVersion uint32
NetworkID uint64
Genesis common.Hash
}
// PeerProgress is synchronization status of a peer
type PeerProgress struct {
Epoch idx.Epoch
LastBlockIdx idx.Block
LastBlockAtropos hash.Event
// Currently unused
HighestLamport idx.Lamport
}
type epochChunk struct {
SessionID uint32
Done bool
IDs hash.Events
Events inter.EventPayloads
}