|
|
@@ -19,81 +19,99 @@
|
|
|
use darkfi_serial::{SerialDecodable, SerialEncodable};
|
|
|
use pasta_curves::{group::ff::Field, pallas};
|
|
|
|
|
|
-/// Auxiliary structure used to keep track of slot validation parameters.
|
|
|
+/// Auxiliary structure used to keep track of slots' previous slot
|
|
|
+/// relevant validation parameters.
|
|
|
#[derive(Debug, Clone, PartialEq, SerialEncodable, SerialDecodable)]
|
|
|
-pub struct Slot {
|
|
|
- /// Slot UID
|
|
|
- pub id: u64,
|
|
|
- /// Previous slot eta
|
|
|
- pub previous_eta: pallas::Base,
|
|
|
- /// Previous slot forks last proposal/block hashes,
|
|
|
+pub struct PreviousSlot {
|
|
|
+ /// Block producers count
|
|
|
+ pub producers: u64,
|
|
|
+ /// Existing forks last proposal/block hashes,
|
|
|
/// as observed by the validator
|
|
|
- pub fork_hashes: Vec<blake3::Hash>,
|
|
|
- /// Previous slot second to last proposal/block hashes,
|
|
|
+ pub last_hashes: Vec<blake3::Hash>,
|
|
|
+ /// Existing forks second to last proposal/block hashes,
|
|
|
/// as observed by the validator
|
|
|
- pub fork_previous_hashes: Vec<blake3::Hash>,
|
|
|
- /// Slot inverse probability `f` of becoming a block producer
|
|
|
+ pub second_to_last_hashes: Vec<blake3::Hash>,
|
|
|
+ /// Slot eta
|
|
|
+ pub eta: pallas::Base,
|
|
|
+ /// Feedback error
|
|
|
+ pub error: f64,
|
|
|
+}
|
|
|
+
|
|
|
+impl PreviousSlot {
|
|
|
+ pub fn new(
|
|
|
+ producers: u64,
|
|
|
+ last_hashes: Vec<blake3::Hash>,
|
|
|
+ second_to_last_hashes: Vec<blake3::Hash>,
|
|
|
+ eta: pallas::Base,
|
|
|
+ error: f64,
|
|
|
+ ) -> Self {
|
|
|
+ Self { producers, last_hashes, second_to_last_hashes, eta, error }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl Default for PreviousSlot {
|
|
|
+ /// Represents the genesis slot previous slot on current timestamp
|
|
|
+ fn default() -> Self {
|
|
|
+ Self::new(0, vec![], vec![], pallas::Base::ZERO, 0.0)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/// Auxiliary structure used to keep track of slot PID output.
|
|
|
+#[derive(Debug, Clone, PartialEq, SerialEncodable, SerialDecodable)]
|
|
|
+pub struct PidOutput {
|
|
|
+ /// Inverse probability `f` of becoming a block producer
|
|
|
pub f: f64,
|
|
|
- /// Slot feedback error
|
|
|
+ /// Feedback error
|
|
|
pub error: f64,
|
|
|
- /// Previous slot feedback error
|
|
|
- pub previous_slot_error: f64,
|
|
|
- /// Total tokens up until this slot
|
|
|
- pub total_tokens: u64,
|
|
|
- /// Slot reward
|
|
|
- pub reward: u64,
|
|
|
/// Slot sigma1
|
|
|
pub sigma1: pallas::Base,
|
|
|
/// Slot sigma2
|
|
|
pub sigma2: pallas::Base,
|
|
|
}
|
|
|
|
|
|
+impl PidOutput {
|
|
|
+ pub fn new(f: f64, error: f64, sigma1: pallas::Base, sigma2: pallas::Base) -> Self {
|
|
|
+ Self { f, error, sigma1, sigma2 }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl Default for PidOutput {
|
|
|
+ /// Represents the genesis slot PID output on current timestamp
|
|
|
+ fn default() -> Self {
|
|
|
+ Self::new(0.0, 0.0, pallas::Base::ZERO, pallas::Base::ZERO)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/// Auxiliary structure used to keep track of slot validation parameters.
|
|
|
+#[derive(Debug, Clone, PartialEq, SerialEncodable, SerialDecodable)]
|
|
|
+pub struct Slot {
|
|
|
+ /// Slot UID
|
|
|
+ pub id: u64,
|
|
|
+ /// Previous slot information
|
|
|
+ pub previous: PreviousSlot,
|
|
|
+ /// Slot PID output
|
|
|
+ pub pid: PidOutput,
|
|
|
+ /// Total tokens up until this slot
|
|
|
+ pub total_tokens: u64,
|
|
|
+ /// Slot reward
|
|
|
+ pub reward: u64,
|
|
|
+}
|
|
|
+
|
|
|
impl Slot {
|
|
|
- #[allow(clippy::too_many_arguments)]
|
|
|
pub fn new(
|
|
|
id: u64,
|
|
|
- previous_eta: pallas::Base,
|
|
|
- fork_hashes: Vec<blake3::Hash>,
|
|
|
- fork_previous_hashes: Vec<blake3::Hash>,
|
|
|
- f: f64,
|
|
|
- error: f64,
|
|
|
- previous_slot_error: f64,
|
|
|
+ previous: PreviousSlot,
|
|
|
+ pid: PidOutput,
|
|
|
total_tokens: u64,
|
|
|
reward: u64,
|
|
|
- sigma1: pallas::Base,
|
|
|
- sigma2: pallas::Base,
|
|
|
) -> Self {
|
|
|
- Self {
|
|
|
- id,
|
|
|
- previous_eta,
|
|
|
- fork_hashes,
|
|
|
- fork_previous_hashes,
|
|
|
- f,
|
|
|
- error,
|
|
|
- previous_slot_error,
|
|
|
- total_tokens,
|
|
|
- reward,
|
|
|
- sigma1,
|
|
|
- sigma2,
|
|
|
- }
|
|
|
+ Self { id, previous, pid, total_tokens, reward }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
impl Default for Slot {
|
|
|
/// Represents the genesis slot on current timestamp
|
|
|
fn default() -> Self {
|
|
|
- Self::new(
|
|
|
- 0,
|
|
|
- pallas::Base::ZERO,
|
|
|
- vec![],
|
|
|
- vec![],
|
|
|
- 0.0,
|
|
|
- 0.0,
|
|
|
- 0.0,
|
|
|
- 0,
|
|
|
- 0,
|
|
|
- pallas::Base::ZERO,
|
|
|
- pallas::Base::ZERO,
|
|
|
- )
|
|
|
+ Self::new(0, PreviousSlot::default(), PidOutput::default(), 0, 0)
|
|
|
}
|
|
|
}
|