forked from celo-org/celo-blockchain
/
protocol.go
65 lines (55 loc) · 2.45 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
// Copyright 2017 The celo Authors
// This file is part of the celo library.
//
// The celo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The celo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the celo library. If not, see <http://www.gnu.org/licenses/>.
package istanbul
import (
"github.com/aaronwinter/celo-blockchain/p2p"
)
// Constants to match up protocol versions and messages
const (
// No longer supported, can be removed.
// The corresponding version upstream (eth/65) is removed in upstream PR #22636.
Celo64 = 64 // eth/63 + the istanbul messages
Celo65 = 65 // incorporates changes from eth/64 (EIP)
// Supported versions
Celo66 = 66 // incorporates changes from eth/65 (EIP-2464)
)
// protocolName is the official short name of the protocol used during capability negotiation.
const ProtocolName = "istanbul"
// ProtocolVersions are the supported versions of the istanbul protocol (first is primary).
// (First is primary in the sense that it's the most current one supported)
var ProtocolVersions = []uint{Celo66}
// protocolLengths are the number of implemented message corresponding to different protocol versions.
var ProtocolLengths = map[uint]uint64{Celo64: 22, Celo65: 27, Celo66: 27}
// Message codes for istanbul related messages
// If you want to add a code, you need to increment the protocolLengths Array size
// and update the IsIstanbulMsg function below!
const (
ConsensusMsg = 0x11
QueryEnodeMsg = 0x12
ValEnodesShareMsg = 0x13
FwdMsg = 0x14
DelegateSignMsg = 0x15
VersionCertificatesMsg = 0x16
EnodeCertificateMsg = 0x17
ValidatorHandshakeMsg = 0x18
)
func IsIstanbulMsg(msg p2p.Msg) bool {
return msg.Code >= ConsensusMsg && msg.Code <= ValidatorHandshakeMsg
}
// IsGossipedMsg specifies which messages should be gossiped throughout the network (as opposed to directly sent to a peer).
func IsGossipedMsg(msgCode uint64) bool {
return msgCode == QueryEnodeMsg || msgCode == VersionCertificatesMsg
}