From ace41c79fd9ff0f2ab1c7d2f3aa078a878db2256 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Mon, 11 Mar 2024 01:44:00 -0400 Subject: [PATCH] Tidy the BlockHasEvents cache --- coordinator/src/substrate/cosign.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/coordinator/src/substrate/cosign.rs b/coordinator/src/substrate/cosign.rs index d885e729..aa585f2f 100644 --- a/coordinator/src/substrate/cosign.rs +++ b/coordinator/src/substrate/cosign.rs @@ -43,7 +43,7 @@ create_db!( SubstrateCosignDb { ScanCosignFrom: () -> u64, IntendedCosign: () -> (u64, Option), - BlockHasEvents: (block: u64) -> HasEvents, + BlockHasEventsCache: (block: u64) -> HasEvents, LatestCosignedBlock: () -> u64, } ); @@ -86,7 +86,7 @@ async fn block_has_events( serai: &Serai, block: u64, ) -> Result { - let cached = BlockHasEvents::get(txn, block); + let cached = BlockHasEventsCache::get(txn, block); match cached { None => { let serai = serai.as_of( @@ -108,7 +108,7 @@ async fn block_has_events( let has_events = if has_no_events { HasEvents::No } else { HasEvents::Yes }; - BlockHasEvents::set(txn, block, &has_events); + BlockHasEventsCache::set(txn, block, &has_events); Ok(has_events) } Some(code) => Ok(code), @@ -288,6 +288,8 @@ async fn advance_cosign_protocol_inner( // If this TX is committed, always start future scanning from the next block ScanCosignFrom::set(&mut txn, &(block + 1)); + // Since we're scanning *from* the next block, tidy the cache + BlockHasEventsCache::del(&mut txn, &block); } if let Some((number, hash)) = to_cosign {