github.com/kisexp/xdchain@v0.0.0-20211206025815-490d6b732aa7/consensus/protocol.go (about) 1 // Quorum 2 package consensus 3 4 import ( 5 "github.com/kisexp/xdchain/common" 6 "github.com/kisexp/xdchain/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 eth63 = 63 15 eth64 = 64 16 eth65 = 65 17 Istanbul64 = 64 18 Istanbul99 = 99 19 // this istanbul subprotocol will be registered in addition to "eth" 20 Istanbul100 = 100 21 ) 22 23 var ( 24 IstanbulProtocol = Protocol{ 25 Name: "istanbul", 26 Versions: []uint{Istanbul100, Istanbul99, Istanbul64}, 27 // istanbul/100 has to have 22 message to be backwards compatible although at the p2p layer it only has 28 // 1 message with msg.Code 17 29 Lengths: map[uint]uint64{Istanbul100: 22, Istanbul99: 18, Istanbul64: 18}, 30 } 31 32 CliqueProtocol = Protocol{ 33 Name: "eth", 34 Versions: []uint{eth65, eth64, eth63}, 35 Lengths: map[uint]uint64{eth65: 17, eth64: 17, eth63: 17}, 36 } 37 38 // Default: Keep up-to-date with eth/protocol.go 39 EthProtocol = Protocol{ 40 Name: "eth", 41 Versions: []uint{eth65, eth64, eth63}, 42 Lengths: map[uint]uint64{eth65: 17, eth64: 17, eth63: 17}, 43 } 44 45 NorewardsProtocol = Protocol{ 46 Name: "Norewards", 47 Versions: []uint{0}, 48 Lengths: map[uint]uint64{0: 0}, 49 } 50 ) 51 52 // Protocol defines the protocol of the consensus 53 type Protocol struct { 54 // Official short name of the protocol used during capability negotiation. 55 Name string 56 // Supported versions of the eth protocol (first is primary). 57 Versions []uint 58 // Number of implemented message corresponding to different protocol versions. 59 Lengths map[uint]uint64 60 } 61 62 // Broadcaster defines the interface to enqueue blocks to fetcher and find peer 63 type Broadcaster interface { 64 // Enqueue add a block into fetcher queue 65 Enqueue(id string, block *types.Block) 66 // FindPeers retrives peers by addresses 67 FindPeers(map[common.Address]bool) map[common.Address]Peer 68 } 69 70 // Peer defines the interface to communicate with peer 71 type Peer interface { 72 // Send sends the message to this peer 73 Send(msgcode uint64, data interface{}) error 74 75 // SendConsensus sends the message to this p2p peer using the consensus specific devp2p subprotocol 76 SendConsensus(msgcode uint64, data interface{}) error 77 78 // SendQBFTConsensus is used to send consensus subprotocol messages from an "eth" peer without encoding the payload 79 SendQBFTConsensus(msgcode uint64, payload []byte) error 80 }