eth/protocols/eth/handler.go — Version Comparison¶
| v1.17.3 | v1.17.4 | |
|---|---|---|
| Branch | etc/v1.17.3-full-node |
etc/v1.17.4-full-node |
| Delta | +12 -4 | +12 -4 |
ETC delta on v1.17.3 (+12 -4)
diff --git a/eth/protocols/eth/handler.go b/eth/protocols/eth/handler.go
index f7d25bd8c..dc52a786f 100644
--- a/eth/protocols/eth/handler.go
+++ b/eth/protocols/eth/handler.go
@@ -102,9 +102,9 @@ type TxPool interface {
}
// MakeProtocols constructs the P2P protocol definitions for `eth`.
-func MakeProtocols(backend Backend, network uint64, disc enode.Iterator) []p2p.Protocol {
- protocols := make([]p2p.Protocol, 0, len(ProtocolVersions))
- for _, version := range ProtocolVersions {
+func MakeProtocols(backend Backend, network uint64, disc enode.Iterator, versions []uint) []p2p.Protocol {
+ protocols := make([]p2p.Protocol, 0, len(versions))
+ for _, version := range versions {
protocols = append(protocols, p2p.Protocol{
Name: ProtocolName,
Version: version,
@@ -169,6 +169,10 @@ type Decoder interface {
Decode(val interface{}) error
}
+// versionHandlers maps protocol versions to their message handler maps.
+// PoW protocol versions (e.g. ETH68) are registered via init() in _pow.go files.
+var versionHandlers = map[uint]map[uint64]msgHandler{}
+
var eth69 = map[uint64]msgHandler{
TransactionsMsg: handleTransactions,
NewPooledTransactionHashesMsg: handleNewPooledTransactionHashes,
@@ -217,7 +221,11 @@ func handleMessage(backend Backend, peer *Peer) error {
case ETH70:
handlers = eth70
default:
- return fmt.Errorf("unknown eth protocol version: %v", peer.version)
+ if h, ok := versionHandlers[peer.version]; ok {
+ handlers = h
+ } else {
+ return fmt.Errorf("unknown eth protocol version: %v", peer.version)
+ }
}
// Track the amount of time it takes to serve the request and run the handler
ETC delta on v1.17.4 (+12 -4)
diff --git a/eth/protocols/eth/handler.go b/eth/protocols/eth/handler.go
index 154b75130..adc3c0d21 100644
--- a/eth/protocols/eth/handler.go
+++ b/eth/protocols/eth/handler.go
@@ -105,9 +105,9 @@ type TxPool interface {
}
// MakeProtocols constructs the P2P protocol definitions for `eth`.
-func MakeProtocols(backend Backend, network uint64, disc enode.Iterator) []p2p.Protocol {
- protocols := make([]p2p.Protocol, 0, len(ProtocolVersions))
- for _, version := range ProtocolVersions {
+func MakeProtocols(backend Backend, network uint64, disc enode.Iterator, versions []uint) []p2p.Protocol {
+ protocols := make([]p2p.Protocol, 0, len(versions))
+ for _, version := range versions {
protocols = append(protocols, p2p.Protocol{
Name: ProtocolName,
Version: version,
@@ -172,6 +172,10 @@ type Decoder interface {
Decode(val interface{}) error
}
+// versionHandlers maps protocol versions to their message handler maps.
+// PoW protocol versions (e.g. ETH68) are registered via init() in _pow.go files.
+var versionHandlers = map[uint]map[uint64]msgHandler{}
+
var eth69 = map[uint64]msgHandler{
TransactionsMsg: handleTransactions,
NewPooledTransactionHashesMsg: handleNewPooledTransactionHashes,
@@ -238,7 +242,11 @@ func handleMessage(backend Backend, peer *Peer) error {
case ETH71:
handlers = eth71
default:
- return fmt.Errorf("unknown eth protocol version: %v", peer.version)
+ if h, ok := versionHandlers[peer.version]; ok {
+ handlers = h
+ } else {
+ return fmt.Errorf("unknown eth protocol version: %v", peer.version)
+ }
}
// Track the amount of time it takes to serve the request and run the handler