github.com/electroneum/electroneum-sc@v0.0.0-20230105223411-3bc1d078281e/eth/ibft_protocol.go (about) 1 package eth 2 3 import ( 4 "errors" 5 6 "github.com/electroneum/electroneum-sc/p2p" 7 ) 8 9 // ibft_protocol enables the eth service to return two different protocols, one for the eth mainnet "eth" service, 10 // and one for the ibft specific consensus algo, obtained from engine.consensus 11 // 2021 Jan in the future consensus (istanbul) may run from its own service and use a single subprotocol there, 12 // instead of overloading the eth service. 13 14 var ( 15 // errEthPeerNil is returned when no eth peer is found to be associated with a p2p peer. 16 errEthPeerNil = errors.New("eth peer was nil") 17 errEthPeerNotRegistered = errors.New("eth peer was not registered") 18 ) 19 20 // ibft consensus Protocol variables are optionally set in addition to the "eth" protocol variables (eth/protocol.go). 21 var ibftConsensusProtocolName = "" 22 23 // ProtocolVersions are the supported versions of the ibft consensus protocol (first is primary), e.g. []uint{Istanbul64, Istanbul99, Istanbul100}. 24 var ibftConsensusProtocolVersions []uint 25 26 // protocol Length describe the number of messages support by the protocol/version map[uint]uint64{Istanbul64: 18, Istanbul99: 18, Istanbul100: 18} 27 var ibftConsensusProtocolLengths map[uint]uint64 28 29 func (s *Ethereum) ibftConsensusProtocols() []p2p.Protocol { 30 protos := make([]p2p.Protocol, len(ibftConsensusProtocolVersions)) 31 for i, vsn := range ibftConsensusProtocolVersions { 32 length, ok := ibftConsensusProtocolLengths[vsn] 33 if !ok { 34 panic("makeIbftConsensusProtocol for unknown version") 35 } 36 protos[i] = s.handler.makeIbftConsensusProtocol(ibftConsensusProtocolName, vsn, length) 37 } 38 return protos 39 }