Skip to content
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
59 changes: 54 additions & 5 deletions light-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ impl<const L1_SYNC_COMMITTEE_SIZE: usize> LightClient
let height = client_state.latest_height;
let timestamp = consensus_state.timestamp;

if client_state.frozen {
return Err(Error::CannotInitializeFrozenClient.into());
}
if client_state.latest_height.revision_height() == 0 {
return Err(Error::UnexpectedLatestHeight(client_state.latest_height).into());
}

Ok(CreateClientResult {
height,
message: UpdateStateProxyMessage {
Expand Down Expand Up @@ -289,6 +296,7 @@ mod test {
use prost::Message;
extern crate std;

#[derive(Default)]
struct MockClientReader {
client_state: Option<ClientState>,
consensus_state: BTreeMap<Height, ConsensusState>,
Expand Down Expand Up @@ -406,11 +414,7 @@ mod test {
let any_cs = Any::try_from(cs.clone()).unwrap();
let result = client
.create_client(
&MockClientReader {
client_state: None,
consensus_state: BTreeMap::new(),
time: None,
},
&MockClientReader::default(),
any_cs.clone(),
Any::try_from(cons_state.clone()).unwrap(),
)
Expand Down Expand Up @@ -438,6 +442,51 @@ mod test {
}
}

#[test]
fn test_create_client_error_frozen() {
let client = OptimismLightClient::<
{ ethereum_consensus::preset::minimal::PRESET.SYNC_COMMITTEE_SIZE },
>;
let (mut cs, cons_state) = get_initial_state();
cs.frozen = true;
let any_cs = Any::try_from(cs.clone()).unwrap();
let err = client
.create_client(
&MockClientReader::default(),
any_cs.clone(),
Any::try_from(cons_state.clone()).unwrap(),
)
.unwrap_err();
assert!(
err.to_string().contains("CannotInitializeFrozenClient"),
"{:?}",
err
);
}

#[test]
fn test_create_client_error_invalid_height() {
let client = OptimismLightClient::<
{ ethereum_consensus::preset::minimal::PRESET.SYNC_COMMITTEE_SIZE },
>;
let (mut cs, cons_state) = get_initial_state();
cs.latest_height = Height::new(0, 0);

let any_cs = Any::try_from(cs.clone()).unwrap();
let err = client
.create_client(
&MockClientReader::default(),
any_cs.clone(),
Any::try_from(cons_state.clone()).unwrap(),
)
.unwrap_err();
assert!(
err.to_string().contains("UnexpectedLatestHeight"),
"{:?}",
err
);
}

#[test]
fn test_update_client() {
let client = OptimismLightClient::<
Expand Down
4 changes: 4 additions & 0 deletions light-client/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ pub enum Error {
NegativeMaxClockDrift,
#[error("UnexpectedRollupConfig: err={0:?}")]
UnexpectedRollupConfig(serde_json::Error),
#[error("CannotInitializeFrozenClient")]
CannotInitializeFrozenClient,
#[error("UnexpectedLatestHeight: height={0}")]
UnexpectedLatestHeight(Height),

// ConsState error
#[error("UnexpectedStorageRoot: proof_height={0} latest_height={1}")]
Expand Down
Loading