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

Commit

Permalink
allow BabeConsensusDataProvider fork existing chains
Browse files Browse the repository at this point in the history
  • Loading branch information
seunlanlege committed Nov 2, 2020
1 parent 6a4ac3c commit 737f7bf
Show file tree
Hide file tree
Showing 21 changed files with 200 additions and 123 deletions.
39 changes: 20 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/node-template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ sc-client-api = { version = "2.0.0", path = "../../../client/api" }
sp-runtime = { version = "2.0.0", path = "../../../primitives/runtime" }

# These dependencies are used for the node template's RPCs
jsonrpc-core = "15.0.0"
jsonrpc-core = "15.1.0"
sc-rpc = { version = "2.0.0", path = "../../../client/rpc" }
sp-api = { version = "2.0.0", path = "../../../primitives/api" }
sc-rpc-api = { version = "0.8.0", path = "../../../client/rpc-api" }
Expand Down
2 changes: 1 addition & 1 deletion bin/node/rpc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
futures = "0.1.29"
hyper = "0.12.35"
jsonrpc-core-client = { version = "15.0.0", default-features = false, features = ["http"] }
jsonrpc-core-client = { version = "15.1.0", default-features = false, features = ["http"] }
log = "0.4.8"
node-primitives = { version = "2.0.0", path = "../primitives" }
sp-tracing = { version = "2.0.0", path = "../../../primitives/tracing" }
Expand Down
2 changes: 1 addition & 1 deletion bin/node/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repository = "https://github.com/paritytech/substrate/"
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
jsonrpc-core = "15.0.0"
jsonrpc-core = "15.1.0"
node-primitives = { version = "2.0.0", path = "../primitives" }
node-runtime = { version = "2.0.0", path = "../runtime" }
pallet-contracts-rpc = { version = "0.8.0", path = "../../../frame/contracts/rpc/" }
Expand Down
2 changes: 1 addition & 1 deletion client/api/src/execution_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<Block: traits::Block> ExecutionExtensions<Block> {
strategies,
keystore,
extensions_factory: RwLock::new(extensions_factory),
transaction_pool,
transaction_pool
}
}

Expand Down
6 changes: 3 additions & 3 deletions client/consensus/babe/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
sc-consensus-babe = { version = "0.8.0", path = "../" }
sc-rpc-api = { version = "0.8.0", path = "../../../rpc-api" }
jsonrpc-core = "15.0.0"
jsonrpc-core-client = "15.0.0"
jsonrpc-derive = "15.0.0"
jsonrpc-core = "15.1.0"
jsonrpc-core-client = "15.1.0"
jsonrpc-derive = "15.1.0"
sp-consensus-babe = { version = "0.8.0", path = "../../../../primitives/consensus/babe" }
serde = { version = "1.0.104", features=["derive"] }
sp-blockchain = { version = "2.0.0", path = "../../../../primitives/blockchain" }
Expand Down
9 changes: 3 additions & 6 deletions client/consensus/babe/src/aux_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ use sp_consensus_babe::{BabeBlockWeight, BabeGenesisConfiguration};
use sc_consensus_epochs::{EpochChangesFor, SharedEpochChanges, migration::EpochChangesForV0};
use crate::{Epoch, migration::EpochV0};

/// Aux key for epoch changes version
pub const BABE_EPOCH_CHANGES_VERSION: &[u8] = b"babe_epoch_changes_version";
/// Aux key for epoch changes
pub const BABE_EPOCH_CHANGES_KEY: &[u8] = b"babe_epoch_changes";
/// hard coded epoch changes version
pub const BABE_EPOCH_CHANGES_CURRENT_VERSION: u32 = 2;
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;

fn block_weight_key<H: Encode>(block_hash: H) -> Vec<u8> {
(b"block_weight", block_hash).encode()
Expand Down
32 changes: 30 additions & 2 deletions client/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,58 +199,86 @@ impl Epoch {
}
}

