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

[Template] Zeroing GasLimitPovSizeRatio #1210

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,10 @@ impl<F: FindAuthor<u32>> FindAuthor<H160> for FindAuthorTruncated<F> {
}

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<Runtime> = FrontierPrecompiles::<_>::new();
pub WeightPerGas: Weight = Weight::from_parts(weight_per_gas(BLOCK_GAS_LIMIT, NORMAL_DISPATCH_RATIO, WEIGHT_MILLISECS_PER_BLOCK), 0);
}
Expand Down
131 changes: 1 addition & 130 deletions ts-tests/tests/test-gas.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;

Expand Down
Loading