Skip to content

Commit

Permalink
Merge pull request #66 from datachainlab/BELC3
Browse files Browse the repository at this point in the history
BELC3 & BELC4
  • Loading branch information
yoshidan authored Nov 25, 2024
2 parents a458056 + 8399ccd commit bacec6f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 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
4 changes: 4 additions & 0 deletions light-client/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,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 @@ -164,6 +165,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 bacec6f

Please sign in to comment.