diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index d905e3d144..104cc68b38 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -317,11 +317,10 @@ impl> FindAuthor for FindAuthorTruncated { } const BLOCK_GAS_LIMIT: u64 = 75_000_000; -const MAX_POV_SIZE: u64 = 5 * 1024 * 1024; parameter_types! { pub BlockGasLimit: U256 = U256::from(BLOCK_GAS_LIMIT); - pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE); + pub const GasLimitPovSizeRatio: u64 = 0; pub PrecompilesValue: FrontierPrecompiles = FrontierPrecompiles::<_>::new(); pub WeightPerGas: Weight = Weight::from_parts(weight_per_gas(BLOCK_GAS_LIMIT, NORMAL_DISPATCH_RATIO, WEIGHT_MILLISECS_PER_BLOCK), 0); } diff --git a/ts-tests/tests/test-gas.ts b/ts-tests/tests/test-gas.ts index ff72ae5d8b..1eea9bdf46 100644 --- a/ts-tests/tests/test-gas.ts +++ b/ts-tests/tests/test-gas.ts @@ -1,20 +1,11 @@ import { expect } from "chai"; -import { ethers } from "ethers"; import { step } from "mocha-steps"; import { AbiItem } from "web3-utils"; import InvalidOpcode from "../build/contracts/InvalidOpcode.json"; import Test from "../build/contracts/Test.json"; import StorageLoop from "../build/contracts/StorageLoop.json"; -import Web3 from "web3"; -import { - GENESIS_ACCOUNT, - GENESIS_ACCOUNT_PRIVATE_KEY, - FIRST_CONTRACT_ADDRESS, - ETH_BLOCK_GAS_LIMIT, - ETH_BLOCK_POV_LIMIT, - TEST_ERC20_BYTECODE, -} from "./config"; +import { GENESIS_ACCOUNT, GENESIS_ACCOUNT_PRIVATE_KEY, FIRST_CONTRACT_ADDRESS, ETH_BLOCK_GAS_LIMIT } from "./config"; import { describeWithFrontier, createAndFinalizeBlock, customRequest } from "./util"; const TEST_ACCOUNT = "0x1111111111111111111111111111111111111111"; @@ -263,126 +254,6 @@ describeWithFrontier("Frontier RPC (Gas limit Weightv2 ref time)", (context) => }); }); -describeWithFrontier("Frontier RPC (Gas limit Weightv2 pov size)", (context) => { - const STORAGE_LOOP_CONTRACT_BYTECODE = StorageLoop.bytecode; - const STORAGE_LOOP_CONTRACT_ABI = StorageLoop.abi as AbiItem[]; - - // First call to contract storageLoop method - const FIRST_CALL = 752_450; - // Rest of calls - const CALL_COST = 735_350; - // Block gas limit - const BLOCK_GAS_LIMIT = ETH_BLOCK_GAS_LIMIT - FIRST_CALL; - // Number of calls per block - const CALLS_PER_BLOCK = Math.floor(BLOCK_GAS_LIMIT / CALL_COST) + 1; - // Available space left after all calls - const REMNANT = Math.floor(ETH_BLOCK_GAS_LIMIT - (CALL_COST * (CALLS_PER_BLOCK - 1) + FIRST_CALL)); - // Big transfer - const CONTRACT_TRANSFER_EFFECTIVE_GAS = 100_520; - // Number of transfers per available space left - const TRANSFERS_PER_BLOCK = Math.floor((REMNANT - CONTRACT_TRANSFER_EFFECTIVE_GAS) / 21_000); - - let contractAddress; - before("create the contract", async function () { - const tx1 = await context.web3.eth.accounts.signTransaction( - { - from: GENESIS_ACCOUNT, - data: STORAGE_LOOP_CONTRACT_BYTECODE, - value: "0x00", - gasPrice: "0x3B9ACA00", - gas: "0x100000", - }, - GENESIS_ACCOUNT_PRIVATE_KEY - ); - await customRequest(context.web3, "eth_sendRawTransaction", [tx1.rawTransaction]); - const tx2 = await context.web3.eth.accounts.signTransaction( - { - from: GENESIS_ACCOUNT, - data: TEST_ERC20_BYTECODE, - gas: "0x1000000", - gasPrice: "0x3B9ACA00", - nonce: 1, - }, - GENESIS_ACCOUNT_PRIVATE_KEY - ); - const { result } = await customRequest(context.web3, "eth_sendRawTransaction", [tx2.rawTransaction]); - await createAndFinalizeBlock(context.web3); - const receipt = await context.web3.eth.getTransactionReceipt(result); - contractAddress = receipt.contractAddress; - }); - - // This test fills a block with regular transfers + a transfer to a contract with big bytecode. - // We consider bytecode "big" when it consumes an effective gas greater than the legacy gas. - step("gas limit bound works with pov size heavy txns", async function () { - this.timeout(10000); - - const contract = new context.web3.eth.Contract(STORAGE_LOOP_CONTRACT_ABI, FIRST_CONTRACT_ADDRESS, { - from: GENESIS_ACCOUNT, - gasPrice: "0x3B9ACA00", - }); - - let nonce = await context.web3.eth.getTransactionCount(GENESIS_ACCOUNT); - let tx = await context.web3.eth.accounts.signTransaction( - { - from: GENESIS_ACCOUNT, - to: contractAddress, - value: "0x1", - gasPrice: "0x3B9ACA00", - gas: "0xF4240", - nonce, - }, - GENESIS_ACCOUNT_PRIVATE_KEY - ); - let contract_transfer_hash = await ( - await customRequest(context.web3, "eth_sendRawTransaction", [tx.rawTransaction]) - ).result; - nonce++; - - for (var i = 0; i < CALLS_PER_BLOCK; i++) { - let data = contract.methods.storageLoop(1000, TEST_ACCOUNT, i); - let tx = await context.web3.eth.accounts.signTransaction( - { - from: GENESIS_ACCOUNT, - to: contract.options.address, - data: data.encodeABI(), - gasPrice: "0x3B9ACA00", - gas: "0x100000", - nonce, - }, - GENESIS_ACCOUNT_PRIVATE_KEY - ); - await customRequest(context.web3, "eth_sendRawTransaction", [tx.rawTransaction]); - nonce++; - } - // because we are using Math.floor for everything, at the end there is room for an additional - // transfer. - for (var i = 0; i < TRANSFERS_PER_BLOCK; i++) { - const tx = await context.web3.eth.accounts.signTransaction( - { - from: GENESIS_ACCOUNT, - to: "0x2111111111111111111111111111111111111111", - value: "0x1", - gasPrice: "0x3B9ACA00", - gas: "0x5208", - nonce, - }, - GENESIS_ACCOUNT_PRIVATE_KEY - ); - let r = await customRequest(context.web3, "eth_sendRawTransaction", [tx.rawTransaction]); - nonce++; - } - - await createAndFinalizeBlock(context.web3); - - let latest = await context.web3.eth.getBlock("latest"); - // Expect all regular transfers to go through + contract transfer. - expect(latest.transactions.length).to.be.eq(CALLS_PER_BLOCK + TRANSFERS_PER_BLOCK); - expect(latest.transactions).contain(contract_transfer_hash); - expect(latest.gasUsed).to.be.lessThanOrEqual(ETH_BLOCK_GAS_LIMIT); - expect(ETH_BLOCK_GAS_LIMIT - latest.gasUsed).to.be.lessThan(21_000); - }); -}); - describeWithFrontier("Frontier RPC (Invalid opcode estimate gas)", (context) => { const INVALID_OPCODE_BYTECODE = InvalidOpcode.bytecode;