Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/ethapi: fix eth_chainId method #22243

Merged
merged 6 commits into from
Apr 6, 2021

Conversation

piersy
Copy link
Contributor

@piersy piersy commented Jan 27, 2021

Although the ChainID is represented as a *big.Int in the ChainConfig, it
was being marshaled as a uint64 by the PublicEthereumAPI. This leads to
discrepancies between the config and calls to the API when the ChainID
is bigger than math.MaxUint64.

Although the ChainID is represented as a *big.Int in the ChainConfig, it
was being marshaled as a uint64 by the PublicEthereumAPI. This leads to
discrepancies between the config and calls to the API when the ChainID
is bigger than math.MaxUint64.
@rjl493456442
Copy link
Member

Thanks for catching it. Apparently, we define two ChainID RPC calls, and even worse, they are all in the same namespace eth.

Here: https://github.com/ethereum/go-ethereum/blob/master/internal/ethapi/api.go#L533
And here: https://github.com/ethereum/go-ethereum/blob/master/eth/api.go#L70

I think we can just remove the API in internal/ethapi/api.go and change the return to hexutil.Big in the eth/api

@fjl
Copy link
Contributor

fjl commented Jan 28, 2021

I would prefer to keep the one in internal/ethapi and delete the implementation in package eth.

@piersy
Copy link
Contributor Author

piersy commented Jan 28, 2021

Thanks for catching it. Apparently, we define two ChainID RPC calls, and even worse, they are all in the same namespace eth.

Here: https://github.com/ethereum/go-ethereum/blob/master/internal/ethapi/api.go#L533
And here: https://github.com/ethereum/go-ethereum/blob/master/eth/api.go#L70

I think we can just remove the API in internal/ethapi/api.go and change the return to hexutil.Big in the eth/api

Yeah, this did confuse me

@piersy
Copy link
Contributor Author

piersy commented Feb 11, 2021

@Fjf @rjl493456442 Just checking in to see if you were expecting any action on my part? I was thinking I'd wait for agreement between you two before taking any further action.

@karalabe
Copy link
Member

karalabe commented Mar 9, 2021

Ok, I agree with @fjl. The one in internal is neeed because it's used by both eth and les. The one in eth apparently overrides it, but it's redundant. Still, the implementation of the one in eth is the more correct one as it handles a chain progress issue.

Could you move the code from eth into the internal one and delete the eth version? Thanks

@karalabe karalabe added this to the 1.10.2 milestone Mar 9, 2021
@holiman
Copy link
Contributor

holiman commented Mar 9, 2021

@karalabe do we want to add something like this?

diff --git a/rpc/service.go b/rpc/service.go
index bef891ea11..e30f8d7382 100644
--- a/rpc/service.go
+++ b/rpc/service.go
@@ -26,6 +26,7 @@ import (
 	"sync"
 	"unicode"
 
+	"github.com/ethereum/go-ethereum/cmd/utils"
 	"github.com/ethereum/go-ethereum/log"
 )
 
@@ -82,11 +83,17 @@ func (r *serviceRegistry) registerName(name string, rcvr interface{}) error {
 		}
 		r.services[name] = svc
 	}
-	for name, cb := range callbacks {
+	for methodName, cb := range callbacks {
 		if cb.isSubscribe {
-			svc.subscriptions[name] = cb
+			if _, exist := svc.subscriptions[methodName]; exist {
+				utils.Fatalf("API double-register of %v.%v\n", name, methodName)
+			}
+			svc.subscriptions[methodName] = cb
 		} else {
-			svc.callbacks[name] = cb
+			if _, exist := svc.callbacks[methodName]; exist {
+				utils.Fatalf("Double-register of %v.%v\n", name, methodName)
+			}
+			svc.callbacks[methodName] = cb
 		}
 	}
 	return nil

Use the implementation of ChainId from eth/api.go in
internal/ethapi/api.go and removed ChainId from eth/api.go.
@piersy
Copy link
Contributor Author

piersy commented Mar 10, 2021

Could you move the code from eth into the internal one and delete the eth version? Thanks

Hi @karalabe I've made this change

Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

@fjl fjl changed the title eth: Fix ethereum API ChainID marshaling internal/ethapi: fix eth_chainId method Mar 19, 2021
@fjl fjl self-assigned this Apr 6, 2021
@fjl fjl merged commit 706683e into ethereum:master Apr 6, 2021
atif-konasl pushed a commit to frozeman/pandora-execution-engine that referenced this pull request Oct 15, 2021
This removes the duplicated definition of eth_chainID
in package eth and updates the definition in internal/ethapi
to treat chain ID as a bigint.

Co-authored-by: Felix Lange <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants