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)) }