1
0
Fork 0
mirror of https://github.com/ACINQ/eclair.git synced 2025-02-23 14:40:34 +01:00

Add delay before setting watches at startup (#1489)

Watching the blockchain is an asynchronous task, so it is "always late"
and it doesn't matter if we don't synchronously set the watch back when
the node is restarted.

It allows us to smoothen the load if needed at startup, because setting
tens of thousands of `watch-spent` all at once at startup is pretty
expensive.

Co-authored-by: Bastien Teinturier <31281497+t-bast@users.noreply.github.com>
This commit is contained in:
Pierre-Marie Padiou 2020-07-22 15:46:56 +02:00 committed by GitHub
parent a3dd365c67
commit bc81cd5272
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 3 deletions

View file

@ -20,6 +20,7 @@ eclair {
# backup-notify-script = "/absolute/path/to/script.sh"
watcher-type = "bitcoind" // other *experimental* values include "electrum"
watch-spent-window = 1 minute // at startup watches will be put back within that window to reduce herd effect; must be > 0s
bitcoind {
host = "localhost"

View file

@ -36,7 +36,7 @@ import fr.acinq.eclair.tor.Socks5ProxyParams
import fr.acinq.eclair.wire.{Color, EncodingType, NodeAddress}
import scodec.bits.ByteVector
import scala.concurrent.duration.FiniteDuration
import scala.concurrent.duration._
import scala.jdk.CollectionConverters._
/**
@ -79,6 +79,7 @@ case class NodeParams(keyManager: KeyManager,
chainHash: ByteVector32,
channelFlags: Byte,
watcherType: WatcherType,
watchSpentWindow: FiniteDuration,
paymentRequestExpiry: FiniteDuration,
multiPartPaymentExpiry: FiniteDuration,
minFundingSatoshis: Satoshi,
@ -167,6 +168,9 @@ object NodeParams {
case _ => BITCOIND
}
val watchSpentWindow = FiniteDuration(config.getDuration("watch-spent-window").getSeconds, TimeUnit.SECONDS)
require(watchSpentWindow > 0.seconds, "watch-spent-window must be strictly greater than 0")
val dustLimitSatoshis = Satoshi(config.getLong("dust-limit-satoshis"))
if (chainHash == Block.LivenetGenesisBlock.hash) {
require(dustLimitSatoshis >= Channel.MIN_DUSTLIMIT, s"dust limit must be greater than ${Channel.MIN_DUSTLIMIT}")
@ -282,6 +286,7 @@ object NodeParams {
chainHash = chainHash,
channelFlags = config.getInt("channel-flags").toByte,
watcherType = watcherType,
watchSpentWindow = watchSpentWindow,
paymentRequestExpiry = FiniteDuration(config.getDuration("payment-request-expiry").getSeconds, TimeUnit.SECONDS),
multiPartPaymentExpiry = FiniteDuration(config.getDuration("multi-part-payment-expiry").getSeconds, TimeUnit.SECONDS),
minFundingSatoshis = Satoshi(config.getLong("min-funding-satoshis")),

View file

@ -44,7 +44,7 @@ import kamon.context.Context
import scala.collection.immutable.SortedMap
import scala.concurrent.duration._
import scala.concurrent.{ExecutionContext, Promise}
import scala.util.Try
import scala.util.{Random, Try}
/**
* Created by PM on 24/05/2016.
@ -90,7 +90,10 @@ class Router(val nodeParams: NodeParams, watcher: ActorRef, initialized: Option[
val txid = pc.fundingTxid
val TxCoordinates(_, _, outputIndex) = ShortChannelId.coordinates(pc.ann.shortChannelId)
val fundingOutputScript = write(pay2wsh(Scripts.multiSig2of2(pc.ann.bitcoinKey1, pc.ann.bitcoinKey2)))
watcher ! WatchSpentBasic(self, txid, outputIndex, fundingOutputScript, BITCOIN_FUNDING_EXTERNAL_CHANNEL_SPENT(pc.ann.shortChannelId))
// avoid herd effect at startup because watch-spent are intensive in terms of rpc calls to bitcoind
context.system.scheduler.scheduleOnce(Random.nextLong(nodeParams.watchSpentWindow.toSeconds).seconds) {
watcher ! WatchSpentBasic(self, txid, outputIndex, fundingOutputScript, BITCOIN_FUNDING_EXTERNAL_CHANNEL_SPENT(pc.ann.shortChannelId))
}
}
// on restart we update our node announcement

View file

@ -179,6 +179,7 @@ object TestConstants {
chainHash = Block.RegtestGenesisBlock.hash,
channelFlags = 1,
watcherType = BITCOIND,
watchSpentWindow = 1 second,
paymentRequestExpiry = 1 hour,
multiPartPaymentExpiry = 30 seconds,
minFundingSatoshis = 1000 sat,
@ -267,6 +268,7 @@ object TestConstants {
chainHash = Block.RegtestGenesisBlock.hash,
channelFlags = 1,
watcherType = BITCOIND,
watchSpentWindow = 1 second,
paymentRequestExpiry = 1 hour,
multiPartPaymentExpiry = 30 seconds,
minFundingSatoshis = 1000 sat,