Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
82500c8
First draft of Sassafras components structure
davxy May 24, 2022
d7bef64
Implementation of Sassafras test node
davxy May 24, 2022
59e5b53
Start filling the placeholders
davxy May 24, 2022
e5a8239
Implemented epoch change using internal trigger
davxy May 31, 2022
7a456e2
Epoch randomness computation using blocks VRF accumulator
davxy Jun 1, 2022
11e009a
Verification on block import
davxy Jun 13, 2022
717a16f
Tickets generation procedure
davxy Jun 14, 2022
d86aef1
Publish tickets on-chain using unsigned extrinsic
davxy Jun 16, 2022
33c163d
Introduced first implementation of secondary slot claiming
davxy Jun 22, 2022
b82cccf
Use ticket to claim slot without proof check
davxy Jun 27, 2022
5e9c1f5
Enact epoch tickets on last epoch block
davxy Jun 28, 2022
9865938
Small refactory
davxy Jun 28, 2022
c3660f5
Unify primary and secondary pre-digest
davxy Jun 28, 2022
b50d9f9
Bump Sassafras components version to 0.1.0
davxy Jun 29, 2022
d78f6a2
Use BTreeSet instead of Vec to store next epoch tickets
davxy Jul 1, 2022
2508a5e
Trick to fetch the fist ticket on epoch change
davxy Jul 1, 2022
1e0e092
Fix epoch ticket get api
davxy Jul 2, 2022
8f4b18c
Blocks verification on import
davxy Jul 4, 2022
622b183
Merge branch 'master' into davxy-sassafras-consensus-prototype1
davxy Jul 19, 2022
cfd4c6a
Fix after master merge
davxy Jul 19, 2022
442d901
Restore good old Cargo.lock
davxy Jul 19, 2022
be27264
Fix unused fields warnings
davxy Jul 19, 2022
2a25d82
Try to make the compiler happy
davxy Jul 19, 2022
0e44362
Removed num-bigint dependency
davxy Jul 20, 2022
cd1ef1c
More robust tickets handling
davxy Jul 20, 2022
3d92632
TODOs priority classification
davxy Jul 20, 2022
3d8d2a8
Resolved TODOs with P1
davxy Jul 20, 2022
ccdfd37
Fix github link
davxy Jul 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
First draft of Sassafras components structure
  • Loading branch information
