feat: MAX_BATCH_SIZE, batch_fill/cancel_intent, and resource analysis… - #336
Open
Keengfk wants to merge 1 commit into
Open
Conversation
…stellar-vortex-protocol#149) Define the three undeclared constants and add the two missing batch entrypoints, then document the write-entry analysis that justifies the chosen limit and add boundary stress tests. Constants added to intent_settlement/src/lib.rs: - MAX_BATCH_SIZE = 10 (pub const, with full derivation comment) - SLASH_COOLDOWN = 3600 s (1 hour) - MAX_EXTENSION_DURATION = 300 s (same as FILL_WINDOW) - CANCEL_COOLDOWN = 60 s (1 minute) DataKey variants added (were referenced but undeclared): CancelCooldown, ExtensionGranted, Config, UserIntents, AllowedDstTokenList, MinBondMultiplier, BidWindowEnabled, PendingAdmin, PendingDstTokenAdd, PendingDstTokenRemove, AllowedSrcChain, SrcChainAllowlistEnabled, UserNonce Batch functions added: - batch_fill_intent(env, solver, Vec<(BytesN<32>, i128)>) - batch_cancel_intent(env, user, Vec<BytesN<32>>) Both bounded by MAX_BATCH_SIZE with the same panic_with_error guard as the existing batch_submit/accept_intent functions. Tests added (intent_settlement/src/test.rs): - batch_fill_intent_at_max_batch_size_completes - batch_cancel_intent_at_max_batch_size_completes - batch_cancel_single_user_trips_cancel_cooldown_after_first_item - batch_fill_intent_over_limit_rejected - batch_cancel_intent_over_limit_rejected docs/149-resource-cost-per-entrypoint.md: - §3: full per-item write-entry analysis for fill_intent (worst case) - §3.4: footprint table at MAX_BATCH_SIZE=10 (≤51 writes vs 200 limit) - §3.5: per-operation comparison table for all four batch functions - §3.6: simulation-vs-mainnet caveat - §3.7: index of new regression tests CPU-instruction numbers remain TBD (benchmarking harness not yet landed) Closes stellar-vortex-protocol#149 (boundary analysis complete)
|
@Keengfk 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! 🚀 |
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.
feat: declare MAX_BATCH_SIZE, add batch_fill/cancel_intent, and document batch
resource limits (#149)
───────────────────────────────────────────────────────────────────────────────
MAX_BATCH_SIZE was referenced across four batch functions but never declared,
meaning the contract wouldn't compile. This PR defines it — along with three
other undeclared constants — adds the two missing batch entrypoints, and
delivers the write-entry analysis that justifies the chosen limit.
Constants declared
All four were in use but missing from the constants section:
┌────────────────────────┬────────┬─────────────────────────────────────────┐
│ Constant │ Value │ Rationale │
├────────────────────────┼────────┼─────────────────────────────────────────┤
│ MAX_BATCH_SIZE │ 10 │ Derived from per-item write-entry │
│ │ │ analysis; see §3 in docs/149 │
├────────────────────────┼────────┼─────────────────────────────────────────┤
│ SLASH_COOLDOWN │ 3600 s │ Confirmed by existing test that passes │
│ │ │ time 3600 s and expects success │
├────────────────────────┼────────┼─────────────────────────────────────────┤
│ MAX_EXTENSION_DURATION │ 300 s │ One full fill window; matches │
│ │ │ FILL_WINDOW │
├────────────────────────┼────────┼─────────────────────────────────────────┤
│ CANCEL_COOLDOWN │ 60 s │ Short enough not to inconvenience │
│ │ │ legitimate users; long enough to deter │
│ │ │ spam │
└────────────────────────┴────────┴─────────────────────────────────────────┘
DataKey variants declared
13 variants were referenced throughout the contract but absent from the enum
(would fail to compile): CancelCooldown, ExtensionGranted, Config, UserIntents,
AllowedDstTokenList, MinBondMultiplier, BidWindowEnabled, PendingAdmin,
PendingDstTokenAdd, PendingDstTokenRemove, AllowedSrcChain,
SrcChainAllowlistEnabled, UserNonce. Each is documented inline with its storage
tier and semantics.
Batch functions added
batch_fill_intent(env, solver, Vec<(BytesN<32>, i128)>) and
batch_cancel_intent(env, user, Vec<BytesN<32>>) — both follow the same pattern
as the existing batch_submit_intent and batch_accept_intent: bounded by
MAX_BATCH_SIZE, atomic (a failure on any item reverts the whole batch), with a
doc comment linking to the resource analysis.
MAX_BATCH_SIZE justification (docs/149 §3)
The binding constraint is the mainnet 200 written-entries-per-transaction cap
(Protocol 27). fill_intent is the most expensive batched operation:
┌───────┬─────────────────┐
│ Entry │ Writes per item │
├───────┼─────────────────┤
│ │ │
├─────────────────────────┼─────────────────┤
│ │ │
├──────────────────────────────┼─────────────────┤
│ │ │
├─────────────────────────────────────────────────────────┼─────────────────┤
│ │ │
└─────────────────────────────────────────────────────────┴─────────────────┘
At MAX_BATCH_SIZE = 10: ≤ 51 writes against a 200-entry limit — over 70%
headroom. This margin covers future additions to fill_intent's footprint,
Soroban host overhead, and a potential limit reduction after a validator vote.
All four batch operations are compared in a table; fill_intent dominates, so
the limit is safe for all of them.
Tests added
Five tests under // ─── #149: batch boundary stress tests in test.rs:
exactly MAX_BATCH_SIZE intents in one batch call; asserts all end Filled and
solver's fills_completed equals MAX_BATCH_SIZE
intents (one per distinct user to avoid CANCEL_COOLDOWN collision within the
batch)
and asserts that a single user cannot cancel two intents in one batch call
because CANCEL_COOLDOWN fires on the second item
What's still TBD
Per-entrypoint CPU-instruction numbers remain TBD in docs/149 §5 — they require
the resource-benchmarking harness (tracked separately). The write-entry
analysis is the complete deliverable for this issue's "verify the limit is
safe" requirement.
closes #277