Skip to content

Update frontier to address pov underestimations #3227

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

Merged
merged 25 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 19 additions & 17 deletions runtime/common/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,22 +340,23 @@ macro_rules! impl_runtime_apis_plus_common {
let without_base_extrinsic_weight = true;


// Estimated encoded transaction size must be based on the heaviest transaction
// type (EIP1559Transaction) to be compatible with all transaction types.
// Estimated encoded transaction size must be based on the transaction
// type (TransactionData) to be compatible with all transaction types.
// TODO: remove, since we will get rid of base_cost
let mut estimated_transaction_len = data.len() +
// pallet ethereum index: 1
// transact call index: 1
// Transaction enum variant: 1
// chain_id 8 bytes
// nonce: 32
// max_priority_fee_per_gas: 32
// max_fee_per_gas: 32
// gas_limit: 32
// action: 21 (enum varianrt + call address)
// value: 32
// access_list: 1 (empty vec size)
// 65 bytes signature
258;
// pallet ethereum index: 1
// transact call index: 1
// Transaction enum variant: 1
// chain_id 8 bytes
// nonce: 32
// max_priority_fee_per_gas: 32
// max_fee_per_gas: 32
// gas_limit: 32
// action: 21 (enum varianrt + call address)
// value: 32
// access_list: 1 (empty vec size)
// 65 bytes signature
258;

if access_list.is_some() {
estimated_transaction_len += access_list.encoded_size();
Expand Down Expand Up @@ -475,8 +476,9 @@ macro_rules! impl_runtime_apis_plus_common {
let is_transactional = false;
let validate = true;

// Estimated encoded transaction size must be based on the heaviest transaction
// type (EIP1559Transaction) to be compatible with all transaction types.
// Estimated encoded transaction size must be based on the transaction
// type (TransactionData) to be compatible with all transaction types.
// TODO: remove, since we will get rid of base_cost
let mut estimated_transaction_len = data.len() +
// pallet ethereum index: 1
// transact call index: 1
Expand Down
18 changes: 16 additions & 2 deletions test/helpers/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,29 @@ export const verifyBlockFees = async (
gasFee = ethTxWrapper.asEip1559.maxFeePerGas.toBigInt();
}

const hash = events
.find((event) => event.section === "ethereum" && event.method === "Executed")!
.data[2].toHex();
await context.viem("public").getTransactionReceipt({ hash });
let effectiveTipPerGas = gasFee - baseFeePerGas;
if (effectiveTipPerGas > priorityFee) {
effectiveTipPerGas = priorityFee;
}

// Calculate the fees paid for the base fee and tip fee independently.
// Only the base fee is subject to the split between burn and treasury.
const baseFeesPaid = gasUsed * baseFeePerGas;
const tipAsFeesPaid = gasUsed * effectiveTipPerGas;
let baseFeesPaid = gasUsed * baseFeePerGas;
let tipAsFeesPaid = gasUsed * effectiveTipPerGas;
const actualPaidFees = (
events.find(
(event) => event.section === "balances" && event.method === "Withdraw"
)!.data[1] as u128
).toBigInt();
if (actualPaidFees < baseFeesPaid + tipAsFeesPaid) {
baseFeesPaid = actualPaidFees < baseFeesPaid ? actualPaidFees : baseFeesPaid;
tipAsFeesPaid =
actualPaidFees < baseFeesPaid ? 0n : actualPaidFees - baseFeesPaid;
}

const { burnt: baseFeePortionsBurnt } = calculateFeePortions(
feesTreasuryProportion,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describeSuite, expect, extractInfo, TransactionTypes } from "@moonwall/cli";
import { describeSuite, expect, TransactionTypes } from "@moonwall/cli";
import {
alith,
ALITH_ADDRESS,
Expand Down Expand Up @@ -172,16 +172,29 @@ describeSuite({
const treasuryIncrease = balAfter - balBefore;
const issuanceDecrease = issuanceBefore - issuanceAfter;
const collatorIncrease = collatorBalAfter - collatorBalBefore;
const fee = extractFee(result?.events)!.amount.toBigInt();
const min = (a: bigint, b: bigint) => (a < b ? a : b);
const tipPaid = withTip
? (() => {
let priorityPerGas = GENESIS_BASE_FEE - baseFee;
if (priorityPerGas > t.priorityFeePerGas) {
priorityPerGas = t.priorityFeePerGas;
const max_fee_per_gas = GENESIS_BASE_FEE;
const max_priority_fee_per_gas = t.priorityFeePerGas;
const actual_priority_fee_per_gas = min(
max_fee_per_gas - baseFee,
max_priority_fee_per_gas
);
const total_fee_per_gas = BigInt(baseFee) + BigInt(actual_priority_fee_per_gas);
const effective_gas = receipt!.gasUsed;
const actual_fee = effective_gas * total_fee_per_gas;
const actual_base_fee = effective_gas * baseFee;
const already_paid = fee;

if (already_paid < actual_base_fee) {
return 0n;
}
return BigInt(priorityPerGas) * BigInt(receipt!.gasUsed);

return actual_fee - actual_base_fee;
})()
: 0n;
const fee = extractFee(result?.events)!.amount.toBigInt();
const feeWithoutTip = fee - tipPaid;

expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describeSuite({
});

// Snapshot estimated gas
expect(estimatedGas).toMatchInlineSnapshot(`55823n`);
expect(estimatedGas).toMatchInlineSnapshot(`56099n`);

// this time we call directly from Baltathar the ERC20 contract
const directBlock = await context.createBlock(
Expand Down
Loading
Loading