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 <trkporter@ucdavis.edu>
Co-authored-by: Nam Chu Hoai <nambrot@googlemail.com>
pull/1939/head
Sergei Patrikeev 2 years ago committed by GitHub
parent 355168d66c
commit d510a19546
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      rust/agents/scraper/src/chain_scraper/sync.rs

@ -34,7 +34,7 @@ pub(super) struct Syncer {
sync_cursor: RateLimitedSyncBlockRangeCursor<Arc<dyn MailboxIndexer>>,
last_valid_range_start_block: u32,
last_nonce: u32,
last_nonce: Option<u32>,
}
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::<Vec<_>>();
debug!(

Loading…
Cancel
Save