Skip to content

Commit

Permalink
Perform more thorough validation of the trusted light block in the li…
Browse files Browse the repository at this point in the history
…ght client builder
  • Loading branch information
romac committed Sep 29, 2020
1 parent 2705247 commit 3f496fd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion light-client/src/builder/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,25 @@ impl LightClientBuilder<NoTrustedState> {
}

fn validate(&self, light_block: &LightBlock) -> Result<(), Error> {
// TODO(ismail, romac): actually verify more predicates of light block?
let header = &light_block.signed_header.header;
let now = self.clock.now();

self.predicates
.is_within_trust_period(header, self.options.trusting_period, now)
.map_err(|e| error::Kind::InvalidLightBlock.context(e))?;

self.predicates
.is_header_from_past(header, self.options.clock_drift, now)
.map_err(|e| error::Kind::InvalidLightBlock.context(e))?;

self.predicates
.validator_sets_match(light_block, &*self.hasher)
.map_err(|e| error::Kind::InvalidLightBlock.context(e))?;

self.predicates
.next_validators_match(light_block, &*self.hasher)
.map_err(|e| error::Kind::InvalidLightBlock.context(e))?;

Ok(())
}
}
Expand Down

0 comments on commit 3f496fd

Please sign in to comment.