Skip to content

Commit

Permalink
BELC3 / BELC4
Browse files Browse the repository at this point in the history
Signed-off-by: Naohiro Yoshida <[email protected]>
  • Loading branch information
Naohiro Yoshida committed Nov 27, 2024
1 parent 78d1349 commit 8ab86da
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
26 changes: 23 additions & 3 deletions light-client/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ impl TryFrom<RawClientState> for ClientState {

let chain_id = ChainId::new(value.chain_id);

if chain_id.version() != raw_latest_height.revision_number {
return Err(Error::UnexpectedLatestHeightRevision(
chain_id.version(),
raw_latest_height.revision_number,
));
}

let latest_height = new_height(
raw_latest_height.revision_number,
raw_latest_height.revision_height,
Expand Down Expand Up @@ -489,6 +496,19 @@ mod test {
err => unreachable!("{:?}", err),
}

cs.latest_height = Some(Height {
revision_number: 1,
revision_height: 0,
});
let err = ClientState::try_from(cs.clone()).unwrap_err();
match err {
Error::UnexpectedLatestHeightRevision(e1, e2) => {
assert_eq!(e1, 0);
assert_eq!(e2, 1);
}
err => unreachable!("{:?}", err),
}

cs.latest_height = Some(Height::default());
let err = ClientState::try_from(cs.clone()).unwrap_err();
match err {
Expand Down Expand Up @@ -609,7 +629,7 @@ mod test {
Time::from_unix_timestamp_nanos(
untrusted_header_timestamp.unix_timestamp_nanos() as u128
)
.unwrap(),
.unwrap(),
Time::from_unix_timestamp_nanos(trusted_state_timestamp.unix_timestamp_nanos() as u128)
.unwrap(),
);
Expand All @@ -631,7 +651,7 @@ mod test {
Time::from_unix_timestamp_nanos(
untrusted_header_timestamp.unix_timestamp_nanos() as u128
)
.unwrap(),
.unwrap(),
Time::from_unix_timestamp_nanos(trusted_state_timestamp.unix_timestamp_nanos() as u128)
.unwrap(),
);
Expand Down Expand Up @@ -660,7 +680,7 @@ mod test {
Time::from_unix_timestamp_nanos(
untrusted_header_timestamp.unix_timestamp_nanos() as u128
)
.unwrap(),
.unwrap(),
Time::from_unix_timestamp_nanos(trusted_state_timestamp.unix_timestamp_nanos() as u128)
.unwrap(),
);
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 @@ -60,6 +60,7 @@ pub enum Error {
UnexpectedTrustedHeight(BlockNumber, BlockNumber),
EmptyHeader,
UnexpectedHeaderRevision(u64, u64),
UnexpectedLatestHeightRevision(u64, u64),
UnexpectedSignature(BlockNumber, signature::Error),
MissingVanityInExtraData(BlockNumber, usize, usize),
MissingSignatureInExtraData(BlockNumber, usize, usize),
Expand Down Expand Up @@ -163,6 +164,9 @@ impl core::fmt::Display for Error {
Error::UnexpectedHeaderRevision(e1, e2) => {
write!(f, "UnexpectedHeaderRevision: {} {}", e1, e2)
}
Error::UnexpectedLatestHeightRevision(e1, e2) => {
write!(f, "UnexpectedLatestHeightRevision: {} {}", e1, e2)
}
Error::UnexpectedSignature(e1, e2) => write!(f, "UnexpectedSignature: {} {}", e1, e2),
Error::MissingVanityInExtraData(e1, e2, e3) => {
write!(f, "MissingVanityInExtraData: {} {} {}", e1, e2, e3)
Expand Down

0 comments on commit 8ab86da

Please sign in to comment.