github.com/electroneum/electroneum-sc@v0.0.0-20230105223411-3bc1d078281e/consensus/protocol.go (about) 1 // Quorum 2 package consensus 3 4 import ( 5 "github.com/electroneum/electroneum-sc/common" 6 "github.com/electroneum/electroneum-sc/core/types" 7 ) 8 9 // Constants to match up protocol versions and messages 10 // istanbul/99 was added to accommodate new eth/64 handshake status data with fork id 11 // this is for backward compatibility which allows a mixed old/new istanbul node network 12 // istanbul/64 will continue using old status data as eth/63 13 const ( 14 eth66 = 66 15 Istanbul100 = 100 16 ) 17 18 var ( 19 IstanbulProtocol = Protocol{ 20 Name: "etn-istanbul", 21 Versions: []uint{Istanbul100}, 22 // istanbul/100 has to have 22 message to be backwards compatible although at the p2p layer it only has 23 // 1 message with msg.Code 17 24 Lengths: map[uint]uint64{Istanbul100: 22}, 25 } 26 27 CliqueProtocol = Protocol{ 28 Name: "etn", 29 Versions: []uint{eth66}, 30 Lengths: map[uint]uint64{eth66: 17}, 31 } 32 33 // Default: Keep up-to-date with eth/protocol.go 34 EthProtocol = Protocol{ 35 Name: "etn", 36 Versions: []uint{eth66}, 37 Lengths: map[uint]uint64{eth66: 17}, 38 } 39 ) 40 41 // Protocol defines the protocol of the consensus 42 type Protocol struct { 43 // Official short name of the protocol used during capability negotiation. 44 Name string 45 // Supported versions of the eth protocol (first is primary). 46 Versions []uint 47 // Number of implemented message corresponding to different protocol versions. 48 Lengths map[uint]uint64 49 } 50 51 // Broadcaster defines the interface to enqueue blocks to fetcher and find peer 52 type Broadcaster interface { 53 // Enqueue add a block into fetcher queue 54 Enqueue(id string, block *types.Block) 55 // FindPeers retrives peers by addresses 56 FindPeers(map[common.Address]bool) map[common.Address]Peer 57 } 58 59 // Peer defines the interface to communicate with peer 60 type Peer interface { 61 // Send sends the message to this peer 62 Send(msgcode uint64, data interface{}) error 63 64 // SendConsensus sends the message to this p2p peer using the consensus specific devp2p subprotocol 65 SendConsensus(msgcode uint64, data interface{}) error 66 67 // SendQBFTConsensus is used to send consensus subprotocol messages from an "eth" peer without encoding the payload 68 SendQBFTConsensus(msgcode uint64, payload []byte) error 69 }