diff --git a/proxy/mempool/mempool.py b/proxy/mempool/mempool.py index 0c0f4e967..2afbcbca3 100644 --- a/proxy/mempool/mempool.py +++ b/proxy/mempool/mempool.py @@ -1,4 +1,5 @@ import asyncio +import dataclasses import logging import math import time @@ -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 diff --git a/proxy/mempool/mempool_schedule.py b/proxy/mempool/mempool_schedule.py index b6d2beb6f..73fcd0dea 100644 --- a/proxy/mempool/mempool_schedule.py +++ b/proxy/mempool/mempool_schedule.py @@ -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')