Skip to content

Splice: Interop Final (probably) with Eclair #8021

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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2fbe599
Splice: Rotating funding pubkey fix
ddustin Jan 21, 2025
fc278a7
splice: Add locked field to inflight db
ddustin Feb 1, 2025
fbc11e4
splice: Resume `splice_locked` on reestablish
ddustin Feb 1, 2025
f44daa8
Splice: Update PSBT version handling
ddustin Feb 4, 2025
e40b360
Add debug outputs and fix prevtx issue
remyers Jan 27, 2025
828387f
splice: Add splice_txid to splice_locked message
remyers Jan 22, 2025
e7aa9db
splice: Add check for correct txid in `splice_locked`
ddustin Feb 4, 2025
06a2bb4
PSBT: Fix compare to not mutate memory
ddustin Feb 7, 2025
38193d9
splice: Use clone instead of steal for PSBT
ddustin Feb 7, 2025
f3fb53a
PSBT: Change bitcoin_tx routine to use TAKES
ddustin Feb 16, 2025
df16c46
PSBT: Add audi_psbt routine
ddustin Feb 18, 2025
312db53
PSBT: tal_wally updates and docs
ddustin Feb 18, 2025
2fa0bcf
splice: Prevent user from signing an unfinal splice
ddustin Feb 18, 2025
746a1ad
PSBT: Clean up PSBT chunk allocations
ddustin Feb 18, 2025
083ec09
splice: Clean error statement
ddustin Mar 14, 2025
9dfc62b
splice: Update `our_funds` during splice_lock
ddustin Apr 17, 2025
2f196dc
splice: Allow commit_sig batch in any order
ddustin Apr 17, 2025
3fac565
splice: Update to Eclair style of reestablish
ddustin Apr 17, 2025
13f8d15
splice: Decrement `next_commitment_number` for Eclair
ddustin Apr 29, 2025
25e6f81
splice: Only send or recv commit sig if needed
ddustin Apr 30, 2025
3e6c57b
splice: Enable the receiving of splice RBF
ddustin May 1, 2025
ae7aeec
splice: Splice script should not abort on sign
ddustin May 1, 2025
9d9d6bc
splice: Enable user splice RBF
ddustin May 1, 2025
b250790
splice: Add verbose log messages for new reestablish TLV
ddustin May 1, 2025
cd03fdc
gossip: Limit announcement sigs reply
ddustin May 2, 2025
1b0eda4
splice: Update test for new reestablish behavior
ddustin May 2, 2025
8994332
splice: Add support for `tx_abort` during RBF
ddustin May 5, 2025
ededb7c
splice: Fix txid watch for splice RBF
ddustin May 5, 2025
98f6370
splice: Improve log message for handle_peer_commit_sig
ddustin May 5, 2025
537cfdf
splice: Changing encoding of TLV funding_txid
ddustin May 5, 2025
a528923
splice: Add test for splice RBF
ddustin May 5, 2025
27571a8
splice: Verbose logging for Eclair interop
ddustin May 5, 2025
f7d1ce8
splice: Message sorting should be using txid parsing
ddustin May 5, 2025
f6134b8
splice: Add more explicit error messages
ddustin May 5, 2025
9b74028
splice: Wait for mempool in tests
ddustin May 12, 2025
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
73 changes: 73 additions & 0 deletions bitcoin/psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,79 @@ struct wally_psbt *combine_psbt(const tal_t *ctx,
return combined_psbt;
}

static bool parent_or_grandparent(const tal_t *goal, const tal_t *child)
{
const tal_t *parent = tal_parent(child);
if (!parent)
return false;
return parent == goal || parent_or_grandparent(goal, parent);
}

#define NULL_OR_MATCH_P(item, parent) \
((item) == NULL || parent_or_grandparent((parent), (item)))

static void audit_map(const tal_t *ctx, const struct wally_map *map)
{
assert(NULL_OR_MATCH_P(map->items, ctx));
for (size_t i = 0; i < map->num_items; i++) {
assert(NULL_OR_MATCH_P(map->items[i].key, ctx));
assert(NULL_OR_MATCH_P(map->items[i].value, ctx));
assert(!map->items[i].key
|| tal_bytelen(map->items[i].key)
== map->items[i].key_len);
assert(!map->items[i].value
|| tal_bytelen(map->items[i].value)
== map->items[i].value_len);
}
}

