Skip to content

Commit

Permalink
Clean up min multiplier (moonbeam-foundation#2070)
Browse files Browse the repository at this point in the history
* Bump moonbase MinimumMultiplier

* Fix endianness; add min multiplier tests

* Add gasPrice expects

* prettier
  • Loading branch information
notlesh authored and imstar15 committed May 16, 2023
1 parent da946d6 commit b363054
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
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

0 comments on commit b363054

Please sign in to comment.