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
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
TEMPORARY
  • Loading branch information
davxy committed Nov 21, 2022
commit 8587461a4c0dc8dc4cd181d7c168778560d113a5
10 changes: 5 additions & 5 deletions Cargo.lock

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

8 changes: 6 additions & 2 deletions client/consensus/sassafras/src/authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub(crate) fn claim_slot(
log::debug!(target: "sassafras", "🌳 [TRY PRIMARY]");
let (authority_idx, ticket_aux) = epoch.tickets_aux.get(&ticket)?.clone();
log::debug!(target: "sassafras", "🌳 Ticket = [ticket: {:02x?}, auth: {}, attempt: {}]",
&ticket.as_bytes()[0..8], authority_idx, ticket_aux.attempt);
&ticket.output.as_bytes()[0..8], authority_idx, ticket_aux.attempt);
(authority_idx, Some(ticket_aux))
},
None => {
Expand Down Expand Up @@ -128,7 +128,11 @@ fn generate_epoch_tickets(epoch: &mut Epoch, keystore: &SyncCryptoStorePtr) -> V
)
.ok()??;

let ticket = VRFOutput(signature.output);
let ticket = Ticket {
output: VRFOutput(signature.output),
// TODO-SASS-P3
proof: VRFProof::try_from([0; 64]).expect("FIXME"),
};
if !sp_consensus_sassafras::check_threshold(&ticket, threshold) {
return None
}
Expand Down
13 changes: 9 additions & 4 deletions frame/sassafras/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use frame_system::offchain::{SendTransactionTypes, SubmitTransaction};
use sp_consensus_sassafras::{
digests::{ConsensusLog, NextEpochDescriptor, PreDigest},
AuthorityId, EquivocationProof, Randomness, SassafrasAuthorityWeight,
SassafrasEpochConfiguration, Slot, Ticket, SASSAFRAS_ENGINE_ID,
SassafrasEpochConfiguration, Slot, Ticket, VRFOutput, VRFProof, SASSAFRAS_ENGINE_ID,
};
use sp_io::hashing;
use sp_runtime::{
Expand Down Expand Up @@ -727,9 +727,14 @@ impl<T: Config> Pallet<T> {
let mut require_sort = max_iter != 0;

let mut sup = if new_segment.len() >= max_tickets {
new_segment[new_segment.len() - 1]
new_segment[new_segment.len() - 1].clone()
} else {
Ticket::try_from([0xFF; 32]).expect("This is a valid ticket value; qed")
Ticket {
output: VRFOutput::try_from([0xFF; 32])
.expect("This is a valid vrf output value; qed"),
proof: VRFProof::try_from([0xFF; 64])
.expect("This is a valid vrf proof value; qed"),
}
};

for _ in 0..max_iter {
Expand All @@ -740,7 +745,7 @@ impl<T: Config> Pallet<T> {
require_sort = false;
new_segment.sort_unstable();
new_segment.truncate(max_tickets);
sup = new_segment[new_segment.len() - 1];
sup = new_segment[new_segment.len() - 1].clone();
}

segments_count -= 1;
Expand Down
35 changes: 32 additions & 3 deletions primitives/consensus/sassafras/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,43 @@ pub struct SassafrasEpochConfiguration {
}

/// Ticket type.
pub type Ticket = VRFOutput;
// TODO-SASS-P3: we are currently using Shnorrkel structures as placeholders.
// Should switch to new RVRF primitive.
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub struct Ticket {
/// Ring VRF output.
pub output: VRFOutput,
/// Ring VRF commitment proof.
pub proof: VRFProof,
// Ticket opaque utility data.
// TODO-SASS-P3: Interpretation of this data is up to the application? Investigate
// Suggested by Jeff:
// - ephemeral_pk: public key used to...
// - revealed_pk: ???
// - gossip_auth_id: identifier to reach this actor in a separate gossip network
//pub data: Vec<u8>,
}

use core::cmp::Ordering;

impl PartialOrd for Ticket {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.output.partial_cmp(&other.output)
}
}

impl Ord for Ticket {
fn cmp(&self, other: &Self) -> Ordering {
self.output.cmp(&other.output)
}
}

/// Ticket auxiliary information.
#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, MaxEncodedLen, TypeInfo)]
pub struct TicketAux {
/// Attempt number.
pub attempt: u32,
/// Ticket proof.
/// Ticket revelation proof.
pub proof: VRFProof,
}

Expand All @@ -144,7 +173,7 @@ pub fn compute_threshold(redundancy: u32, slots: u32, attempts: u32, validators:

/// Returns true if the given VRF output is lower than the given threshold, false otherwise.
pub fn check_threshold(ticket: &Ticket, threshold: U256) -> bool {
U256::from(ticket.as_bytes()) < threshold
U256::from(ticket.output.as_bytes()) < threshold
}

/// An opaque type used to represent the key ownership proof at the runtime API boundary.
Expand Down