Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Gap sync
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar committed Aug 2, 2021
1 parent f00ec46 commit 4157e96
Show file tree
Hide file tree
Showing 28 changed files with 656 additions and 125 deletions.
2 changes: 2 additions & 0 deletions bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
let warp_sync = Arc::new(sc_finality_grandpa::warp_proof::NetworkProvider::new(
backend.clone(),
grandpa_link.shared_authority_set().clone(),
Vec::default(),
));

let (network, system_rpc_tx, network_starter) =
Expand Down Expand Up @@ -388,6 +389,7 @@ pub fn new_light(mut config: Configuration) -> Result<TaskManager, ServiceError>
let warp_sync = Arc::new(sc_finality_grandpa::warp_proof::NetworkProvider::new(
backend.clone(),
grandpa_link.shared_authority_set().clone(),
Vec::default(),
));

let (network, system_rpc_tx, network_starter) =
Expand Down
2 changes: 2 additions & 0 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ pub fn new_full_base(
let warp_sync = Arc::new(grandpa::warp_proof::NetworkProvider::new(
backend.clone(),
import_setup.1.shared_authority_set().clone(),
Vec::default(),
));

let (network, system_rpc_tx, network_starter) =
Expand Down Expand Up @@ -510,6 +511,7 @@ pub fn new_light_base(
let warp_sync = Arc::new(grandpa::warp_proof::NetworkProvider::new(
backend.clone(),
grandpa_link.shared_authority_set().clone(),
Vec::default(),
));

let (network, system_rpc_tx, network_starter) =
Expand Down
1 change: 1 addition & 0 deletions client/api/src/in_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ impl<Block: BlockT> HeaderBackend<Block> for Blockchain<Block> {
None
},
number_leaves: storage.leaves.count(),
block_gap: None,
}
}

Expand Down
1 change: 1 addition & 0 deletions client/authority-discovery/src/worker/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl<Block: BlockT> HeaderBackend<Block> for TestApi {
genesis_hash: Default::default(),
number_leaves: Default::default(),
finalized_state: None,
block_gap: None,
}
}

Expand Down
4 changes: 2 additions & 2 deletions client/cli/src/commands/check_block_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
params::{BlockNumberOrHash, ImportParams, SharedParams},
CliConfiguration,
};
use sc_client_api::{BlockBackend, UsageProvider};
use sc_client_api::{BlockBackend, HeaderBackend};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT};
use std::{fmt::Debug, str::FromStr, sync::Arc};
use structopt::StructOpt;
Expand Down Expand Up @@ -53,7 +53,7 @@ impl CheckBlockCmd {
pub async fn run<B, C, IQ>(&self, client: Arc<C>, import_queue: IQ) -> error::Result<()>
where
B: BlockT + for<'de> serde::Deserialize<'de>,
C: BlockBackend<B> + UsageProvider<B> + Send + Sync + 'static,
C: BlockBackend<B> + HeaderBackend<B> + Send + Sync + 'static,
IQ: sc_service::ImportQueue<B> + 'static,
B::Hash: FromStr,
<B::Hash as FromStr>::Err: Debug,
Expand Down
4 changes: 2 additions & 2 deletions client/cli/src/commands/import_blocks_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
params::{ImportParams, SharedParams},
CliConfiguration,
};
use sc_client_api::UsageProvider;
use sc_client_api::HeaderBackend;
use sc_service::chain_ops::import_blocks;
use sp_runtime::traits::Block as BlockT;
use std::{
Expand Down Expand Up @@ -68,7 +68,7 @@ impl ImportBlocksCmd {
/// Run the import-blocks command
pub async fn run<B, C, IQ>(&self, client: Arc<C>, import_queue: IQ) -> error::Result<()>
where
C: UsageProvider<B> + Send + Sync + 'static,
C: HeaderBackend<B> + Send + Sync + 'static,
B: BlockT + for<'de> serde::Deserialize<'de>,
IQ: sc_service::ImportQueue<B> + 'static,
{
Expand Down
12 changes: 9 additions & 3 deletions client/consensus/babe/src/aux_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ use log::info;

use crate::{migration::EpochV0, Epoch};
use sc_client_api::backend::AuxStore;
use sc_consensus_epochs::{migration::EpochChangesForV0, EpochChangesFor, SharedEpochChanges};
use sc_consensus_epochs::{
migration::{EpochChangesForV0, EpochChangesForV1},
EpochChangesFor, SharedEpochChanges,
};
use sp_blockchain::{Error as ClientError, Result as ClientResult};
use sp_consensus_babe::{BabeBlockWeight, BabeGenesisConfiguration};
use sp_runtime::traits::Block as BlockT;

const BABE_EPOCH_CHANGES_VERSION: &[u8] = b"babe_epoch_changes_version";
const BABE_EPOCH_CHANGES_KEY: &[u8] = b"babe_epoch_changes";
const BABE_EPOCH_CHANGES_CURRENT_VERSION: u32 = 2;
const BABE_EPOCH_CHANGES_CURRENT_VERSION: u32 = 3;

/// The aux storage key used to store the block weight of the given block hash.
pub fn block_weight_key<H: Encode>(block_hash: H) -> Vec<u8> {
Expand Down Expand Up @@ -65,6 +68,9 @@ pub fn load_epoch_changes<Block: BlockT, B: AuxStore>(
Some(1) =>
load_decode::<_, EpochChangesFor<Block, EpochV0>>(backend, BABE_EPOCH_CHANGES_KEY)?
.map(|v1| v1.map(|_, _, epoch| epoch.migrate(config))),
Some(2) =>
load_decode::<_, EpochChangesForV1<Block, Epoch>>(backend, BABE_EPOCH_CHANGES_KEY)?
.map(|v2| v2.migrate()),
Some(BABE_EPOCH_CHANGES_CURRENT_VERSION) =>
load_decode::<_, EpochChangesFor<Block, Epoch>>(backend, BABE_EPOCH_CHANGES_KEY)?,
Some(other) =>
Expand Down Expand Up @@ -202,6 +208,6 @@ mod test {
client.insert_aux(values, &[]).unwrap();
});

assert_eq!(load_decode::<_, u32>(&client, BABE_EPOCH_CHANGES_VERSION).unwrap(), Some(2));
assert_eq!(load_decode::<_, u32>(&client, BABE_EPOCH_CHANGES_VERSION).unwrap(), Some(3));
}
}
12 changes: 9 additions & 3 deletions client/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,6 @@ where
// imported.
let prune_and_import = || {
prune_finalized(self.client.clone(), &mut epoch_changes)?;

epoch_changes
.import(
descendent_query(&*self.client),
Expand All @@ -1575,8 +1574,12 @@ where
*block.header.parent_hash(),
next_epoch,
)
.map_err(|e| ConsensusError::ClientImport(format!("{:?}", e)))?;

.map_err(|e| {
ConsensusError::ClientImport(format!(
"Error importing epoch changes: {:?}",
e
))
})?;
Ok(())
};

Expand Down Expand Up @@ -1664,6 +1667,9 @@ where
Client: HeaderBackend<Block> + HeaderMetadata<Block, Error = sp_blockchain::Error>,
{
let info = client.info();
if info.block_gap.is_none() {
epoch_changes.clear_gap();
}

let finalized_slot = {
let finalized_header = client
Expand Down
Loading

0 comments on commit 4157e96

Please sign in to comment.