Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add advanced rbf guide #237

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions docs/vault/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,55 @@ If your Vault clients holds at least _some BTC in custody_, you have two options

- **Replace**: leaving through _replace_, requires you to request being replaced by another Vault. You can request to be replaced through the Vault dashboard by replace 100% of the BTC that is locked with the Vault and waiting for other Vaults to accept the request. Once the replace request is accepted, your Vault client will execute the replace request by sending BTC to the accepting Vault and executing the request on the parachain.
- **Redeem**, leaving through _redeem_ requires you to wait for a user or yourself to redeem the entire amount of BTC that the Vault has in custody. Only after you have 0 BTC, can the Vault client withdraw its entire collateral. If you redeem with your own Vault, the Vault will not receive fees for this such that 0 BTC remains in your Vault client.

## Replace-By-Fee

When the Bitcoin mempool is significantly congested it may take some time for redeem payments to be included on mainnet. In the worst case this could lead to a theft report on the parachain if the request period has elapsed. For this reason, all transactions made by the Vault should be "bip125-replaceable" to allow Vault operators to set a higher fee.

!> "Here be dragons" - please only use this guide as a last resort. You might consider third-party transaction acceleration first.
gregdhill marked this conversation as resolved.
Show resolved Hide resolved

Note the `$TXID` which is the transaction identifier of that which will be replaced.

### Simple (Not Recommended)

The easiest way to bump the transaction fees is by using the `bumpfee` command.
gregdhill marked this conversation as resolved.
Show resolved Hide resolved

```shell
bitcoin-cli bumpfee $TXID
```

This is not recommended however since it may insert an additional (unregistered) change address.

### Advanced (Recommended)

This approach is slightly more involved but the following commands will reduce some overhead.

You will need to set `-rpcwallet` when using `bitcoin-cli`. For example if the transaction was made by your `KSM-KBTC` wallet this should be `$KEYNAME-KSM-KBTC` where `$KEYNAME` is the `AccountId` your Vault would point to.

Before continuing you will need to set the `$CHANGE_ADDRESS` to an address already registered by your Vault.

```shell
bitcoin-cli listunspent
...

CHANGE_ADDRESS="<INSERT_HERE>"
gregdhill marked this conversation as resolved.
Show resolved Hide resolved
```

Review the optimal `feeRate` in BTC/kvB and set `$FEE_RATE` (for example `0.0001`).

?> This was only tested on `regtest` so caution is to be advised for `mainnet` usage.

```shell
# get the previous inputs
rawinputs=$(bitcoin-cli decoderawtransaction $(bitcoin-cli getrawtransaction $TXID) | jq '.vin[] | {txid, vout, sequence}' | jq -cs)
# get the previous outputs
rawoutputs=$(bitcoin-cli decoderawtransaction $(bitcoin-cli getrawtransaction $TXID) | jq '.vout[] | {value, address: .scriptPubKey.address} | ({(.address): .value})' | jq -cs)
# use those to create a new transaction
rawtx=$(bitcoin-cli createrawtransaction $rawinputs $rawoutputs)
# fund that tx with a better fee rate
fundedtx=$(bitcoin-cli fundrawtransaction $rawtx "{\"changeAddress\": \"$CHANGE_ADDRESS\", \"feeRate\": $FEE_RATE}" | jq -r .hex)
Copy link
Member

Choose a reason for hiding this comment

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

You are counting on all addresses in the wallet to have been registered to the parachain, which is most cases will be true, but it's still a risky assumption. If e.g. a non-empty wallet was used when first starting the vault this would not hold (we do tell vaults not to do this.. but still)

Copy link
Member Author

Choose a reason for hiding this comment

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

Theft reporting was removed here, addresses are no longer required to be registered.

# sign that with your wallet
signedtx=$(bitcoin-cli signrawtransactionwithwallet $fundedtx | jq -r .hex)
# finally broadcast the replaced tx
bitcoin-cli sendrawtransaction $signedtx
```