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

Clean up min multiplier #2070

Merged
merged 4 commits into from
Feb 3, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ parameter_types! {
/// Minimum amount of the multiplier. This value cannot be too low. A test case should ensure
/// that combined with `AdjustmentVariable`, we can recover from the minimum.
/// See `multiplier_can_grow_from_zero` in integration_tests.rs.
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000);
pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 10);
/// Maximum multiplier. We pick a value that is expensive but not impossibly so; it should act
/// as a safety net.
pub MaximumMultiplier: Multiplier = Multiplier::from(100_000u128);
Expand Down
2 changes: 1 addition & 1 deletion runtime/moonbase/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3331,7 +3331,7 @@ mod fee_tests {
// 1 "real" day (at 12-second blocks)
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(0), 7200),
U256::from(1_250_000), // lower bound enforced
U256::from(125_000_000), // lower bound enforced
);
assert_eq!(
sim(1_000_000_000, Perbill::from_percent(25), 7200),
Expand Down
46 changes: 44 additions & 2 deletions tests/tests/test-fees/test-fee-multiplier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ describeDevMoonbeam("Max Fee Multiplier", (context) => {
.toString();

const U128_MAX = new BN("340282366920938463463374607431768211455");
const newMultiplierValue = context.polkadotApi.createType("u128", U128_MAX);

// set transaction-payment's multiplier to something above max in storage. on the next round,
// it should enforce its upper bound and reset it.
await context.polkadotApi.tx.sudo
.sudo(
context.polkadotApi.tx.system.setStorage([
[MULTIPLIER_STORAGE_KEY, bnToHex(newMultiplierValue)],
[MULTIPLIER_STORAGE_KEY, bnToHex(U128_MAX, { isLe: true, bitLength: 128 })],
])
)
.signAndSend(alith);
Expand All @@ -49,6 +48,10 @@ describeDevMoonbeam("Max Fee Multiplier", (context) => {
await context.polkadotApi.query.transactionPayment.nextFeeMultiplier()
).toBigInt();
expect(multiplier).to.equal(100_000_000_000_000_000_000_000n);

const result = await context.ethers.send("eth_gasPrice", []);
const gasPrice = BigInt(result);
expect(gasPrice).to.eq(125_000_000_000_000n);
});

it("should have spendable runtime upgrade", async () => {
Expand Down Expand Up @@ -148,12 +151,51 @@ describeDevMoonbeam("Max Fee Multiplier", (context) => {
});
});

describeDevMoonbeam("Min Fee Multiplier", (context) => {
beforeEach("set to min multiplier", async () => {
const MULTIPLIER_STORAGE_KEY = context.polkadotApi.query.transactionPayment.nextFeeMultiplier
.key(0)
.toString();

// set transaction-payment's multiplier to something above max in storage. on the next round,
// it should enforce its upper bound and reset it.
await context.polkadotApi.tx.sudo
.sudo(
context.polkadotApi.tx.system.setStorage([
[MULTIPLIER_STORAGE_KEY, bnToHex(1n, { isLe: true, bitLength: 128 })],
])
)
.signAndSend(alith);
await context.createBlock();
});

it("should enforce lower bound", async () => {
const MULTIPLIER_STORAGE_KEY = context.polkadotApi.query.transactionPayment.nextFeeMultiplier
.key(0)
.toString();

// we set it to u128_max, but the max should have been enforced in on_finalize()
const multiplier = (
await context.polkadotApi.query.transactionPayment.nextFeeMultiplier()
).toBigInt();
expect(multiplier).to.equal(100_000_000_000_000_000n);

const result = await context.ethers.send("eth_gasPrice", []);
const gasPrice = BigInt(result);
expect(gasPrice).to.eq(125_000_000n);
});
});

describeDevMoonbeam("Max Fee Multiplier - initial value", (context) => {
it("should start with genesis value", async () => {
const initialValue = (
await context.polkadotApi.query.transactionPayment.nextFeeMultiplier()
).toBigInt();
expect(initialValue).to.equal(8_000_000_000_000_000_000n);

const result = await context.ethers.send("eth_gasPrice", []);
const gasPrice = BigInt(result);
expect(gasPrice).to.eq(10_000_000_000n);
});
});

Expand Down