From b8f710998809ae45766e56862b57630d358354ae Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 27 Oct 2023 07:37:16 -0700 Subject: [PATCH] fix: api: compute the effective gas cost with the correct base-fee (#11357) fixes #11252 --- itests/eth_transactions_test.go | 17 ++++++++++++++++- node/impl/full/eth_utils.go | 8 +++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/itests/eth_transactions_test.go b/itests/eth_transactions_test.go index b39632795..6d60f6786 100644 --- a/itests/eth_transactions_test.go +++ b/itests/eth_transactions_test.go @@ -81,12 +81,16 @@ func TestValueTransferValidSignature(t *testing.T) { receipt, err := waitForEthTxReceipt(ctx, client, hash) require.NoError(t, err) require.NotNil(t, receipt) + require.EqualValues(t, ethAddr, receipt.From) + require.EqualValues(t, ethAddr2, *receipt.To) + require.EqualValues(t, hash, receipt.TransactionHash) // Success. require.EqualValues(t, ethtypes.EthUint64(0x1), receipt.Status) + // Validate that we sent the expected transaction. ethTx, err := client.EthGetTransactionByHash(ctx, &hash) - require.Nil(t, err) + require.NoError(t, err) require.EqualValues(t, ethAddr, ethTx.From) require.EqualValues(t, ethAddr2, *ethTx.To) require.EqualValues(t, tx.ChainID, ethTx.ChainID) @@ -269,6 +273,17 @@ func TestContractInvocation(t *testing.T) { // Success. require.EqualValues(t, ethtypes.EthUint64(0x1), receipt.Status) + + // Validate that we correctly computed the gas outputs. + mCid, err := client.EthGetMessageCidByTransactionHash(ctx, &hash) + require.NoError(t, err) + require.NotNil(t, mCid) + + invokResult, err := client.StateReplay(ctx, types.EmptyTSK, *mCid) + require.NoError(t, err) + require.EqualValues(t, invokResult.GasCost.GasUsed, big.NewInt(int64(receipt.GasUsed))) + effectiveGasPrice := big.Div(invokResult.GasCost.TotalCost, invokResult.GasCost.GasUsed) + require.EqualValues(t, effectiveGasPrice, big.Int(receipt.EffectiveGasPrice)) } func TestGetBlockByNumber(t *testing.T) { diff --git a/node/impl/full/eth_utils.go b/node/impl/full/eth_utils.go index 5908c9412..17695dd76 100644 --- a/node/impl/full/eth_utils.go +++ b/node/impl/full/eth_utils.go @@ -627,7 +627,13 @@ func newEthTxReceipt(ctx context.Context, tx ethtypes.EthTx, lookup *api.MsgLook return api.EthTxReceipt{}, xerrors.Errorf("failed to lookup tipset %s when constructing the eth txn receipt: %w", lookup.TipSet, err) } - baseFee := ts.Blocks()[0].ParentBaseFee + // The tx is located in the parent tipset + parentTs, err := cs.LoadTipSet(ctx, ts.Parents()) + if err != nil { + return api.EthTxReceipt{}, xerrors.Errorf("failed to lookup tipset %s when constructing the eth txn receipt: %w", ts.Parents(), err) + } + + baseFee := parentTs.Blocks()[0].ParentBaseFee gasOutputs := vm.ComputeGasOutputs(lookup.Receipt.GasUsed, int64(tx.Gas), baseFee, big.Int(tx.MaxFeePerGas), big.Int(tx.MaxPriorityFeePerGas), true) totalSpent := big.Sum(gasOutputs.BaseFeeBurn, gasOutputs.MinerTip, gasOutputs.OverEstimationBurn)