fix: api: compute the effective gas cost with the correct base-fee (#11357)
fixes #11252
This commit is contained in:
parent
6e22c08c1d
commit
420f33017e
@ -81,12 +81,16 @@ func TestValueTransferValidSignature(t *testing.T) {
|
|||||||
receipt, err := waitForEthTxReceipt(ctx, client, hash)
|
receipt, err := waitForEthTxReceipt(ctx, client, hash)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, receipt)
|
require.NotNil(t, receipt)
|
||||||
|
require.EqualValues(t, ethAddr, receipt.From)
|
||||||
|
require.EqualValues(t, ethAddr2, *receipt.To)
|
||||||
|
require.EqualValues(t, hash, receipt.TransactionHash)
|
||||||
|
|
||||||
// Success.
|
// Success.
|
||||||
require.EqualValues(t, ethtypes.EthUint64(0x1), receipt.Status)
|
require.EqualValues(t, ethtypes.EthUint64(0x1), receipt.Status)
|
||||||
|
|
||||||
|
// Validate that we sent the expected transaction.
|
||||||
ethTx, err := client.EthGetTransactionByHash(ctx, &hash)
|
ethTx, err := client.EthGetTransactionByHash(ctx, &hash)
|
||||||
require.Nil(t, err)
|
require.NoError(t, err)
|
||||||
require.EqualValues(t, ethAddr, ethTx.From)
|
require.EqualValues(t, ethAddr, ethTx.From)
|
||||||
require.EqualValues(t, ethAddr2, *ethTx.To)
|
require.EqualValues(t, ethAddr2, *ethTx.To)
|
||||||
require.EqualValues(t, tx.ChainID, ethTx.ChainID)
|
require.EqualValues(t, tx.ChainID, ethTx.ChainID)
|
||||||
@ -269,6 +273,17 @@ func TestContractInvocation(t *testing.T) {
|
|||||||
|
|
||||||
// Success.
|
// Success.
|
||||||
require.EqualValues(t, ethtypes.EthUint64(0x1), receipt.Status)
|
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) {
|
func TestGetBlockByNumber(t *testing.T) {
|
||||||
|
@ -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)
|
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)
|
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)
|
totalSpent := big.Sum(gasOutputs.BaseFeeBurn, gasOutputs.MinerTip, gasOutputs.OverEstimationBurn)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user