Skip to content

Commit

Permalink
Fix wrong uses of internal light client state instead of the supplied…
Browse files Browse the repository at this point in the history
… one
  • Loading branch information
romac committed Jun 5, 2020
1 parent 04f0546 commit 8ce22d9
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions light-client/src/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ impl LightClient {
/// See `verify_to_target`
// #[pre(
// light_store_contains_block_within_trusting_period(
// self.state.light_store.as_ref(),
// state.light_store.as_ref(),
// self.options.trusting_period,
// self.clock.now(),
// )
// )]
#[post(
ret.is_ok() ==> trusted_store_contains_block_at_target_height(
self.state.light_store.as_ref(),
state.light_store.as_ref(),
target_height,
)
)]
Expand All @@ -186,8 +186,7 @@ impl LightClient {

loop {
// Get the latest trusted state
let trusted_state = self
.state
let trusted_state = state
.light_store
.latest(VerifiedStatus::Verified)
.ok_or_else(|| ErrorKind::NoInitialTrustedState)?;
Expand Down Expand Up @@ -260,19 +259,17 @@ impl LightClient {
///
/// ## Postcondition
/// - The provider of block that is returned matches the given peer.
// TODO: Uncomment when provider field is available
// #[post(ret.map(|lb| lb.provider == peer).unwrap_or(false))]
#[post(ret.as_ref().map(|lb| lb.provider == self.peer).unwrap_or(true))]
pub fn get_or_fetch_block(
&self,
current_height: Height,
state: &mut State,
) -> Result<LightBlock, Error> {
let current_block = self
.state
let current_block = state
.light_store
.get(current_height, VerifiedStatus::Verified)
.or_else(|| {
self.state
state
.light_store
.get(current_height, VerifiedStatus::Unverified)
});
Expand Down

0 comments on commit 8ce22d9

Please sign in to comment.