feat(contract): use LOW_WATERMARK threshold for TTL bumps - #902
Open
Adjutant500 wants to merge 1 commit into
Open
feat(contract): use LOW_WATERMARK threshold for TTL bumps#902Adjutant500 wants to merge 1 commit into
Adjutant500 wants to merge 1 commit into
Conversation
Replace unconditional extend_ttl(&key, MAX_TTL, MAX_TTL) calls with the threshold form extend_ttl(&key, LOW_WATERMARK, MAX_TTL) in both the registry and agents contracts. The host skips the bump (and charges nothing) when remaining TTL already exceeds LOW_WATERMARK, so rent is only paid when the entry has genuinely decayed into the lower half of its lifetime window. This halves the worst-case cost on the hot update_reputation path (Service + LastVote bumped per vote) and record_payment path (Agent + Policy bumped per call). Constants added: - Registry: LOW_WATERMARK = 1_555_200 (~90 days, half of MAX_TTL 3_110_400) - Agents: LOW_WATERMARK = 50_000_000 (half of MAX_TTL 100_000_000) Test-only extend_ttl(TEST_MAX_TTL, TEST_MAX_TTL) calls in storage-seeding helpers are unchanged — they are not production rent paths. Docs updated: storage-layout.md TTL columns, TTL classes section, and README hackathon section now accurately describe threshold semantics.
|
@Adjutant500 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Here's a PR description you can paste in:
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────
feat(contract): use LOW_WATERMARK threshold for TTL bumps
What
Replaces every extend_ttl(&key, MAX_TTL, MAX_TTL) call in both Soroban contracts with the threshold form
extend_ttl(&key, LOW_WATERMARK, MAX_TTL).
Two new constants are added:
┌─────────────────────────────────────┬───────────────────────┬──────────────────────┐
│ Contract │ MAX_TTL │ LOW_WATERMARK │
├─────────────────────────────────────┼───────────────────────┼──────────────────────┤
│ Registry (contract/src/lib.rs) │ 3_110_400 (~180 days) │ 1_555_200 (~90 days) │
├─────────────────────────────────────┼───────────────────────┼──────────────────────┤
│ Agents (contract/agents/src/lib.rs) │ 100_000_000 │ 50_000_000 │
└─────────────────────────────────────┴───────────────────────┴──────────────────────┘
Both watermarks are set at ½ × MAX_TTL.
Why
The previous unconditional bump charged the caller for the full TTL window on every write, even when the entry's
remaining TTL was, say, 179 days and almost nothing had decayed. The threshold form tells the host: only perform
the bump (and bill the rent) if remaining TTL has actually fallen below LOW_WATERMARK. This halves the worst-case
rent cost on the two hottest paths:
What is not changed
extend_ttl(TEST_MAX_TTL, TEST_MAX_TTL) calls inside #[cfg(test)] storage-seeding helpers are left as-is — those
are direct test setup writes, not production rent paths, and they need the full value to satisfy the ledger mock.
Docs
added; "TTL classes" section rewritten
Testing
Existing test suite covers update_reputation and record_payment behaviour. No test logic was changed; all tests
should pass once the Rust toolchain is available in CI.
Closes #297