Lag the block listener 5 blocks

This commit is contained in:
Luke Van Seters 2021-10-11 16:00:58 -07:00
parent b5f625112e
commit d76bb52016

View File

@ -19,6 +19,10 @@ logging.basicConfig(filename="listener.log", level=logging.INFO)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
# lag to make sure the blocks we see are settled
BLOCK_NUMBER_LAG = 5
def run(): def run():
rpc = os.getenv("RPC_URL") rpc = os.getenv("RPC_URL")
if rpc is None: if rpc is None:
@ -39,7 +43,9 @@ def run():
logger.info(f"Latest block: {latest_block_number}") logger.info(f"Latest block: {latest_block_number}")
logger.info(f"Last written block: {last_written_block}") logger.info(f"Last written block: {last_written_block}")
if last_written_block is None or last_written_block < latest_block_number: if (last_written_block is None) or (
last_written_block < (latest_block_number - BLOCK_NUMBER_LAG)
):
block_number = ( block_number = (
latest_block_number latest_block_number
if last_written_block is None if last_written_block is None