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

Test increase gas limits to 30mln [TEST ONLY / DO NOT MERGE] #2819

Closed
wants to merge 2 commits into from
Closed
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
16 changes: 8 additions & 8 deletions runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub mod currency {

/// Maximum weight per block
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND, u64::MAX)
.saturating_mul(2)
.saturating_mul(1)
.set_proof_size(relay_chain::MAX_POV_SIZE as u64);

pub const MILLISECS_PER_BLOCK: u64 = 6_000;
Expand Down Expand Up @@ -398,15 +398,15 @@ impl pallet_evm_chain_id::Config for Runtime {}

/// Current approximation of the gas/s consumption considering
/// EVM execution over compiled WASM (on 4.4Ghz CPU).
/// Given the 2 sec Weight, from which 75% only are used for transactions,
/// the total EVM execution gas limit is: GAS_PER_SECOND * 2 * 0.75 ~= 60_000_000.
/// Given the 1000ms Weight, from which 75% only are used for transactions,
/// the total EVM execution gas limit is: GAS_PER_SECOND * 1 * 0.75 ~= 30_000_000.
pub const GAS_PER_SECOND: u64 = 40_000_000;

/// Approximate ratio of the amount of Weight per Gas.
/// u64 works for approximations because Weight is a very small unit compared to gas.
pub const WEIGHT_PER_GAS: u64 = WEIGHT_REF_TIME_PER_SECOND / GAS_PER_SECOND;
/// The highest amount of new storage that can be created in a block (160KB).
pub const BLOCK_STORAGE_LIMIT: u64 = 160 * 1024;
/// The highest amount of new storage that can be created in a block (80KB).
pub const BLOCK_STORAGE_LIMIT: u64 = 80 * 1024;
parameter_types! {
pub BlockGasLimit: U256
= U256::from(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT.ref_time() / WEIGHT_PER_GAS);
Expand All @@ -426,15 +426,15 @@ parameter_types! {
pub MaximumMultiplier: Multiplier = Multiplier::from(100_000u128);
pub PrecompilesValue: MoonbasePrecompiles<Runtime> = MoonbasePrecompiles::<_>::new();
pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0);
/// The amount of gas per pov. A ratio of 16 if we convert ref_time to gas and we compare
/// The amount of gas per pov. A ratio of 8 if we convert ref_time to gas and we compare
/// it with the pov_size for a block. E.g.
/// ceil(
/// (max_extrinsic.ref_time() / max_extrinsic.proof_size()) / WEIGHT_PER_GAS
/// )
/// We should re-check `xcm_config::Erc20XcmBridgeTransferGasLimit` when changing this value
pub const GasLimitPovSizeRatio: u64 = 16;
pub const GasLimitPovSizeRatio: u64 = 8;
/// The amount of gas per storage (in bytes): BLOCK_GAS_LIMIT / BLOCK_STORAGE_LIMIT
/// (60_000_000 / 160 kb)
/// (30_000_000 / 80 kb)
pub GasLimitStorageGrowthRatio: u64 = 366;
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbase/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ parameter_types! {

// To be able to support almost all erc20 implementations,
// we provide a sufficiently hight gas limit.
pub Erc20XcmBridgeTransferGasLimit: u64 = 800_000;
pub Erc20XcmBridgeTransferGasLimit: u64 = 400_000;
}

impl pallet_erc20_xcm_bridge::Config for Runtime {
Expand Down
6 changes: 3 additions & 3 deletions test/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ export const GAS_PER_SECOND = 40_000_000n;
export const GAS_PER_WEIGHT = WEIGHT_PER_SECOND / GAS_PER_SECOND;

// Maximum Gas to PoV ratio used in the gasometer
export const GAS_PER_POV_BYTES = 16n;
export const GAS_PER_POV_BYTES = 8n;
// Our weight limit is 2s.
export const BLOCK_WEIGHT_LIMIT = WEIGHT_PER_SECOND * 2n;
export const BLOCK_WEIGHT_LIMIT = WEIGHT_PER_SECOND;
export const BLOCK_GAS_LIMIT = BLOCK_WEIGHT_LIMIT / GAS_PER_WEIGHT;

// Maximum extrinsic weight is taken from the max allowed transaction weight per block (75%),
Expand All @@ -73,4 +73,4 @@ export const EXTRINSIC_GAS_LIMIT = (BLOCK_GAS_LIMIT * 3n) / 4n - BLOCK_GAS_LIMIT
// Maximum PoV size in bytes allowed by the gasometer for one ethereum transaction
export const MAX_ETH_POV_PER_TX = EXTRINSIC_GAS_LIMIT / GAS_PER_POV_BYTES;

export const GAS_LIMIT_POV_RATIO = 16;
export const GAS_LIMIT_POV_RATIO = 8;
2 changes: 1 addition & 1 deletion test/suites/dev/moonbase/test-block/test-block-1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describeSuite({
author: ALITH_ADDRESS.toLocaleLowerCase(),
difficulty: 0n,
extraData: "0x",
gasLimit: 60000000n,
gasLimit: 30000000n,
gasUsed: 0n,
logsBloom: `0x${"0".repeat(512)}`,
miner: ALITH_ADDRESS.toLocaleLowerCase(),
Expand Down
2 changes: 1 addition & 1 deletion test/suites/dev/moonbase/test-block/test-block-gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describeSuite({
args: [],
functionName: "getGasLimit",
})
).to.equal(60000000n);
).to.equal(30_000_000n);
},
});
},
Expand Down
4 changes: 2 additions & 2 deletions test/suites/dev/moonbase/test-block/test-block-genesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describeSuite({
author: "0x0000000000000000000000000000000000000000",
difficulty: 0n,
extraData: "0x",
gasLimit: 60000000n,
gasLimit: 30000000n,
gasUsed: 0n,
logsBloom: `0x${"0".repeat(512)}`,
number: 0n,
Expand Down Expand Up @@ -49,7 +49,7 @@ describeSuite({
author: "0x0000000000000000000000000000000000000000",
difficulty: 0n,
extraData: "0x",
gasLimit: 60000000n,
gasLimit: 30000000n,
gasUsed: 0n,
logsBloom: `0x${"0".repeat(512)}`,
number: 0n,
Expand Down
2 changes: 1 addition & 1 deletion test/suites/dev/moonbase/test-contract/test-eip-6780.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describeSuite({

beforeEach(async function () {
const { contractAddress } = await context.deployContract!("Suicide", {
gas: 45_000_000n,
gas: 20_000_000n,
});
contract = contractAddress;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describeSuite({
feeResults.baseFeePerGas.length,
"baseFeePerGas should always the requested block range + 1 (the next derived base fee)"
).toBe(block_count + 1);
expect(feeResults.gasUsedRatio).to.be.deep.eq(Array(block_count).fill(0.0105225));
expect(feeResults.gasUsedRatio).to.be.deep.eq(Array(block_count).fill(0.021045));
expect(
feeResults.reward.length,
"should return two-dimensional reward list for the requested block range"
Expand Down
6 changes: 3 additions & 3 deletions test/suites/dev/moonbase/test-fees/test-fee-multiplier-max.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describeSuite({
// grab the first withdraw event and hope it's the right one...
const withdrawEvent = result?.events.filter(({ event }) => event.method == "Withdraw")[0];
const amount = withdrawEvent.event.data.amount.toBigInt();
expect(amount).to.equal(6_000_000_012_598_000_941_192n);
expect(amount).to.equal(3_000_000_012_598_000_941_192n);
},
});

Expand Down Expand Up @@ -139,7 +139,7 @@ describeSuite({
blockNumber = (await context.polkadotJs().rpc.chain.getHeader()).number.toBigInt();
baseFeePerGas = (await context.viem().getBlock({ blockNumber: blockNumber }))
.baseFeePerGas!;
expect(baseFeePerGas).to.equal(124_827_007_821_127n);
expect(baseFeePerGas).to.equal(124_828_893_170_769n);

const rawSigned = await createEthersTransaction(context, {
to: contractAddress,
Expand Down Expand Up @@ -171,7 +171,7 @@ describeSuite({
expect(withdrawEvents?.length).to.equal(1);
const withdrawEvent = withdrawEvents![0];
const amount = withdrawEvent.event.data.amount.toBigInt();
expect(amount).to.equal(11_875_042_908_039_453_764n);
expect(amount).to.equal(11_875_222_265_121_596_508n);
},
});
},
Expand Down
2 changes: 1 addition & 1 deletion test/suites/dev/moonbase/test-fees/test-length-fees2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describeSuite({
const modexp_min_cost = 200n * 20n; // see MIN_GAS_COST in frontier's modexp precompile
const entire_fee = non_zero_byte_fee + zero_byte_fee + base_ethereum_fee + modexp_min_cost;
// the gas used should be the maximum of the legacy gas and the pov gas
const expected = BigInt(Math.max(Number(entire_fee), 3797 * GAS_LIMIT_POV_RATIO));
const expected = BigInt(Math.max(Number(entire_fee), 1898 * GAS_LIMIT_POV_RATIO));
expect(receipt.gasUsed, "gasUsed does not match manual calculation").toBe(expected);
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describeSuite({
args: [],
}),
})
).rejects.toThrowError("gas required exceeds allowance 6000000");
).rejects.toThrowError("gas required exceeds allowance 3000000");
},
});
},
Expand Down
8 changes: 4 additions & 4 deletions test/suites/dev/moonbase/test-pov/test-evm-over-pov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describeSuite({
to: proxyAddress,
data: callData,
txnType: "eip1559",
gasLimit: 12_000_000,
gasLimit: 6_000_000,
});

const { result, block } = await context.createBlock(rawSigned);
Expand Down Expand Up @@ -96,9 +96,9 @@ describeSuite({
log(`block.proof_size: ${block.proofSize} (successful: ${result?.successful})`);
// The block still contain the failed (out of gas) transaction so the PoV is still included
// in the block.
// 1M Gas allows ~62k of PoV, so we verify we are within range.
expect(block.proofSize).to.be.at.least(50_000);
expect(block.proofSize).to.be.at.most(100_000);
// 1M Gas allows ~125k of PoV, so we verify we are within range.
expect(block.proofSize).to.be.at.least(100_000);
expect(block.proofSize).to.be.at.most(200_000);
expect(result?.successful).to.equal(true);
expectEVMResult(result!.events, "Error", "OutOfGas");
},
Expand Down
2 changes: 1 addition & 1 deletion test/suites/dev/moonbase/test-pov/test-evm-over-pov2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describeSuite({
const rawSigned = await createEthersTransaction(context, {
to: proxyAddress,
data: callData,
gasLimit: 52_000_000,
gasLimit: 26_000_000,
txnType: "eip1559",
});

Expand Down
6 changes: 3 additions & 3 deletions test/suites/dev/moonbase/test-pov/test-precompile-over-pov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ describeSuite({

const { result, block } = await context.createBlock(rawSigned);

// With 1M gas we are allowed to use ~62kb of POV, so verify the range.
// With 1M gas we are allowed to use ~125kb of POV, so verify the range.
// The tx is still included in the block because it contains the failed tx,
// so POV is included in the block as well.
expect(block.proofSize).to.be.at.least(50_000);
expect(block.proofSize).to.be.at.most(100_000);
expect(block.proofSize).to.be.at.least(100_000);
expect(block.proofSize).to.be.at.most(200_000);
expect(result?.successful).to.equal(true);
expectEVMResult(result!.events, "Error", "OutOfGas");
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describeSuite({
const rawSigned = await createEthersTransaction(context, {
to: PRECOMPILE_BATCH_ADDRESS,
data: callData,
gasLimit: 52_000_000,
gasLimit: 26_000_000,
});

const { result, block } = await context.createBlock(rawSigned);
Expand Down
20 changes: 10 additions & 10 deletions test/suites/dev/moonbase/test-pov/test-xcm-to-evm-pov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describeSuite({
id: "T01",
title: "should fail to execute evm tx with insufficient gas to cover PoV",
test: async function () {
const GAS_LIMIT = 2_000_000;
const GAS_LIMIT = 1_000_000;
const xcmTransactions = [
{
V1: {
Expand Down Expand Up @@ -123,7 +123,7 @@ describeSuite({
Transact: {
originKind: "SovereignAccount",
requireWeightAtMost: {
refTime: 50_025_000_000,
refTime: 25_025_000_000,
proofSize: GAS_LIMIT / GAS_LIMIT_POV_RATIO,
},
call: {
Expand All @@ -142,11 +142,11 @@ describeSuite({
// This block is the one that processes the xcm messages
const { result, block } = await context.createBlock();

// With 500k gas we are allowed to use ~150k of POV, so verify the range.
// With 500k gas we are allowed to use ~62k of POV, so verify the range.
// The tx is still included in the block because it contains the failed tx,
// so POV is included in the block as well.
expect(block.proofSize).to.be.at.least(130_000);
expect(block.proofSize).to.be.at.most(190_000);
expect(block.proofSize).to.be.at.least(10_000);
expect(block.proofSize).to.be.at.most(200_000);

// Check the evm tx was not executed because of OutOfGas error
const ethEvents = (await context.polkadotJs().query.system.events()).filter(({ event }) =>
Expand All @@ -163,13 +163,13 @@ describeSuite({
id: "T02",
title: "should execute evm tx with enough gas to cover PoV",
test: async function () {
// Note: we can't use more than 6.4M gas through an XCM message, because it makes the entire
// Note: we can't use more than 3.2M gas through an XCM message, because it makes the entire
// message weight to go over the allowed weight to execute an XCM message. This is called
// "overweight".
//
// If we use more than 6.4M gas, we receive the "WeightLimitReached" error and
// If we use more than 3.2M gas, we receive the "WeightLimitReached" error and
// "OverweightEnqueued" event from the xcmpQueue pallet.
const GAS_LIMIT = 6_400_000;
const GAS_LIMIT = 3_200_000;
const xcmTransactions = [
{
V1: {
Expand All @@ -193,7 +193,7 @@ describeSuite({
},
];

const targetXcmWeight = BigInt(GAS_LIMIT) * 25000n + 25_000_000n + 800000000n;
const targetXcmWeight = BigInt(GAS_LIMIT) * 25000n + 25_000_000n + 800_000_000n;
const targetXcmFee = targetXcmWeight * 50_000n;
const transferCall = context
.polkadotJs()
Expand Down Expand Up @@ -224,7 +224,7 @@ describeSuite({
Transact: {
originKind: "SovereignAccount",
requireWeightAtMost: {
refTime: 160_025_000_000,
refTime: 80_025_000_000,
proofSize: GAS_LIMIT / GAS_LIMIT_POV_RATIO,
},
call: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,9 @@ describeSuite({
const randomAccount = "0x1ced798a66b803d0dbb665680283980a939a6432";
// The tx can create an account, so record 148 bytes of storage growth
// Storage growth ratio is 366
// storage_gas = 148 * 366 = 54168
// pov_gas = 5693 * 16 = 91088
const expectedGas = 91_088n;
// storage_gas = 148 * 366 = 54168 // this is the highest
// pov_gas = 5693 * 8 = 45544
const expectedGas = 54_168n;
const rawTxn = await context.writePrecompile!({
precompileName: "Proxy",
functionName: "addProxy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describeSuite({
testCases: ({ context, it, log }) => {
it({
id: "T01",
title: "should fill a block with 61 tx at most",
title: "should fill a block with 131 tx at most",
test: async function () {
const { abi, bytecode } = fetchCompiledContract("Fibonacci");
const deployData = encodeDeployData({
Expand All @@ -28,7 +28,7 @@ describeSuite({
}

await context.createBlock();
expect((await context.viem().getBlock()).transactions.length).toBe(264);
expect((await context.viem().getBlock()).transactions.length).toBe(131);
},
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describeSuite({
// The tx can create an account, so record 148 bytes of storage growth
// Storage growth ratio is 366
// storage_gas = 148 * 366 = 54168
// pov_gas = 5693 * 16 = 91088
const expectedGas = 91_088n;
// pov_gas = 5693 * 8 = 45544
const expectedGas = 54_168n;

it({
id: "T01",
Expand Down
6 changes: 3 additions & 3 deletions test/suites/dev/moonbase/test-txpool/test-txpool-limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ describeSuite({
testCases: ({ context, it, log }) => {
it({
id: "T01",
title: "should be able to fill a block with 2650 tx",
title: "should be able to fill a block with 1428 tx",
test: async function () {
// TODO: test how many transactions can fit in the block
for (let i = 0; i < 2650; i++) {
for (let i = 0; i < 1428; i++) {
const rawTxn = await createRawTransfer(context, BALTATHAR_ADDRESS, 1n, {
nonce: i,
});
await sendRawTransaction(context, rawTxn);
}

await context.createBlock();
expect((await context.viem().getBlock()).transactions.length).toBe(2650);
expect((await context.viem().getBlock()).transactions.length).toBe(1428);
},
});
},
Expand Down
4 changes: 2 additions & 2 deletions test/suites/dev/moonbase/test-txpool/test-txpool-limits2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describeSuite({
testCases: ({ context, it, log }) => {
it({
id: "T01",
title: "should be able to fill a block with 70 contract creations tx",
title: "should be able to fill a block with 141 contract creations tx",
test: async function () {
const { abi, bytecode } = fetchCompiledContract("MultiplyBy7");
const deployData = encodeDeployData({
Expand All @@ -32,7 +32,7 @@ describeSuite({
}

await context.createBlock();
expect((await context.viem().getBlock()).transactions.length).toBe(284);
expect((await context.viem().getBlock()).transactions.length).toBe(141);
},
});
},
Expand Down
Loading