From ebb9a631076048567bc01151a813a1291069c148 Mon Sep 17 00:00:00 2001 From: wanwiset25 Date: Mon, 24 Jun 2024 14:08:35 +0400 Subject: [PATCH] differentiate xdpos 2.2 protocol version --- eth/handler.go | 2 +- eth/peer.go | 8 ++++---- eth/protocol.go | 54 +++++++++++++++++++++++++++++++++++++++++++------ eth/sync.go | 4 ++-- 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/eth/handler.go b/eth/handler.go index 3739b11c58..d1c9e64df9 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -1128,7 +1128,7 @@ func (pm *ProtocolManager) BroadcastTransactions(txs types.Transactions, propaga } } for peer, hashes := range annos { - if peer.version >= eth65 { + if peer.version >= eth65 { //implement peer.AsyncSendPooledTransactionHashes(hashes) } else { peer.AsyncSendTransactions(hashes) diff --git a/eth/peer.go b/eth/peer.go index c468f89830..f17bc08d36 100644 --- a/eth/peer.go +++ b/eth/peer.go @@ -799,7 +799,7 @@ func (p *peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis CurrentBlock: head, GenesisBlock: genesis, }) - case p.version >= eth64: + case p.version >= eth64 || p.version >= xdpos22: errc <- p2p.Send(p.rw, StatusMsg, &statusData{ ProtocolVersion: uint32(p.version), NetworkID: network, @@ -814,11 +814,11 @@ func (p *peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis }() go func() { switch { - case p.version == xdpos2: + case p.version == xdpos2: errc <- p.readStatusLegacy(network, &status63, genesis) case p.version == eth63: errc <- p.readStatusLegacy(network, &status63, genesis) - case p.version >= eth64: + case p.version >= eth64 || p.version >= xdpos22: //include xdpos22 condition for completeness errc <- p.readStatus(network, &status, genesis, forkFilter) default: panic(fmt.Sprintf("unsupported eth protocol version: %d", p.version)) @@ -841,7 +841,7 @@ func (p *peer) Handshake(network uint64, td *big.Int, head common.Hash, genesis p.td, p.head = status63.TD, status63.CurrentBlock case p.version == eth63: p.td, p.head = status63.TD, status63.CurrentBlock - case p.version >= eth64: + case p.version >= eth64 || p.version >= xdpos22: //include xdpos22 for completeness p.td, p.head = status.TD, status.Head default: panic(fmt.Sprintf("unsupported eth protocol version: %d", p.version)) diff --git a/eth/protocol.go b/eth/protocol.go index d037d6afe1..0e5aea743e 100644 --- a/eth/protocol.go +++ b/eth/protocol.go @@ -31,20 +31,62 @@ import ( // Constants to match up protocol versions and messages const ( - eth63 = 63 - eth64 = 64 - eth65 = 65 - xdpos2 = 100 + eth63 = 63 + eth64 = 64 + eth65 = 65 + xdpos2 = 100 //xdpos2.1 = eth62+eth63 + xdpos22 = 101 //xdpos2.2 = eth63+eth64+eth65 ) +func supportsEth63(version int) bool { + switch { + case version < 63: + return false + case version > 63: + return true + default: + return false + } +} + +func supportsEth64(version int) bool { + switch { + case version < 64: + return false + case version < 100: + return true + case version == 100: + return false + case version > 100: + return true + default: + return false + } +} + +func supportsEth65(version int) bool { + switch { + case version < 65: + return false + case version < 100: + return true + case version == 100: + return false + case version > 100: + return true + default: + return false + } +} + // protocolName is the official short name of the protocol used during capability negotiation. const protocolName = "eth" // ProtocolVersions are the supported versions of the eth protocol (first is primary). -var ProtocolVersions = []uint{xdpos2, eth65, eth64, eth63} +var ProtocolVersions = []uint{xdpos22, xdpos2, eth65, eth64, eth63} // protocolLengths are the number of implemented message corresponding to different protocol versions. -var protocolLengths = map[uint]uint64{xdpos2: 227, eth65: 17, eth64: 17, eth63: 17} +var protocolLengths = map[uint]uint64{xdpos22: 227, xdpos2: 227, eth65: 17, eth64: 17, eth63: 17} const protocolMaxMsgSize = 10 * 1024 * 1024 // Maximum cap on the size of a protocol message diff --git a/eth/sync.go b/eth/sync.go index 73e3796e71..76ad1c2c49 100644 --- a/eth/sync.go +++ b/eth/sync.go @@ -61,7 +61,7 @@ func (pm *ProtocolManager) syncTransactions(p *peer) { // The eth/65 protocol introduces proper transaction announcements, so instead // of dripping transactions across multiple peers, just send the entire list as // an announcement and let the remote side decide what they need (likely nothing). - if p.version >= eth65 { + if supportsEth65(p.version) { hashes := make([]common.Hash, len(txs)) for i, tx := range txs { hashes[i] = tx.Hash() @@ -89,7 +89,7 @@ func (pm *ProtocolManager) txsyncLoop64() { ) // send starts a sending a pack of transactions from the sync. send := func(s *txsync) { - if s.p.version >= eth65 { + if supportsEth65(s.p.version) { panic("initial transaction syncer running on eth/65+") } // Fill pack with transactions up to the target size.