ACINQ / phoenix

Phoenix is a self-custodial Bitcoin wallet using Lightning to send/receive payments.
https://phoenix.acinq.co
Apache License 2.0
632 stars 95 forks source link

Recheck for payment confirmation when a new block is mined #381

Closed robbiehanson closed 1 year ago

robbiehanson commented 1 year ago

The payment.confirmedAt flag wasn't always being set properly, because this collection: paymentsDb.listUnconfirmedTransactions().collect { ... }

only fired when:

So if you create a new unconfirmed tx, and then wait, the above collection won't trigger when the tx is finally mined.

The fix is to simply tweak the collection to also fire when there's a new mined block:

combine(
  paymentsDb.listUnconfirmedTransactions(),
  appConfigurationManager.electrumMessages
).collect { }

Note that we're not using electrumClient.notifications because we'd have to first filter that for instances of HeaderSubscriptionResponse. But we also don't want to wait for a new block to start monitoring. What we really want is a StateFlow<HeaderSubscriptionResponse?> which AppConfigurationManager already provides.