Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
palango committed Aug 8, 2019
1 parent 0f72671 commit 1c0ad28
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
45 changes: 22 additions & 23 deletions src/monitoring_service/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,31 +178,30 @@ def _check_pending_transactions(self) -> None:
smallest nonce, and continue from there when this one is mined and confirmed. However,
as it is not expected that this list becomes to big this isn't optimized currently.
"""

for tx_hash in self.context.db.get_waiting_transactions():
receipt = self.web3.eth.getTransactionReceipt(tx_hash)
if receipt is not None:
tx_block = receipt.get("blockNumber")
if tx_block is None:
return

confirmation_block = tx_block + self.context.required_confirmations
if self.context.last_known_block < confirmation_block:
return

self.context.db.remove_waiting_transaction(tx_hash)
if receipt["status"] == 1:
log.info(
"Transaction was mined successfully",
transaction_hash=tx_hash,
receipt=receipt,
)
else:
log.error(
"Transaction was not mined successfully",
transaction_hash=tx_hash,
receipt=receipt,
)
if receipt is None:
continue

tx_block = receipt.get("blockNumber")
if tx_block is None:
continue

confirmation_block = tx_block + self.context.required_confirmations
if self.web3.eth.blockNumber < confirmation_block:
continue

self.context.db.remove_waiting_transaction(tx_hash)
if receipt["status"] == 1:
log.info(
"Transaction was mined successfully", transaction_hash=tx_hash, receipt=receipt
)
else:
log.error(
"Transaction was not mined successfully",
transaction_hash=tx_hash,
receipt=receipt,
)

def _purge_old_monitor_requests(self) -> None:
""" Delete all old MRs for which still no channel exists.
Expand Down
1 change: 0 additions & 1 deletion tests/monitoring/monitoring_service/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def test_check_pending_transactions(web3, wait_for_blocks, monitoring_service: M
) as remove_mock:

for should_call in (False, False, False, True):
monitoring_service.context.last_known_block = web3.eth.blockNumber
monitoring_service._check_pending_transactions() # pylint: disable=protected-access # noqa

assert remove_mock.called == should_call
Expand Down

0 comments on commit 1c0ad28

Please sign in to comment.