Skip to content

Commit

Permalink
params refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
moshababo committed Dec 22, 2023
1 parent 4526f51 commit 6350384
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion node/actors/bft/src/leader/replica_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl StateMachine {
// We add the message to the incrementally-constructed QC.
self.commit_qcs
.entry(message.view)
.or_insert(CommitQC::new(message, self.inner.validator_set.len()))
.or_insert(CommitQC::new(message, &self.inner.validator_set))
.add(&signed_message.sig, validator_index);

// We store the message in our cache.
Expand Down
3 changes: 2 additions & 1 deletion node/actors/bft/src/leader/replica_prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ impl StateMachine {
// We add the message to the incrementally-constructed QC.
self.prepare_qcs.entry(message.view).or_default().add(
&signed_message,
(validator_index, self.inner.validator_set.len()),
validator_index,
&self.inner.validator_set,
);

// We store the message in our cache.
Expand Down
13 changes: 6 additions & 7 deletions node/libs/roles/src/validator/messages/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,17 @@ impl PrepareQC {
}

/// Add a validator's signed message.
/// * `signed_message` - A signed message.
/// * `validator_index` - A tuple containing the index of the validator and the total size of the set.
pub fn add(
&mut self,
signed_message: &Signed<ReplicaPrepare>,
validator_index: (usize, usize),
validator_index: usize,
validator_set: &ValidatorSet,
) {
self.map
.entry(signed_message.msg.clone())
.or_insert_with(|| Signers(BitVec::from_elem(validator_index.1, false)))
.or_insert_with(|| Signers(BitVec::from_elem(validator_set.len(), false)))
.0
.set(validator_index.0, true);
.set(validator_index, true);

self.signature.add(&signed_message.sig);
}
Expand Down Expand Up @@ -284,10 +283,10 @@ pub struct CommitQC {

impl CommitQC {
/// Create a new empty instance for a given `ReplicaCommit` message and a validator set size.
pub fn new(message: ReplicaCommit, validator_set_size: usize) -> Self {
pub fn new(message: ReplicaCommit, validator_set: &ValidatorSet) -> Self {
Self {
message,
signers: Signers(BitVec::from_elem(validator_set_size, false)),
signers: Signers(BitVec::from_elem(validator_set.len(), false)),
signature: validator::AggregateSignature::default(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions node/libs/roles/src/validator/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl PrepareQC {
.index(&signed_message.key)
.context("Message signer isn't in the validator set")?;

prepare_qc.add(signed_message, (index, validators.len()));
prepare_qc.add(signed_message, index, validators);
}

Ok(prepare_qc)
Expand All @@ -115,7 +115,7 @@ impl CommitQC {
) -> anyhow::Result<Self> {
// Store the signed messages in a Hashmap.
let message = signed_messages[0].msg;
let mut commit_qc = CommitQC::new(message, validators.len());
let mut commit_qc = CommitQC::new(message, &validators);

for signed_message in signed_messages {
// Check that the votes are all for the same message.
Expand Down

0 comments on commit 6350384

Please sign in to comment.