Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
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 @@ -179,6 +179,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 @@ -409,6 +410,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 @@ -244,6 +244,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 @@ -531,6 +532,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};
Comment thread
cheme marked this conversation as resolved.
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
22 changes: 15 additions & 7 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::{EpochChangesV0For, EpochChangesV1For},
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 @@ -60,11 +63,16 @@ pub fn load_epoch_changes<Block: BlockT, B: AuxStore>(

let maybe_epoch_changes = match version {
None =>
load_decode::<_, EpochChangesForV0<Block, EpochV0>>(backend, BABE_EPOCH_CHANGES_KEY)?
load_decode::<_, EpochChangesV0For<Block, EpochV0>>(backend, BABE_EPOCH_CHANGES_KEY)?
.map(|v0| v0.migrate().map(|_, _, epoch| epoch.migrate(config))),
Some(1) =>
load_decode::<_, EpochChangesFor<Block, EpochV0>>(backend, BABE_EPOCH_CHANGES_KEY)?
.map(|v1| v1.map(|_, _, epoch| epoch.migrate(config))),
load_decode::<_, EpochChangesV1For<Block, EpochV0>>(backend, BABE_EPOCH_CHANGES_KEY)?
.map(|v1| v1.migrate().map(|_, _, epoch| epoch.migrate(config))),
Some(2) => {
// v2 still uses `EpochChanges` v1 format but with a different `Epoch` type.
load_decode::<_, EpochChangesV1For<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 @@ -164,7 +172,7 @@ mod test {
.insert_aux(
&[(
BABE_EPOCH_CHANGES_KEY,
&EpochChangesForV0::<TestBlock, EpochV0>::from_raw(v0_tree).encode()[..],
&EpochChangesV0For::<TestBlock, EpochV0>::from_raw(v0_tree).encode()[..],
)],
&[],
)
Expand Down Expand Up @@ -202,6 +210,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));
}
}
11 changes: 9 additions & 2 deletions client/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1578,8 +1578,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 @@ -1667,6 +1671,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