Skip to content

Commit

Permalink
NDEV-2111 mempool: increase gas-price on full mempool
Browse files Browse the repository at this point in the history
  • Loading branch information
afalaleev committed Oct 27, 2023
1 parent 5c5636a commit 13d4acf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions proxy/mempool/mempool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import dataclasses
import logging
import math
import time
Expand Down Expand Up @@ -150,6 +151,9 @@ def get_pending_tx_by_sender_nonce(self, sender_addr: str, tx_nonce: int) -> MPN
return self._completed_tx_dict.get_tx_by_sender_nonce(sender_addr, tx_nonce)

def get_gas_price(self) -> Optional[MPGasPriceResult]:
min_gas_price = self._tx_schedule.min_gas_price
if min_gas_price > self._gas_price.suggested_gas_price:
return dataclasses.replace(self._gas_price, suggested_gas_price=min_gas_price)
return self._gas_price

@staticmethod
Expand Down
10 changes: 10 additions & 0 deletions proxy/mempool/mempool_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@ def __init__(self, capacity: int) -> None:
)
self._suspended_sender_set: Set[str] = set()

@property
def min_gas_price(self) -> int:
if self.tx_cnt < int(self._capacity * 0.9): # if there are more than 90%
return 0

lower_tx = self._tx_dict.peek_lower_tx()
if not lower_tx:
return 0
return int(lower_tx.gas_price * 1.3) # increase gas-price in 30%

def _add_tx_to_sender_pool(self, sender_pool: MPSenderTxPool, tx: MPTxRequest) -> None:
LOG.debug(f'Add tx {tx.sig} to mempool with {self.tx_cnt} txs')

Expand Down

0 comments on commit 13d4acf

Please sign in to comment.