Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 6f13e1c

Browse files
v1.18: chains Merkle shreds in broadcast duplicates (backport of #35058) (#35292)
chains Merkle shreds in broadcast duplicates (#35058) The commit migrates turbine/src/broadcast_stage/broadcast_duplicates_run.rs to use chained Merkle shreds variant. (cherry picked from commit 1b9dfd4) Co-authored-by: behzad nouri <[email protected]>
1 parent b369831 commit 6f13e1c

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

turbine/src/broadcast_stage/broadcast_duplicates_run.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct BroadcastDuplicatesConfig {
3737
pub(super) struct BroadcastDuplicatesRun {
3838
config: BroadcastDuplicatesConfig,
3939
current_slot: Slot,
40+
chained_merkle_root: Hash,
4041
next_shred_index: u32,
4142
next_code_index: u32,
4243
shred_version: u16,
@@ -57,6 +58,7 @@ impl BroadcastDuplicatesRun {
5758
));
5859
Self {
5960
config,
61+
chained_merkle_root: Hash::default(),
6062
next_shred_index: u32::MAX,
6163
next_code_index: 0,
6264
shred_version,
@@ -76,7 +78,7 @@ impl BroadcastRun for BroadcastDuplicatesRun {
7678
fn run(
7779
&mut self,
7880
keypair: &Keypair,
79-
_blockstore: &Blockstore,
81+
blockstore: &Blockstore,
8082
receiver: &Receiver<WorkingBankEntry>,
8183
socket_sender: &Sender<(Arc<Vec<Shred>>, Option<BroadcastShredBatchInfo>)>,
8284
blockstore_sender: &Sender<(Arc<Vec<Shred>>, Option<BroadcastShredBatchInfo>)>,
@@ -87,6 +89,12 @@ impl BroadcastRun for BroadcastDuplicatesRun {
8789
let last_tick_height = receive_results.last_tick_height;
8890

8991
if bank.slot() != self.current_slot {
92+
self.chained_merkle_root = broadcast_utils::get_chained_merkle_root_from_parent(
93+
bank.slot(),
94+
bank.parent_slot(),
95+
blockstore,
96+
)
97+
.unwrap();
9098
self.next_shred_index = 0;
9199
self.next_code_index = 0;
92100
self.current_slot = bank.slot();
@@ -169,18 +177,25 @@ impl BroadcastRun for BroadcastDuplicatesRun {
169177
)
170178
.expect("Expected to create a new shredder");
171179

180+
// Chained Merkle shreds are always discarded in epoch 0, due to
181+
// feature_set::enable_chained_merkle_shreds. Below can be removed once
182+
// the feature gated code is removed.
183+
let should_chain_merkle_shreds = bank.epoch() > 0;
184+
172185
let (data_shreds, coding_shreds) = shredder.entries_to_shreds(
173186
keypair,
174187
&receive_results.entries,
175188
last_tick_height == bank.max_tick_height() && last_entries.is_none(),
176-
None, // chained_merkle_root
189+
should_chain_merkle_shreds.then_some(self.chained_merkle_root),
177190
self.next_shred_index,
178191
self.next_code_index,
179192
true, // merkle_variant
180193
&self.reed_solomon_cache,
181194
&mut ProcessShredsStats::default(),
182195
);
183-
196+
if let Some(shred) = data_shreds.iter().max_by_key(|shred| shred.index()) {
197+
self.chained_merkle_root = shred.merkle_root().unwrap();
198+
}
184199
self.next_shred_index += data_shreds.len() as u32;
185200
if let Some(index) = coding_shreds.iter().map(Shred::index).max() {
186201
self.next_code_index = index + 1;
@@ -191,7 +206,7 @@ impl BroadcastRun for BroadcastDuplicatesRun {
191206
keypair,
192207
&[original_last_entry],
193208
true,
194-
None, // chained_merkle_root
209+
should_chain_merkle_shreds.then_some(self.chained_merkle_root),
195210
self.next_shred_index,
196211
self.next_code_index,
197212
true, // merkle_variant
@@ -205,7 +220,7 @@ impl BroadcastRun for BroadcastDuplicatesRun {
205220
keypair,
206221
&duplicate_extra_last_entries,
207222
true,
208-
None, // chained_merkle_root
223+
should_chain_merkle_shreds.then_some(self.chained_merkle_root),
209224
self.next_shred_index,
210225
self.next_code_index,
211226
true, // merkle_variant
@@ -222,6 +237,8 @@ impl BroadcastRun for BroadcastDuplicatesRun {
222237
sigs,
223238
);
224239

240+
assert_eq!(original_last_data_shred.len(), 1);
241+
assert_eq!(partition_last_data_shred.len(), 1);
225242
self.next_shred_index += 1;
226243
(original_last_data_shred, partition_last_data_shred)
227244
});

0 commit comments

Comments
 (0)