Skip to content

Commit

Permalink
Clear eth txs index by sender when clearing mempool (#2398)
Browse files Browse the repository at this point in the history
* Clear eth txs index by sender when clearing mempool

* Fix feature evm
  • Loading branch information
sieniven authored Sep 4, 2023
1 parent 1fd221e commit edf134e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
1 change: 1 addition & 0 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ void CTxMemPool::_clear()
mapTx.clear();
vTxHashes.clear();
mapNextTx.clear();
ethTxsBySender.clear();
totalTxSize = 0;
cachedInnerUsage = 0;
lastRollingFeeUpdate = GetTime();
Expand Down
64 changes: 32 additions & 32 deletions test/functional/feature_evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ def evm_rollback(self):

def mempool_tx_limit(self):
# Test max limit of TX from a specific sender
for i in range(63):
for i in range(64):
self.nodes[0].evmtx(self.eth_address, i, 21, 21001, self.to_address, 1)

# Test error at the 64th EVM TX
Expand All @@ -1017,7 +1017,7 @@ def mempool_tx_limit(self):
"too-many-eth-txs-by-sender",
self.nodes[0].evmtx,
self.eth_address,
63,
64,
21,
21001,
self.to_address,
Expand All @@ -1030,39 +1030,39 @@ def mempool_tx_limit(self):
block_txs = self.nodes[0].getblock(
self.nodes[0].getblockhash(self.nodes[0].getblockcount())
)["tx"]
assert_equal(len(block_txs), 64)
assert_equal(len(block_txs), 65)

# Check accounting of EVM fees
attributes = self.nodes[0].getgov("ATTRIBUTES")["ATTRIBUTES"]
assert_equal(
attributes["v0/live/economy/evm/block/fee_burnt"], self.burnt_fee * 63
attributes["v0/live/economy/evm/block/fee_burnt"], self.burnt_fee * 64
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_burnt_min"], self.burnt_fee * 63
attributes["v0/live/economy/evm/block/fee_burnt_min"], self.burnt_fee * 64
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_burnt_min_hash"], self.blockHash
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_burnt_max"], self.burnt_fee * 63
attributes["v0/live/economy/evm/block/fee_burnt_max"], self.burnt_fee * 64
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_burnt_max_hash"], self.blockHash
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_priority"], self.priority_fee * 63
attributes["v0/live/economy/evm/block/fee_priority"], self.priority_fee * 64
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_priority_min"],
self.priority_fee * 63,
self.priority_fee * 64,
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_priority_min_hash"],
self.blockHash,
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_priority_max"],
self.priority_fee * 63,
self.priority_fee * 64,
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_priority_max_hash"],
Expand All @@ -1072,22 +1072,22 @@ def mempool_tx_limit(self):
# Check Eth balances after transfer
assert_equal(
int(self.nodes[0].eth_getBalance(self.eth_address)[2:], 16),
136972217000000000000,
135971776000000000000,
)
assert_equal(
int(self.nodes[0].eth_getBalance(self.to_address)[2:], 16),
63000000000000000000,
64000000000000000000,
)

# Try and send another TX to make sure mempool has removed entires
tx = self.nodes[0].evmtx(self.eth_address, 63, 21, 21001, self.to_address, 1)
# Try and send another TX to make sure mempool has removed entries
tx = self.nodes[0].evmtx(self.eth_address, 64, 21, 21001, self.to_address, 1)
self.nodes[0].generate(1)
self.blockHash1 = self.nodes[0].getblockhash(self.nodes[0].getblockcount())

# Check accounting of EVM fees
attributes = self.nodes[0].getgov("ATTRIBUTES")["ATTRIBUTES"]
assert_equal(
attributes["v0/live/economy/evm/block/fee_burnt"], self.burnt_fee * 64
attributes["v0/live/economy/evm/block/fee_burnt"], self.burnt_fee * 65
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_burnt_min"], self.burnt_fee
Expand All @@ -1096,13 +1096,13 @@ def mempool_tx_limit(self):
attributes["v0/live/economy/evm/block/fee_burnt_min_hash"], self.blockHash1
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_burnt_max"], self.burnt_fee * 63
attributes["v0/live/economy/evm/block/fee_burnt_max"], self.burnt_fee * 64
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_burnt_max_hash"], self.blockHash
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_priority"], self.priority_fee * 64
attributes["v0/live/economy/evm/block/fee_priority"], self.priority_fee * 65
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_priority_min"], self.priority_fee
Expand All @@ -1113,7 +1113,7 @@ def mempool_tx_limit(self):
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_priority_max"],
self.priority_fee * 63,
self.priority_fee * 64,
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_priority_max_hash"],
Expand All @@ -1128,11 +1128,11 @@ def mempool_tx_limit(self):

def multiple_eth_rbf(self):
# Test multiple replacement TXs with differing fees
self.nodes[0].evmtx(self.eth_address, 64, 22, 21001, self.to_address, 1)
self.nodes[0].evmtx(self.eth_address, 64, 23, 21001, self.to_address, 1)
tx0 = self.nodes[0].evmtx(self.eth_address, 64, 25, 21001, self.to_address, 1)
self.nodes[0].evmtx(self.eth_address, 64, 21, 21001, self.to_address, 1)
self.nodes[0].evmtx(self.eth_address, 64, 24, 21001, self.to_address, 1)
self.nodes[0].evmtx(self.eth_address, 65, 22, 21001, self.to_address, 1)
self.nodes[0].evmtx(self.eth_address, 65, 23, 21001, self.to_address, 1)
tx0 = self.nodes[0].evmtx(self.eth_address, 65, 25, 21001, self.to_address, 1)
self.nodes[0].evmtx(self.eth_address, 65, 21, 21001, self.to_address, 1)
self.nodes[0].evmtx(self.eth_address, 65, 24, 21001, self.to_address, 1)
self.nodes[0].evmtx(self.to_address, 0, 22, 21001, self.eth_address, 1)
self.nodes[0].evmtx(self.to_address, 0, 23, 21001, self.eth_address, 1)
tx1 = self.nodes[0].evmtx(self.to_address, 0, 25, 21001, self.eth_address, 1)
Expand All @@ -1141,29 +1141,29 @@ def multiple_eth_rbf(self):
self.nodes[0].generate(1)

# Check accounting of EVM fees
txLegacy64 = {
txLegacy65 = {
"nonce": "0x1",
"from": self.eth_address,
"value": "0x1",
"gas": "0x5208", # 21000
"gasPrice": "0x5D21DBA00", # 25_000_000_000,
}
fees64 = self.nodes[0].debug_feeEstimate(txLegacy64)
self.burnt_fee64 = hex_to_decimal(fees64["burnt_fee"])
self.priority_fee64 = hex_to_decimal(fees64["priority_fee"])
fees65 = self.nodes[0].debug_feeEstimate(txLegacy65)
self.burnt_fee65 = hex_to_decimal(fees65["burnt_fee"])
self.priority_fee65 = hex_to_decimal(fees65["priority_fee"])
attributes = self.nodes[0].getgov("ATTRIBUTES")["ATTRIBUTES"]
assert_equal(
attributes["v0/live/economy/evm/block/fee_burnt"],
self.burnt_fee * 64 + 2 * self.burnt_fee64,
self.burnt_fee * 65 + 2 * self.burnt_fee65,
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_priority"],
self.priority_fee * 64 + 2 * self.priority_fee64,
self.priority_fee * 65 + 2 * self.priority_fee65,
)
attributes = self.nodes[0].getgov("ATTRIBUTES")["ATTRIBUTES"]
assert_equal(
attributes["v0/live/economy/evm/block/fee_burnt"],
self.burnt_fee * 64 + 2 * self.burnt_fee64,
self.burnt_fee * 65 + 2 * self.burnt_fee65,
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_burnt_min"], self.burnt_fee
Expand All @@ -1172,14 +1172,14 @@ def multiple_eth_rbf(self):
attributes["v0/live/economy/evm/block/fee_burnt_min_hash"], self.blockHash1
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_burnt_max"], self.burnt_fee * 63
attributes["v0/live/economy/evm/block/fee_burnt_max"], self.burnt_fee * 64
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_burnt_max_hash"], self.blockHash
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_priority"],
self.priority_fee * 64 + 2 * self.priority_fee64,
self.priority_fee * 65 + 2 * self.priority_fee65,
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_priority_min"], self.priority_fee
Expand All @@ -1190,7 +1190,7 @@ def multiple_eth_rbf(self):
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_priority_max"],
self.priority_fee * 63,
self.priority_fee * 64,
)
assert_equal(
attributes["v0/live/economy/evm/block/fee_priority_max_hash"],
Expand Down

0 comments on commit edf134e

Please sign in to comment.