-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
light-client: treat
Trusted
status as a special case of Verified
…
…as per the spec (#419) * Refactor LightStore::latest_trusted_or_verified * Look for trusted or verified blocks in bisection loop Only looking for blocks with `Status::Verified` might miss a block that has previously gone through fork detection and marked as `Trusted`. We would then fetch it again from the peer, go through verification again, and then override its status to `Verified`, thus downgrading it from `Trusted` to `Verified`. This commit fixes this by asking the light store for blocks which are either trusted or verified. * Small readability improvement in get_or_fetch_block * Ensure blocks are not downgraded from trusted to verified * Preserve Trusted status when updating a block that was just verified * Fix typo in comment Co-authored-by: Ismail Khoffi <Ismail.Khoffi@gmail.com> * Remove Status::least_verified method * Update changelog * Rename LightStore::get_any to get_non_failed * Fix contracts to take into account the Trusted status * Rename utils module to std_ext with inner modules * Improve doc of `get_or_fetch_block` Co-authored-by: Ismail Khoffi <Ismail.Khoffi@gmail.com>
- Loading branch information
Showing
9 changed files
with
136 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
pub mod cmp { | ||
|
||
/// Stable version of `std::cmp::max_by_key`. | ||
pub fn max_by_key<A, B: Ord>(a: A, b: A, key: impl Fn(&A) -> B) -> A { | ||
if key(&a) >= key(&b) { | ||
a | ||
} else { | ||
b | ||
} | ||
} | ||
} | ||
|
||
pub mod option { | ||
|
||
/// Choose between two optional values. | ||
/// | ||
/// If either value is `None`, the other one will be returned. | ||
/// If both values are `Some`, then the given function will pick one of the two values. | ||
pub fn select<A>(a: Option<A>, b: Option<A>, f: impl FnOnce(A, A) -> A) -> Option<A> { | ||
match (a, b) { | ||
(None, b) => b, | ||
(a, None) => a, | ||
(Some(a), Some(b)) => Some(f(a, b)), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters