From 920fdfdf85386ff00deea4049a3b45c31ad3bdc7 Mon Sep 17 00:00:00 2001 From: Aayush Date: Fri, 3 Mar 2023 16:42:57 -0500 Subject: [PATCH] fix: EthAPI: Correctly get parent hash --- itests/eth_api_test.go | 22 ++++++++++++++++++++++ node/impl/full/eth.go | 6 +----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/itests/eth_api_test.go b/itests/eth_api_test.go index 32949cc71..c24b32416 100644 --- a/itests/eth_api_test.go +++ b/itests/eth_api_test.go @@ -87,3 +87,25 @@ func TestFilecoinAddressToEthAddress(t *testing.T) { require.ErrorContains(t, err, ethtypes.ErrInvalidAddress.Error()) } + +func TestEthGetGenesis(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() + + ethBlk, err := client.EVM().EthGetBlockByNumber(ctx, "0x0", true) + require.NoError(t, err) + + genesis, err := client.ChainGetGenesis(ctx) + require.NoError(t, err) + + genesisCid, err := genesis.Key().Cid() + require.NoError(t, err) + + genesisHash, err := ethtypes.EthHashFromCid(genesisCid) + require.NoError(t, err) + require.Equal(t, ethBlk.Hash, genesisHash) +} diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index b1d03db4b..c826aca91 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -1763,11 +1763,7 @@ func (e *ethSubscription) stop() { } func newEthBlockFromFilecoinTipSet(ctx context.Context, ts *types.TipSet, fullTxInfo bool, cs *store.ChainStore, sa StateAPI) (ethtypes.EthBlock, error) { - parent, err := cs.LoadTipSet(ctx, ts.Parents()) - if err != nil { - return ethtypes.EthBlock{}, err - } - parentKeyCid, err := parent.Key().Cid() + parentKeyCid, err := ts.Parents().Cid() if err != nil { return ethtypes.EthBlock{}, err }