differentiate xdpos 2.2 protocol version

This commit is contained in:
wanwiset25 2024-06-24 14:08:35 +04:00
parent 57b11ab4c9
commit ebb9a63107
4 changed files with 55 additions and 13 deletions

View file

@ -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)

View file

@ -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))

View file

@ -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

View file

@ -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.