Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
format using black formatter for python3.10
Browse files Browse the repository at this point in the history
Signed-off-by: Pranay Valson <[email protected]>
  • Loading branch information
noslav committed Mar 14, 2023
1 parent 4b22b02 commit 0ae939f
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/dbmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ def _process_outputs(self, outputs):
chainId = output[3]
deadline = output[5]
finalizationHash = output[6]
fr = FinalizationRequest(chainId=chainId, blockHeight=blockHeight, deadline=deadline, block_id=block_id)
fr = FinalizationRequest(
chainId=chainId,
blockHeight=blockHeight,
deadline=deadline,
block_id=block_id,
)

if finalizationHash is None:
if not fr.waiting_for_confirm() and not fr.waiting_for_finalize():
Expand All @@ -60,12 +65,12 @@ def __connect(self):
host=self.host,
database=self.database,
user=self.user,
password=self.password
password=self.password,
)

def __main_loop(self):
try:
self.logger.info('Connecting to the database...')
self.logger.info("Connecting to the database...")
if not self.caught_up:
self.logger.info(f"Initial scan block_id={self.last_block_id}")

Expand All @@ -74,7 +79,8 @@ def __main_loop(self):
# we are catching up. So we only need to grab what we need to attempt for finalizing
cur.execute(
r'SELECT * FROM chain_moonbeam_moonbase_alpha."_proof_chain_events" WHERE observer_chain_session_start_block_id > %s AND observer_chain_finalization_tx_hash IS NULL AND origin_chain_block_height > 16805810;',
(self.last_block_id,))
(self.last_block_id,),
)

outputs = cur.fetchall()

Expand All @@ -87,11 +93,14 @@ def __main_loop(self):
while True:
with self.__connect() as conn:
with conn.cursor() as cur:
self.logger.info(f"Incremental scan block_id={self.last_block_id}")
self.logger.info(
f"Incremental scan block_id={self.last_block_id}"
)
# we need everything after last max block number
cur.execute(
r'SELECT * FROM chain_moonbeam_moonbase_alpha."_proof_chain_events" WHERE observer_chain_session_start_block_id > %s AND origin_chain_block_height > 16805810;',
(self.last_block_id,))
(self.last_block_id,),
)
outputs = cur.fetchall()

if self._process_outputs(outputs) == 0:
Expand All @@ -100,7 +109,7 @@ def __main_loop(self):
time.sleep(40)

except (Exception, psycopg2.DatabaseError) as ex:
self.logger.critical(''.join(traceback.format_exception(ex)))
self.logger.critical("".join(traceback.format_exception(ex)))

def run(self):
# we need to avoid recursion in order to avoid stack depth exceeded exception
Expand All @@ -113,7 +122,7 @@ def run(self):
self.__main_loop()
time.sleep(60)
except (Exception, psycopg2.DatabaseError) as ex:
self.logger.warning(''.join(traceback.format_exception(ex)))
self.logger.warning("".join(traceback.format_exception(ex)))
# this should never happen
self.__main_loop()

Expand All @@ -122,14 +131,16 @@ def __fetch_last_block(self):
self.logger.info("Determining initial cursor position...")
with self.__connect() as conn:
with conn.cursor() as cur:
cur.execute(r'SELECT observer_chain_session_start_block_id FROM chain_moonbeam_moonbase_alpha."_proof_chain_events" WHERE observer_chain_finalization_tx_hash IS NULL LIMIT 1')
cur.execute(
r'SELECT observer_chain_session_start_block_id FROM chain_moonbeam_moonbase_alpha."_proof_chain_events" WHERE observer_chain_finalization_tx_hash IS NULL LIMIT 1'
)
block_id = cur.fetchone()
if block_id is not None:
self.last_block_id = block_id[0] - 1
else:
self.last_block_id = 1
except Exception as ex:
self.logger.warning(''.join(traceback.format_exception(ex)))
self.logger.warning("".join(traceback.format_exception(ex)))

def _update_cursor(self, block_id):
for fr in FinalizationRequest.get_requests_to_be_confirmed():
Expand Down

0 comments on commit 0ae939f

Please sign in to comment.