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

Commit 4a8a6d0

Browse files
authored
Remove loop (#8496)
automerge
1 parent a64b8a2 commit 4a8a6d0

File tree

1 file changed

+120
-128
lines changed

1 file changed

+120
-128
lines changed

core/src/replay_stage.rs

Lines changed: 120 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -252,145 +252,137 @@ impl ReplayStage {
252252
);
253253

254254
let ancestors = Arc::new(bank_forks.read().unwrap().ancestors());
255-
loop {
256-
let start = allocated.get();
257-
let mut frozen_banks: Vec<_> = bank_forks
258-
.read()
259-
.unwrap()
260-
.frozen_banks()
261-
.values()
262-
.cloned()
263-
.collect();
264-
let newly_computed_slot_stats = Self::compute_bank_stats(
265-
&my_pubkey,
266-
&ancestors,
267-
&mut frozen_banks,
255+
let start = allocated.get();
256+
let mut frozen_banks: Vec<_> = bank_forks
257+
.read()
258+
.unwrap()
259+
.frozen_banks()
260+
.values()
261+
.cloned()
262+
.collect();
263+
let newly_computed_slot_stats = Self::compute_bank_stats(
264+
&my_pubkey,
265+
&ancestors,
266+
&mut frozen_banks,
267+
&tower,
268+
&mut progress,
269+
);
270+
for slot in newly_computed_slot_stats {
271+
let fork_stats = &progress.get(&slot).unwrap().fork_stats;
272+
let confirmed_forks = Self::confirm_forks(
268273
&tower,
269-
&mut progress,
274+
&fork_stats.stake_lockouts,
275+
fork_stats.total_staked,
276+
&progress,
277+
&bank_forks,
270278
);
271-
for slot in newly_computed_slot_stats {
272-
let fork_stats = &progress.get(&slot).unwrap().fork_stats;
273-
let confirmed_forks = Self::confirm_forks(
274-
&tower,
275-
&fork_stats.stake_lockouts,
276-
fork_stats.total_staked,
277-
&progress,
278-
&bank_forks,
279-
);
280279

281-
for slot in confirmed_forks {
282-
progress
283-
.get_mut(&slot)
284-
.unwrap()
285-
.fork_stats
286-
.confirmation_reported = true;
287-
}
280+
for slot in confirmed_forks {
281+
progress
282+
.get_mut(&slot)
283+
.unwrap()
284+
.fork_stats
285+
.confirmation_reported = true;
288286
}
287+
}
289288

290-
let vote_bank = Self::select_fork(&frozen_banks, &tower, &progress);
291-
datapoint_debug!(
292-
"replay_stage-memory",
293-
("select_fork", (allocated.get() - start) as i64, i64),
294-
);
295-
if vote_bank.is_none() {
296-
break;
297-
}
298-
let bank = vote_bank.unwrap();
299-
let (is_locked_out, vote_threshold, fork_weight, total_staked) = {
300-
let fork_stats = &progress.get(&bank.slot()).unwrap().fork_stats;
301-
(
302-
fork_stats.is_locked_out,
303-
fork_stats.vote_threshold,
304-
fork_stats.weight,
305-
fork_stats.total_staked,
306-
)
307-
};
308-
let mut done = false;
309-
let mut vote_bank_slot = None;
310-
let start = allocated.get();
311-
if !is_locked_out && vote_threshold {
312-
info!("voting: {} {}", bank.slot(), fork_weight);
313-
subscriptions.notify_subscribers(bank.slot(), &bank_forks);
314-
if let Some(votable_leader) =
315-
leader_schedule_cache.slot_leader_at(bank.slot(), Some(&bank))
316-
{
317-
Self::log_leader_change(
318-
&my_pubkey,
319-
bank.slot(),
320-
&mut current_leader,
321-
&votable_leader,
322-
);
323-
}
324-
vote_bank_slot = Some(bank.slot());
325-
Self::handle_votable_bank(
326-
&bank,
327-
&bank_forks,
328-
&mut tower,
329-
&mut progress,
330-
&vote_account,
331-
&voting_keypair,
332-
&cluster_info,
333-
&blockstore,
334-
&leader_schedule_cache,
335-
&root_bank_sender,
336-
total_staked,
337-
&lockouts_sender,
338-
&snapshot_package_sender,
339-
&latest_root_senders,
340-
)?;
341-
}
342-
datapoint_debug!(
343-
"replay_stage-memory",
344-
("votable_bank", (allocated.get() - start) as i64, i64),
345-
);
346-
let start = allocated.get();
347-
if last_reset != bank.last_blockhash() {
348-
Self::reset_poh_recorder(
289+
let vote_bank = Self::select_fork(&frozen_banks, &tower, &progress);
290+
datapoint_debug!(
291+
"replay_stage-memory",
292+
("select_fork", (allocated.get() - start) as i64, i64),
293+
);
294+
if vote_bank.is_none() {
295+
break;
296+
}
297+
let bank = vote_bank.unwrap();
298+
let (is_locked_out, vote_threshold, fork_weight, total_staked) = {
299+
let fork_stats = &progress.get(&bank.slot()).unwrap().fork_stats;
300+
(
301+
fork_stats.is_locked_out,
302+
fork_stats.vote_threshold,
303+
fork_stats.weight,
304+
fork_stats.total_staked,
305+
)
306+
};
307+
let mut vote_bank_slot = None;
308+
let start = allocated.get();
309+
if !is_locked_out && vote_threshold {
310+
info!("voting: {} {}", bank.slot(), fork_weight);
311+
subscriptions.notify_subscribers(bank.slot(), &bank_forks);
312+
if let Some(votable_leader) =
313+
leader_schedule_cache.slot_leader_at(bank.slot(), Some(&bank))
314+
{
315+
Self::log_leader_change(
349316
&my_pubkey,
350-
&blockstore,
351-
&bank,
352-
&poh_recorder,
353-
&leader_schedule_cache,
354-
);
355-
last_reset = bank.last_blockhash();
356-
tpu_has_bank = false;
357-
info!(
358-
"vote bank: {:?} reset bank: {}",
359-
vote_bank_slot,
360-
bank.slot()
317+
bank.slot(),
318+
&mut current_leader,
319+
&votable_leader,
361320
);
362-
if !partition && vote_bank_slot != Some(bank.slot()) {
363-
warn!(
364-
"PARTITION DETECTED waiting to join fork: {} last vote: {:?}",
365-
bank.slot(),
366-
tower.last_vote()
367-
);
368-
inc_new_counter_info!("replay_stage-partition_detected", 1);
369-
datapoint_info!(
370-
"replay_stage-partition",
371-
("slot", bank.slot() as i64, i64)
372-
);
373-
partition = true;
374-
} else if partition && vote_bank_slot == Some(bank.slot()) {
375-
warn!(
376-
"PARTITION resolved fork: {} last vote: {:?}",
377-
bank.slot(),
378-
tower.last_vote()
379-
);
380-
partition = false;
381-
inc_new_counter_info!("replay_stage-partition_resolved", 1);
382-
}
383-
} else {
384-
done = true;
385321
}
386-
datapoint_debug!(
387-
"replay_stage-memory",
388-
("reset_bank", (allocated.get() - start) as i64, i64),
322+
vote_bank_slot = Some(bank.slot());
323+
Self::handle_votable_bank(
324+
&bank,
325+
&bank_forks,
326+
&mut tower,
327+
&mut progress,
328+
&vote_account,
329+
&voting_keypair,
330+
&cluster_info,
331+
&blockstore,
332+
&leader_schedule_cache,
333+
&root_bank_sender,
334+
total_staked,
335+
&lockouts_sender,
336+
&snapshot_package_sender,
337+
&latest_root_senders,
338+
)?;
339+
}
340+
datapoint_debug!(
341+
"replay_stage-memory",
342+
("votable_bank", (allocated.get() - start) as i64, i64),
343+
);
344+
let start = allocated.get();
345+
if last_reset != bank.last_blockhash() {
346+
Self::reset_poh_recorder(
347+
&my_pubkey,
348+
&blockstore,
349+
&bank,
350+
&poh_recorder,
351+
&leader_schedule_cache,
352+
);
353+
last_reset = bank.last_blockhash();
354+
tpu_has_bank = false;
355+
info!(
356+
"vote bank: {:?} reset bank: {}",
357+
vote_bank_slot,
358+
bank.slot()
389359
);
390-
if done {
391-
break;
360+
if !partition && vote_bank_slot != Some(bank.slot()) {
361+
warn!(
362+
"PARTITION DETECTED waiting to join fork: {} last vote: {:?}",
363+
bank.slot(),
364+
tower.last_vote()
365+
);
366+
inc_new_counter_info!("replay_stage-partition_detected", 1);
367+
datapoint_info!(
368+
"replay_stage-partition",
369+
("slot", bank.slot() as i64, i64)
370+
);
371+
partition = true;
372+
} else if partition && vote_bank_slot == Some(bank.slot()) {
373+
warn!(
374+
"PARTITION resolved fork: {} last vote: {:?}",
375+
bank.slot(),
376+
tower.last_vote()
377+
);
378+
partition = false;
379+
inc_new_counter_info!("replay_stage-partition_resolved", 1);
392380
}
393381
}
382+
datapoint_debug!(
383+
"replay_stage-memory",
384+
("reset_bank", (allocated.get() - start) as i64, i64),
385+
);
394386

395387
let start = allocated.get();
396388
if !tpu_has_bank {

0 commit comments

Comments
 (0)