fix: conditionally emit TTL extension event; add test for healthy TTL - #694
Open
Eeboade wants to merge 2 commits into
Open
fix: conditionally emit TTL extension event; add test for healthy TTL#694Eeboade wants to merge 2 commits into
Eeboade wants to merge 2 commits into
Conversation
- Added TTL_EXTENSION_THRESHOLD constant (100 ledgers) to gate event emission - Modified extend_creator_ttl to only emit TTL_EXTENDED_EVENT_NAME when the remaining TTL is below the threshold, keeping extend_ttl SDK calls unconditional - Added integration test test_no_ttl_extension_event_when_ttl_healthy verifying: - No TTL extension event is emitted when TTL is well above threshold - Buy event is still present (transaction succeeded) - Creator storage TTL unchanged after the buy - Test uses TTL value at least 2x the extension threshold
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.
Closes #649
Summary
Fixes the TTL extension logic so that a
TTL_EXTENDED_EVENT_NAMEevent is only emitted when the creator's storage TTL actually needs extension (remaining TTL drops belowTTL_EXTENSION_THRESHOLD). Adds an integration test confirming no event is emitted when TTL is healthy.Problem
The
extend_creator_ttlfunction unconditionally emitted attl_extevent on every successful buy or sell, even when the creator's storage TTL was already well above the minimum threshold. This polluted event logs with noisy, unnecessary events that indexers and off-chain consumers had to filter out.Changes
creator-keys/src/lib.rsTTL_EXTENSION_THRESHOLDconstant (100ledgers) — the minimum remaining TTL below which a TTL extension event is emitted.extend_creator_ttlto:extend_ttl(usingget_ttl).ttl::should_extend(ttl_before, TTL_EXTENSION_THRESHOLD).extend_ttlon all storage keys — the Soroban SDK call is a no-op when TTL is already healthy, preserving the existing on-chain behavior.TTL_EXTENDED_EVENT_NAMEevent when the check above returnstrue.creator-keys/tests/ttl_extension_on_buy.rstest_no_ttl_extension_event_when_ttl_healthyintegration test that:TTL_EXTENSION_THRESHOLD.ttl_extevent is present among emitted events.buyevent is present confirming the transaction succeeded.Acceptance Criteria
Testing
cargo fmt --all -- --checkcargo clippy --workspace --all-targets -- -D warningscargo test --workspaceNote: All existing TTL tests (
test_buy_extends_creator_ttl,test_ttl_extension_event_topics_and_payload,test_ttl_not_extended_when_already_high,test_sell_extends_creator_ttl_after_successful_sell,test_failed_sell_does_not_extend_creator_ttl) remain compatible because:should_extendreturnstrueand the event is still emitted.extend_ttlSDK calls happen unconditionally — only event emission is gated.Checklist
creator-keysunit/integration tests for every changed contract behavior, including failure paths for new or reachableContractErrorvariantscargo fmt --all -- --check,cargo clippy --workspace --all-targets -- -D warnings, andcargo test --workspace, or explained exactly why a command was not rundocs/storage-key-invariants.md; any storage layout change includes a migration/backward-compatibility notedocs/contract-event-conventions.md, or documented the breaking change and versioning plan