Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify some light client types and testing #132

Merged
merged 33 commits into from
Feb 2, 2020
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e05cc8f
Differentiate error from verify_commit_(trusting vs full)
liamsi Jan 25, 2020
5b2355f
Fix failing test :-)
liamsi Jan 25, 2020
2886635
Refactoring and simplifications: param struct for TrustedState, Signe…
liamsi Jan 26, 2020
7505e82
Remove obsolete TODO: we don't take a ref anymore
liamsi Jan 26, 2020
368461f
some checked arithmetic for height
liamsi Jan 26, 2020
07e289c
type alias Mock types
liamsi Jan 26, 2020
68e7bb1
Add TrustThresholdFraction and a default for it
liamsi Jan 26, 2020
a471444
remove obsolete clone
liamsi Jan 26, 2020
eecef32
remove unused lifetime (initially introduced to get rid of `clone`s
liamsi Jan 27, 2020
9a18314
improve doc
liamsi Jan 27, 2020
0da2f2c
remove TestSuite struct from JSON tests
liamsi Jan 27, 2020
45d6400
Add tests for TrustThresholdFraction
liamsi Jan 27, 2020
43af079
add test-case for `is_within_trust_period` to increase test-coverage
liamsi Jan 27, 2020
215d702
remove `votes_len` from commit; add a validate method to commit
liamsi Jan 27, 2020
847ee8f
unexport `verify_single` and use `verify_and_update_single` in tests …
liamsi Jan 28, 2020
2b8d5e9
type alias doesn't need to be `pub` here
liamsi Jan 28, 2020
cf24fc0
update doc comment and revert to making State public in tendermint-lite
liamsi Jan 28, 2020
c00205d
Remove len & is_empty() from ValidatSet trait
liamsi Jan 29, 2020
418cd04
add some very simple unit tests for basic types
liamsi Jan 29, 2020
28ecf94
update comments and move mock types into a mock module (only accessib…
liamsi Jan 30, 2020
4831a41
add missing #[cfg(test)] attribute (saves some compile time)
liamsi Jan 30, 2020
31550c3
remove store from inner recursion function
liamsi Jan 30, 2020
8b2b964
remove store from `verify_and_update_bisection` too
liamsi Jan 30, 2020
d3d1d65
rename some public methods of the verifier to be more aligned with th…
liamsi Jan 30, 2020
9f161ec
make trust_level satisfy Copy + Clone and don't pass by reference
liamsi Jan 30, 2020
48a7a37
refactor bisection to return a list of intermediate states (using mem…
liamsi Jan 30, 2020
ed8c06e
use Vec instead of HashMap to memoize / return the interm. sates
liamsi Jan 30, 2020
5f5b416
rename test helpers the assert_single_*
liamsi Jan 30, 2020
712ead7
WIP: quick first test for bisection
liamsi Jan 30, 2020
691acbc
WIP: add debug output to mocks & modify init_trusted_state to take ne…
liamsi Jan 31, 2020
e1e9f3c
WIP: minor refactoring: intro method to ensure uniqueness in the retu…
liamsi Jan 31, 2020
1879aba
Add some comments and clean-up the code to be slightly more consisten…
liamsi Jan 31, 2020
b7282b8
fix accidentally broken test
liamsi Jan 31, 2020
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
30 changes: 13 additions & 17 deletions tendermint/src/lite/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,30 +260,25 @@ where

// inner recursive function which assumes
// trusting_period check is already done.
_verify_and_update_bisection(untrusted_height, trust_threshold, req, store)
let new_trusted =
verify_and_update_bisection_inner(trusted_state, untrusted_height, trust_threshold, req)?;
store.add(new_trusted)
}

// inner recursive function for verify_and_update_bisection.
// see that function's docs.
fn _verify_and_update_bisection<H, C, L, R, S>(
fn verify_and_update_bisection_inner<H, C, L, R>(
trusted_state: &TrustedState<C, H>,
untrusted_height: Height,
trust_threshold: &L,
req: &R,
store: &mut S,
) -> Result<(), Error>
) -> Result<TrustedState<C, H>, Error>
liamsi marked this conversation as resolved.
Show resolved Hide resolved
where
H: Header,
C: Commit,
L: TrustThreshold,
R: Requester<C, H>,
S: Store<C, H>,
{
// this get is redundant the first time.
// TODO: possibly refactor so this func takes and returns
// trusted_state.
let trusted_state = store.get(0)?;
let trusted_sh = trusted_state.last_header();

// fetch the header and vals for the new height
let untrusted_sh = &req.signed_header(untrusted_height)?;
let untrusted_vals = &req.validator_set(untrusted_height)?;
Expand All @@ -300,9 +295,8 @@ where
) {
Ok(_) => {
// Successfully verified!
// Trust the new state and return.
let new_trusted_state = TrustedState::new(untrusted_sh, untrusted_next_vals);
return store.add(new_trusted_state);
// return the new to be trusted state and return.
return Ok(TrustedState::new(untrusted_sh, untrusted_next_vals));
}
Err(e) => {
// If something went wrong, return the error.
Expand All @@ -316,17 +310,19 @@ where
}

// Get the pivot height for bisection.
let trusted_h = trusted_sh.header().height();
let trusted_h = trusted_state.last_header().header().height();
let untrusted_h = untrusted_height;
let pivot_height = trusted_h.checked_add(untrusted_h).expect("height overflow") / 2;

// Recursive call to update to the pivot height.
// When this completes, we will either return an error or
// have updated the store to the pivot height.
_verify_and_update_bisection(pivot_height, trust_threshold, req, store)?;
let trusted_left =
verify_and_update_bisection_inner(trusted_state, pivot_height, trust_threshold, req)?;
// TODO: clarify that we do not store these intermediate states anymore?

// Recursive call to update to the original untrusted_height.
_verify_and_update_bisection(untrusted_height, trust_threshold, req, store)
verify_and_update_bisection_inner(&trusted_left, untrusted_height, trust_threshold, req)
}

#[cfg(test)]
Expand Down