Skip to content

Commit

Permalink
Add denunciations documentation (massalabs#3877)
Browse files Browse the repository at this point in the history
* Add denunciations documentation

* Cargo fmt pass

* Update massa-models/src/denunciation.rs

Co-authored-by: Damir Vodenicarevic <[email protected]>

* Update massa-models/src/denunciation.rs

Co-authored-by: Damir Vodenicarevic <[email protected]>

* Update massa-models/src/denunciation.rs

Co-authored-by: Damir Vodenicarevic <[email protected]>

* Update massa-models/src/denunciation.rs

Co-authored-by: Damir Vodenicarevic <[email protected]>

* Update massa-models/src/denunciation.rs

Co-authored-by: Damir Vodenicarevic <[email protected]>

* Update massa-models/src/denunciation.rs

Co-authored-by: Damir Vodenicarevic <[email protected]>

* Update massa-models/src/denunciation.rs

Co-authored-by: Damir Vodenicarevic <[email protected]>

* Update massa-models/src/denunciation.rs

Co-authored-by: Damir Vodenicarevic <[email protected]>

---------

Co-authored-by: sydhds <[email protected]>
Co-authored-by: Damir Vodenicarevic <[email protected]>
  • Loading branch information
3 people authored Apr 27, 2023
1 parent 14a3f88 commit b65b175
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 92 deletions.
4 changes: 2 additions & 2 deletions massa-bootstrap/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn stream_final_state_and_consensus(
pos_cycle_part,
pos_credits_part,
exec_ops_part,
processed_de_part,
exec_de_part,
final_state_changes,
consensus_part,
consensus_outdated_ids,
Expand Down Expand Up @@ -75,7 +75,7 @@ fn stream_final_state_and_consensus(
.set_executed_ops_part(exec_ops_part);
let last_de_step = write_final_state
.executed_denunciations
.set_processed_de_part(processed_de_part);
.set_executed_de_part(exec_de_part);
for (changes_slot, changes) in final_state_changes.iter() {
write_final_state.ledger.apply_changes(
changes.ledger_changes.clone(),
Expand Down
29 changes: 14 additions & 15 deletions massa-bootstrap/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use massa_consensus_exports::bootstrapable_graph::{
BootstrapableGraph, BootstrapableGraphDeserializer, BootstrapableGraphSerializer,
};
use massa_executed_ops::{
ExecutedOpsDeserializer, ExecutedOpsSerializer, ProcessedDenunciationsDeserializer,
ProcessedDenunciationsSerializer,
ExecutedDenunciationsDeserializer, ExecutedDenunciationsSerializer, ExecutedOpsDeserializer,
ExecutedOpsSerializer,
};
use massa_final_state::{StateChanges, StateChangesDeserializer, StateChangesSerializer};
use massa_ledger_exports::{Key as LedgerKey, KeyDeserializer, KeySerializer};
Expand Down Expand Up @@ -83,7 +83,7 @@ pub enum BootstrapServerMessage {
/// Part of the executed operations
exec_ops_part: BTreeMap<Slot, PreHashSet<OperationId>>,
/// Part of the executed operations
processed_de_part: BTreeMap<Slot, HashSet<DenunciationIndex>>,
exec_de_part: BTreeMap<Slot, HashSet<DenunciationIndex>>,
/// Ledger change for addresses inferior to `address` of the client message until the actual slot.
final_state_changes: Vec<(Slot, StateChanges)>,
/// Part of the consensus graph
Expand Down Expand Up @@ -155,7 +155,7 @@ pub struct BootstrapServerMessageSerializer {
opt_pos_cycle_serializer: OptionSerializer<CycleInfo, CycleInfoSerializer>,
pos_credits_serializer: DeferredCreditsSerializer,
exec_ops_serializer: ExecutedOpsSerializer,
processed_de_serializer: ProcessedDenunciationsSerializer,
exec_de_serializer: ExecutedDenunciationsSerializer,
opt_last_start_period_serializer: OptionSerializer<u64, U64VarIntSerializer>,
store_serializer: MipStoreRawSerializer,
}
Expand Down Expand Up @@ -184,7 +184,7 @@ impl BootstrapServerMessageSerializer {
opt_pos_cycle_serializer: OptionSerializer::new(CycleInfoSerializer::new()),
pos_credits_serializer: DeferredCreditsSerializer::new(),
exec_ops_serializer: ExecutedOpsSerializer::new(),
processed_de_serializer: ProcessedDenunciationsSerializer::new(),
exec_de_serializer: ExecutedDenunciationsSerializer::new(),
opt_last_start_period_serializer: OptionSerializer::new(U64VarIntSerializer::new()),
store_serializer: MipStoreRawSerializer::new(),
}
Expand Down Expand Up @@ -235,7 +235,7 @@ impl Serializer<BootstrapServerMessage> for BootstrapServerMessageSerializer {
pos_cycle_part,
pos_credits_part,
exec_ops_part,
processed_de_part,
exec_de_part,
final_state_changes,
consensus_part,
consensus_outdated_ids,
Expand All @@ -260,8 +260,7 @@ impl Serializer<BootstrapServerMessage> for BootstrapServerMessageSerializer {
// executed operations
self.exec_ops_serializer.serialize(exec_ops_part, buffer)?;
// processed denunciations
self.processed_de_serializer
.serialize(processed_de_part, buffer)?;
self.exec_de_serializer.serialize(exec_de_part, buffer)?;
// changes length
self.u64_serializer
.serialize(&(final_state_changes.len() as u64), buffer)?;
Expand Down Expand Up @@ -327,7 +326,7 @@ pub struct BootstrapServerMessageDeserializer {
opt_pos_cycle_deserializer: OptionDeserializer<CycleInfo, CycleInfoDeserializer>,
pos_credits_deserializer: DeferredCreditsDeserializer,
exec_ops_deserializer: ExecutedOpsDeserializer,
processed_de_deserializer: ProcessedDenunciationsDeserializer,
executed_de_deserializer: ExecutedDenunciationsDeserializer,
opt_last_start_period_deserializer: OptionDeserializer<u64, U64VarIntDeserializer>,
store_deserializer: MipStoreRawDeserializer,
}
Expand Down Expand Up @@ -404,7 +403,7 @@ impl BootstrapServerMessageDeserializer {
args.max_executed_ops_length,
args.max_operations_per_block as u64,
),
processed_de_deserializer: ProcessedDenunciationsDeserializer::new(
executed_de_deserializer: ExecutedDenunciationsDeserializer::new(
args.thread_count,
args.endorsement_count,
args.max_denunciation_changes_length,
Expand Down Expand Up @@ -528,8 +527,8 @@ impl Deserializer<BootstrapServerMessage> for BootstrapServerMessageDeserializer
context("Failed exec_ops_part deserialization", |input| {
self.exec_ops_deserializer.deserialize(input)
}),
context("Failed processed_de_part deserialization", |input| {
self.processed_de_deserializer.deserialize(input)
context("Failed exec_de_part deserialization", |input| {
self.executed_de_deserializer.deserialize(input)
}),
context(
"Failed final_state_changes deserialization",
Expand Down Expand Up @@ -561,7 +560,7 @@ impl Deserializer<BootstrapServerMessage> for BootstrapServerMessageDeserializer
pos_cycle_part,
pos_credits_part,
exec_ops_part,
processed_de_part,
exec_de_part,
final_state_changes,
consensus_part,
consensus_outdated_ids,
Expand All @@ -574,7 +573,7 @@ impl Deserializer<BootstrapServerMessage> for BootstrapServerMessageDeserializer
pos_cycle_part,
pos_credits_part,
exec_ops_part,
processed_de_part,
exec_de_part,
final_state_changes,
consensus_part,
consensus_outdated_ids,
Expand Down Expand Up @@ -623,7 +622,7 @@ pub enum BootstrapClientMessage {
last_credits_step: StreamingStep<Slot>,
/// Last received executed operation associated slot
last_ops_step: StreamingStep<Slot>,
/// Last received processed denunciations associated slot
/// Last received executed denunciations associated slot
last_de_step: StreamingStep<Slot>,
/// Last received consensus block slot
last_consensus_step: StreamingStep<PreHashSet<BlockId>>,
Expand Down
8 changes: 4 additions & 4 deletions massa-bootstrap/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ pub fn stream_bootstrap_information(
let pos_cycle_part;
let pos_credits_part;
let exec_ops_part;
let processed_de_part;
let exec_de_part;
let final_state_changes;
let last_start_period;

Expand Down Expand Up @@ -576,8 +576,8 @@ pub fn stream_bootstrap_information(

let (de_data, new_de_step) = final_state_read
.executed_denunciations
.get_processed_de_part(last_de_step);
processed_de_part = de_data;
.get_executed_de_part(last_de_step);
exec_de_part = de_data;

if let Some(slot) = last_slot && slot != final_state_read.slot {
if slot > final_state_read.slot {
Expand Down Expand Up @@ -690,7 +690,7 @@ pub fn stream_bootstrap_information(
pos_cycle_part,
pos_credits_part,
exec_ops_part,
processed_de_part,
exec_de_part,
final_state_changes,
consensus_part,
consensus_outdated_ids,
Expand Down
2 changes: 1 addition & 1 deletion massa-bootstrap/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub struct BootstrapConfig {
pub mip_store_stats_counters_max: usize,
/// max denunciations in block header
pub max_denunciations_per_block_header: u32,
/// max processed denunciations changes
/// max executed denunciations changes
pub max_denunciation_changes_length: u64,
}

Expand Down
4 changes: 2 additions & 2 deletions massa-executed-ops/src/denunciations_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ impl Deserializer<ExecutedDenunciationsChanges> for ExecutedDenunciationsChanges
buffer: &'a [u8],
) -> IResult<&'a [u8], ExecutedDenunciationsChanges, E> {
context(
"ProcessedDenunciationsChanges",
"ExecutedDenunciationsChanges",
length_count(
context("ProcessedDenunciationsChanges length", |input| {
context("ExecutedDenunciationsChanges length", |input| {
self.u64_deserializer.deserialize(input)
}),
tuple((context("denunciation index", |input| {
Expand Down
54 changes: 27 additions & 27 deletions massa-executed-ops/src/executed_denunciations.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Copyright (c) 2023 MASSA LABS <[email protected]>
//! This file defines a structure to list and prune previously processed denunciations.
//! This file defines a structure to list and prune previously executed denunciations.
//! Used to detect denunciation reuse.
use std::collections::{BTreeMap, HashSet};
Expand Down Expand Up @@ -28,21 +28,21 @@ use massa_serialization::{

const EXECUTED_DENUNCIATIONS_HASH_INITIAL_BYTES: &[u8; 32] = &[0; HASH_SIZE_BYTES];

/// A structure to list and prune previously processed denunciations
/// A structure to list and prune previously executed denunciations
#[derive(Debug, Clone)]
pub struct ExecutedDenunciations {
/// Processed denunciations configuration
/// Executed denunciations configuration
config: ExecutedDenunciationsConfig,
/// for better pruning complexity
pub sorted_denunciations: BTreeMap<Slot, HashSet<DenunciationIndex>>,
/// for better insertion complexity
pub denunciations: HashSet<DenunciationIndex>,
/// Accumulated hash of the processed denunciations
/// Accumulated hash of the executed denunciations
pub hash: Hash,
}

impl ExecutedDenunciations {
/// Create a new `ProcessedDenunciations`
/// Create a new `ExecutedDenunciations`
pub fn new(config: ExecutedDenunciationsConfig) -> Self {
Self {
config,
Expand Down Expand Up @@ -71,7 +71,7 @@ impl ExecutedDenunciations {
self.denunciations.is_empty()
}

/// Check if a denunciation (e.g. a denunciation index) was processed
/// Check if a denunciation (e.g. a denunciation index) was executed
pub fn contains(&self, de_idx: &DenunciationIndex) -> bool {
self.denunciations.contains(de_idx)
}
Expand All @@ -88,7 +88,7 @@ impl ExecutedDenunciations {
}
}

/// Apply speculative operations changes to the final processed denunciations state
/// Apply speculative operations changes to the final executed denunciations state
pub fn apply_changes(&mut self, changes: ExecutedDenunciationsChanges, slot: Slot) {
self.extend_and_compute_hash(changes.iter());
for de_idx in changes {
Expand Down Expand Up @@ -128,12 +128,12 @@ impl ExecutedDenunciations {
}
}

/// Get a part of the processed denunciations.
/// Get a part of the executed denunciations.
/// Used exclusively by the bootstrap server.
///
/// # Returns
/// A tuple containing the data and the next executed de streaming step
pub fn get_processed_de_part(
pub fn get_executed_de_part(
&self,
cursor: StreamingStep<Slot>,
) -> (
Expand Down Expand Up @@ -162,13 +162,13 @@ impl ExecutedDenunciations {
}
}

/// Set a part of the processed denunciations.
/// Set a part of the executed denunciations.
/// Used exclusively by the bootstrap client.
/// Takes the data returned from `get_processed_de_part` as input.
/// Takes the data returned from `get_executed_de_part` as input.
///
/// # Returns
/// The next executed de streaming step
pub fn set_processed_de_part(
pub fn set_executed_de_part(
&mut self,
part: BTreeMap<Slot, HashSet<DenunciationIndex>>,
) -> StreamingStep<Slot> {
Expand All @@ -186,21 +186,21 @@ impl ExecutedDenunciations {
}
}

/// `ProcessedDenunciations` Serializer
pub struct ProcessedDenunciationsSerializer {
/// `ExecutedDenunciations` Serializer
pub struct ExecutedDenunciationsSerializer {
slot_serializer: SlotSerializer,
de_idx_serializer: DenunciationIndexSerializer,
u64_serializer: U64VarIntSerializer,
}

impl Default for ProcessedDenunciationsSerializer {
impl Default for ExecutedDenunciationsSerializer {
fn default() -> Self {
Self::new()
}
}

impl ProcessedDenunciationsSerializer {
/// Create a new `ProcessedDenunciations` Serializer
impl ExecutedDenunciationsSerializer {
/// Create a new `ExecutedDenunciations` Serializer
pub fn new() -> Self {
Self {
slot_serializer: SlotSerializer::new(),
Expand All @@ -210,13 +210,13 @@ impl ProcessedDenunciationsSerializer {
}
}

impl Serializer<BTreeMap<Slot, HashSet<DenunciationIndex>>> for ProcessedDenunciationsSerializer {
impl Serializer<BTreeMap<Slot, HashSet<DenunciationIndex>>> for ExecutedDenunciationsSerializer {
fn serialize(
&self,
value: &BTreeMap<Slot, HashSet<DenunciationIndex>>,
buffer: &mut Vec<u8>,
) -> Result<(), SerializeError> {
// processed denunciations length
// exec denunciations length
self.u64_serializer
.serialize(&(value.len() as u64), buffer)?;
// executed ops
Expand All @@ -234,20 +234,20 @@ impl Serializer<BTreeMap<Slot, HashSet<DenunciationIndex>>> for ProcessedDenunci
}
}

/// Deserializer for `ProcessedDenunciations`
pub struct ProcessedDenunciationsDeserializer {
/// Deserializer for `ExecutedDenunciations`
pub struct ExecutedDenunciationsDeserializer {
de_idx_deserializer: DenunciationIndexDeserializer,
slot_deserializer: SlotDeserializer,
ops_length_deserializer: U64VarIntDeserializer,
slot_ops_length_deserializer: U64VarIntDeserializer,
}

impl ProcessedDenunciationsDeserializer {
/// Create a new deserializer for `ProcessedDenunciations`
impl ExecutedDenunciationsDeserializer {
/// Create a new deserializer for `ExecutedDenunciations`
pub fn new(
thread_count: u8,
endorsement_count: u32,
max_processed_de_length: u64,
max_executed_de_length: u64,
max_denunciations_per_block_header: u64,
) -> Self {
Self {
Expand All @@ -261,7 +261,7 @@ impl ProcessedDenunciationsDeserializer {
),
ops_length_deserializer: U64VarIntDeserializer::new(
Included(u64::MIN),
Included(max_processed_de_length),
Included(max_executed_de_length),
),
slot_ops_length_deserializer: U64VarIntDeserializer::new(
Included(u64::MIN),
Expand All @@ -272,14 +272,14 @@ impl ProcessedDenunciationsDeserializer {
}

impl Deserializer<BTreeMap<Slot, HashSet<DenunciationIndex>>>
for ProcessedDenunciationsDeserializer
for ExecutedDenunciationsDeserializer
{
fn deserialize<'a, E: ParseError<&'a [u8]> + ContextError<&'a [u8]>>(
&self,
buffer: &'a [u8],
) -> IResult<&'a [u8], BTreeMap<Slot, HashSet<DenunciationIndex>>, E> {
context(
"ProcessedDenunciations",
"ExecutedDenunciations",
length_count(
context("length", |input| {
self.ops_length_deserializer.deserialize(input)
Expand Down
Loading

0 comments on commit b65b175

Please sign in to comment.