From 158f72cc0c889739f49dde42210328902073353d Mon Sep 17 00:00:00 2001
From: Marius van der Wijden <m.vanderwijden@live.de>
Date: Wed, 23 Dec 2020 13:43:22 +0100
Subject: [PATCH] internal/ethapi: restore net_version RPC method (#22061)

During the snap and eth refactor, the net_version rpc call was falsely deprecated.
This restores the net_version RPC handler as most eth2 nodes and other software
depend on it.
---
 eth/backend.go         |  2 +-
 internal/ethapi/api.go | 12 +++++++++---
 les/client.go          |  2 +-
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/eth/backend.go b/eth/backend.go
index 987dee6d5..c1732d3ce 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -230,7 +230,7 @@ func New(stack *node.Node, config *Config) (*Ethereum, error) {
 		return nil, err
 	}
 	// Start the RPC service
-	eth.netRPCService = ethapi.NewPublicNetAPI(eth.p2pServer)
+	eth.netRPCService = ethapi.NewPublicNetAPI(eth.p2pServer, config.NetworkId)
 
 	// Register the backend on the node
 	stack.RegisterAPIs(eth.APIs())
diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go
index 9ff1781e4..b424435b5 100644
--- a/internal/ethapi/api.go
+++ b/internal/ethapi/api.go
@@ -1900,12 +1900,13 @@ func (api *PrivateDebugAPI) SetHead(number hexutil.Uint64) {
 
 // PublicNetAPI offers network related RPC methods
 type PublicNetAPI struct {
-	net *p2p.Server
+	net            *p2p.Server
+	networkVersion uint64
 }
 
 // NewPublicNetAPI creates a new net API instance.
-func NewPublicNetAPI(net *p2p.Server) *PublicNetAPI {
-	return &PublicNetAPI{net}
+func NewPublicNetAPI(net *p2p.Server, networkVersion uint64) *PublicNetAPI {
+	return &PublicNetAPI{net, networkVersion}
 }
 
 // Listening returns an indication if the node is listening for network connections.
@@ -1918,6 +1919,11 @@ func (s *PublicNetAPI) PeerCount() hexutil.Uint {
 	return hexutil.Uint(s.net.PeerCount())
 }
 
+// Version returns the current ethereum protocol version.
+func (s *PublicNetAPI) Version() string {
+	return fmt.Sprintf("%d", s.networkVersion)
+}
+
 // checkTxFee is an internal function used to check whether the fee of
 // the given transaction is _reasonable_(under the cap).
 func checkTxFee(gasPrice *big.Int, gas uint64, cap float64) error {
diff --git a/les/client.go b/les/client.go
index 198255dc5..47997a098 100644
--- a/les/client.go
+++ b/les/client.go
@@ -171,7 +171,7 @@ func New(stack *node.Node, config *eth.Config) (*LightEthereum, error) {
 		leth.blockchain.DisableCheckFreq()
 	}
 
-	leth.netRPCService = ethapi.NewPublicNetAPI(leth.p2pServer)
+	leth.netRPCService = ethapi.NewPublicNetAPI(leth.p2pServer, leth.config.NetworkId)
 
 	// Register the backend on the node
 	stack.RegisterAPIs(leth.APIs())
-- 
GitLab