Skip to content

Commit

Permalink
differentiate xdpos 2.2 protocol version
Browse files Browse the repository at this point in the history
  • Loading branch information
wanwiset25 committed Jun 28, 2024
1 parent 57b11ab commit ebb9a63
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
2 changes: 1 addition & 1 deletion eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions eth/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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))
Expand All @@ -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))
Expand Down
54 changes: 48 additions & 6 deletions eth/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions eth/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit ebb9a63

Please sign in to comment.