From ce25a408a07d8a88a7bd23f43b96f9620733d874 Mon Sep 17 00:00:00 2001 From: dhruvja Date: Sat, 7 Sep 2024 12:04:18 +0530 Subject: [PATCH] use solana height and timestamp for cf-guest host metdata --- .../programs/solana-ibc/src/client_state.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs index 9b10c32a..fe34d240 100644 --- a/solana/solana-ibc/programs/solana-ibc/src/client_state.rs +++ b/solana/solana-ibc/programs/solana-ibc/src/client_state.rs @@ -1,5 +1,6 @@ use anchor_lang::prelude::borsh; use anchor_lang::prelude::borsh::maybestd::io; +use spl_token::solana_program::sysvar::Sysvar; use crate::consensus_state::AnyConsensusState; use crate::ibc; @@ -236,14 +237,20 @@ impl cf_guest::CommonContext type AnyConsensusState = AnyConsensusState; fn host_metadata(&self) -> Result<(ibc::Timestamp, ibc::Height)> { - let timestamp = self.borrow().chain.head()?.timestamp_ns.get(); - let timestamp = - ibc::Timestamp::from_nanoseconds(timestamp).map_err(|err| { - ibc::ClientError::Other { description: err.to_string() } + let clock = anchor_lang::solana_program::sysvar::clock::Clock::get() + .map_err(|e| ibc::ClientError::ClientSpecific { + description: e.to_string(), })?; - let height = u64::from(self.borrow().chain.head()?.block_height); - let height = ibc::Height::new(1, height)?; + let slot = clock.slot; + let timestamp_sec = clock.unix_timestamp as u64; + + let timestamp = + ibc::Timestamp::from_nanoseconds(timestamp_sec * 10u64.pow(9)) + .map_err(|e| ibc::ClientError::ClientSpecific { + description: e.to_string(), + })?; + let height = ibc::Height::new(1, slot)?; Ok((timestamp, height)) }