From d510a19546a0dda470cf6c2b0225c849bc38d1ea Mon Sep 17 00:00:00 2001 From: Sergei Patrikeev Date: Wed, 15 Mar 2023 06:51:58 -0700 Subject: [PATCH] fix: index the message with zero nonce. (#1925) ### Description Proposed fix of #1924 ### Backward compatibility _Are these changes backward compatible?_ Yes _Are there any infrastructure implications, e.g. changes that would prohibit deploying older commits using this infra tooling?_ None ### Testing _What kind of testing have these changes undergone?_ Manual --------- Co-authored-by: Trevor Porter Co-authored-by: Nam Chu Hoai --- rust/agents/scraper/src/chain_scraper/sync.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/rust/agents/scraper/src/chain_scraper/sync.rs b/rust/agents/scraper/src/chain_scraper/sync.rs index ab8b98006..245efaa0e 100644 --- a/rust/agents/scraper/src/chain_scraper/sync.rs +++ b/rust/agents/scraper/src/chain_scraper/sync.rs @@ -34,7 +34,7 @@ pub(super) struct Syncer { sync_cursor: RateLimitedSyncBlockRangeCursor>, last_valid_range_start_block: u32, - last_nonce: u32, + last_nonce: Option, } impl Deref for Syncer { @@ -82,7 +82,7 @@ impl Syncer { let chunk_size = scraper.chunk_size; let initial_height = scraper.cursor.height().await as u32; let last_valid_range_start_block = initial_height; - let last_nonce = scraper.last_message_nonce().await?.unwrap_or(0); + let last_nonce = scraper.last_message_nonce().await?; let sync_cursor = RateLimitedSyncBlockRangeCursor::new( scraper.contracts.indexer.clone(), @@ -126,7 +126,7 @@ impl Syncer { let (sorted_messages, deliveries) = self.scrape_range(from, to).await?; let validation = validate_message_continuity( - Some(self.last_nonce), + self.last_nonce, &sorted_messages .iter() .map(|r| &r.message) @@ -137,9 +137,7 @@ impl Syncer { let max_nonce_of_batch = self.record_data(sorted_messages, deliveries).await?; self.cursor.update(from as u64).await; - if let Some(idx) = max_nonce_of_batch { - self.last_nonce = idx; - } + self.last_nonce = max_nonce_of_batch; self.last_valid_range_start_block = from; self.indexed_message_height.set(to as i64); self.indexed_deliveries_height.set(to as i64); @@ -213,7 +211,10 @@ impl Syncer { let sorted_messages = sorted_messages .into_iter() .map(|(message, meta)| HyperlaneMessageWithMeta { message, meta }) - .filter(|m| m.message.nonce > self.last_nonce) + .filter(|m| { + self.last_nonce + .map_or(true, |last_nonce| m.message.nonce > last_nonce) + }) .collect::>(); debug!(