davxy committed May 24, 2022
commit 82500c8baceb86378ebdfa471c797fed1140fc7e
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ members = [
"client/consensus/epochs",
"client/consensus/manual-seal",
"client/consensus/pow",
"client/consensus/sassafras",
"client/consensus/slots",
"client/consensus/uncles",
"client/db",
Expand Down Expand Up @@ -118,6 +119,7 @@ members = [
"frame/recovery",
"frame/referenda",
"frame/remark",
"frame/sassafras",
"frame/scheduler",
"frame/scored-pool",
"frame/session",
Expand Down Expand Up @@ -165,6 +167,7 @@ members = [
"primitives/consensus/babe",
"primitives/consensus/common",
"primitives/consensus/pow",
"primitives/consensus/sassafras",
"primitives/consensus/vrf",
"primitives/core",
"primitives/core/hashing",
Expand Down
62 changes: 62 additions & 0 deletions client/consensus/sassafras/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[package]
name = "sc-consensus-sassafras"
version = "0.0.1"
authors = ["Parity Technologies <[email protected]>"]
description = "Sassafras consensus algorithm for substrate"
edition = "2021"
license = "Apache 2.0"
homepage = "https://substrate.io"
repository = "https://github.com/paritytech/substrate/"
documentation = "https://docs.rs/sc-consensus-sassafras"
readme = "README.md"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
async-trait = "0.1.50"
scale-codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"] }
futures = "0.3.21"
log = "0.4.16"
#merlin = "2.0"
#num-bigint = "0.2.3"
#num-rational = "0.2.2"
#num-traits = "0.2.8"
parking_lot = "0.12.0"
#rand = "0.7.2"
#retain_mut = "0.1.4"
#schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated"] }
#serde = { version = "1.0.136", features = ["derive"] }
#thiserror = "1.0"
#fork-tree = { version = "3.0.0", path = "../../../utils/fork-tree" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", version = "0.10.0-dev", path = "../../../utils/prometheus" }
sc-client-api = { version = "4.0.0-dev", path = "../../api" }
sc-consensus = { version = "0.10.0-dev", path = "../../../client/consensus/common" }
sc-consensus-epochs = { version = "0.10.0-dev", path = "../epochs" }
sc-consensus-slots = { version = "0.10.0-dev", path = "../slots" }
#sc-keystore = { version = "4.0.0-dev", path = "../../keystore" }
sc-telemetry = { version = "4.0.0-dev", path = "../../telemetry" }
sp-api = { version = "4.0.0-dev", path = "../../../primitives/api" }
#sp-application-crypto = { version = "6.0.0", path = "../../../primitives/application-crypto" }
sp-block-builder = { version = "4.0.0-dev", path = "../../../primitives/block-builder" }
sp-blockchain = { version = "4.0.0-dev", path = "../../../primitives/blockchain" }
sp-consensus = { version = "0.10.0-dev", path = "../../../primitives/consensus/common" }
sp-consensus-sassafras = { version = "0.0.1", path = "../../../primitives/consensus/sassafras" }
sp-consensus-slots = { version = "0.10.0-dev", path = "../../../primitives/consensus/slots" }
#sp-consensus-vrf = { version = "0.10.0-dev", path = "../../../primitives/consensus/vrf" }
sp-core = { version = "6.0.0", path = "../../../primitives/core" }
sp-inherents = { version = "4.0.0-dev", path = "../../../primitives/inherents" }
#sp-io = { version = "6.0.0", path = "../../../primitives/io" }
#sp-keystore = { version = "0.12.0", path = "../../../primitives/keystore" }
sp-runtime = { version = "6.0.0", path = "../../../primitives/runtime" }
#sp-version = { version = "5.0.0", path = "../../../primitives/version" }

#[dev-dependencies]
#rand_chacha = "0.2.2"
#tempfile = "3.1.0"
#sc-block-builder = { version = "0.10.0-dev", path = "../../block-builder" }
#sc-network = { version = "0.10.0-dev", path = "../../network" }
#sc-network-test = { version = "0.8.0", path = "../../network/test" }
#sp-timestamp = { version = "4.0.0-dev", path = "../../../primitives/timestamp" }
#sp-tracing = { version = "5.0.0", path = "../../../primitives/tracing" }
#substrate-test-runtime-client = { version = "2.0.0", path = "../../../test-utils/runtime/client" }
69 changes: 69 additions & 0 deletions client/consensus/sassafras/src/aux_schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// This file is part of Substrate.

// Copyright (C) 2022 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Schema for Sassafras epoch changes in the aux-db.

use log::info;
use scale_codec::{Decode, Encode};

use sc_client_api::backend::AuxStore;
use sc_consensus_epochs::{EpochChangesFor, SharedEpochChanges};
use sp_blockchain::{Error as ClientError, Result as ClientResult};
use sp_runtime::traits::Block as BlockT;

use crate::Epoch;

const SASSAFRAS_EPOCH_CHANGES_KEY: &[u8] = b"sassafras_epoch_changes";

fn load_decode<B, T>(backend: &B, key: &[u8]) -> ClientResult<Option<T>>
where
B: AuxStore,
T: Decode,
{
match backend.get_aux(key)? {
Some(t) => T::decode(&mut &t[..]).map(Some).map_err(|e| {
ClientError::Backend(format!("Sassafras db is corrupted, Decode error: {}", e))
}),
None => Ok(None),
}
}

/// Load or initialize persistent epoch change data from backend.
pub fn load_epoch_changes<B: BlockT, AS: AuxStore>(
backend: &AS,
) -> ClientResult<SharedEpochChanges<B, Epoch>> {
let maybe_epoch_changes =
load_decode::<_, EpochChangesFor<B, Epoch>>(backend, SASSAFRAS_EPOCH_CHANGES_KEY)?;

let epoch_changes =
SharedEpochChanges::<B, Epoch>::new(maybe_epoch_changes.unwrap_or_else(|| {
info!(
target: "babe",
"👶 Creating empty BABE epoch changes on what appears to be first startup.",
);
EpochChangesFor::<B, Epoch>::default()
}));

// rebalance the tree after deserialization. this isn't strictly necessary
// since the tree is now rebalanced on every update operation. but since the
// tree wasn't rebalanced initially it's useful to temporarily leave it here
// to avoid having to wait until an import for rebalancing.
epoch_changes.shared_data().rebalance();

Ok(epoch_changes)
}
Loading