Skip to content

Commit

Permalink
Merge pull request #266 from chainbound/nico/fix/constraints-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Bostoen authored Oct 4, 2024
2 parents 1db6847 + 5adefe7 commit 40bdd47
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions bolt-boost/src/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,16 @@ impl ConstraintsCache {

let message_with_data = ConstraintsWithProofData::try_from(constraints)?;

if let Some(cs) = self.cache.write().get_mut(&slot) {
let mut cache = self.cache.write();
if let Some(cs) = cache.get_mut(&slot) {
if cs.len() >= MAX_CONSTRAINTS_PER_SLOT {
error!("Max constraints per slot reached for slot {}", slot);
return Err(Error::LimitReached(slot));
}

cs.push(message_with_data);
} else {
self.cache.write().insert(slot, vec![message_with_data]);
cache.insert(slot, vec![message_with_data]);
}

metrics::CONSTRAINTS_CACHE_SIZE.inc();
Expand Down Expand Up @@ -127,15 +128,15 @@ mod tests {
transactions: vec![tx],
};

cache.insert(0, constraints.clone()).unwrap();

assert!(cache.conflicts_with(&0, &constraints).is_none());
assert!(cache.conflicts_with(&1, &constraints).is_none());

cache.insert(0, constraints.clone()).unwrap();

assert!(matches!(
cache.conflicts_with(&0, &constraints),
Some(Conflict::DuplicateTransaction)
));

assert!(cache.conflicts_with(&1, &constraints).is_none());
}
}

0 comments on commit 40bdd47

Please sign in to comment.