feat(splitter): implement bounded cascade distribution helper - #275
Closed
Opulencechuks wants to merge 4 commits into
Closed
feat(splitter): implement bounded cascade distribution helper#275Opulencechuks wants to merge 4 commits into
Opulencechuks wants to merge 4 commits into
Conversation
Draining a nested split tree currently needs one distribute call per node. This change introduces a `distribute_cascade` function that distributes a parent split and recursively distributes any freshly-credited direct children (and their children, etc.) in a single call. The cascade is bounded by a `max_depth` parameter up to `MAX_CASCADE_DEPTH` (5) to protect against Soroban gas limit exhaustion. A private helper `distribute_node` is extracted to reuse the balance-draining logic. Unit tests cover a two-level tree, depth bounds, and maximum depth limits.
Contributor
|
@Opulencechuks kindly resolve conflicts |
Contributor
|
Heads up: this looks like the same feature as #284 (both titled "implement bounded cascade distribution helper"), and equivalent functionality ( |
Contributor
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 #49
Pull Request Description
Draining a nested split tree currently needs one distribute call per node. This change introduces a
distribute_cascadefunction that distributes a parent split and recursively distributes any freshly-credited direct children (and their children, etc.) in a single call.The cascade is bounded by a
max_depthparameter up toMAX_CASCADE_DEPTH(5) to protect against Soroban gas limit exhaustion.A private helper
distribute_nodeis extracted to reuse the balance-draining logic. Unit tests cover a two-level tree, depth bounds, and maximum depth limits.What this changes
distribute_nodefunction. Added a recursive helperdistribute_recursive.distribute_cascade(env: Env, id: u64, token: Address, max_depth: u32) -> Result<i128, Error>on theSplittercontract.MAX_CASCADE_DEPTH(5) to limit the recursion and prevent stack/gas exhaustion.Error::MaxDepthExceeded(Code 13) when the specified recursion depth exceeds the allowed maximum.Why
Draining nested split trees previously required a separate external
distributeinvocation for each individual node in the tree. This cascade helper improves UX by allowing client applications to route and drain multiple levels of a tree in a single, atomic on-chain call.Checklist
cargo fmt --allandcargo clippy --all-targets -- -D warningspasscargo testpasses