This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
Replies: 1 comment
-
Closing as duplicate of stacks-network/sbtc#321 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The sBTC SIP calls for there to be at most one in-flight withdrawal transaction at any given time. Each withdrawal fulfillment transaction on Bitcoin can fulfill many withdrawal requests on Stacks via batching (this isn't in the SIP yet, but it's easy to describe and easy to implement).
However, what if there are more withdrawal requests pending than TXOs that can fit in a relay-policy-conforming Bitcoin transaction? The solution would be to send multiple withdrawal transactions which consume unconfirmed UTXOs from already-sent (but not confirmed) withdrawal transactions. Assuming that an optimal scheduling can be found, then given that the maximum unconfirmed UTXO chaining depth is 25 and the maximum number of TXOs is 200 (I'm guessing this number), we could fulfill at most 200**(25 - 1) withdraw requests without waiting for confirmation. The Stackers would create a UTXO fan-out tree of depth 24, where each transaction funded 200 additional UTXOs. The tree nodes at depth 25 would spend these UTXOs to fulfill withdraw requests. This means that, in theory, we'd always have sufficient withdraw-processing capacity.
If we consider the task of processing N pending withdrawals, and if we assume that we are always willing to spend all of the BTC wallet's UTXOs each time we proceed to process them, then I think this sketch of an algorithm would suffice:
I'm eliding some details above, but they're straight-forward. In particular, the fee calculation isn't shown, but this can be deduced by the size of the transaction and the going fee set in
.sbtc
. I'm sure there are bugs and edge cases in the above, but the gist of the idea is that if we can't fit all pending withdrawals into a single batched tx, we can build up a tree of intermediate Bitcoin transactions that we can then immediately spend fulfill all withdrawal requests. The intermediate Bitcoin transactions' UTXOs are all consumed by their children nodes, terminating with the withdrawal fulfillment transaction. The last withdrawal fulfillment transaction creates a single change address with the remaining wallet balance.Beta Was this translation helpful? Give feedback.
All reactions