Skip to content

Commit

Permalink
[resharding] Check proof size limit while reading delayed receipts
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyan-gupta committed Jan 11, 2025
1 parent 6e62db1 commit f9273dd
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions runtime/runtime/src/congestion_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,16 +804,24 @@ impl<'a> DelayedReceiptQueueWrapper<'a> {
) -> Result<Option<ReceiptOrStateStoredReceipt>, RuntimeError> {
// While processing receipts, we need to keep track of the gas and bytes
// even for receipts that may be filtered out due to a resharding event
while let Some(receipt) = self.queue.pop_front(trie_update)? {
let delayed_gas = receipt_congestion_gas(&receipt, &config)?;
let delayed_bytes = receipt_size(&receipt)? as u64;
self.removed_delayed_gas = safe_add_gas(self.removed_delayed_gas, delayed_gas)?;
self.removed_delayed_bytes = safe_add_gas(self.removed_delayed_bytes, delayed_bytes)?;

// TODO(resharding): The filter function check here is bypassing the limit check for state witness.
// Track gas and bytes for receipt above and return only receipt that belong to the shard.
if self.receipt_filter_fn(&receipt) {
return Ok(Some(receipt));
loop {
// Check proof size limit before each receipt is popped.
if trie_update.trie.check_proof_size_limit_exceed() {
break;
}
if let Some(receipt) = self.queue.pop_front(trie_update)? {
let delayed_gas = receipt_congestion_gas(&receipt, &config)?;
let delayed_bytes = receipt_size(&receipt)? as u64;
self.removed_delayed_gas = safe_add_gas(self.removed_delayed_gas, delayed_gas)?;
self.removed_delayed_bytes =
safe_add_gas(self.removed_delayed_bytes, delayed_bytes)?;

// Track gas and bytes for receipt above and return only receipt that belong to the shard.
if self.receipt_filter_fn(&receipt) {
return Ok(Some(receipt));
}
} else {
break;
}
}
Ok(None)
Expand Down

0 comments on commit f9273dd

Please sign in to comment.