Skip to content

feat(lightclient): add CommitClientStatus message to persist client s… #4859

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

Closed

Conversation

0xumutkk
Copy link

Adds a new 'CommitClientStatus' message to explicitly commit the client's status (Active, Expired, or Frozen) into state storage as a hashed commitment using 'store_commit'.

Closes #4842

Copy link

vercel bot commented Jul 19, 2025

Someone is attempting to deploy a commit to the unionbuild Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@benluelo benluelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work! this also needs to be implemented in the solidity ibc stack for feature parity.

@benluelo
Copy link
Contributor

also please verify your commits as per our contributing guide.

@0xumutkk 0xumutkk force-pushed the feat/lightclient-commit-status branch from 55a5626 to 8e70297 Compare July 21, 2025 07:52
) -> RpcResult<Option<u8>> {
let status = self
.query_smart::<_, u8>(
&ibc_union_msg::query::QueryMsg::GetStatus { client_id },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the wrong query; you need to use GetCommittedStatus

aeryz
aeryz previously approved these changes Jul 24, 2025
Copy link
Contributor

@aeryz aeryz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do the rename in the following PR.

client_id: msg.client_id,
}
.key(),
&commit(status_bytes),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

store the bytes directly, as a U256 value

&self,
height: Height,
client_id: ClientId,
) -> RpcResult<Option<u8>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should return Option<Status>

&self,
height: Height,
client_id: ClientId,
) -> RpcResult<Option<u8>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option<Status>

%client_id
)
)]
async fn query_client_status(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename this to query_committed_client_status (in the evm impl as well)

Copy link
Contributor

@benluelo benluelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove your merge commit and rebase off of main

client_id: msg.client_id,
}
.key(),
&commit(U256::from(status as u32).to_le_bytes()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't store the commit, but the u256 value directly

GetStatus { client_id: ClientId },
#[cfg_attr(feature = "cw-orch-interface", returns(Option<H256>))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return status here

@0xumutkk 0xumutkk force-pushed the feat/lightclient-commit-status branch from 5641ae7 to b3cb34c Compare July 31, 2025 08:43
},
)?;
let encoded = U256::from(status as u32);
deps.storage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be written to the commitment store, not the regular storage. it needs to be committed as the un-hashed value. use store_commit.

@@ -2186,6 +2200,13 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result<Binary, ContractErr
)?;
Ok(to_json_binary(&status)?)
}
QueryMsg::GetCommittedStatus { client_id } => {
let val = deps.storage.read::<ClientStatuses>(&client_id)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above, use read_commit here.

Comment on lines 177 to 194
pub enum ClientStatuses {}
impl Store for ClientStatuses {
const PREFIX: Prefix = Prefix::new(b"client_status");

type Key = ClientId;
type Value = U256;
}
id_key!(ClientStatuses);
impl ValueCodec<U256> for ClientStatuses {
fn encode_value(value: &U256) -> Bytes {
value.to_le_bytes().into()
}

fn decode_value(raw: &Bytes) -> StdResult<U256> {
read_fixed_bytes(raw).map(U256::from_le_bytes)
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this store

Comment on lines 116 to 127
impl TryFrom<u8> for Status {
type Error = &'static str;

fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
1 => Ok(Status::Active),
2 => Ok(Status::Expired),
3 => Ok(Status::Frozen),
_ => Err("Invalid status value"),
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use UnknownEnumVariant<u8> here

@@ -111,3 +112,16 @@ impl fmt::Display for Status {
})
}
}

impl TryFrom<u8> for Status {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also add a TryFrom<U256> impl

"{} invalid committed status value: {value}",
ContractErrorKind::from(self)
)]
InvalidClientStatusValue { value: u32 },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why use u32?

let val = deps.storage.read::<ClientStatuses>(&client_id)?;
let raw = val.to_le_bytes()[0];
let status = Status::try_from(raw)
.map_err(|_| ContractError::InvalidClientStatusValue { value: raw as u32 })?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't arbitrarily cast to an integer width. you need to consider all possible values this may take. additionally, since we control this error type, we don't need to cast to a specific integer width - we can just change the field type (as i mentioned in another comment).

@0xumutkk 0xumutkk force-pushed the feat/lightclient-commit-status branch from cff7db0 to dc6a8d9 Compare August 5, 2025 16:23
@0xumutkk 0xumutkk requested a review from benluelo August 6, 2025 09:25
type Error = UnknownEnumVariant;

fn try_from(value: U256) -> Result<Self, Self::Error> {
let byte = value.to_le_bytes()[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this drops the majority of the u256. implement this correctly

Comment on lines +115 to +118
#[derive(Debug, Clone, PartialEq)]
pub struct UnknownEnumVariant {
pub value: u8,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't redefine this, reuse it from unionlabs

@cor cor closed this Aug 6, 2025
@unionlabs unionlabs locked and limited conversation to collaborators Aug 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Client status commitment
4 participants