Skip to content

splicing: Adds the features needed to enable collaborative splicing & resizing of active channels. #6253

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

Merged
merged 13 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 11 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@ jobs:
TEST_NETWORK: regtest
DEVELOPER: 1
EXPERIMENTAL_DUAL_FUND: 1
# And splicing!
- NAME: splicing
CFG: gcc-dev1
TEST_DB_PROVIDER: sqlite3
COMPILER: gcc
TEST_NETWORK: regtest
DEVELOPER: 1
EXPERIMENTAL_DUAL_FUND: 1
EXPERIMENTAL_SPLICING: 1
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -290,6 +299,7 @@ jobs:
DEVELOPER: ${{ matrix.DEVELOPER }}
COMPILER: ${{ matrix.COMPILER }}
EXPERIMENTAL_DUAL_FUND: ${{ matrix.EXPERIMENTAL_DUAL_FUND }}
EXPERIMENTAL_SPLICING: ${{ matrix.EXPERIMENTAL_SPLICING }}
COMPAT: 1
CFG: ${{ matrix.CFG }}
SLOW_MACHINE: 1
Expand Down Expand Up @@ -391,7 +401,7 @@ jobs:
- NAME: ASan/UBSan (01/10)
PYTEST_OPTS: --test-group=1 --test-group-count=10
- NAME: ASan/UBSan (02/10)
PYTEST_OPTS: --test-group=2 --test-group-count=10
PYTEST_OPTS: --test-group=2 --test-group-count=10 -n 1
- NAME: ASan/UBSan (03/10)
PYTEST_OPTS: --test-group=3 --test-group-count=10
- NAME: ASan/UBSan (04/10)
Expand Down
11 changes: 11 additions & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
"ListpeerchannelsChannelsState": {
"AWAITING_UNILATERAL": 6,
"CHANNELD_AWAITING_LOCKIN": 1,
"CHANNELD_AWAITING_SPLICE": 11,
"CHANNELD_NORMAL": 2,
"CHANNELD_SHUTTING_DOWN": 3,
"CLOSINGD_COMPLETE": 5,
Expand Down Expand Up @@ -1131,6 +1132,7 @@
"ListPeerChannels.channels[].inflight[].funding_txid": 1,
"ListPeerChannels.channels[].inflight[].our_funding_msat": 5,
"ListPeerChannels.channels[].inflight[].scratch_txid": 6,
"ListPeerChannels.channels[].inflight[].splice_amount": 7,
"ListPeerChannels.channels[].inflight[].total_funding_msat": 4
},
"ListpeerchannelsChannelsState_changes": {
Expand Down Expand Up @@ -1241,6 +1243,7 @@
"ListPeers.peers[].channels[].inflight[].funding_txid": 1,
"ListPeers.peers[].channels[].inflight[].our_funding_msat": 5,
"ListPeers.peers[].channels[].inflight[].scratch_txid": 6,
"ListPeers.peers[].channels[].inflight[].splice_amount": 7,
"ListPeers.peers[].channels[].inflight[].total_funding_msat": 4
},
"ListpeersPeersLog": {
Expand Down Expand Up @@ -4078,6 +4081,10 @@
"added": "v23.02",
"deprecated": false
},
"ListPeerChannels.channels[].inflight[].splice_amount": {
"added": "v23.08",
"deprecated": false
},
"ListPeerChannels.channels[].inflight[].total_funding_msat": {
"added": "v23.02",
"deprecated": false
Expand Down Expand Up @@ -4422,6 +4429,10 @@
"added": "pre-v0.10.1",
"deprecated": false
},
"ListPeers.peers[].channels[].inflight[].splice_amount": {
"added": "v23.08",
"deprecated": false
},
"ListPeers.peers[].channels[].inflight[].total_funding_msat": {
"added": "pre-v0.10.1",
"deprecated": false
Expand Down
46 changes: 45 additions & 1 deletion bitcoin/psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ bool psbt_is_finalized(const struct wally_psbt *psbt)
}

