Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,12 @@ impl SequenceAwareIndexer<HyperlaneMessage> for CwMailboxDispatchIndexer {
async fn latest_sequence_count_and_tip(&self) -> ChainResult<(Option<u32>, u32)> {
let tip = Indexer::<HyperlaneMessage>::get_finalized_block_number(&self).await?;

let sequence = self.mailbox.nonce_at_block(tip.into()).await?;
let nonce = self.mailbox.nonce_at_block(tip.into()).await?;
// Convert nonce (next message count) to the last indexed sequence (nonce - 1)
// If nonce is 0, there are no messages sent yet
let sequence = nonce.checked_sub(1);

Ok((Some(sequence), tip))
Ok((sequence, tip))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl MerkleTreeHook for CwMerkleTreeHook {
merkle_tree_hook_address: self.address,
mailbox_domain: self.domain.id(),
root: response.root.parse()?,
index: response.count,
index: response.count.saturating_sub(1),
},
block_height: Some(height),
})
Expand Down Expand Up @@ -355,9 +355,12 @@ impl Indexer<MerkleTreeInsertion> for CwMerkleTreeHookIndexer {
impl SequenceAwareIndexer<MerkleTreeInsertion> for CwMerkleTreeHookIndexer {
async fn latest_sequence_count_and_tip(&self) -> ChainResult<(Option<u32>, u32)> {
let tip = CosmosEventIndexer::get_finalized_block_number(self).await?;
let sequence = self.merkle_tree_hook.count_at_block(tip.into()).await?;
let count = self.merkle_tree_hook.count_at_block(tip.into()).await?;
// Convert count to the last indexed sequence (count - 1)
// If count is 0, there are no indexed sequences yet
let sequence = count.checked_sub(1);

Ok((Some(sequence), tip))
Ok((sequence, tip))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ impl SequenceAwareIndexer<HyperlaneMessage> for CosmosNativeDispatchIndexer {
.mailbox(self.address.encode_hex(), Some(tip as u64))
.await?;
match mailbox.mailbox {
Some(mailbox) => Ok((Some(mailbox.message_sent), tip)),
// Convert count to the last indexed sequence (count - 1)
// If count is 0, there are no messages sent yet
Some(mailbox) => Ok((mailbox.message_sent.checked_sub(1), tip)),
_ => Ok((None, tip)),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ impl SequenceAwareIndexer<MerkleTreeInsertion> for CosmosNativeMerkleTreeHook {
.as_ref()
.and_then(|m| m.merkle_tree.as_ref())
.map(|merkle_tree| merkle_tree.count);
Ok((merkle_tree_count, tip))
// Convert count to the last indexed sequence (count - 1)
// If count is 0, there are no indexed sequences yet
let merkle_tree_sequence = merkle_tree_count.and_then(|count| count.checked_sub(1));
Ok((merkle_tree_sequence, tip))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,11 @@ where
{
async fn latest_sequence_count_and_tip(&self) -> ChainResult<(Option<u32>, u32)> {
let tip = Indexer::<HyperlaneMessage>::get_finalized_block_number(self).await?;
let sequence = self.contract.nonce().block(u64::from(tip)).call().await?;
Ok((Some(sequence), tip))
let nonce = self.contract.nonce().block(u64::from(tip)).call().await?;
// Convert nonce (next message count) to the last indexed sequence (nonce - 1)
// If nonce is 0, there are no messages sent yet
let sequence = nonce.checked_sub(1);
Ok((sequence, tip))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@ where
// `SequenceAwareIndexer` and `Indexer`.
async fn latest_sequence_count_and_tip(&self) -> ChainResult<(Option<u32>, u32)> {
let tip = self.get_finalized_block_number().await?;
let sequence = self.contract.count().block(u64::from(tip)).call().await?;
Ok((Some(sequence), tip))
let count = self.contract.count().block(u64::from(tip)).call().await?;
// Convert count to the last indexed sequence (count - 1)
// If count is 0, there are no messages indexed yet
let sequence = count.checked_sub(1);
Ok((sequence, tip))
}
}

Expand Down