Skip to content

Commit

Permalink
Change bump_object_execution_cost to use saturating add and allow 0-c…
Browse files Browse the repository at this point in the history
…ost tx (#20368)

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
aschran authored Nov 21, 2024
1 parent c138be2 commit fbe16db
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,14 @@ impl SharedObjectCongestionTracker {
let start_cost = self.compute_tx_start_at_cost(&shared_input_objects);

// Allow tx if it's within budget.
if start_cost + tx_cost <= self.max_accumulated_txn_cost_per_object_in_commit {
if start_cost.saturating_add(tx_cost) <= self.max_accumulated_txn_cost_per_object_in_commit
{
return None;
}

// Allow over-budget tx if it's not above the overage limit.
if start_cost <= self.max_accumulated_txn_cost_per_object_in_commit
&& start_cost + tx_cost
&& start_cost.saturating_add(tx_cost)
<= self
.max_accumulated_txn_cost_per_object_in_commit
.saturating_add(self.max_txn_cost_overage_per_object_in_commit)
Expand Down Expand Up @@ -210,12 +211,12 @@ impl SharedObjectCongestionTracker {

let shared_input_objects: Vec<_> = cert.shared_input_objects().collect();
let start_cost = self.compute_tx_start_at_cost(&shared_input_objects);
let end_cost = start_cost + tx_cost;
let end_cost = start_cost.saturating_add(tx_cost);

for obj in shared_input_objects {
if obj.mutable {
let old_end_cost = self.object_execution_cost.insert(obj.id, end_cost);
assert!(old_end_cost.is_none() || old_end_cost.unwrap() < end_cost);
assert!(old_end_cost.is_none() || old_end_cost.unwrap() <= end_cost);
}
}
}
Expand Down

0 comments on commit fbe16db

Please sign in to comment.