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
Prev Previous commit
Next Next commit
Start filling the placeholders
  • Loading branch information
davxy committed May 30, 2022
commit 59e5b53db4644f89055bb1c70de0cfa1befa9cec
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions bin/node-sassafras/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ pub fn new_full(mut config: Configuration) -> Result<TaskManager, ServiceError>

let sassafras_config = sc_consensus_sassafras::SassafrasParams {
client: client.clone(),
keystore: keystore_container.sync_keystore(),
select_chain,
env: proposer,
block_import,
Expand Down
2 changes: 2 additions & 0 deletions bin/node-sassafras/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ impl_runtime_apis! {
fn configuration() -> sp_consensus_sassafras::SassafrasGenesisConfiguration {
sp_consensus_sassafras::SassafrasGenesisConfiguration {
slot_duration: Sassafras::slot_duration(),
epoch_length: EpochDuration::get(),
genesis_authorities: Sassafras::authorities().to_vec(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions client/consensus/sassafras/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ parking_lot = "0.12.0"
#retain_mut = "0.1.4"
#schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated"] }
#serde = { version = "1.0.136", features = ["derive"] }
#thiserror = "1.0"
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" }
Expand All @@ -47,7 +47,7 @@ sp-consensus-slots = { version = "0.10.0-dev", path = "../../../primitives/conse
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-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" }

Expand Down
103 changes: 103 additions & 0 deletions client/consensus/sassafras/src/authorship.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// 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/>.

//! Sassafras authority selection and slot claiming.

use crate::Epoch;

use sp_consensus_sassafras::{
digests::{PreDigest, PrimaryPreDigest},
AuthorityId, Slot,
};
use sp_core::ByteArray;
use sp_keystore::{SyncCryptoStore, SyncCryptoStorePtr};

/// Tries to claim the given slot number. This method starts by trying to claim
/// a primary VRF based slot. If we are not able to claim it, then if we have
/// secondary slots enabled for the given epoch, we will fallback to trying to
/// claim a secondary slot.
pub fn claim_slot(
slot: Slot,
epoch: &Epoch,
keystore: &SyncCryptoStorePtr,
) -> Option<(PreDigest, AuthorityId)> {
let authorities = epoch
.authorities
.iter()
.enumerate()
.map(|(index, a)| (a.0.clone(), index))
.collect::<Vec<_>>();
claim_slot_using_keys(slot, epoch, keystore, &authorities)
}

/// Like `claim_slot`, but allows passing an explicit set of key pairs. Useful if we intend
/// to make repeated calls for different slots using the same key pairs.
pub fn claim_slot_using_keys(
slot: Slot,
epoch: &Epoch,
keystore: &SyncCryptoStorePtr,
keys: &[(AuthorityId, usize)],
) -> Option<(PreDigest, AuthorityId)> {
// TODO-SASS
// claim_primary_slot(slot, epoch, keystore, keys).or_else(|| {
// if epoch.config.allowed_slots.is_secondary_plain_slots_allowed() ||
// epoch.config.allowed_slots.is_secondary_vrf_slots_allowed()
// {
// claim_secondary_slot(
// slot,
// epoch,
// keys,
// keystore,
// epoch.config.allowed_slots.is_secondary_vrf_slots_allowed(),
// )
// } else {
// None
// }
// })
claim_primary_slot(slot, epoch, keystore, keys)
}

/// Claim a primary slot if it is our turn. Returns `None` if it is not our turn.
/// This hashes the slot number, epoch, genesis hash, and chain randomness into
/// the VRF. If the VRF produces a value less than `threshold`, it is our turn,
/// so it returns `Some(_)`. Otherwise, it returns `None`.
fn claim_primary_slot(
slot: Slot,
epoch: &Epoch,
keystore: &SyncCryptoStorePtr,
keys: &[(AuthorityId, usize)],
) -> Option<(PreDigest, AuthorityId)> {
// TODO-SASS: this is a dummy placeholder

use sp_core::crypto::key_types::SASSAFRAS;

for (authority_id, authority_index) in keys {
if SyncCryptoStore::has_keys(
keystore.as_ref(),
&[(authority_id.clone().to_raw_vec(), SASSAFRAS)],
) {
let pre_digest = PreDigest::Primary(PrimaryPreDigest {
authority_index: *authority_index as u32,
slot,
});
return Some((pre_digest, authority_id.clone()))
}
}

None
}
4 changes: 2 additions & 2 deletions client/consensus/sassafras/src/aux_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ pub fn load_epoch_changes<B: BlockT, AS: AuxStore>(
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.",
target: "sassafras",
"🍁 Creating empty Sassafras epoch changes on what appears to be first startup.",
);
EpochChangesFor::<B, Epoch>::default()
}));
Expand Down
Loading