Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

imp: enhance client implementation + organize DA agnostic structs under sov-client-types #140

Merged
merged 8 commits into from
Apr 13, 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
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ibc-primitives = { git = "https://github.com/cosmos/ibc-rs.git"
ibc-query = { git = "https://github.com/cosmos/ibc-rs.git", rev = "c579628c67" }
ibc-testkit = { git = "https://github.com/cosmos/ibc-rs.git", rev = "c579628c67" }

basecoin = { git = "https://github.com/informalsystems/basecoin-rs.git", rev = "75fbb86" }
basecoin = { git = "https://github.com/informalsystems/basecoin-rs.git", rev = "c996c41" }
jmt = { git = "https://github.com/penumbra-zone/jmt.git", rev = "1d007e11cb68aa5ca13e9a5af4a12e6439d5f7b6" }

sov-modules-api = { path = "vendor/sovereign-sdk/module-system/sov-modules-api" }
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.AUTH_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --all-targets

clippy-no-default-features:
Expand Down
56 changes: 35 additions & 21 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"
members = [
"proto",
"proto/compiler",
"clients/sov-types",
"clients/sov-celestia/types",
"clients/sov-celestia",
"clients/sov-celestia-cw",
Expand Down
4 changes: 3 additions & 1 deletion clients/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# `sov-celestia-client`
<div align="center">
<h1>Sovereign IBC Light Clients</h1>
</div>
2 changes: 1 addition & 1 deletion clients/sov-celestia-cw/src/context/client_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use ibc_core::host::types::identifiers::ClientId;
use ibc_core::host::types::path::{iteration_key, ClientConsensusStatePath, ClientStatePath};
use ibc_core::primitives::proto::{Any, Protobuf};
use ibc_core::primitives::Timestamp;
use sov_celestia_client::types::codec::AnyCodec;

use super::Context;
use crate::types::ClientType;
use crate::utils::AnyCodec;

impl<'a, C: ClientType<'a>> ClientValidationContext for Context<'a, C> {
type ClientStateRef = C::ClientState;
Expand Down
6 changes: 2 additions & 4 deletions clients/sov-celestia-cw/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ use ibc_core::host::types::path::{
};
use ibc_core::primitives::proto::{Any, Protobuf};
use prost::Message;
use sov_celestia_client::types::codec::AnyCodec;

use crate::types::{
parse_height, ClientType, ContractError, GenesisMetadata, HeightTravel, MigrationPrefix,
};
use crate::types::{ClientType, ContractError, GenesisMetadata, HeightTravel, MigrationPrefix};
use crate::utils::{parse_height, AnyCodec};

type Checksum = Vec<u8>;

Expand Down
3 changes: 0 additions & 3 deletions clients/sov-celestia-cw/src/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use cosmwasm_std::{to_json_binary, Binary};
use ibc_core::client::context::client_state::{
ClientStateCommon, ClientStateExecution, ClientStateValidation,
};
use ibc_core::client::context::prelude::*;
use ibc_core::host::types::path::ClientConsensusStatePath;
use ibc_core::primitives::proto::Any;
Expand Down
1 change: 1 addition & 0 deletions clients/sov-celestia-cw/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod context;
pub mod entrypoints;
pub mod handlers;
pub mod types;
pub mod utils;

#[cfg(test)]
pub mod tests;
46 changes: 32 additions & 14 deletions clients/sov-celestia-cw/src/tests/fixture.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ops::Add;
use std::ops::{Add, Sub};
use std::time::Duration;

use cosmwasm_std::testing::{mock_env, mock_info};
Expand All @@ -8,28 +8,30 @@ use ibc_core::client::types::{Height, Status};
use ibc_core::host::types::identifiers::ChainId;
use ibc_core::primitives::Timestamp;
use sov_celestia_client::types::client_message::test_util::dummy_sov_header;
use sov_celestia_client::types::client_message::{Root, SovTmHeader};
use sov_celestia_client::types::client_message::SovTmHeader;
use sov_celestia_client::types::client_state::test_util::{
dummy_checksum, dummy_sov_consensus_state, mock_celestia_chain_id, ClientStateConfig,
TendermintParamsConfig,
};
use sov_celestia_client::types::client_state::SovTmClientState;
use sov_celestia_client::types::codec::AnyCodec;
use sov_celestia_client::types::consensus_state::SovTmConsensusState;
use sov_celestia_client::types::sovereign::{Root, SovereignParamsConfig};
use tendermint_testgen::{Generator, Validator};

use crate::entrypoints::SovTmContext;
use crate::types::{
CheckForMisbehaviourMsgRaw, ExportMetadataMsg, GenesisMetadata, InstantiateMsg, QueryMsg,
QueryResponse, StatusMsg, VerifyClientMessageRaw,
};
use crate::utils::AnyCodec;

/// Test fixture
#[derive(Clone, Debug)]
pub struct Fixture {
pub chain_id: ChainId,
pub trusted_timestamp: Timestamp,
pub trusted_height: Height,
pub genesis_da_height: Height,
pub trusted_da_height: Height,
pub target_height: Height,
pub validators: Vec<Validator>,
pub migration_mode: bool,
Expand All @@ -43,7 +45,8 @@ impl Default for Fixture {
// timestamp of the `mock_env()`.
trusted_timestamp: Timestamp::from_nanoseconds(1_571_797_419_879_305_533)
.expect("never fails"),
trusted_height: Height::new(0, 5).unwrap(),
genesis_da_height: Height::new(0, 3).unwrap(),
trusted_da_height: Height::new(0, 5).unwrap(),
target_height: Height::new(0, 10).unwrap(),
validators: vec![
Validator::new("1").voting_power(40),
Expand Down Expand Up @@ -82,14 +85,22 @@ impl Fixture {
}

pub fn dummy_instantiate_msg(&self) -> InstantiateMsg {
// Setting the `trusting_period`` to 1 second allows for a quick client
// freeze in the `happy_cw_client_recovery` test
let tendermint_params = TendermintParamsConfig::builder()
// Setting the `trusting_period` to 1 second allows the quick client
// freeze for the `happy_cw_client_recovery` test.
let sovereign_params = SovereignParamsConfig::builder()
.genesis_da_height(self.genesis_da_height)
.trusting_period(Duration::from_secs(1))
.latest_height(
self.trusted_da_height
.sub(self.genesis_da_height.revision_height())
.unwrap(),
)
.build();

let tendermint_params = TendermintParamsConfig::builder().build();

let sov_client_state = ClientStateConfig::builder()
.latest_height(self.trusted_height)
.sovereign_params(sovereign_params)
.tendermint_params(tendermint_params)
.build();

Expand Down Expand Up @@ -126,28 +137,35 @@ impl Fixture {
let tm_header = Header {
signed_header: light_block.signed_header,
validator_set: light_block.validators,
trusted_height: self.trusted_height,
trusted_height: self.trusted_da_height,
trusted_next_validator_set: light_block.next_validators,
};

let sov_header = dummy_sov_header(
tm_header,
self.trusted_height,
header_height,
self.trusted_da_height
.revision_height()
.sub(self.genesis_da_height.revision_height()),
header_height
.revision_height()
.sub(self.genesis_da_height.revision_height()),
Root::from([0; 32]),
);

SovTmHeader::encode_thru_any(sov_header)
}

pub fn dummy_client_message(&self) -> Vec<u8> {
self.dummy_header(self.target_height)
self.dummy_header(
self.target_height
.add(self.genesis_da_height.revision_height()),
)
}

/// Constructs a dummy misbehaviour message that is one block behind the
/// trusted height, but with a future timestamp.
pub fn dummy_misbehaviour_message(&self) -> Vec<u8> {
let prev_height = self.trusted_height.decrement().expect("never fails");
let prev_height = self.trusted_da_height.decrement().expect("never fails");

self.dummy_header(prev_height)
}
Expand Down
3 changes: 1 addition & 2 deletions clients/sov-celestia-cw/src/types/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use alloc::string::String;
use std::error::Error;

use cosmwasm_std::StdError;
Expand All @@ -8,7 +7,7 @@ use ibc_core::commitment_types::error::CommitmentError;
use ibc_core::handler::types::error::ContextError;
use ibc_core::host::types::error::IdentifierError;
use ibc_core::host::types::path::PathError;
use sov_celestia_client::types::error::Error as SovCelestiaClientError;
use sov_celestia_client::types::sovereign::Error as SovCelestiaClientError;

#[derive(From, Display, Debug)]
pub enum ContractError {
Expand Down
Loading
Loading