Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions maintainer/maintainer/config/.sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ SUMMA_RELAY_INFURA_KEY=""
# no default
# target relay smart contract address
SUMMA_RELAY_CONTRACT=0x...

# default: 100
DEFAULT_GAS_PRICE_GWEI=100

# default: 600
MAX_GAS_PRICE_GWEI=600
2 changes: 2 additions & 0 deletions maintainer/maintainer/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def set() -> RelayConfig:
BCOIN_WS_URL=f'ws://{BCOIN_HOST}:{BCOIN_PORT}',
PROJECT_ID=os.environ.get('SUMMA_RELAY_INFURA_KEY', ''),
CONTRACT=os.environ.get('SUMMA_RELAY_CONTRACT', ''),
DEFAULT_GAS_PRICE_GWEI=os.environ.get('DEFAULT_GAS_PRICE_GWEI', 100),
MAX_GAS_PRICE_GWEI=os.environ.get('MAX_GAS_PRICE_GWEI', 600),
)

return CONFIG
12 changes: 7 additions & 5 deletions maintainer/maintainer/ethereum/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@

logger = logging.getLogger('root.summa_relay.shared_eth')


GWEI = 1000000000
DEFAULT_GAS = 500_000
DEFAULT_GAS_PRICE = 100 * GWEI
MAX_GAS_PRICE = 600 * GWEI

CONNECTION: ethrpc.BaseRPC
NONCE: Iterator[int] # yields ints, takes no sends
Expand All @@ -32,13 +29,16 @@ def _nonce(i: int) -> Iterator[int]:
async def init() -> None:
'''Set up a connection to the interwebs'''
global CONNECTION
global MAX_GAS_PRICE
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed that configurable variables are generally read from config wherever they are needed and not stored globally in Relay Maintainer, e.g:
URL = config.get()['BCOIN_URL']

Perhaps we could limit the number of global variables by doing the same with MAX_GAS_PRICE?
Just a suggestion.


c = config.get()
network = c['NETWORK']
project_id = c['PROJECT_ID']
uri = c['ETHER_URL']
force_https = project_id != ''

MAX_GAS_PRICE = int(c['MAX_GAS_PRICE_GWEI']) * GWEI

logger.info(f'contract is {c["CONTRACT"]}')

CONNECTION = ethrpc.get_client(
Expand Down Expand Up @@ -213,10 +213,12 @@ def _adjust_gas_price(gas_price: int) -> int:
def _compute_tx_gas_price(tx_nonce, tx_ticks):
'''Compute the proper gas price, adjusting for other pending txes and how
long this tx has been pending, taking the max gas price into account.'''
defaultGasPrice = int(config.get()['DEFAULT_GAS_PRICE_GWEI']) * GWEI
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor remark:
Local variables seem to follow underscore notation, so perhaps "default_gas_price"?


gas_price_factor = max((LATEST_PENDING_NONCE - tx_nonce + 1) * tx_ticks, 0)
adjusted_gas_price = round((1 + gas_price_factor * 0.5) * DEFAULT_GAS_PRICE)
adjusted_gas_price = round((1 + gas_price_factor * 0.5) * defaultGasPrice)

return max(min(adjusted_gas_price, MAX_GAS_PRICE), DEFAULT_GAS_PRICE)
return max(min(adjusted_gas_price, MAX_GAS_PRICE), defaultGasPrice)

async def _track_tx_result(tx: UnsignedEthTx, tx_id: str, ticks: int = 0) -> None:
'''Keep track of the result of a transaction by polling every 25 seconds'''
Expand Down