void audit_psbt(const tal_t *ctx, const struct wally_psbt *psbt)
{
assert(psbt);
assert(NULL_OR_MATCH_P(psbt->tx, ctx));
assert(NULL_OR_MATCH_P(psbt->inputs, ctx));
assert(NULL_OR_MATCH_P(psbt->outputs, ctx));
audit_map(ctx, &psbt->unknowns);
audit_map(ctx, &psbt->global_xpubs);
#ifndef WALLY_ABI_NO_ELEMENTS
audit_map(ctx, &psbt->global_scalars);
#endif
for (size_t i = 0; i < psbt->num_inputs; i++) {
assert(NULL_OR_MATCH_P(psbt->inputs[i].utxo, ctx));
assert(NULL_OR_MATCH_P(psbt->inputs[i].witness_utxo, ctx));
assert(NULL_OR_MATCH_P(psbt->inputs[i].final_witness, ctx));
audit_map(ctx, &psbt->inputs[i].keypaths);
audit_map(ctx, &psbt->inputs[i].signatures);
audit_map(ctx, &psbt->inputs[i].unknowns);
audit_map(ctx, &psbt->inputs[i].preimages);
audit_map(ctx, &psbt->inputs[i].psbt_fields);
audit_map(ctx, &psbt->inputs[i].taproot_leaf_signatures);
audit_map(ctx, &psbt->inputs[i].taproot_leaf_scripts);
audit_map(ctx, &psbt->inputs[i].taproot_leaf_hashes);
audit_map(ctx, &psbt->inputs[i].taproot_leaf_paths);
/* DTODO: Investigate if taproot wally maps have child maps */
#ifndef WALLY_ABI_NO_ELEMENTS
assert(NULL_OR_MATCH_P(psbt->inputs[i].pegin_tx, ctx));
assert(NULL_OR_MATCH_P(psbt->inputs[i].pegin_witness, ctx));
audit_map(ctx, &psbt->inputs[i].pset_fields);
#endif
}
for (size_t i = 0; i < psbt->num_outputs; i++) {
assert(NULL_OR_MATCH_P(psbt->outputs[i].script, ctx));
assert(psbt->outputs[i].script_len
== tal_bytelen(psbt->outputs[i].script));
audit_map(ctx, &psbt->outputs[i].keypaths);
audit_map(ctx, &psbt->outputs[i].unknowns);
audit_map(ctx, &psbt->outputs[i].psbt_fields);
audit_map(ctx, &psbt->outputs[i].taproot_tree);
audit_map(ctx, &psbt->outputs[i].taproot_leaf_hashes);
audit_map(ctx, &psbt->outputs[i].taproot_leaf_paths);
#ifndef WALLY_ABI_NO_ELEMENTS
audit_map(ctx, &psbt->outputs[i].pset_fields);
#endif
}
}

bool psbt_is_finalized(const struct wally_psbt *psbt)
{
size_t is_finalized;
Expand Down
11 changes: 11 additions & 0 deletions bitcoin/psbt.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ struct wally_psbt *combine_psbt(const tal_t *ctx,
const struct wally_psbt *psbt0,
const struct wally_psbt *psbt1);

/**
* audit_psbt - Audit the memory structure of the PSBT.
*
* This checks all known memory allocations in the PSBT and asserts that they
* are all allocated with 'ctx' being it's parent.
*
* ctx - the ctx all memory *should* be attached to
* psbt - the PSBT to audit.
* */
void audit_psbt(const tal_t *ctx, const struct wally_psbt *psbt);

/**
* psbt_is_finalized - Check if tx is ready to be extracted
*
Expand Down
1 change: 1 addition & 0 deletions bitcoin/test/run-psbt-from-tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ int main(int argc, char *argv[])
const struct wally_map_item *final_scriptsig = wally_map_get_integer(&tx2->psbt->inputs[0].psbt_fields, /* PSBT_IN_FINAL_SCRIPTSIG */ 0x07);
assert(final_scriptsig->value_len > 0);
assert(tx2->psbt->inputs[0].final_witness != NULL);
audit_psbt(tx2->psbt, tx2->psbt);

common_shutdown();
return 0;
Expand Down
6 changes: 5 additions & 1 deletion bitcoin/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,13 @@ void bitcoin_tx_finalize(struct bitcoin_tx *tx)
assert(bitcoin_tx_check(tx));
}

struct bitcoin_tx *bitcoin_tx_with_psbt(const tal_t *ctx, struct wally_psbt *psbt STEALS)
struct bitcoin_tx *bitcoin_tx_with_psbt(const tal_t *ctx, struct wally_psbt *psbt TAKES)
{
size_t locktime;

if (!taken(psbt))
psbt = clone_psbt(NULL, psbt);

wally_psbt_get_locktime(psbt, &locktime);
struct bitcoin_tx *tx = bitcoin_tx(ctx, chainparams,
psbt->num_inputs,
Expand Down
3 changes: 2 additions & 1 deletion bitcoin/tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ bool bitcoin_txid_to_hex(const struct bitcoin_txid *txid,
char *hexstr, size_t hexstr_len);

/* Create a bitcoin_tx from a psbt */
struct bitcoin_tx *bitcoin_tx_with_psbt(const tal_t *ctx, struct wally_psbt *psbt);
struct bitcoin_tx *bitcoin_tx_with_psbt(const tal_t *ctx,
struct wally_psbt *psbt TAKES);

/* Internal de-linearization functions. */
/* Pull a bitcoin tx, and create a PSBT wrapper for it */
Expand Down
Loading
Loading