mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-01 02:11:01 +00:00
Warp sync part II (#9284)
* Gap sync * Gap epoch test * Simplified network requests * Update client/db/src/utils.rs Co-authored-by: cheme <emericchevalier.pro@gmail.com> * Fixed v1 migration and added some comments * Next epoch is always regular * Removed fork tree change * Apply suggestions from code review Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Added a comment and converted assert to error Co-authored-by: cheme <emericchevalier.pro@gmail.com> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -168,7 +168,7 @@ pub struct AuthoritySet<H, N> {
|
||||
/// Track at which blocks the set id changed. This is useful when we need to prove finality for
|
||||
/// a given block since we can figure out what set the block belongs to and when the set
|
||||
/// started/ended.
|
||||
authority_set_changes: AuthoritySetChanges<N>,
|
||||
pub(crate) authority_set_changes: AuthoritySetChanges<N>,
|
||||
}
|
||||
|
||||
impl<H, N> AuthoritySet<H, N>
|
||||
@@ -714,6 +714,17 @@ impl<N: Ord + Clone> AuthoritySetChanges<N> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn insert(&mut self, block_number: N) {
|
||||
let idx = self
|
||||
.0
|
||||
.binary_search_by_key(&block_number, |(_, n)| n.clone())
|
||||
.unwrap_or_else(|b| b);
|
||||
|
||||
let set_id = if idx == 0 { 0 } else { self.0[idx - 1].0 + 1 };
|
||||
assert!(idx == self.0.len() || self.0[idx].0 != set_id);
|
||||
self.0.insert(idx, (set_id, block_number));
|
||||
}
|
||||
|
||||
/// Returns an iterator over all historical authority set changes starting at the given block
|
||||
/// number (excluded). The iterator yields a tuple representing the set id and the block number
|
||||
/// of the last block in that set.
|
||||
@@ -1632,6 +1643,18 @@ mod tests {
|
||||
assert_eq!(authorities.pending_forced_changes.first().unwrap().canon_hash, "D");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn authority_set_changes_insert() {
|
||||
let mut authority_set_changes = AuthoritySetChanges::empty();
|
||||
authority_set_changes.append(0, 41);
|
||||
authority_set_changes.append(1, 81);
|
||||
authority_set_changes.append(4, 121);
|
||||
|
||||
authority_set_changes.insert(101);
|
||||
assert_eq!(authority_set_changes.get_set_id(100), AuthoritySetChangeId::Set(2, 101));
|
||||
assert_eq!(authority_set_changes.get_set_id(101), AuthoritySetChangeId::Set(2, 101));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn authority_set_changes_for_complete_data() {
|
||||
let mut authority_set_changes = AuthoritySetChanges::empty();
|
||||
|
||||
Reference in New Issue
Block a user