1
0
mirror of https://github.com/ACINQ/eclair.git synced 2024-11-20 02:27:32 +01:00

peer watcher: confirmed already spent txs rihgt away

When processing WatchConfirmed messages, check if the tx has already been confirmed and
trigger the watch immediately if possible. This will let us detect if a channel has been
confirmed while the node was offline or turned off
This commit is contained in:
sstone 2017-02-27 19:23:57 +01:00
parent f5ea399f71
commit df6633eed0

View File

@ -81,6 +81,19 @@ class PeerWatcher(client: ExtendedBitcoinClient)(implicit ec: ExecutionContext =
}
}
case w@WatchConfirmed(channel, txId, minDepth, event) => {
client.getTxConfirmations(txId.toString).map {
case Some(confirmations) if confirmations >= minDepth =>
client.getTransactionShortId(txId.toString).map {
// TODO: this is a workaround to not have WatchConfirmed triggered multiple times in testing
// the reason is that we cannot do a become(watches - w, ...) because it happens in the future callback
case (height, index) => self ! ('trigger, w, WatchEventConfirmed(w.event, height, index))
}
case _ => ()
}
addWatch(w, watches, block2tx, lastTxes)
}
case w: Watch => addWatch(w, watches, block2tx, lastTxes)
case PublishAsap(tx) =>