1
0
Fork 0
mirror of https://github.com/ACINQ/eclair.git synced 2025-02-23 06:35:11 +01:00

Minor improvements to the watcher (#1531)

We were watching actors for ignored watches (WatchLost), and printing
useless logs when ignoring duplicate watches.

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
This commit is contained in:
Pierre-Marie Padiou 2020-09-21 10:19:32 +02:00 committed by GitHub
parent eed82e262f
commit 750b372b28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -46,12 +46,20 @@ class ZmqWatcher(blockCount: AtomicLong, client: ExtendedBitcoinClient)(implicit
import ZmqWatcher._
context.system.eventStream.subscribe(self, classOf[BlockchainEvent])
context.system.eventStream.subscribe(self, classOf[NewBlock])
context.system.eventStream.subscribe(self, classOf[NewTransaction])
context.system.eventStream.subscribe(self, classOf[CurrentBlockCount])
// this is to initialize block count
self ! TickNewBlock
case class TriggerEvent(w: Watch, e: WatchEvent)
// @formatter: off
private case class TriggerEvent(w: Watch, e: WatchEvent)
private sealed trait AddWatchResult
private case object Keep extends AddWatchResult
private case object Ignore extends AddWatchResult
// @formatter: on
def receive: Receive = watching(Set(), Map(), SortedMap(), None)
@ -113,8 +121,11 @@ class ZmqWatcher(blockCount: AtomicLong, client: ExtendedBitcoinClient)(implicit
toPublish.values.flatten.foreach(tx => publish(tx))
context become watching(watches, watchedUtxos, block2tx -- toPublish.keys, nextTick)
case w: Watch if !watches.contains(w) =>
w match {
case w: Watch =>
val result = w match {
case _ if watches.contains(w) => Ignore // we ignore duplicates
case WatchSpentBasic(_, txid, outputIndex, _, _) =>
// NB: we assume parent tx was published, we just need to make sure this particular output has not been spent
client.isTransactionOutputSpendable(txid, outputIndex, includeMempool = true).collect {
@ -122,6 +133,7 @@ class ZmqWatcher(blockCount: AtomicLong, client: ExtendedBitcoinClient)(implicit
log.info(s"output=$outputIndex of txid=$txid has already been spent")
self ! TriggerEvent(w, WatchEventSpentBasic(w.event))
}
Keep
case WatchSpent(_, txid, outputIndex, _, _) =>
// first let's see if the parent tx was published or not
@ -146,17 +158,22 @@ class ZmqWatcher(blockCount: AtomicLong, client: ExtendedBitcoinClient)(implicit
}
}
}
Keep
case w: WatchConfirmed => checkConfirmed(w) // maybe the tx is already tx, in that case the watch will be triggered and removed immediately
case w: WatchConfirmed =>
checkConfirmed(w) // maybe the tx is already confirmed, in that case the watch will be triggered and removed immediately
Keep
case _: WatchLost => () // TODO: not implemented
case w => log.warning("ignoring {}", w)
case _: WatchLost => Ignore // TODO: not implemented, we ignore it silently
}
log.debug("adding watch {} for {}", w, sender)
context.watch(w.replyTo)
context become watching(watches + w, addWatchedUtxos(watchedUtxos, w), block2tx, nextTick)
result match {
case Keep =>
log.debug("adding watch {} for {}", w, sender)
context.watch(w.replyTo)
context become watching(watches + w, addWatchedUtxos(watchedUtxos, w), block2tx, nextTick)
case Ignore => ()
}
case PublishAsap(tx) =>
val blockCount = this.blockCount.get()
@ -267,4 +284,4 @@ object ZmqWatcher {
}
}
}
}