struct wally_psbt_input *psbt_add_input(struct wally_psbt *psbt,
struct wally_tx_input *input,
const struct wally_tx_input *input,
size_t insert_at)
{
const u32 flags = WALLY_PSBT_FLAG_NON_FINAL; /* Skip script/witness */
Expand Down Expand Up @@ -322,6 +322,15 @@ void psbt_input_set_utxo(struct wally_psbt *psbt, size_t in,
assert(wally_err == WALLY_OK);
}

void psbt_input_set_outpoint(struct wally_psbt *psbt, size_t in,
struct bitcoin_outpoint outpoint)
{
assert(in < psbt->num_inputs);
psbt->inputs[in].index = outpoint.n;
memcpy(psbt->inputs[in].txhash, &outpoint.txid,
sizeof(struct bitcoin_txid));
}

void psbt_input_set_witscript(struct wally_psbt *psbt, size_t in, const u8 *wscript)
{
int wally_err;
Expand Down Expand Up @@ -446,6 +455,28 @@ struct amount_sat psbt_input_get_amount(const struct wally_psbt *psbt,
return val;
}

size_t psbt_input_get_weight(const struct wally_psbt *psbt,
size_t in)
{
size_t weight;
const struct wally_map_item *redeem_script;

redeem_script = wally_map_get_integer(&psbt->inputs[in].psbt_fields, /* PSBT_IN_REDEEM_SCRIPT */ 0x04);

/* txid + txout + sequence */
weight = (32 + 4 + 4) * 4;
if (redeem_script) {
weight +=
(redeem_script->value_len +
varint_size(redeem_script->value_len)) * 4;
} else {
/* zero scriptSig length */
weight += varint_size(0) * 4;
}

return weight;
}

struct amount_sat psbt_output_get_amount(const struct wally_psbt *psbt,
size_t out)
{
Expand All @@ -456,6 +487,13 @@ struct amount_sat psbt_output_get_amount(const struct wally_psbt *psbt,
return amount_asset_to_sat(&asset);
}

size_t psbt_output_get_weight(const struct wally_psbt *psbt,
size_t outnum)
{
return (8 /* amount*/ + varint_size(psbt->outputs[outnum].script_len) +
psbt->outputs[outnum].script_len) * 4;
}

static void add(u8 **key, const void *mem, size_t len)
{
size_t oldlen = tal_count(*key);
Expand Down Expand Up @@ -733,6 +771,12 @@ const u8 *psbt_get_bytes(const tal_t *ctx, const struct wally_psbt *psbt,
return bytes;
}

bool validate_psbt(const struct wally_psbt *psbt)
{
size_t len;
return wally_psbt_get_length(psbt, 0, &len) == WALLY_OK;
}

struct wally_psbt *psbt_from_bytes(const tal_t *ctx, const u8 *bytes,
size_t byte_len)
{
Expand Down
14 changes: 13 additions & 1 deletion bitcoin/psbt.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct wally_tx *psbt_final_tx(const tal_t *ctx, const struct wally_psbt *psbt);
u8 *psbt_make_key(const tal_t *ctx, u8 key_subtype, const u8 *key_data);

struct wally_psbt_input *psbt_add_input(struct wally_psbt *psbt,
struct wally_tx_input *input,
const struct wally_tx_input *input,
size_t insert_at);

/* One stop shop for adding an input + metadata to a PSBT */
Expand All @@ -127,6 +127,9 @@ void psbt_input_set_wit_utxo(struct wally_psbt *psbt, size_t in,
void psbt_input_set_utxo(struct wally_psbt *psbt, size_t in,
const struct wally_tx *prev_tx);

void psbt_input_set_outpoint(struct wally_psbt *psbt, size_t in,
struct bitcoin_outpoint outpoint);

/* psbt_elements_input_set_asset - Set the asset/value fields for an
* Elements PSBT (PSET, technically */
void psbt_elements_input_set_asset(struct wally_psbt *psbt, size_t in,
Expand Down Expand Up @@ -211,6 +214,10 @@ void psbt_output_set_unknown(const tal_t *ctx,
struct amount_sat psbt_input_get_amount(const struct wally_psbt *psbt,
size_t in);

/* psbt_input_get_weight - Calculate the tx weight for input index `in` */
size_t psbt_input_get_weight(const struct wally_psbt *psbt,
size_t in);

/* psbt_output_get_amount - Returns the value of this output
*
* @psbt - psbt
Expand All @@ -219,6 +226,10 @@ struct amount_sat psbt_input_get_amount(const struct wally_psbt *psbt,
struct amount_sat psbt_output_get_amount(const struct wally_psbt *psbt,
size_t out);

/* psbt_output_get_weight - Calculate the tx weight for output index `outnum` */
size_t psbt_output_get_weight(const struct wally_psbt *psbt,
size_t outnum);

/* psbt_compute_fee - Returns value of fee for PSBT
*
* @psbt -psbt
Expand Down Expand Up @@ -266,6 +277,7 @@ struct wally_psbt *psbt_from_b64(const tal_t *ctx,
char *psbt_to_b64(const tal_t *ctx, const struct wally_psbt *psbt);
const u8 *psbt_get_bytes(const tal_t *ctx, const struct wally_psbt *psbt,
size_t *bytes_written);
bool validate_psbt(const struct wally_psbt *psbt);
struct wally_psbt *psbt_from_bytes(const tal_t *ctx, const u8 *bytes,
size_t byte_len);
void towire_wally_psbt(u8 **pptr, const struct wally_psbt *psbt);
Expand Down
13 changes: 11 additions & 2 deletions channeld/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ CHANNELD_HEADERS := \
CHANNELD_SRC := channeld/channeld.c \
channeld/commit_tx.c \
channeld/full_channel.c \
channeld/splice.c \
channeld/inflight.c \
channeld/channeld_wiregen.c \
channeld/watchtower.c

Expand All @@ -25,8 +27,13 @@ ALL_C_HEADERS += $(CHANNELD_HEADERS)
ALL_PROGRAMS += lightningd/lightning_channeld

# Here's what lightningd depends on
LIGHTNINGD_CONTROL_HEADERS += channeld/channeld_wiregen.h
LIGHTNINGD_CONTROL_OBJS += channeld/channeld_wiregen.o
LIGHTNINGD_CONTROL_HEADERS += \
channeld/channeld_wiregen.h \
channeld/inflight.h
LIGHTNINGD_CONTROL_OBJS += \
channeld/channeld_wiregen.o \
channeld/inflight.o


# Common source we use.
CHANNELD_COMMON_OBJS := \
Expand All @@ -53,6 +60,7 @@ CHANNELD_COMMON_OBJS := \
common/status_wiregen.o \
common/gossip_store.o \
common/hmac.o \
common/interactivetx.o \
common/htlc_state.o \
common/htlc_trim.o \
common/htlc_tx.o \
Expand All @@ -73,6 +81,7 @@ CHANNELD_COMMON_OBJS := \
common/ping.o \
common/psbt_keypath.o \
common/psbt_open.o \
common/psbt_internal.o \
common/private_channel_announcement.o \
common/pseudorand.o \
common/read_peer_msg.o \
Expand Down
Loading