Skip to content

Conversation

@gregorydemay
Copy link
Contributor

@gregorydemay gregorydemay commented Dec 1, 2025

Improve the efficiency of the ckBTC minter when handling withdrawals, where the main cost driver in terms of number of instructions is lead by finding a suitable subset of UTXOs that can be used in a Bitcoin transaction. Using the benchmarks introduced in #7782, the number of instructions required to prepare an unsigned transaction is reduced by a factor 5 to more than 600 on mainnet, depending on the withdrawal amount.

The main optimization consists of storing the UTXOs being sorted by value, instead of the canonical order defined on ic-btc-interface::Utxo consisting of the lexicographic order on OutPoint.

Bench Before After Reduction factor
build_unsigned_transaction_1_50k_sats 14,675,909 2,691,537 5
build_unsigned_transaction_2_100k_sats 14,675,757 2,691,629 5
build_unsigned_transaction_3_1m_sats 13,738,959 2,692,824 5
build_unsigned_transaction_4_10m_sats 14,282,438 2,693,220 5
build_unsigned_transaction_5_1_btc 416,462,644 3,121,724 133
build_unsigned_transaction_6_10_btc 4,916,848,618 7,842,419 626

@github-actions github-actions bot added the perf label Dec 1, 2025
# Conflicts:
#	rs/bitcoin/ckbtc/minter/canbench/results.yml
#	rs/bitcoin/ckbtc/minter/src/lib.rs
@gregorydemay gregorydemay added the CI_ALL_BAZEL_TARGETS Runs all bazel targets and uploads them to S3 label Dec 1, 2025
@gregorydemay gregorydemay changed the title perf(ckbtc): Reduce the number of instructions to build an unsigned transaction by at least 100x perf(ckbtc): Reduce the number of instructions to build an unsigned transaction by a factor 5x to 600x Dec 1, 2025
@gregorydemay gregorydemay marked this pull request as ready for review December 1, 2025 13:31
@gregorydemay gregorydemay requested a review from a team as a code owner December 1, 2025 13:31
@gregorydemay gregorydemay added this pull request to the merge queue Dec 3, 2025
Merged via the queue into master with commit bc357af Dec 3, 2025
40 checks passed
@gregorydemay gregorydemay deleted the gdemay/DEFI-2518-sort-utxos branch December 3, 2025 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI_ALL_BAZEL_TARGETS Runs all bazel targets and uploads them to S3 @defi-team perf

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants