Skip to content

Remove watch txids and make watches more bwatch-like: part 1#8927

Draft
rustyrussell wants to merge 24 commits intoElementsProject:masterfrom
rustyrussell:guilt/remove-watch_txid
Draft

Remove watch txids and make watches more bwatch-like: part 1#8927
rustyrussell wants to merge 24 commits intoElementsProject:masterfrom
rustyrussell:guilt/remove-watch_txid

Conversation

@rustyrussell
Copy link
Contributor

@sangbida is working on a generic watching plugin called bwatch; this is an internal cleanup and refactor to get us closer to being able to use her APIs.

This introduces internal scriptpubkey watches and blockdepth watches, which we then use to replace almost all the "txid" watches. I say almost all because onchaind needs to be reworked to avoid them too, but that will be a separate PR.

Still a draft: there have been some splicing and df breakages....

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
…while iterating.

Not all of them, but I've done the ones which weren't obvious.

Also, there's never a problem deleting during iteration, so remove places which
tried to "handle" that problem.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
It's outpoint->txid in all cases.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
We return this when we can: it's just a u64.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
…he block

We'll actually have it directly when we use outpoint watches from
chaintopology, so we will be able to avoid the lookup.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
If it fails, we cannot proceed with the channel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
…e locked.

This means splitting up the deptch_update_scid() a little.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
…inflight_txwatch.

We use typesafe callbacks: void * arguments are strongly eschewed.
Indeed, when we fix this one, we find it's getting called wrong in
splice_inflight_txwatch.

Since we handed the wrong arg to splice_inflight_txwatch (channel
instead of inflight), it never worked.  Indeed, we always get:

	Splice inflight event but not in AWAITING_SPLICE, ending watch of txid f6f0cb65584389caf7722b06d9ffe98aea3ad8fd04d74b2b11e2e227cf28cffe

So remove it.  The watch will delete itself (as above), or be freed with the inflight.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
… output numbers.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
txfilter.c keeps a hash with interface:
  * INSERT: txfilter_add_scriptpubkey &txfilter_add_derkey
  * SEARCH: txfilter_match & txfilter_scriptpubkey_matches.  It simply returns true/false.

wallet.c keeps an our_addresses hash:
  * INSERT: on-demand when asked based on max keyidx (plus gap)
  * SEARCH: wallet_can_spend (and thus its caller wallet_extract_owned_outputs).

Here are the places which populate the txfilter:

lightningd/channel.c:
  - When we generate our own address final address
  => this is already covered when we call wallet_get_newindex() to get the final_key_idx
lightningd/lightningd.c:
  - init_txfilter initializes all the prior addresses
  => wallet_can_spend populates this on first call.
wallet/reservation.c:
  - finish_psbt and json_addpsbtoutput for change output
  => this is already covered when get call wallet_get_newindex() in the same funciton.
wallet/wallet.c:
  - got_utxo for unconfirmed outputs
  => This is called when we have already determined we can spend the output (wallet_extract_owned_outputs), or on the fixup migration where the addresses are populated from a keyindex we've already created.
wallet/walletrpc.c:
  - newaddr_inner
  => Already covered by wallet_get_newindex()

The result: we can just rely on the wallet to find our addresses, and
we don't need the txfilter at all.  Just make chaintopology ask the
wallet directly.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
chaintopology was the only user, so we don't need the txfilter at all.
Remove it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Vital for hashing.  But adding script_with_len_hash here breaks
fuzzing build, so that requires a little modification.

I also noticed that `#include <common/randbytes.h>` is redundant in
all the common/ unit tests, so removed it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
The wallet has "our_addresses" which contains our own addresses; this
adds a more generic callback mechanism which can be used for funding
txs and splices.

This will map better onto bwatch, which won't have ability to watch by
txid.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
…the funding tx.

funding_depth_cb handled three cases, implicitly:

1. First time we see the funding tx.
2. When we see the funding tx block reorged out.
3. When we see the tx depth increase.

This replaces first one with a scriptpubkey watch.  The other two stay
using the watch_txid for now.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This handles the reorg case, ready to use a blockdepth callback next.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This is more explicit, and will work far better with an external watcher.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
…lly closed.

This is unnecessary now, since we have a destructor, but it'll be important when
we move watching out to `bwatch`.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
It doesn't need to reinvent the wheel.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
…ches for dual funding.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
…ts mined.

This also removed the last call to wallet_transaction_locate, so remove that too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
…n closing.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
@rustyrussell rustyrussell added this to the v26.04 milestone Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant