From 7ce92f1422d9b28b4454631e36725f0e81356d1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Sat, 11 Mar 2023 23:26:26 +0000 Subject: [PATCH 1/2] Eth API: make net_version return the chain ID. --- itests/eth_api_test.go | 15 +++++++++++++++ node/impl/full/eth.go | 9 ++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/itests/eth_api_test.go b/itests/eth_api_test.go index c24b32416..6506b01b1 100644 --- a/itests/eth_api_test.go +++ b/itests/eth_api_test.go @@ -2,9 +2,11 @@ package itests import ( "context" + "strconv" "testing" "time" + "github.com/filecoin-project/lotus/build" "github.com/stretchr/testify/require" "github.com/filecoin-project/go-state-types/builtin" @@ -109,3 +111,16 @@ func TestEthGetGenesis(t *testing.T) { require.NoError(t, err) require.Equal(t, ethBlk.Hash, genesisHash) } + +func TestNetVersion(t *testing.T) { + blockTime := 100 * time.Millisecond + client, _, ens := kit.EnsembleMinimal(t, kit.MockProofs(), kit.ThroughRPC()) + ens.InterconnectAll().BeginMining(blockTime) + + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + + version, err := client.NetVersion(ctx) + require.NoError(t, err) + require.Equal(t, strconv.Itoa(build.Eip155ChainId), version) +} diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index d8271fcdb..662531b7c 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -766,13 +766,8 @@ func (a *EthModule) EthFeeHistory(ctx context.Context, p jsonrpc.RawParams) (eth return ret, nil } -func (a *EthModule) NetVersion(ctx context.Context) (string, error) { - // Note that networkId is not encoded in hex - nv, err := a.StateNetworkVersion(ctx, types.EmptyTSK) - if err != nil { - return "", err - } - return strconv.FormatUint(uint64(nv), 10), nil +func (a *EthModule) NetVersion(_ context.Context) (string, error) { + return strconv.FormatInt(build.Eip155ChainId, 10), nil } func (a *EthModule) NetListening(ctx context.Context) (bool, error) { From 4763104b99fc2f518ac6d6cd8ef6d00af5a89758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Kripalani?= Date: Sun, 12 Mar 2023 00:42:56 +0000 Subject: [PATCH 2/2] fix imports. --- itests/eth_api_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/itests/eth_api_test.go b/itests/eth_api_test.go index 6506b01b1..43b4b5266 100644 --- a/itests/eth_api_test.go +++ b/itests/eth_api_test.go @@ -6,11 +6,11 @@ import ( "testing" "time" - "github.com/filecoin-project/lotus/build" "github.com/stretchr/testify/require" "github.com/filecoin-project/go-state-types/builtin" + "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types/ethtypes" "github.com/filecoin-project/lotus/chain/wallet/key"