Skip to content
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

Fix Ethereum post-dispatch weight #1807

Merged
merged 3 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
40 changes: 20 additions & 20 deletions Cargo.lock

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

44 changes: 44 additions & 0 deletions tests/tests/test-eth-fee/test-eth-txn-weights.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import "@moonbeam-network/api-augment";

import { expect } from "chai";
import { ethers } from "ethers";

import { alith, ALITH_PRIVATE_KEY } from "../../util/accounts";
import { getCompiled } from "../../util/contracts";
import { customWeb3Request } from "../../util/providers";
import { describeDevMoonbeamAllEthTxTypes, DevTestContext } from "../../util/setup-dev-tests";
import { EXTRINSIC_GAS_LIMIT } from "../../util/constants";

// This tests an issue where pallet Ethereum in Frontier does not properly account for weight after
// transaction application. Specifically, it accounts for weight before a transaction by multiplying
// GasToWeight by gas_price, but does not adjust this afterwards. This leads to accounting for too
// much weight in a block.
describeDevMoonbeamAllEthTxTypes("Ethereum Weight Accounting", (context) => {
it("should account for weight used", async function () {
this.timeout(10000);

let signer = new ethers.Wallet(ALITH_PRIVATE_KEY, context.ethers);

let tx = await signer.signTransaction({
from: alith.address,
to: null,
value: "0x0",
gasLimit: EXTRINSIC_GAS_LIMIT,
gasPrice: 1_000_000_000,
data: null,
nonce: await context.web3.eth.getTransactionCount(alith.address),
});

// TODO: tweak, also derive from gas used * gas_to_weight
const expected_weight = 525_000_000;

const { block } = await context.createBlock(tx);

const apiAt = await context.polkadotApi.at(block.hash);

let blockWeightsUsed = await apiAt.query.system.blockWeight();
let normalWeight = blockWeightsUsed.normal;

expect(normalWeight.toNumber()).to.equal(expected_weight);
});
});