Skip to content

Commit

Permalink
turbine::broadcast_stage: then_some/ok_or_else => if
Browse files Browse the repository at this point in the history
`if/else` seems easier to follow, as it produces less nesting.

Assignment of `self.chained_merkle_root` into `chained_merkle_root`,
that is then assigned back into `self.chained_merkle_root` is a no-op.
While I can see how it is separating the computation of the
`chained_merkle_root` for the current step from the update of the
`self`, I think, overall, it is more confusing then helpful.

The `Finish previous slot ...` comment is actually part of a
multi-paragraph sequence of steps, that document the whole
`process_receive_results()`.  Step number was accidentally removed in
`#1057`:

    commit 6b45dc9
    Author: behzad nouri <[email protected]>
    Date:   Fri May 3 20:20:10 2024 +0000

        retains chained Merkle root across leader slots (#1057)
  • Loading branch information
ilya-bobyr committed May 14, 2024
1 parent af6930d commit 9e25cbd
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions turbine/src/broadcast_stage/standard_broadcast_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use {
super::{
broadcast_utils::{self, ReceiveResults},
broadcast_utils::{self, get_chained_merkle_root_from_parent, ReceiveResults},
*,
},
crate::cluster_nodes::ClusterNodesCache,
Expand Down Expand Up @@ -207,8 +207,9 @@ impl StandardBroadcastRun {
let mut to_shreds_time = Measure::start("broadcast_to_shreds");
let cluster_type = bank.cluster_type();

// 1) Finish previous slot.
if self.slot != bank.slot() {
// Finish previous slot if it was interrupted.
// Was it interrupted?
if !self.completed {
let shreds = self.finish_prev_slot(
keypair,
Expand Down Expand Up @@ -242,29 +243,30 @@ impl StandardBroadcastRun {
// Refrain from generating shreds for the slot.
return Err(Error::DuplicateSlotBroadcast(bank.slot()));
}

// Reinitialize state for this slot.
let chained_merkle_root = (self.slot == bank.parent_slot())
.then_some(self.chained_merkle_root)
.ok_or_else(|| {
broadcast_utils::get_chained_merkle_root_from_parent(
bank.slot(),
bank.parent_slot(),
blockstore,
)
})

if self.slot != bank.parent_slot() {
self.chained_merkle_root = get_chained_merkle_root_from_parent(
bank.slot(),
bank.parent_slot(),
blockstore,
)
.unwrap_or_else(|err| {
error!("Unknown chained Merkle root: {err:?}");
process_stats.err_unknown_chained_merkle_root += 1;
Hash::default()
});
}

self.slot = bank.slot();
self.parent = bank.parent_slot();
self.chained_merkle_root = chained_merkle_root;
self.next_shred_index = 0u32;
self.next_code_index = 0u32;
self.completed = false;
self.slot_broadcast_start = Instant::now();
self.num_batches = 0;

receive_elapsed = Duration::ZERO;
coalesce_elapsed = Duration::ZERO;
}
Expand Down

0 comments on commit 9e25cbd

Please sign in to comment.