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

Add ChainId to Starknet and Comet client state #173

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

ljoss17
Copy link
Contributor

@ljoss17 ljoss17 commented Jan 8, 2025

Closes: #147

Status

  • Added chain_id field to CometClientState in relayer code
  • Added chain_id field to CometClientState in Cairo code
  • Added chain_id field to StarknetClientState in relayer code
  • Added chain_id field to StarknetClientState in Cairo code

@rnbguy rnbguy force-pushed the luca_joss/add-chain-id-field-to-client-state branch from b8dcf58 to ae71a7b Compare January 10, 2025 14:14
@rnbguy rnbguy force-pushed the luca_joss/add-chain-id-field-to-client-state branch from ae71a7b to 546bd98 Compare January 10, 2025 14:34
@rnbguy rnbguy force-pushed the luca_joss/add-chain-id-field-to-client-state branch from 31af839 to 9904ef4 Compare January 10, 2025 14:45
@@ -190,6 +190,7 @@ pub trait CanUseStarknetLightClientEncoding:
+ CanConvertBothWays<Any, StarknetHeader>
+ CanEncodeAndDecodeMut<ViaProtobuf, Timestamp>
+ CanEncodeAndDecodeMut<ViaProtobuf, CommitmentRoot>
// + CanEncodeAndDecodeMut<ViaProtobuf, ChainId>
Copy link
Member

@rnbguy rnbguy Jan 10, 2025

Choose a reason for hiding this comment

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

Uncommenting this line fails our build.

Specifically, CanEncodeAndDecodeMut<ViaProtobuf, ChainId> doesn't satisfy.

Comment on lines +185 to +213
pub struct EncodeChainId;

impl<Encoding, Strategy> MutEncoder<Encoding, Strategy, ChainId> for EncodeChainId
where
Encoding: CanEncodeMut<Strategy, String>,
{
fn encode_mut(
encoding: &Encoding,
chain_id: &ChainId,
buffer: &mut Encoding::EncodeBuffer,
) -> Result<(), Encoding::Error> {
let chain_id_str = chain_id.as_str().to_string();
encoding.encode_mut(&chain_id_str, buffer)?;
Ok(())
}
}

impl<Encoding, Strategy> MutDecoder<Encoding, Strategy, ChainId> for EncodeChainId
where
Encoding: CanDecodeMut<Strategy, String> + CanRaiseError<&'static str>,
{
fn decode_mut<'a>(
encoding: &Encoding,
buffer: &mut Encoding::DecodeBuffer<'a>,
) -> Result<ChainId, Encoding::Error> {
let chain_id_str = encoding.decode_mut(buffer)?;
ChainId::new(&chain_id_str).map_err(|_| Encoding::raise_error("invalid chain id"))
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this correct to satisfy CanEncodeAndDecodeMut<ViaProtobuf, ChainId>?

Comment on lines +25 to +28
// EncodeField<
// symbol!("chain_id"),
// EncodeLengthDelimitedProtoField<2, UseContext>,
// >,
Copy link
Member

@rnbguy rnbguy Jan 10, 2025

Choose a reason for hiding this comment

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

The commented out parts in this file are done the same way as EncodeStarknetConsensusState and EncodeStarknetHeader. Not sure why this doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Store chain ID in both Starknet and Comet client state
2 participants