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

Commit

Permalink
Sassafras Prototype 2.2 (#12314)
Browse files Browse the repository at this point in the history
* First experiments with equivocations report
* Good enough set of tests for client and pallet code
* Better submit-tickets extrinsic tag (hashed) and longevity
* Aux data revert implementation
* Handle skipped epochs on block-import
* Fix in the skipped epochs management code
* Insert tickets aux data after block import
* Working next epoch tickets incremental sort
  • Loading branch information
davxy authored Oct 29, 2022
1 parent 8f43727 commit 2b51690
Show file tree
Hide file tree
Showing 22 changed files with 1,783 additions and 210 deletions.
8 changes: 8 additions & 0 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions bin/node-sassafras/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use sc_service::PartialComponents;

impl SubstrateCli for Cli {
fn impl_name() -> String {
"Substrate Node".into()
"Sassafras Node".into()
}

fn impl_version() -> String {
Expand All @@ -30,7 +30,7 @@ impl SubstrateCli for Cli {
}

fn copyright_start_year() -> i32 {
2017
2022
}

fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Expand Down Expand Up @@ -96,7 +96,8 @@ pub fn run() -> sc_cli::Result<()> {
runner.async_run(|config| {
let PartialComponents { client, task_manager, backend, .. } =
service::new_partial(&config)?;
let aux_revert = Box::new(|client, _, blocks| {
let aux_revert = Box::new(|client, backend, blocks| {
sc_consensus_sassafras::revert(backend, blocks)?;
sc_finality_grandpa::revert(client, blocks)?;
Ok(())
});
Expand Down
3 changes: 1 addition & 2 deletions bin/node-sassafras/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>

let slot_duration = sassafras_link.genesis_config().slot_duration();

let sassafras_params = sc_consensus_sassafras::SassafrasParams {
let sassafras_params = sc_consensus_sassafras::SassafrasWorkerParams {
client: client.clone(),
keystore: keystore_container.sync_keystore(),
select_chain,
Expand Down Expand Up @@ -303,7 +303,6 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>
if role.is_authority() { Some(keystore_container.sync_keystore()) } else { None };

let grandpa_config = sc_finality_grandpa::Config {
// FIXME #1578 make this available through chainspec
gossip_duration: Duration::from_millis(333),
justification_period: 512,
name: Some(name),
Expand Down
15 changes: 15 additions & 0 deletions bin/node-sassafras/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,21 @@ impl_runtime_apis! {
fn slot_ticket(slot: sp_consensus_sassafras::Slot) -> Option<sp_consensus_sassafras::Ticket> {
Sassafras::slot_ticket(slot)
}

fn generate_key_ownership_proof(
_slot: sp_consensus_sassafras::Slot,
_authority_id: sp_consensus_sassafras::AuthorityId,
) -> Option<sp_consensus_sassafras::OpaqueKeyOwnershipProof> {
None
}

fn submit_report_equivocation_unsigned_extrinsic(
equivocation_proof: sp_consensus_sassafras::EquivocationProof<<Block as BlockT>::Header>,
_key_owner_proof: sp_consensus_sassafras::OpaqueKeyOwnershipProof,
) -> bool {
//let key_owner_proof = key_owner_proof.decode()?;
Sassafras::submit_unsigned_equivocation_report(equivocation_proof)
}
}

impl sp_session::SessionKeys<Block> for Runtime {
Expand Down
15 changes: 7 additions & 8 deletions client/consensus/babe/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ use sp_consensus_babe::{
inherents::InherentDataProvider, make_transcript, make_transcript_data, AllowedSlots,
AuthorityPair, Slot,
};
use sp_consensus_slots::SlotDuration;
use sp_core::crypto::Pair;
use sp_keystore::{vrf::make_transcript as transcript_from_data, SyncCryptoStore};
use sp_runtime::{
Expand Down Expand Up @@ -68,8 +67,6 @@ type Mutator = Arc<dyn Fn(&mut TestHeader, Stage) + Send + Sync>;
type BabeBlockImport =
PanickingBlockImport<crate::BabeBlockImport<TestBlock, TestClient, Arc<TestClient>>>;

const SLOT_DURATION_MS: u64 = 1000;

#[derive(Clone)]
struct DummyFactory {
client: Arc<TestClient>,
Expand Down Expand Up @@ -318,14 +315,15 @@ impl TestNetFactory for BabeTestNet {

let (_, longest_chain) = TestClientBuilder::new().build_with_longest_chain();

let slot_duration = data.link.config.slot_duration();
TestVerifier {
inner: BabeVerifier {
client: client.clone(),
select_chain: longest_chain,
create_inherent_data_providers: Box::new(|_, _| async {
create_inherent_data_providers: Box::new(move |_, _| async move {
let slot = InherentDataProvider::from_timestamp_and_slot_duration(
Timestamp::current(),
SlotDuration::from_millis(SLOT_DURATION_MS),
slot_duration,
);
Ok((slot,))
}),
Expand Down Expand Up @@ -425,17 +423,18 @@ fn run_one_test(mutator: impl Fn(&mut TestHeader, Stage) + Send + Sync + 'static
.for_each(|_| future::ready(())),
);

let slot_duration = data.link.config.slot_duration();
babe_futures.push(
start_babe(BabeParams {
block_import: data.block_import.lock().take().expect("import set up during init"),
select_chain,
client,
env: environ,
sync_oracle: DummyOracle,
create_inherent_data_providers: Box::new(|_, _| async {
create_inherent_data_providers: Box::new(move |_, _| async move {
let slot = InherentDataProvider::from_timestamp_and_slot_duration(
Timestamp::current(),
SlotDuration::from_millis(SLOT_DURATION_MS),
slot_duration,
);
Ok((slot,))
}),
Expand Down Expand Up @@ -1004,7 +1003,7 @@ fn obsolete_blocks_aux_data_cleanup() {
let data = peer.data.as_ref().expect("babe link set up during initialization");
let client = peer.client().as_client();

// Register the handler (as done by `babe_start`)
// Register the handler (as done by Babe's `block_import` method)
let client_clone = client.clone();
let on_finality = move |summary: &FinalityNotification<TestBlock>| {
aux_storage_cleanup(client_clone.as_ref(), summary)
Expand Down
10 changes: 5 additions & 5 deletions client/consensus/epochs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,11 +777,6 @@ where
}
}

/// Return the inner fork tree.
pub fn tree(&self) -> &ForkTree<Hash, Number, PersistedEpochHeader<E>> {
&self.inner
}

/// Reset to a specified pair of epochs, as if they were announced at blocks `parent_hash` and
/// `hash`.
pub fn reset(&mut self, parent_hash: Hash, hash: Hash, number: Number, current: E, next: E) {
Expand Down Expand Up @@ -832,6 +827,11 @@ where
self.epochs.remove(&(h, n));
});
}

/// Return the inner fork tree (mostly useful for testing)
pub fn tree(&self) -> &ForkTree<Hash, Number, PersistedEpochHeader<E>> {
&self.inner
}
}

/// Type alias to produce the epoch-changes tree from a block type.
Expand Down
8 changes: 8 additions & 0 deletions client/consensus/sassafras/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,11 @@ sp-core = { version = "6.0.0", path = "../../../primitives/core" }
sp-inherents = { version = "4.0.0-dev", path = "../../../primitives/inherents" }
sp-keystore = { version = "0.12.0", path = "../../../primitives/keystore" }
sp-runtime = { version = "6.0.0", path = "../../../primitives/runtime" }

[dev-dependencies]
sc-block-builder = { version = "0.10.0-dev", path = "../../block-builder" }
sc-keystore = { version = "4.0.0-dev", path = "../../keystore" }
sc-network-test = { version = "0.8.0", path = "../../network/test" }
sp-keyring = { version = "6.0.0", path = "../../../primitives/keyring" }
sp-timestamp = { version = "4.0.0-dev", path = "../../../primitives/timestamp" }
substrate-test-runtime-client = { version = "2.0.0", path = "../../../test-utils/runtime/client" }
Loading

0 comments on commit 2b51690

Please sign in to comment.