/// Errors encountered by the babe authorship task.
#[derive(derive_more::Display, Debug)]
enum Error<B: BlockT> {
pub enum Error<B: BlockT> {
/// Multiple BABE pre-runtime digests
#[display(fmt = "Multiple BABE pre-runtime digests, rejecting!")]
MultiplePreRuntimeDigests,
/// No BABE pre-runtime digest found
#[display(fmt = "No BABE pre-runtime digest found")]
NoPreRuntimeDigest,
/// Multiple BABE epoch change digests
#[display(fmt = "Multiple BABE epoch change digests, rejecting!")]
MultipleEpochChangeDigests,
/// Multiple BABE config change digests
#[display(fmt = "Multiple BABE config change digests, rejecting!")]
MultipleConfigChangeDigests,
/// Could not extract timestamp and slot
#[display(fmt = "Could not extract timestamp and slot: {:?}", _0)]
Extraction(sp_consensus::Error),
/// Could not fetch epoch
#[display(fmt = "Could not fetch epoch at {:?}", _0)]
FetchEpoch(B::Hash),
/// Header rejected: too far in the future
#[display(fmt = "Header {:?} rejected: too far in the future", _0)]
TooFarInFuture(B::Hash),
/// Parent unavailable. Cannot import
#[display(fmt = "Parent ({}) of {} unavailable. Cannot import", _0, _1)]
ParentUnavailable(B::Hash, B::Hash),
/// Slot number must increase
#[display(fmt = "Slot number must increase: parent slot: {}, this slot: {}", _0, _1)]
SlotNumberMustIncrease(u64, u64),
/// Header has a bad seal
#[display(fmt = "Header {:?} has a bad seal", _0)]
HeaderBadSeal(B::Hash),
/// Header is unsealed
#[display(fmt = "Header {:?} is unsealed", _0)]
HeaderUnsealed(B::Hash),
/// Slot author not found
#[display(fmt = "Slot author not found")]
SlotAuthorNotFound,
/// Secondary slot assignments are disabled for the current epoch.
#[display(fmt = "Secondary slot assignments are disabled for the current epoch.")]
SecondarySlotAssignmentsDisabled,
/// Bad signature
#[display(fmt = "Bad signature on {:?}", _0)]
BadSignature(B::Hash),
/// Invalid author: Expected secondary author
#[display(fmt = "Invalid author: Expected secondary author: {:?}, got: {:?}.", _0, _1)]
InvalidAuthor(AuthorityId, AuthorityId),
/// No secondary author expected.
#[display(fmt = "No secondary author expected.")]
NoSecondaryAuthorExpected,
/// VRF verification of block by author failed
#[display(fmt = "VRF verification of block by author {:?} failed: threshold {} exceeded", _0, _1)]
VRFVerificationOfBlockFailed(AuthorityId, u128),
/// VRF verification failed
#[display(fmt = "VRF verification failed: {:?}", _0)]
VRFVerificationFailed(SignatureError),
/// Could not fetch parent header
#[display(fmt = "Could not fetch parent header: {:?}", _0)]
FetchParentHeader(sp_blockchain::Error),
/// Expected epoch change to happen.
#[display(fmt = "Expected epoch change to happen at {:?}, s{}", _0, _1)]
ExpectedEpochChange(B::Hash, u64),
/// Unexpected config change.
#[display(fmt = "Unexpected config change")]
UnexpectedConfigChange,
/// Unexpected epoch change
#[display(fmt = "Unexpected epoch change")]
UnexpectedEpochChange,
/// Parent block has no associated weight
#[display(fmt = "Parent block of {} has no associated weight", _0)]
ParentBlockNoAssociatedWeight(B::Hash),
#[display(fmt = "Checking inherents failed: {}", _0)]
/// Check Inherents error
CheckInherents(String),
/// Client error
Client(sp_blockchain::Error),
/// Runtime error
Runtime(sp_inherents::Error),
/// Fork tree error
ForkTree(Box<fork_tree::Error<sp_blockchain::Error>>),
}

Expand Down Expand Up @@ -669,7 +697,7 @@ impl<B, C, E, I, Error, SO> sc_consensus_slots::SimpleSlotWorker<B> for BabeSlot

/// Extract the BABE pre digest from the given header. Pre-runtime digests are
/// mandatory, the function will return `Err` if none is found.
fn find_pre_digest<B: BlockT>(header: &B::Header) -> Result<PreDigest, Error<B>>
pub fn find_pre_digest<B: BlockT>(header: &B::Header) -> Result<PreDigest, Error<B>>
{
// genesis block doesn't contain a pre digest so let's generate a
// dummy one to not break any invariants in the rest of the code
Expand Down
7 changes: 4 additions & 3 deletions client/consensus/manual-seal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
derive_more = "0.99.2"
futures = "0.3.4"
jsonrpc-core = "15.0.0"
jsonrpc-core-client = "15.0.0"
jsonrpc-derive = "15.0.0"
jsonrpc-core = "15.1.0"
jsonrpc-core-client = "15.1.0"
jsonrpc-derive = "15.1.0"
log = "0.4.8"
parking_lot = "0.10.0"
codec = { package = "parity-scale-codec", version = "1.3.1" }
Expand All @@ -36,6 +36,7 @@ sp-inherents = { path = "../../../primitives/inherents", version = "2.0.0" }
sp-runtime = { path = "../../../primitives/runtime", version = "2.0.0" }
sp-core = { path = "../../../primitives/core", version = "2.0.0" }
sp-keystore = { path = "../../../primitives/keystore", version = "0.8.0" }
sp-keyring = { path = "../../../primitives/keyring", version = "2.0.0" }
sp-api = { path = "../../../primitives/api", version = "2.0.0" }
sp-transaction-pool = { path = "../../../primitives/transaction-pool", version = "2.0.0" }
sp-timestamp = { path = "../../../primitives/timestamp", version = "2.0.0" }
Expand Down
Loading

0 comments on commit 737f7bf

Please sign in to comment.