forked from polkadot-evm/frontier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
eth_maxPriorityFeeperGas
(polkadot-evm#607)
* Add `max_priority_fee_per_gas` rpc method * Remove unused arg * Add ts tests * Simple transfer instead contract create * editorconfig
- Loading branch information
1 parent
b91af2f
commit 110fd8d
Showing
4 changed files
with
146 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { ethers } from "ethers"; | ||
import { expect } from "chai"; | ||
import { step } from "mocha-steps"; | ||
|
||
import { createAndFinalizeBlock, describeWithFrontier, customRequest } from "./util"; | ||
|
||
// We use ethers library in this test as apparently web3js's types are not fully EIP-1559 compliant yet. | ||
describeWithFrontier("Frontier RPC (Max Priority Fee Per Gas)", (context) => { | ||
|
||
const GENESIS_ACCOUNT = "0x6be02d1d3665660d22ff9624b7be0551ee1ac91b"; | ||
const GENESIS_ACCOUNT_PRIVATE_KEY = "0x99B3C12287537E38C90A9219D4CB074A89A16E9CDB20BF85728EBD97C343E342"; | ||
|
||
async function sendTransaction(context, payload: any) { | ||
let signer = new ethers.Wallet(GENESIS_ACCOUNT_PRIVATE_KEY, context.ethersjs); | ||
// Ethers internally matches the locally calculated transaction hash against the one returned as a response. | ||
// Test would fail in case of mismatch. | ||
const tx = await signer.sendTransaction(payload); | ||
return tx; | ||
} | ||
|
||
let nonce = 0; | ||
|
||
function get_percentile(percentile, array) { | ||
array.sort(function (a, b) { return a - b; }); | ||
let index = ((percentile/100) * (array.length))-1; | ||
if (Math.floor(index) == index) { | ||
return array[index]; | ||
} | ||
else { | ||
return Math.ceil((array[Math.floor(index)] + array[Math.ceil(index)])/2); | ||
} | ||
} | ||
|
||
async function createBlocks(block_count, priority_fees) { | ||
for(var b = 0; b < block_count; b++) { | ||
for(var p = 0; p < priority_fees.length; p++) { | ||
await sendTransaction(context, { | ||
from: GENESIS_ACCOUNT, | ||
to: "0x0000000000000000000000000000000000000000", | ||
data: "0x", | ||
value: "0x00", | ||
maxFeePerGas: "0x3B9ACA00", | ||
maxPriorityFeePerGas: context.web3.utils.numberToHex(priority_fees[p]), | ||
accessList: [], | ||
nonce: nonce, | ||
gasLimit: "0x5208", | ||
chainId: 42 | ||
}); | ||
nonce++; | ||
} | ||
await createAndFinalizeBlock(context.web3); | ||
} | ||
} | ||
|
||
step("should default to zero on genesis", async function () { | ||
let result = await customRequest(context.web3, "eth_maxPriorityFeePerGas", []); | ||
expect(result.result).to.be.eq("0x0"); | ||
}); | ||
|
||
step("should default to zero on empty blocks", async function () { | ||
await createAndFinalizeBlock(context.web3); | ||
let result = await customRequest(context.web3, "eth_maxPriorityFeePerGas", []); | ||
expect(result.result).to.be.eq("0x0"); | ||
}); | ||
|
||
// - Create 20 blocks, each with 10 txns. | ||
// - Every txn includes a monotonically increasing tip. | ||
// - The oracle returns the minimum fee in the percentile 60 for the last 20 blocks. | ||
// - In this case, and being the first tip 0, that minimum fee is 5. | ||
step("maxPriorityFeePerGas should suggest the percentile 60 tip", async function () { | ||
this.timeout(100000); | ||
|
||
let block_count = 20; | ||
let txns_per_block = 10; | ||
|
||
let priority_fee = 0; | ||
|
||
for(let i = 0; i < block_count; i++) { | ||
let priority_fees = []; | ||
for(let j = 0; j < txns_per_block; j++) { | ||
priority_fees.push(priority_fee) | ||
priority_fee++; | ||
} | ||
await createBlocks(1, priority_fees); | ||
} | ||
|
||
let result = (await customRequest(context.web3, "eth_maxPriorityFeePerGas", [])).result; | ||
expect(result).to.be.eq("0x5"); | ||
}); | ||
|
||
// If in the last 20 blocks at least one is empty (or only contains zero-tip txns), the | ||
// suggested tip will be zero. | ||
// That's the expected behaviour in this simplified oracle version: there is a decent chance of | ||
// being able to include a zero-tip txn in a low congested network. | ||
step("maxPriorityFeePerGas should suggest zero if there are recent empty blocks", async function () { | ||
this.timeout(100000); | ||
|
||
for(let i = 0; i < 10; i++) { | ||
await createBlocks(1, [0, 1, 2, 3, 4, 5]); | ||
} | ||
await createAndFinalizeBlock(context.web3); | ||
for(let i = 0; i < 9; i++) { | ||
await createBlocks(1, [0, 1, 2, 3, 4, 5]); | ||
} | ||
|
||
let result = (await customRequest(context.web3, "eth_maxPriorityFeePerGas", [])).result; | ||
expect(result).to.be.eq("0x0"); | ||
}); | ||
}); |