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

Increase block gas limit #2735

Merged
merged 22 commits into from Apr 10, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 8 additions & 9 deletions runtime/moonbase/src/lib.rs
Expand Up @@ -151,9 +151,8 @@ pub mod currency {
}

/// Maximum weight per block
// TODO: multiply MAXIMUM_BLOCK_WEIGHT times 4 when async backing will be definitly enabled
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND, u64::MAX)
.saturating_div(2)
.saturating_mul(2)
.set_proof_size(relay_chain::MAX_POV_SIZE as u64);

pub const MILLISECS_PER_BLOCK: u64 = 6_000;
Expand Down Expand Up @@ -396,15 +395,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 500ms Weight, from which 75% only are used for transactions,
/// the total EVM execution gas limit is: GAS_PER_SECOND * 0.500 * 0.75 ~= 15_000_000.
/// 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.
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 (40KB).
pub const BLOCK_STORAGE_LIMIT: u64 = 40 * 1024;
/// The highest amount of new storage that can be created in a block (160KB).
pub const BLOCK_STORAGE_LIMIT: u64 = 160 * 1024;
parameter_types! {
pub BlockGasLimit: U256
= U256::from(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT.ref_time() / WEIGHT_PER_GAS);
Expand All @@ -424,14 +423,14 @@ 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 4 if we convert ref_time to gas and we compare
/// The amount of gas per pov. A ratio of 16 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
/// )
pub const GasLimitPovSizeRatio: u64 = 4;
pub const GasLimitPovSizeRatio: u64 = 16;
/// The amount of gas per storage (in bytes): BLOCK_GAS_LIMIT / BLOCK_STORAGE_LIMIT
/// (15_000_000 / 40kb)
/// (60_000_000 / 160 kb)
pub GasLimitStorageGrowthRatio: u64 = 366;
}

Expand Down
21 changes: 21 additions & 0 deletions test/helpers/constants.ts
Expand Up @@ -53,3 +53,24 @@ export const RUNTIME_CONSTANTS = {
OLD_TARGET_FILL_PERMILL: 250_000n,
},
} as const;

// Weight correspond to 1 picosecond
export const WEIGHT_PER_SECOND = 1_000_000_000_000n;

