Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split "on_success_quorum" into smaller and more manageable functions #2636

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
consensus: add get_iteration_atts, set_attestation
fed-franz committed Oct 9, 2024
commit d4b5bca48707cbba62ade964ecfa38bf8b2e8712
58 changes: 50 additions & 8 deletions consensus/src/step_votes_reg.rs
Original file line number Diff line number Diff line change
@@ -179,17 +179,59 @@ impl AttInfoRegistry {
if sv == StepVotes::default() {
return None;
}
let att = self
.att_list
.entry(iteration)
.or_insert_with(|| IterationAtts::new(*generator));

let att_info = att.get_or_insert(vote);
let iter_atts = self.get_iteration_atts(iteration, generator);
let att_info = iter_atts.get_or_insert(vote);

att_info.set_sv(iteration, sv, step, quorum_reached);
att_info
.is_ready()
.then(|| Self::build_quorum_msg(&self.ru, iteration, att_info.att))

let attestation = att_info.att;
let is_ready = att_info.is_ready();

if is_ready {
return Some(Self::build_quorum_msg(
&self.ru,
iteration,
attestation,
));
}

None
}

fn get_iteration_atts(
&mut self,
iteration: u8,
generator: &PublicKeyBytes,
) -> &mut IterationAtts {
self.att_list
.entry(iteration)
.or_insert_with(|| IterationAtts::new(*generator))
}

pub(crate) fn set_attestation(
&mut self,
iteration: u8,
attestation: Attestation,
generator: &PublicKeyBytes,
) {
let iter_atts = self.get_iteration_atts(iteration, generator);

let vote = attestation.result.vote();
let att_info = iter_atts.get_or_insert(vote);

att_info.set_sv(
iteration,
attestation.validation,
StepName::Validation,
true,
);
att_info.set_sv(
iteration,
attestation.ratification,
StepName::Ratification,
true,
);
}

fn build_quorum_msg(