Skip to content

Commit

Permalink
fix add_proof
Browse files Browse the repository at this point in the history
  • Loading branch information
fgimenez committed Nov 22, 2024
1 parent 4daa927 commit e734d3f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions crates/engine/tree/src/tree/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,22 @@ impl ProofSequencer {

/// Adds a proof and returns all sequential proofs if we have a continuous sequence
pub(crate) fn add_proof(&mut self, sequence: u64, proof: MultiProof) -> Vec<MultiProof> {
self.next_sequence = self.next_sequence.max(sequence + 1);
if sequence < self.next_sequence {
return vec![proof];
}

// Insert the new proof into pending proofs
self.pending_proofs.insert(sequence, proof);
let mut ready_proofs = Vec::with_capacity(self.pending_proofs.len());

while let Some((&lowest_seq, _)) = self.pending_proofs.iter().next() {
if let Some(proof) = self.pending_proofs.remove(&lowest_seq) {
ready_proofs.push(proof);
}
let mut consecutive_proofs = Vec::with_capacity(self.pending_proofs.len());

// Keep taking proofs from pending_proofs as long as they form a consecutive sequence
while let Some(proof) = self.pending_proofs.remove(&self.next_sequence) {
consecutive_proofs.push(proof);
self.next_sequence += 1;
}

ready_proofs
consecutive_proofs
}

/// Returns true if we still have pending proofs
Expand Down

0 comments on commit e734d3f

Please sign in to comment.