Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 10 additions & 5 deletions crates/humanode-runtime/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,16 @@ pub mod evm_fees {
/// The amount of fee per gas unit.
/// Comes from the following rationale:
/// - a simple transfer costs 21000 gas
/// - we want the cost of this transfer to be around ~134 HMND
/// - so we must charge about 134 * 10^18 / 21000 fee per a unit of gas
/// The value below is a nice round number that fits the requirements outlined above:
/// the base value of `100_000_000_000_000` prices a single transfer at ~2 HMND.
pub const FEE_PER_GAS: u128 = 67 * 100_000_000_000_000;
/// - we want the cost of this transfer to be around ~90 HMND
/// - so we must charge about 90 * 10^18 / 21000 fee per a unit of gas
/// The value below is a nice round number that fits the requirements outlined above.
///
/// Note: this value is intentionally decoupled from the weight-based fee
/// (see [`crate::constants::fees::WEIGHT_TO_FEE`]): pricing the gas-to-weight mapping of the
/// same transfer through the weight-based fee would give ~135 HMND, but Ethereum transactions
/// pay their fees through the EVM gas accounting and not through the transaction payment,
/// so we set the gas price to target the fee we actually want.
pub const FEE_PER_GAS: u128 = 4_300_000_000_000_000;

/// The max proof size ratio per block.
/// Set to the zero as humanode is solo chain. Otherwise, additional used gas has
Expand Down
18 changes: 12 additions & 6 deletions crates/humanode-runtime/src/tests/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,13 @@ fn simple_balances_transfer_keep_alive() {
})
}

/// A test that validates that a simple EVM balance transfer with a keep alive costs 134 HMND.
/// A test that validates the substrate-side fee estimate of a simple EVM balance transfer.
/// Computes the fee via [`TransactionPayment::query_call_info`].
///
/// This estimate is weight-based and is intentionally decoupled from the actual gas-based
/// charge (~90 HMND, see [`constants::evm_fees::FEE_PER_GAS`]): Ethereum transactions do not pay
/// their fees through the transaction payment, so this value is what substrate-side tooling
/// would display, not what is charged.
#[test]
fn simple_evm_transaction_via_query_call_info() {
// Build the state from the config.
Expand Down Expand Up @@ -258,8 +263,9 @@ fn simple_evm_transaction_via_query_call_info() {
}),
});

// The expected fee that we aim to target: 134 HMND.
let expected_fee = 134 * ONE_BALANCE_UNIT;
// The weight-derived fee estimate: ~135 HMND (21000 gas mapped to weight and priced
// via `WEIGHT_TO_FEE`). This is not what an EVM transaction actually pays.
let expected_fee = 135 * ONE_BALANCE_UNIT;

// The tolerance within which the actual fee is allowed to be around the expected fee.
let epsilon = expected_fee / 10;
Expand All @@ -268,7 +274,7 @@ fn simple_evm_transaction_via_query_call_info() {
})
}

/// A test that validates that a simple EVM balance transfer with a keep alive costs 134 HMND.
/// A test that validates that a simple EVM balance transfer with a keep alive costs 90 HMND.
/// Computes the fee via an estimate EVM runner invocation.
#[test]
fn simple_evm_transaction_via_runner_estimate() {
Expand Down Expand Up @@ -334,8 +340,8 @@ fn simple_evm_transaction_via_runner_estimate() {
}
);

// The expected fee that we aim to target: 134 HMND.
let expected_fee = 134 * ONE_BALANCE_UNIT;
// The expected fee that we aim to target: 90 HMND.
let expected_fee = 90 * ONE_BALANCE_UNIT;

// The tolerance within which the actual fee is allowed to be around the expected fee.
let epsilon = expected_fee / 10;
Expand Down
2 changes: 1 addition & 1 deletion utils/e2e-tests/ts/tests/base/rpc/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe("eth rpc", () => {
describe("fee", () => {
describe("when transferring 1 eHMND", () => {
const transferValue = ethers.parseEther("1");
const expectedFee = ethers.parseEther("134");
const expectedFee = ethers.parseEther("90");
const tolerance = expectedFee / 10n;

it("is within the tolerance around the expected cost", async () => {
Expand Down