feat: merge large utxos#29
Open
frolvanya wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the relayer’s active UTXO consolidation logic to support two configurable modes—“small-merge” (merge smallest UTXOs when pool count is high) and “large-merge” (merge largest UTXOs when the top-of-pool liquidity is too low)—with tie-breaking in favor of large-merge.
Changes:
- Restructures
ActiveUtxoManagementconfig into optionalsmall/largesub-blocks and updates the example TOML accordingly. - Implements large-merge decisioning using a top‑N balance sum gate and routes the correct
merge_largestflag + per-mode fee/max-input settings. - Adds unit tests for merge decision logic and top‑N sum computation; bumps
omni-relayerversion to0.6.18.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| omni-relayer/src/startup/active_utxo_manager.rs | Adds merge decision logic (small vs large), computes top‑N sum for large-merge gating, and includes unit tests. |
| omni-relayer/src/main.rs | Skips spawning the active UTXO manager when neither mode is configured. |
| omni-relayer/src/config.rs | Introduces SmallMerge and LargeMerge config structs under ActiveUtxoManagement. |
| omni-relayer/example-mainnet-config.toml | Updates sample configuration to the new nested small/large structure with comments. |
| omni-relayer/Cargo.toml | Bumps relayer crate version. |
| Cargo.lock | Updates locked version for omni-relayer. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+89
to
112
| // If large-merge is configured we need the full UTXO map to compute | ||
| // the top-N sum; otherwise the cheap count call is enough. | ||
| let (utxo_count, top_sum) = if let Some(large) = settings.large.as_ref() { | ||
| let utxos = match near_bridge_client.get_utxos(chain).await { | ||
| Ok(u) => u, | ||
| Err(err) => { | ||
| warn!("Active UTXO manager: failed to fetch UTXOs for {chain:?}: {err:?}"); | ||
| continue; | ||
| } | ||
| }; | ||
| let count = u32::try_from(utxos.len()).unwrap_or(u32::MAX); | ||
| let mut balances: Vec<u64> = utxos.values().map(|u| u.balance).collect(); | ||
| let sum = top_n_sum(&mut balances, large.top_n_window); | ||
| (count, sum) | ||
| } else { | ||
| match near_bridge_client.get_utxo_num(chain).await { | ||
| Ok(n) => (n, None), | ||
| Err(err) => { | ||
| warn!("Active UTXO manager: failed to fetch UTXO count for {chain:?}: {err:?}"); | ||
| continue; | ||
| } | ||
| } | ||
| }; | ||
|
|
| let Some(active_utxo_management) = config.active_utxo_management(chain).cloned() else { | ||
| continue; | ||
| }; | ||
| if active_utxo_management.small.is_none() && active_utxo_management.large.is_none() { |
Comment on lines
+491
to
499
| /// Size of the "top of the pool" window (by balance) whose sum is checked | ||
| /// against `top_n_sum_threshold`. | ||
| pub top_n_window: u32, | ||
| /// Trigger `active_utxo_management` with `merge_largest = true` when the | ||
| /// sum of the top `top_n_window` UTXO balances is strictly less than this | ||
| /// value. Denominated in chain-native base units (sats for BTC, zatoshis | ||
| /// for Zcash). | ||
| pub top_n_sum_threshold: u64, | ||
| /// Optional fixed fee rate (sats/kvB) to pass to `active_utxo_management`. |
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.
No description provided.