Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Rodriguez committed May 13, 2024
1 parent f70f3d2 commit 4f328a5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 29 deletions.
18 changes: 12 additions & 6 deletions src/client_state/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use crate::client_state::{rollkit_client_type, ClientState};

impl ClientStateCommon for ClientState {
fn verify_consensus_state(&self, consensus_state: Any) -> Result<(), ClientError> {
self.tendermint_client_state.verify_consensus_state(consensus_state)
self.tendermint_client_state
.verify_consensus_state(consensus_state)
}

fn client_type(&self) -> ClientType {
Expand All @@ -27,7 +28,8 @@ impl ClientStateCommon for ClientState {
}

fn validate_proof_height(&self, proof_height: Height) -> Result<(), ClientError> {
self.tendermint_client_state.validate_proof_height(proof_height)
self.tendermint_client_state
.validate_proof_height(proof_height)
}

fn verify_upgrade_client(
Expand Down Expand Up @@ -113,7 +115,11 @@ pub fn verify_upgrade_client(
// TODO: is it ok if we use the upgrade path from the tendermint client state?
// TODO: is it ok that in the tendermint upgrade path the chain commits to a rollkit client state?
// Check to see if the upgrade path is set
let mut upgrade_path = client_state.tendermint_client_state.inner().upgrade_path.clone();
let mut upgrade_path = client_state
.tendermint_client_state
.inner()
.upgrade_path
.clone();

if upgrade_path.pop().is_none() {
return Err(ClientError::ClientSpecific {
Expand All @@ -128,7 +134,7 @@ pub fn verify_upgrade_client(

// Verify the proof of the upgraded client state
verify_membership(
&client_state,
client_state,
&upgrade_path_prefix,
&proof_upgrade_client,
root,
Expand All @@ -138,7 +144,7 @@ pub fn verify_upgrade_client(

// Verify the proof of the upgraded consensus state
verify_membership(
&client_state,
client_state,
&upgrade_path_prefix,
&proof_upgrade_consensus_state,
root,
Expand Down Expand Up @@ -182,4 +188,4 @@ pub fn verify_non_membership(
client_state
.tendermint_client_state
.verify_non_membership(prefix, proof, root, path)
}
}
24 changes: 15 additions & 9 deletions src/client_state/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ pub struct ClientState {
}

impl ClientState {
pub fn new(tendermint_client_state: TendermintClientState, da_params: Option<DaParams>) -> Self {
pub fn new(
tendermint_client_state: TendermintClientState,
da_params: Option<DaParams>,
) -> Self {
Self {
tendermint_client_state,
da_params: da_params,
da_params,
}
}

Expand All @@ -44,14 +47,17 @@ impl ClientState {
pub fn with_header(self, header: RollkitHeader) -> Result<Self, Error> {
let tendermint_header = header.tendermint_header;

match self.tendermint_client_state.inner().clone().with_header(tendermint_header) {
match self
.tendermint_client_state
.inner()
.clone()
.with_header(tendermint_header)
{
Err(e) => Err(Error::invalid(e.to_string())),
Ok(tendermint_client_state) => {
Ok(Self {
tendermint_client_state: tendermint_client_state.into(),
..self
})
}
Ok(tendermint_client_state) => Ok(Self {
tendermint_client_state: tendermint_client_state.into(),
..self
}),
}
}

Expand Down
26 changes: 18 additions & 8 deletions src/client_state/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ibc_client_tendermint::types::ClientState as TendermintClientStateType;
use ibc_client_tendermint::types::ConsensusState as TendermintConsensusStateType;
use ibc_core::client::context::client_state::{ClientStateCommon, ClientStateExecution};
use ibc_core::client::context::{
Convertible, ClientExecutionContext, ExtClientExecutionContext, ExtClientValidationContext,
ClientExecutionContext, Convertible, ExtClientExecutionContext, ExtClientValidationContext,
};
use ibc_core::client::types::error::ClientError;
use ibc_core::client::types::Height;
Expand Down Expand Up @@ -183,7 +183,8 @@ where
let host_timestamp = ExtClientValidationContext::host_timestamp(ctx)?;
let host_height = ExtClientValidationContext::host_height(ctx)?;

let new_tendermint_consensus_state = TendermintConsensusStateType::from(rollkit_header.tendermint_header.clone());
let new_tendermint_consensus_state =
TendermintConsensusStateType::from(rollkit_header.tendermint_header.clone());
let new_rollkit_client_state = client_state.clone().with_header(rollkit_header)?;

ctx.store_consensus_state(
Expand Down Expand Up @@ -314,10 +315,14 @@ where
TendermintConsensusStateType: Convertible<E::ConsensusStateRef>,
{
let upgraded_rollkit_client_state = ClientState::try_from(upgraded_client_state)?;
let upgraded_tendermint_consensus_state: TendermintConsensusStateType = upgraded_consensus_state.try_into()?;
let upgraded_tendermint_consensus_state: TendermintConsensusStateType =
upgraded_consensus_state.try_into()?;

let tendermint_client_state = client_state.tendermint_client_state.inner();
let upgraded_tendermint_client_state = upgraded_rollkit_client_state.tendermint_client_state.inner().clone();
let upgraded_tendermint_client_state = upgraded_rollkit_client_state
.tendermint_client_state
.inner()
.clone();

let new_tendermint_client_state = TendermintClientStateType::new(
upgraded_tendermint_client_state.chain_id,
Expand Down Expand Up @@ -411,11 +416,15 @@ where
E::ClientStateRef: From<ClientState>,
TendermintConsensusStateType: Convertible<E::ConsensusStateRef>,
{
let subject_tendermint_client_state = subject_client_state.tendermint_client_state.inner().clone();
let subject_tendermint_client_state =
subject_client_state.tendermint_client_state.inner().clone();

let substitute_rollkit_client_state = ClientState::try_from(substitute_client_state)?;
let substitute_tendermint_client_state = substitute_rollkit_client_state.tendermint_client_state.inner().clone();

let substitute_tendermint_client_state = substitute_rollkit_client_state
.tendermint_client_state
.inner()
.clone();

// tendermint client state parameters that are allowed to change
let chain_id = substitute_tendermint_client_state.chain_id;
let trusting_period = substitute_tendermint_client_state.trusting_period;
Expand All @@ -439,7 +448,8 @@ where
let host_timestamp = E::host_timestamp(ctx)?;
let host_height = E::host_height(ctx)?;

let tendermint_consensus_state: TendermintConsensusStateType = substitute_consensus_state.try_into()?;
let tendermint_consensus_state: TendermintConsensusStateType =
substitute_consensus_state.try_into()?;

ctx.store_consensus_state(
ClientConsensusStatePath::new(
Expand Down
12 changes: 6 additions & 6 deletions src/client_state/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,9 @@ where
TendermintConsensusStateType: Convertible<V::ConsensusStateRef>,
ClientError: From<<TendermintConsensusStateType as TryFrom<V::ConsensusStateRef>>::Error>,
{
client_state.tendermint_client_state.check_for_misbehaviour(
ctx,
client_id,
client_message,
)
client_state
.tendermint_client_state
.check_for_misbehaviour(ctx, client_id, client_message)
}

/// Query the status of the client state.
Expand Down Expand Up @@ -173,5 +171,7 @@ where
ClientError: From<<TendermintConsensusStateType as TryFrom<V::ConsensusStateRef>>::Error>,
{
// TODO: discuss if da params are allowed to differ.
subject_client_state.tendermint_client_state.check_substitute(ctx, substitute_client_state)
subject_client_state
.tendermint_client_state
.check_substitute(ctx, substitute_client_state)
}

0 comments on commit 4f328a5

Please sign in to comment.