// Current gas per second
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;
// Our weight limit is 2s.
export const BLOCK_WEIGHT_LIMIT = WEIGHT_PER_SECOND * 2n;
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%),
// minus the block initialization (10%) and minus the extrinsic base cost.
export const EXTRINSIC_GAS_LIMIT = (BLOCK_GAS_LIMIT * 3n) / 4n - BLOCK_GAS_LIMIT / 10n;
// 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;
2 changes: 1 addition & 1 deletion test/suites/dev/moonbase/test-block/test-block-1.ts
Expand Up @@ -41,7 +41,7 @@ describeSuite({
author: ALITH_ADDRESS.toLocaleLowerCase(),
difficulty: 0n,
extraData: "0x",
gasLimit: 15000000n,
gasLimit: 60000000n,
gasUsed: 0n,
logsBloom: `0x${"0".repeat(512)}`,
miner: ALITH_ADDRESS.toLocaleLowerCase(),
Expand Down
4 changes: 2 additions & 2 deletions test/suites/dev/moonbase/test-block/test-block-gas.ts
Expand Up @@ -5,7 +5,7 @@ import {
expect,
deployCreateCompiledContract,
} from "@moonwall/cli";
import { EXTRINSIC_GAS_LIMIT } from "@moonwall/util";
import { EXTRINSIC_GAS_LIMIT } from "../../../../helpers/constants";

describeSuite({
id: "D010403",
Expand Down Expand Up @@ -55,7 +55,7 @@ describeSuite({
args: [],
functionName: "getGasLimit",
})
).to.equal(15000000n);
).to.equal(60000000n);
},
});
},
Expand Down
4 changes: 2 additions & 2 deletions test/suites/dev/moonbase/test-block/test-block-genesis.ts
Expand Up @@ -20,7 +20,7 @@ describeSuite({
author: "0x0000000000000000000000000000000000000000",
difficulty: 0n,
extraData: "0x",
gasLimit: 15000000n,
gasLimit: 60000000n,
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: 15000000n,
gasLimit: 60000000n,
gasUsed: 0n,
logsBloom: `0x${"0".repeat(512)}`,
number: 0n,
Expand Down
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.04209));
expect(feeResults.gasUsedRatio).to.be.deep.eq(Array(block_count).fill(0.0105225));
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
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(1_500_000_012_598_000_941_192n);
expect(amount).to.equal(6_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_758_310_508_112n);
expect(baseFeePerGas).to.equal(124_752_265_078_107n);

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_868_507_595_257_710_784n);
expect(amount).to.equal(11_867_932_481_410_475_124n);
},
});
},
Expand Down
10 changes: 9 additions & 1 deletion test/suites/dev/moonbase/test-fees/test-fee-multiplier-xcm.ts
Expand Up @@ -14,7 +14,7 @@ import {
// export const TARGET_FILL_AMOUNT =
// ((MAX_BLOCK_WEIGHT * 0.75 * 0.25 - EXTRINSIC_BASE_WEIGHT) / MAX_BLOCK_WEIGHT) * 1_000_000_000;
// In 0.9.43 rootTesting::fillBlock() now uses more weight so we need to account for that
const TARGET_FILL_AMOUNT = 374_427_918;
const TARGET_FILL_AMOUNT = 374_713_000;

// Note on the values from 'transactionPayment.nextFeeMultiplier': this storage item is actually a
// FixedU128, which is basically a u128 with an implicit denominator of 10^18. However, this
Expand Down Expand Up @@ -97,7 +97,15 @@ describeSuite({
.polkadotJs()
.tx.sudo.sudo(context.polkadotJs().tx.rootTesting.fillBlock(TARGET_FILL_AMOUNT))
);

const postValue = await context.polkadotJs().query.transactionPayment.nextFeeMultiplier();

// this is useful to manually find out what is the
// TARGET_FILL_AMOUNT that will result in a static fee multiplier
// console.log(`pre ${initialValue.toHuman()}`);
// console.log(`post ${postValue.toHuman()}`);
// console.log(`diff ${initialValue.sub(postValue)}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it planned to keep this comment?


expect(initialValue.eq(postValue), "Fee multiplier not static on ideal fill ratio").to.be
.true;
},
Expand Down
13 changes: 8 additions & 5 deletions test/suites/dev/moonbase/test-fees/test-length-fees2.ts
@@ -1,6 +1,7 @@
import "@moonbeam-network/api-augment";
import { describeSuite, expect } from "@moonwall/cli";
import { EXTRINSIC_GAS_LIMIT, createViemTransaction } from "@moonwall/util";
import { createViemTransaction } from "@moonwall/util";
import { EXTRINSIC_GAS_LIMIT, GAS_LIMIT_POV_RATIO } from "../../../../helpers/constants";

describeSuite({
id: "D011607",
Expand Down Expand Up @@ -49,17 +50,19 @@ describeSuite({
// * 31_794_757_632 / WEIGHT_PER_GAS = 1_271_790
//
// conclusion: the LengthToFee modifier is NOT involved

const expected = 37708n;
expect(receipt.gasUsed, "gasUsed does not match manual calculation").toBe(expected);
expect(receipt.gasUsed, "gasUsed does not match manual calculation").toBeLessThan(
1_271_790n
);

// furthermore, we can account for the entire fee:
const non_zero_byte_fee = 3n * 16n;
const zero_byte_fee = 3165n * 4n;
const base_ethereum_fee = 21000n;
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;
expect(entire_fee, "entire fee doesn't match manual calculation").to.equal(expected);
// 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));
expect(receipt.gasUsed, "gasUsed does not match manual calculation").toBe(expected);
},
});
},
Expand Down
Expand Up @@ -164,7 +164,7 @@ describeSuite({
args: [],
}),
})
).rejects.toThrowError("gas required exceeds allowance 1500000");
).rejects.toThrowError("gas required exceeds allowance 6000000");
},
});
},
Expand Down
8 changes: 4 additions & 4 deletions test/suites/dev/moonbase/test-pov/test-evm-over-pov.ts
Expand Up @@ -66,7 +66,7 @@ describeSuite({
to: proxyAddress,
data: callData,
txnType: "eip1559",
gasLimit: 3_000_000,
gasLimit: 12_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 ~250k of PoV, so we verify we are within range.
expect(block.proofSize).to.be.at.least(230_000);
expect(block.proofSize).to.be.at.most(300_000);
// 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);
expect(result?.successful).to.equal(true);
expectEVMResult(result!.events, "Error", "OutOfGas");
},
Expand Down
7 changes: 4 additions & 3 deletions test/suites/dev/moonbase/test-pov/test-evm-over-pov2.ts
@@ -1,8 +1,9 @@
import "@moonbeam-network/api-augment";
import { beforeAll, deployCreateCompiledContract, describeSuite, expect } from "@moonwall/cli";
import { MAX_ETH_POV_PER_TX, createEthersTransaction } from "@moonwall/util";
import { createEthersTransaction } from "@moonwall/util";
import { Abi, encodeFunctionData } from "viem";
import { HeavyContract, deployHeavyContracts } from "../../../../helpers";
import { MAX_ETH_POV_PER_TX } from "../../../../helpers/constants";

describeSuite({
id: "D012702",
Expand Down Expand Up @@ -55,7 +56,7 @@ describeSuite({
const rawSigned = await createEthersTransaction(context, {
to: proxyAddress,
data: callData,
gasLimit: 13_000_000,
gasLimit: 52_000_000,
txnType: "eip1559",
});

Expand Down Expand Up @@ -83,7 +84,7 @@ describeSuite({
const rawSigned = await createEthersTransaction(context, {
to: proxyAddress,
data: callData,
gasLimit: 15_000_000,
gasLimit: 60_000_000,
txnType: "eip1559",
});

Expand Down
8 changes: 4 additions & 4 deletions test/suites/dev/moonbase/test-pov/test-precompile-over-pov.ts
Expand Up @@ -69,11 +69,11 @@ describeSuite({

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

// With 1M gas we are allowed to use ~250k of POV, so verify the range.
// With 1M gas we are allowed to use ~62kb 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(230_000);
expect(block.proofSize).to.be.at.most(290_000);
expect(block.proofSize).to.be.at.least(50_000);
expect(block.proofSize).to.be.at.most(100_000);
expect(result?.successful).to.equal(true);
expectEVMResult(result!.events, "Error", "OutOfGas");
},
Expand Down Expand Up @@ -111,7 +111,7 @@ describeSuite({
const rawSigned = await createEthersTransaction(context, {
to: PRECOMPILE_BATCH_ADDRESS,
data: callData,
gasLimit: 6_000_000,
gasLimit: 24_000_000,
txnType: "eip1559",
});

Expand Down
12 changes: 4 additions & 8 deletions test/suites/dev/moonbase/test-pov/test-precompile-over-pov2.ts
Expand Up @@ -6,13 +6,9 @@ import {
expect,
fetchCompiledContract,
} from "@moonwall/cli";
import {
MAX_ETH_POV_PER_TX,
PRECOMPILE_BATCH_ADDRESS,
createEthersTransaction,
} from "@moonwall/util";
import { PRECOMPILE_BATCH_ADDRESS, createEthersTransaction } from "@moonwall/util";
import { Abi, encodeFunctionData } from "viem";
import { HeavyContract, deployHeavyContracts } from "../../../../helpers";
import { HeavyContract, deployHeavyContracts, MAX_ETH_POV_PER_TX } from "../../../../helpers";

describeSuite({
id: "D012705",
Expand Down Expand Up @@ -73,7 +69,7 @@ describeSuite({
const rawSigned = await createEthersTransaction(context, {
to: PRECOMPILE_BATCH_ADDRESS,
data: callData,
gasLimit: 13_000_000,
gasLimit: 52_000_000,
});

const { result, block } = await context.createBlock(rawSigned);
Expand Down Expand Up @@ -109,7 +105,7 @@ describeSuite({
const rawSigned = await createEthersTransaction(context, {
to: PRECOMPILE_BATCH_ADDRESS,
data: callData,
gasLimit: 15_000_000,
gasLimit: 60_000_000,
});

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