Skip to content

Commit

Permalink
Check if ClientStatePath is empty during client creation (#605)
Browse files Browse the repository at this point in the history
* Check if ClientStatePath is empty during client creation

* Rewrite ClientState present check with is_ok
  • Loading branch information
Farhad-Shabani authored Apr 12, 2023
1 parent a723116 commit 907ed69
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Check if `ClientStatePath` is empty during client creation process
([#604](https://github.com/cosmos/ibc-rs/issues/604))
6 changes: 4 additions & 2 deletions crates/ibc/src/core/ics02_client/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ pub enum ClientError {
counter: u64,
validation_error: ValidationError,
},
/// client not found: `{client_id}`
ClientNotFound { client_id: ClientId },
/// client is frozen with description: `{description}`
ClientFrozen { description: String },
/// client state not found: `{client_id}`
ClientStateNotFound { client_id: ClientId },
/// client state already exists: `{client_id}`
ClientStateAlreadyExists { client_id: ClientId },
/// consensus state not found at: `{client_id}` at height `{height}`
ConsensusStateNotFound { client_id: ClientId, height: Height },
/// implementation specific error
Expand Down
6 changes: 5 additions & 1 deletion crates/ibc/src/core/ics02_client/handler/create_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ where

let client_type = client_state.client_type();

let _client_id = ClientId::new(client_type, id_counter).map_err(|e| {
let client_id = ClientId::new(client_type, id_counter).map_err(|e| {
ClientError::ClientIdentifierConstructor {
client_type: client_state.client_type(),
counter: id_counter,
validation_error: e,
}
})?;

if ctx.client_state(&client_id).is_ok() {
return Err(ClientError::ClientStateAlreadyExists { client_id }.into());
};

Ok(())
}

Expand Down
8 changes: 4 additions & 4 deletions crates/ibc/src/mock/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,11 @@ impl ValidationContext for MockContext {
client_record
.client_state
.clone()
.ok_or_else(|| ClientError::ClientNotFound {
.ok_or_else(|| ClientError::ClientStateNotFound {
client_id: client_id.clone(),
})
}
None => Err(ClientError::ClientNotFound {
None => Err(ClientError::ClientStateNotFound {
client_id: client_id.clone(),
}),
}
Expand Down Expand Up @@ -771,7 +771,7 @@ impl ValidationContext for MockContext {
ibc_store
.clients
.get(client_id)
.ok_or_else(|| ClientError::ClientNotFound {
.ok_or_else(|| ClientError::ClientStateNotFound {
client_id: client_id.clone(),
})?;

Expand Down Expand Up @@ -801,7 +801,7 @@ impl ValidationContext for MockContext {
ibc_store
.clients
.get(client_id)
.ok_or_else(|| ClientError::ClientNotFound {
.ok_or_else(|| ClientError::ClientStateNotFound {
client_id: client_id.clone(),
})?;

Expand Down

0 comments on commit 907ed69

Please sign in to comment.