Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add chain metrics for cosmos and sealevel chains #5193

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 @@ -354,21 +354,8 @@ impl CosmosProvider {

Ok(fee / gas_limit)
}
}

impl HyperlaneChain for CosmosProvider {
fn domain(&self) -> &HyperlaneDomain {
&self.domain
}

fn provider(&self) -> Box<dyn HyperlaneProvider> {
Box::new(self.clone())
}
}

#[async_trait]
impl HyperlaneProvider for CosmosProvider {
async fn get_block_by_height(&self, height: u64) -> ChainResult<BlockInfo> {
async fn block_info_by_height(&self, height: u64) -> ChainResult<BlockInfo> {
let response = self
.rpc_client
.call(|provider| Box::pin(async move { provider.get_block(height as u32).await }))
Expand All @@ -392,7 +379,24 @@ impl HyperlaneProvider for CosmosProvider {
timestamp: time.unix_timestamp() as u64,
number: block_height,
};
Ok(block_info)
}
}

impl HyperlaneChain for CosmosProvider {
fn domain(&self) -> &HyperlaneDomain {
&self.domain
}

fn provider(&self) -> Box<dyn HyperlaneProvider> {
Box::new(self.clone())
}
}

#[async_trait]
impl HyperlaneProvider for CosmosProvider {
async fn get_block_by_height(&self, height: u64) -> ChainResult<BlockInfo> {
let block_info = self.block_info_by_height(height).await?;
Ok(block_info)
}

Expand Down Expand Up @@ -459,6 +463,12 @@ impl HyperlaneProvider for CosmosProvider {
}

async fn get_chain_metrics(&self) -> ChainResult<Option<ChainInfo>> {
Ok(None)
let height = self.grpc_provider.latest_block_height().await?;
let latest_block = self.block_info_by_height(height).await?;
let chain_info = ChainInfo {
latest_block,
min_gas_price: None,
};
Ok(Some(chain_info))
}
}
40 changes: 25 additions & 15 deletions rust/main/chains/hyperlane-sealevel/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ impl SealevelProvider {
))?,
})
}

async fn block_info_by_height(&self, slot: u64) -> Result<BlockInfo, ChainCommunicationError> {
let confirmed_block = self.rpc_client.get_block(slot).await?;

let block_hash = decode_h256(&confirmed_block.blockhash)?;

let block_time = confirmed_block
.block_time
.ok_or(HyperlaneProviderError::CouldNotFindBlockByHeight(slot))?;

let block_info = BlockInfo {
hash: block_hash,
timestamp: block_time as u64,
number: slot,
};
Ok(block_info)
}
}

impl HyperlaneChain for SealevelProvider {
Expand All @@ -180,20 +197,7 @@ impl HyperlaneChain for SealevelProvider {
#[async_trait]
impl HyperlaneProvider for SealevelProvider {
async fn get_block_by_height(&self, slot: u64) -> ChainResult<BlockInfo> {
let confirmed_block = self.rpc_client.get_block(slot).await?;

let block_hash = decode_h256(&confirmed_block.blockhash)?;

let block_time = confirmed_block
.block_time
.ok_or(HyperlaneProviderError::CouldNotFindBlockByHeight(slot))?;

let block_info = BlockInfo {
hash: block_hash,
timestamp: block_time as u64,
number: slot,
};

let block_info = self.block_info_by_height(slot).await?;
Ok(block_info)
}

Expand Down Expand Up @@ -260,6 +264,12 @@ impl HyperlaneProvider for SealevelProvider {
}

async fn get_chain_metrics(&self) -> ChainResult<Option<ChainInfo>> {
Ok(None)
let slot = self.rpc_client.get_slot_raw().await?;
let latest_block = self.block_info_by_height(slot).await?;
let chain_info = ChainInfo {
latest_block,
min_gas_price: None,
};
Ok(Some(chain_info))
}
}
14 changes: 10 additions & 4 deletions rust/main/chains/hyperlane-sealevel/src/rpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use solana_client::{
},
rpc_response::{Response, RpcSimulateTransactionResult},
};
use solana_program::clock::Slot;
use solana_sdk::{
account::Account,
commitment_config::CommitmentConfig,
Expand Down Expand Up @@ -189,16 +190,21 @@ impl SealevelRpcClient {

pub async fn get_slot(&self) -> ChainResult<u32> {
let slot = self
.0
.get_slot_with_commitment(CommitmentConfig::finalized())
.await
.map_err(ChainCommunicationError::from_other)?
.get_slot_raw()
.await?
.try_into()
// FIXME solana block height is u64...
.expect("sealevel block slot exceeds u32::MAX");
Ok(slot)
}

pub async fn get_slot_raw(&self) -> ChainResult<Slot> {
self.0
.get_slot_with_commitment(CommitmentConfig::finalized())
.await
.map_err(ChainCommunicationError::from_other)
}

pub async fn get_transaction(
&self,
signature: &Signature,
Expand Down
4 changes: 2 additions & 2 deletions typescript/infra/config/environments/mainnet3/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ const hyperlane: RootAgentConfig = {
validators: {
docker: {
repo,
tag: '53fafa6-20250110-125541',
tag: '11a4e95-20250116-145528',
},
rpcConsensusType: RpcConsensusType.Quorum,
chains: validatorChainConfig(Contexts.Hyperlane),
Expand Down Expand Up @@ -700,7 +700,7 @@ const releaseCandidate: RootAgentConfig = {
validators: {
docker: {
repo,
tag: 'a64af8b-20241024-120818',
tag: '11a4e95-20250116-145528',
},
rpcConsensusType: RpcConsensusType.Quorum,
chains: validatorChainConfig(Contexts.ReleaseCandidate),
Expand Down
Loading