Skip to content
This repository was archived by the owner on Oct 6, 2026. It is now read-only.

Commit 906d1e3

Browse files
committed
fix lazy evaluation pattern
1 parent 321ef82 commit 906d1e3

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎examples/oft-evm-move-adapters/sources/shared_oft/oft_impl_config.move‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ module oft::oft_impl_config {
216216
public(friend) fun checkpoint_rate_limit_in_flight(eid: u32, timestamp: u64) acquires Config {
217217
let inflight = in_flight_at_time(eid, timestamp);
218218
let rate_limit = table::borrow_mut(&mut store_mut().rate_limit_by_eid, eid);
219-
rate_limit.in_flight_on_last_update = inflight;
219+
// Cap in_flight_on_last_update to the current limit to prevent it from exceeding the limit
220+
// when the limit is lowered
221+
rate_limit.in_flight_on_last_update = min(inflight, rate_limit.limit);
220222
rate_limit.last_update = timestamp;
221223
}
222224

@@ -250,7 +252,8 @@ module oft::oft_impl_config {
250252
let rate_limit = *table::borrow(&store().rate_limit_by_eid, eid);
251253
if (timestamp > rate_limit.last_update) {
252254
// If the timestamp is greater than the last update, calculate the decayed in-flight amount
253-
let elapsed = min(timestamp - rate_limit.last_update, rate_limit.window_seconds);
255+
// Remove min() cap to allow decay beyond one window when in_flight exceeds limit
256+
let elapsed = timestamp - rate_limit.last_update;
254257
let decay = ((((elapsed as u128) * (rate_limit.limit as u128)) / (rate_limit.window_seconds as u128)) as u64);
255258

256259
// Ensure the decayed in-flight amount is not negative

0 commit comments

Comments
 (0)