Skip to content

feat: merge large utxos#29

Open
frolvanya wants to merge 2 commits into
mainfrom
feat/merge-large-utxos
Open

feat: merge large utxos#29
frolvanya wants to merge 2 commits into
mainfrom
feat/merge-large-utxos

Conversation

@frolvanya

Copy link
Copy Markdown
Contributor

No description provided.

@frolvanya
frolvanya requested a review from a team as a code owner May 26, 2026 08:34
@frolvanya
frolvanya requested a review from Copilot May 26, 2026 08:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ActiveUtxoManagement config into optional small / large sub-blocks and updates the example TOML accordingly.
  • Implements large-merge decisioning using a top‑N balance sum gate and routes the correct merge_largest flag + per-mode fee/max-input settings.
  • Adds unit tests for merge decision logic and top‑N sum computation; bumps omni-relayer version to 0.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;
}
}
};

Comment thread omni-relayer/src/main.rs
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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants