Skip to content

Commit

Permalink
splice: first pass on splice_out command
Browse files Browse the repository at this point in the history
Added splice_out RPC command and a simple test of it as well.

ChangeLog-Added: splice_out command added for doing a splice out more easily.
  • Loading branch information
ddustin committed Oct 15, 2023
1 parent e936eea commit 41f58ea
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 36 deletions.
8 changes: 8 additions & 0 deletions bitcoin/test/run-tx-bitcoin_tx_2of2_input_witness_weight.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ bool psbt_finalize(struct wally_psbt *psbt UNNEEDED)
struct amount_sat psbt_input_get_amount(const struct wally_psbt *psbt UNNEEDED,
size_t in UNNEEDED)
{ fprintf(stderr, "psbt_input_get_amount called!\n"); abort(); }
/* Generated stub for psbt_input_get_weight */
size_t psbt_input_get_weight(const struct wally_psbt *psbt UNNEEDED,
size_t in UNNEEDED)
{ fprintf(stderr, "psbt_input_get_weight called!\n"); abort(); }
/* Generated stub for psbt_output_get_weight */
size_t psbt_output_get_weight(const struct wally_psbt *psbt UNNEEDED,
size_t out UNNEEDED)
{ fprintf(stderr, "psbt_output_get_weight called!\n"); abort(); }
/* Generated stub for psbt_input_set_wit_utxo */
void psbt_input_set_wit_utxo(struct wally_psbt *psbt UNNEEDED, size_t in UNNEEDED,
const u8 *scriptPubkey UNNEEDED, struct amount_sat amt UNNEEDED)
Expand Down
14 changes: 14 additions & 0 deletions bitcoin/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,20 @@ u8 *linearize_wtx(const tal_t *ctx, const struct wally_tx *wtx)
return arr;
}

size_t wally_psbt_weight(const struct wally_psbt *psbt)
{
size_t weight = bitcoin_tx_core_weight(psbt->num_inputs,
psbt->num_outputs);

for (size_t i = 0; i < psbt->num_inputs; i++)
weight += psbt_input_get_weight(psbt, i);

for (size_t i = 0; i < psbt->num_outputs; i++)
weight += psbt_output_get_weight(psbt, i);

return weight;
}

size_t wally_tx_weight(const struct wally_tx *wtx)
{
size_t weight;
Expand Down
1 change: 1 addition & 0 deletions bitcoin/tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ u8 *linearize_wtx(const tal_t *ctx, const struct wally_tx *wtx);
/* Get weight of tx in Sipa; assumes it will have witnesses! */
size_t bitcoin_tx_weight(const struct bitcoin_tx *tx);
size_t wally_tx_weight(const struct wally_tx *wtx);
size_t wally_psbt_weight(const struct wally_psbt *psbt);

/* Allocate a tx: you just need to fill in inputs and outputs (they're
* zeroed with inputs' sequence_number set to FFFFFFFF) */
Expand Down
13 changes: 13 additions & 0 deletions contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,19 @@ def openchannel_abort(self, channel_id):
}
return self.call("openchannel_abort", payload)

def splice_out(self, chan_id, amount, feerate_per_kw=None, force_feerate=None, initialpsbt=None, locktime=None, sign_first=None):
""" Initiate a splice """
payload = {
"channel_id": chan_id,
"amount": amount,
"feerate_per_kw": feerate_per_kw,
"force_feerate": force_feerate,
"initialpsbt": initialpsbt,
"locktime": locktime,
"sign_first": sign_first,
}
return self.call("splice_out", payload)

def splice_init(self, chan_id, amount, initialpsbt=None, feerate_per_kw=None):
""" Initiate a splice """
payload = {
Expand Down
40 changes: 40 additions & 0 deletions doc/schemas/splice_out.request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"required": [
"channel_id",
"amount"
],
"added": "v23.11",
"properties": {
"channel_id": {
"type": "string",
"description": "the channel id of the channel to take funds from"
},
"amount": {
"type": "msat",
"description": "a positive amount of satoshis to be taken from the channel"
},
"initialpsbt": {
"type": "string",
"description": "the (optional) base 64 encoded PSBT to begin with. If not specified, one will be generated automatically"
},
"feerate_per_kw": {
"type": "u32",
"description": "the miner fee we will pay from our channel funds. It is calculated by `feerate_per_kw` * our_bytes_in_splice_tx / 1000"
},
"force_feerate": {
"type": "boolean",
"description": "by default splices will fail if the fee provided looks too high. This is to protect against accidentally setting your fee higher than intended. Set `force_feerate` to true to skip this saftey check"
},
"locktime": {
"type": "u32",
"description": "the locktime to use if initialpsbt is not specified."
},
"sign_first": {
"type": "bool",
"description": "offer to our peer to sign the splice first."
}
}
}
20 changes: 20 additions & 0 deletions doc/schemas/splice_out.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"required": [
"tx",
"txid"
],
"added": "v23.11",
"properties": {
"tx": {
"type": "hex",
"description": "The hex representation of the final transaction that is published"
},
"txid": {
"type": "txid",
"description": "The txid is of the final transaction"
}
}
}
Loading

0 comments on commit 41f58ea

Please sign in to comment.