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

Implement and test update client methods on relay context #107

Merged
merged 7 commits into from
Nov 7, 2024
Merged
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
8 changes: 4 additions & 4 deletions light-client/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 27 additions & 27 deletions relayer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use cgp::core::component::WithProvider;
use cgp::core::types::impls::UseDelegatedType;
use cgp::prelude::*;
use hermes_chain_components::impls::queries::consensus_state_height::QueryConsensusStateHeightsAndFindHeightBefore;
use hermes_chain_components::impls::queries::consensus_state_heights::QueryLatestConsensusStateHeightAsHeights;
pub use hermes_cosmos_chain_components::components::client::*;
use hermes_cosmos_chain_components::impls::packet::packet_fields::CosmosPacketFieldReader;
use hermes_cosmos_chain_components::impls::types::chain::ProvideCosmosChainTypes;
Expand Down Expand Up @@ -198,6 +200,10 @@ define_components! {
QueryCometClientState,
ConsensusStateQuerierComponent:
QueryCometConsensusState,
ConsensusStateHeightQuerierComponent:
QueryConsensusStateHeightsAndFindHeightBefore,
ConsensusStateHeightsQuerierComponent:
QueryLatestConsensusStateHeightAsHeights,
ContractAddressQuerierComponent:
GetContractAddressFromField,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ use crate::types::client_id::ClientId;
use crate::types::cosmos::consensus_state::CometConsensusState;
use crate::types::cosmos::height::Height;

#[derive(Debug)]
pub struct ConsensusStateNotFound {
pub client_id: ClientId,
pub height: Height,
}

pub struct QueryCometConsensusState;

impl<Chain, Counterparty, Encoding> ConsensusStateQuerier<Chain, Counterparty>
Expand All @@ -34,6 +40,7 @@ where
+ HasBlobType<Blob = Vec<Felt>>
+ HasEncoding<AsFelt, Encoding = Encoding>
+ CanQueryContractAddress<symbol!("ibc_client_contract_address")>
+ CanRaiseError<ConsensusStateNotFound>
+ CanRaiseError<Encoding::Error>,
Counterparty:
HasConsensusStateType<Chain, ConsensusState = CometConsensusState> + HasHeightFields,
Expand All @@ -45,22 +52,21 @@ where
async fn query_consensus_state(
chain: &Chain,
_tag: PhantomData<Counterparty>,
client_id: &Chain::ClientId,
client_id: &ClientId,
consensus_height: &Counterparty::Height,
_query_height: &Chain::Height, // TODO: figure whether we can perform height specific queries on Starknet
) -> Result<Counterparty::ConsensusState, Chain::Error> {
let encoding = chain.encoding();

let contract_address = chain.query_contract_address(PhantomData).await?;

let height = Height {
revision_number: Counterparty::revision_number(consensus_height),
revision_height: Counterparty::revision_height(consensus_height),
};

let calldata = encoding
.encode(&(
client_id.sequence,
Height {
revision_number: Counterparty::revision_number(consensus_height),
revision_height: Counterparty::revision_height(consensus_height),
},
))
.encode(&(client_id.sequence, height.clone()))
.map_err(Chain::raise_error)?;

let output = chain
Expand All @@ -74,6 +80,15 @@ where
.decode(&raw_consensus_state)
.map_err(Chain::raise_error)?;

// FIXME: Temporary workaround, as the current Cairo contract returns
// default value when the entry is not found.
if consensus_state.root.is_empty() {
return Err(Chain::raise_error(ConsensusStateNotFound {
client_id: client_id.clone(),
height,
}));
}

Ok(consensus_state)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ use crate::types::cosmos::update::CometUpdateHeader;

pub struct BuildUpdateCometClientPayload;

/*
Stub implementation of UpdateClient payload builder from Cosmos to Starknet.
We basically build a `CosmosCreateClientPayload`, and then use the state root
of the consensus state to build a dummy update header.

TODO: refactor Cosmos UpdateClient header so that they are more easily
be converted into the Cairo encoding for the Starknet Comet contract.
*/
impl<Chain, Counterparty> UpdateClientPayloadBuilder<Chain, Counterparty>
for BuildUpdateCometClientPayload
where
Expand All @@ -33,6 +41,7 @@ where
async fn build_update_client_payload(
chain: &Chain,
trusted_height: &CosmosHeight,
// Ignore the target height for the dummy implementation
_target_height: &CosmosHeight,
_client_state: Chain::ClientState,
) -> Result<CometUpdateHeader, Chain::Error> {
Expand Down
Loading
Loading