fix: Use block slot instead of block height for Sealevel chains (#4862)

### Description

Use block slot instead of block height for Sealevel chains

### Backward compatibility

Yes

### Testing

Manual run of validator against Solana mainnet

Co-authored-by: Danil Nemirovsky <4614623+ameten@users.noreply.github.com>
pull/4877/head
Danil Nemirovsky 7 days ago committed by GitHub
parent 515980e627
commit 33b6f58418
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 7
      rust/main/chains/hyperlane-sealevel/src/interchain_gas.rs
  2. 38
      rust/main/chains/hyperlane-sealevel/src/mailbox.rs
  3. 5
      rust/main/chains/hyperlane-sealevel/src/merkle_tree_hook.rs
  4. 24
      rust/main/chains/hyperlane-sealevel/src/rpc/client.rs

@ -257,7 +257,10 @@ impl Indexer<InterchainGasPayment> for SealevelInterchainGasPaymasterIndexer {
#[instrument(level = "debug", err, ret, skip(self))]
#[allow(clippy::blocks_in_conditions)] // TODO: `rustc` 1.80.1 clippy issue
async fn get_finalized_block_number(&self) -> ChainResult<u32> {
self.rpc_client.get_block_height().await
// we should not report block height since SequenceAwareIndexer uses block slot in
// `latest_sequence_count_and_tip` and we should not report block slot here
// since block slot cannot be used as watermark
unimplemented!()
}
}
@ -277,7 +280,7 @@ impl SequenceAwareIndexer<InterchainGasPayment> for SealevelInterchainGasPaymast
.payment_count
.try_into()
.map_err(StrOrIntParseError::from)?;
let tip = self.rpc_client.get_block_height().await?;
let tip = self.igp.provider.rpc().get_slot().await?;
Ok((Some(payment_count), tip))
}
}

@ -679,10 +679,6 @@ impl SealevelMailboxIndexer {
&self.mailbox.rpc()
}
async fn get_finalized_block_number(&self) -> ChainResult<u32> {
self.rpc().get_block_height().await
}
async fn get_dispatched_message_with_nonce(
&self,
nonce: u32,
@ -867,17 +863,6 @@ impl SealevelMailboxIndexer {
}
}
#[async_trait]
impl SequenceAwareIndexer<HyperlaneMessage> for SealevelMailboxIndexer {
#[instrument(err, skip(self))]
async fn latest_sequence_count_and_tip(&self) -> ChainResult<(Option<u32>, u32)> {
let tip = Indexer::<HyperlaneMessage>::get_finalized_block_number(self).await?;
// TODO: need to make sure the call and tip are at the same height?
let count = Mailbox::count(&self.mailbox, &ReorgPeriod::None).await?;
Ok((Some(count), tip))
}
}
#[async_trait]
impl Indexer<HyperlaneMessage> for SealevelMailboxIndexer {
async fn fetch_logs_in_range(
@ -898,7 +883,21 @@ impl Indexer<HyperlaneMessage> for SealevelMailboxIndexer {
}
async fn get_finalized_block_number(&self) -> ChainResult<u32> {
self.get_finalized_block_number().await
// we should not report block height since SequenceAwareIndexer uses block slot in
// `latest_sequence_count_and_tip` and we should not report block slot here
// since block slot cannot be used as watermark
unimplemented!()
}
}
#[async_trait]
impl SequenceAwareIndexer<HyperlaneMessage> for SealevelMailboxIndexer {
#[instrument(err, skip(self))]
async fn latest_sequence_count_and_tip(&self) -> ChainResult<(Option<u32>, u32)> {
let tip = self.mailbox.provider.rpc().get_slot().await?;
// TODO: need to make sure the call and tip are at the same height?
let count = Mailbox::count(&self.mailbox, &ReorgPeriod::None).await?;
Ok((Some(count), tip))
}
}
@ -922,7 +921,10 @@ impl Indexer<H256> for SealevelMailboxIndexer {
}
async fn get_finalized_block_number(&self) -> ChainResult<u32> {
self.get_finalized_block_number().await
// we should not report block height since SequenceAwareIndexer uses block slot in
// `latest_sequence_count_and_tip` and we should not report block slot here
// since block slot cannot be used as watermark
unimplemented!()
}
}
@ -931,7 +933,7 @@ impl SequenceAwareIndexer<H256> for SealevelMailboxIndexer {
async fn latest_sequence_count_and_tip(&self) -> ChainResult<(Option<u32>, u32)> {
// TODO: implement when sealevel scraper support is implemented
info!("Message delivery indexing not implemented");
let tip = Indexer::<H256>::get_finalized_block_number(self).await?;
let tip = self.mailbox.provider.rpc().get_slot().await?;
Ok((Some(1), tip))
}
}

@ -93,7 +93,10 @@ impl Indexer<MerkleTreeInsertion> for SealevelMerkleTreeHookIndexer {
}
async fn get_finalized_block_number(&self) -> ChainResult<u32> {
Indexer::<HyperlaneMessage>::get_finalized_block_number(&self.0).await
// we should not report block height since SequenceAwareIndexer uses block slot in
// `latest_sequence_count_and_tip` and we should not report block slot here
// since block slot cannot be used as watermark
unimplemented!()
}
}

@ -125,18 +125,6 @@ impl SealevelRpcClient {
.map_err(Into::into)
}
pub async fn get_block_height(&self) -> ChainResult<u32> {
let height = self
.0
.get_block_height_with_commitment(CommitmentConfig::finalized())
.await
.map_err(ChainCommunicationError::from_other)?
.try_into()
// FIXME solana block height is u64...
.expect("sealevel block height exceeds u32::MAX");
Ok(height)
}
pub async fn get_multiple_accounts_with_finalized_commitment(
&self,
pubkeys: &[Pubkey],
@ -183,6 +171,18 @@ impl SealevelRpcClient {
.map_err(ChainCommunicationError::from_other)
}
pub async fn get_slot(&self) -> ChainResult<u32> {
let slot = self
.0
.get_slot_with_commitment(CommitmentConfig::finalized())
.await
.map_err(ChainCommunicationError::from_other)?
.try_into()
// FIXME solana block height is u64...
.expect("sealevel block slot exceeds u32::MAX");
Ok(slot)
}
pub async fn get_transaction(
&self,
signature: &Signature,

Loading…
Cancel
Save