Fix light client synchronization on master (#3301)

* value ranges in consensus cache

* skip values in cache

* read epoch0 + epoch1 data from genesis in babe

* sync authorities + session validators at genesis

* removed some debug printlns

* fixed cache encoding

* Revert "skip values in cache"

This reverts commit ce451c32823aaa4b67d99ca5b58f1bf3984df4db.

* Revert "value ranges in consensus cache"

This reverts commit 9062f9434cddd14a01275ddbfcd904b04282e63b.

* get rid of cache::AUTHORITIES in Babe

* cleaning up

* cleaning up

* update spec version

* lost changes

* fixed tests

* Update node/runtime/src/lib.rs

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* fix once-per-block condition

* fix standalone babe + temp_storage in BuildGenesis

* fix benhes compilation

* fixed comment

* re-added light nodes to integration tests

* finalize_with_ancestors from extra_requests

* post-merge fix

* aaand removed debug code

* (another one)

* fix warn in logs (do not call ForkTree::finalize twice for the same block)

* sync digest.next_authorities with actual next authorities

* more docs

* reverting all commits affecting storage

* also remove keys from babe trait

* fixed warnings

* post-merge fixes

* reverted some redundant changes

* reverted more changes
This commit is contained in:
Svyatoslav Nikolsky
2019-08-16 12:51:49 +03:00
committed by Gavin Wood
parent d1dde7e087
commit 3825a21bac
13 changed files with 367 additions and 115 deletions
@@ -19,7 +19,7 @@ use crate::protocol::sync::{PeerSync, PeerSyncState};
use fork_tree::ForkTree;
use libp2p::PeerId;
use log::warn;
use sr_primitives::traits::{Block as BlockT, NumberFor};
use sr_primitives::traits::{Block as BlockT, NumberFor, Zero};
use std::collections::{HashMap, HashSet, VecDeque};
use std::time::{Duration, Instant};
@@ -38,6 +38,8 @@ pub(crate) type ExtraRequest<B> = (<B as BlockT>::Hash, NumberFor<B>);
#[derive(Debug)]
pub(crate) struct ExtraRequests<B: BlockT> {
tree: ForkTree<B::Hash, NumberFor<B>, ()>,
/// best finalized block number that we have seen since restart
best_seen_finalized_number: NumberFor<B>,
/// requests which have been queued for later processing
pending_requests: VecDeque<ExtraRequest<B>>,
/// requests which are currently underway to some peer
@@ -52,6 +54,7 @@ impl<B: BlockT> ExtraRequests<B> {
pub(crate) fn new() -> Self {
ExtraRequests {
tree: ForkTree::new(),
best_seen_finalized_number: Zero::zero(),
pending_requests: VecDeque::new(),
active_requests: HashMap::new(),
failed_requests: HashMap::new(),
@@ -80,7 +83,7 @@ impl<B: BlockT> ExtraRequests<B> {
match self.tree.import(request.0, request.1, (), &is_descendent_of) {
Ok(true) => {
// this is a new root so we add it to the current `pending_requests`
self.pending_requests.push_back((request.0, request.1))
self.pending_requests.push_back((request.0, request.1));
}
Err(err) => {
warn!(target: "sync", "Failed to insert request {:?} into tree: {:?}", request, err);
@@ -93,7 +96,7 @@ impl<B: BlockT> ExtraRequests<B> {
/// Retry any pending request if a peer disconnected.
pub(crate) fn peer_disconnected(&mut self, who: &PeerId) {
if let Some(request) = self.active_requests.remove(who) {
self.pending_requests.push_front(request)
self.pending_requests.push_front(request);
}
}
@@ -128,7 +131,10 @@ impl<B: BlockT> ExtraRequests<B> {
return Ok(())
}
self.tree.finalize(best_finalized_hash, best_finalized_number, &is_descendent_of)?;
if best_finalized_number > self.best_seen_finalized_number {
self.tree.finalize_with_ancestors(best_finalized_hash, best_finalized_number, &is_descendent_of)?;
self.best_seen_finalized_number = best_finalized_number;
}
let roots = self.tree.roots().collect::<HashSet<_>>();
@@ -176,6 +182,7 @@ impl<B: BlockT> ExtraRequests<B> {
self.active_requests.clear();
self.pending_requests.clear();
self.pending_requests.extend(self.tree.roots().map(|(&h, &n, _)| (h, n)));
self.best_seen_finalized_number = finalized_number;
true
}