edr
edr copied to clipboard
The `MemPool` should check the sum of outstanding gas costs for an account before allowing a new transaction for that account
The MemPool currently only validates that the max cost of a transaction is not larger than the balance of the sender's account. We should ensure that the sum of balances of all queued & pending transactions + sent transaction is lower the the balance of the sender's account.
TBC with geth or other production node
Confirmed with geth that this is a bug in EDR. Reproduction:
- Send
62_999wei to some address that doesn't have balance - Disable automining and set next block base fee to
1 - Send three transactions from that address, with gas limit of
21_000and gas price of1 - Call
hardhat_mineto mine a block
Expected: the third send should be rejected because the two first transactions have a max cost of 42_000, which makes the (tentative) balance be 20_999.
Actual: the transaction is accepted. What's worse, then hardhat_mine throws an error, instead of just mining a block with the first two transactions discarding the third one.
So we have two problems here: the one in the original description, and how hardhat_mine works when the next tx to mine in the mempool is invalid.
Keep in mind though that, if we fix the first problem, then I don't know how to reproduce the second problem. But it's worth checking the mining code to improve that logic anyway.