Skip to content

Commit

Permalink
Merge branch 'master' into drop_tor_v2_services
Browse files Browse the repository at this point in the history
  • Loading branch information
rorp committed Jun 3, 2022
2 parents 2e61e33 + 9610fe3 commit 52f8182
Show file tree
Hide file tree
Showing 135 changed files with 3,601 additions and 2,986 deletions.
2 changes: 1 addition & 1 deletion eclair-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-scala-scalatest_${scala.version.short}</artifactId>
<version>1.5.9</version>
<version>1.17.5</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
1 change: 0 additions & 1 deletion eclair-core/src/main/scala/fr/acinq/eclair/Features.scala
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ object Features {
BasicMultiPartPayment -> (PaymentSecret :: Nil),
AnchorOutputs -> (StaticRemoteKey :: Nil),
AnchorOutputsZeroFeeHtlcTx -> (StaticRemoteKey :: Nil),
DualFunding -> (AnchorOutputsZeroFeeHtlcTx :: Nil),
TrampolinePaymentPrototype -> (PaymentSecret :: Nil),
KeySend -> (VariableLengthOnion :: Nil)
)
Expand Down
9 changes: 6 additions & 3 deletions eclair-core/src/main/scala/fr/acinq/eclair/Logs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,18 @@ object Logs {
parentPaymentId_opt: Option[UUID] = None,
paymentId_opt: Option[UUID] = None,
paymentHash_opt: Option[ByteVector32] = None,
txPublishId_opt: Option[UUID] = None): Map[String, String] =
txPublishId_opt: Option[UUID] = None,
nodeAlias_opt: Option[String] = None): Map[String, String] =
Seq(
// nb: we preformat MDC values so that there is no white spaces in logs when they are not defined
category_opt.map(l => "category" -> s" ${l.category}"),
remoteNodeId_opt.map(n => "nodeId" -> s" n:$n"), // nb: we preformat MDC values so that there is no white spaces in logs when they are not defined
remoteNodeId_opt.map(n => "nodeId" -> s" n:$n"),
channelId_opt.map(c => "channelId" -> s" c:$c"),
parentPaymentId_opt.map(p => "parentPaymentId" -> s" p:$p"),
paymentId_opt.map(i => "paymentId" -> s" i:$i"),
paymentHash_opt.map(h => "paymentHash" -> s" h:$h"),
txPublishId_opt.map(t => "txPublishId" -> s" t:$t")
txPublishId_opt.map(t => "txPublishId" -> s" t:$t"),
nodeAlias_opt.map(a => "nodeAlias" -> s" a:$a"),
).flatten.toMap

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1884,7 +1884,7 @@ class Channel(val nodeParams: NodeParams, val wallet: OnChainChannelFunder, val
case INPUT_RESTORED(data) => data.channelId
case _ => stateData.channelId
}
Logs.mdc(category_opt, remoteNodeId_opt = Some(remoteNodeId), channelId_opt = Some(id))
Logs.mdc(category_opt, remoteNodeId_opt = Some(remoteNodeId), channelId_opt = Some(id), nodeAlias_opt = Some(nodeParams.alias))
}

// we let the peer decide what to do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ object MempoolTxMonitor {
private case class InputStatus(spentConfirmed: Boolean, spentUnconfirmed: Boolean) extends Command
private case class CheckInputFailed(reason: Throwable) extends Command
private case class TxConfirmations(confirmations: Int, blockHeight: BlockHeight) extends Command
private case class ParentTxStatus(confirmed: Boolean, blockHeight: BlockHeight) extends Command
private case object TxNotFound extends Command
private case class GetTxConfirmationsFailed(reason: Throwable) extends Command
private case class WrappedCurrentBlockHeight(currentBlockHeight: BlockHeight) extends Command
Expand All @@ -58,7 +59,7 @@ object MempoolTxMonitor {
sealed trait TxResult
sealed trait IntermediateTxResult extends TxResult
/** The transaction is still unconfirmed and available in the mempool. */
case class TxInMempool(txid: ByteVector32, blockHeight: BlockHeight) extends IntermediateTxResult
case class TxInMempool(txid: ByteVector32, blockHeight: BlockHeight, parentConfirmed: Boolean) extends IntermediateTxResult
/** The transaction is confirmed, but hasn't reached min depth yet, we should wait for more confirmations. */
case class TxRecentlyConfirmed(txid: ByteVector32, confirmations: Int) extends IntermediateTxResult
sealed trait FinalTxResult extends TxResult
Expand Down Expand Up @@ -147,7 +148,10 @@ private class MempoolTxMonitor(nodeParams: NodeParams,
Behaviors.same
case TxConfirmations(confirmations, currentBlockHeight) =>
if (confirmations == 0) {
cmd.replyTo ! TxInMempool(cmd.tx.txid, currentBlockHeight)
context.pipeToSelf(bitcoinClient.getTxConfirmations(cmd.input.txid)) {
case Success(parentConfirmations_opt) => ParentTxStatus(parentConfirmations_opt.exists(_ >= 1), currentBlockHeight)
case Failure(reason) => GetTxConfirmationsFailed(reason)
}
Behaviors.same
} else if (confirmations < nodeParams.channelConf.minDepthBlocks) {
log.info("txid={} has {} confirmations, waiting to reach min depth", cmd.tx.txid, confirmations)
Expand All @@ -158,6 +162,9 @@ private class MempoolTxMonitor(nodeParams: NodeParams,
context.system.eventStream ! EventStream.Publish(TransactionConfirmed(txPublishContext.channelId_opt.getOrElse(ByteVector32.Zeroes), txPublishContext.remoteNodeId, cmd.tx))
sendFinalResult(TxDeeplyBuried(cmd.tx), Some(messageAdapter))
}
case ParentTxStatus(confirmed, currentBlockHeight) =>
cmd.replyTo ! TxInMempool(cmd.tx.txid, currentBlockHeight, confirmed)
Behaviors.same
case TxNotFound =>
log.warn("txid={} has been evicted from the mempool", cmd.tx.txid)
checkInputStatus(cmd.input)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import fr.acinq.eclair.blockchain.fee.{FeeEstimator, FeeratePerKw}
import fr.acinq.eclair.channel.publish.ReplaceableTxFunder.FundedTx
import fr.acinq.eclair.channel.publish.ReplaceableTxPrePublisher.{ClaimLocalAnchorWithWitnessData, ReplaceableTxWithWitnessData}
import fr.acinq.eclair.channel.publish.TxPublisher.TxPublishContext
import fr.acinq.eclair.transactions.Transactions
import fr.acinq.eclair.{BlockHeight, NodeParams}

import scala.concurrent.duration.{DurationInt, DurationLong}
Expand Down Expand Up @@ -195,10 +196,17 @@ private class ReplaceableTxPublisher(nodeParams: NodeParams,
Behaviors.receiveMessagePartial {
case WrappedTxResult(txResult) =>
txResult match {
case MempoolTxMonitor.TxInMempool(_, currentBlockHeight) =>
context.pipeToSelf(hasEnoughSafeUtxos(nodeParams.onChainFeeConf.feeTargets.safeUtxosThreshold)) {
case Success(isSafe) => CheckUtxosResult(isSafe, currentBlockHeight)
case Failure(_) => CheckUtxosResult(isSafe = false, currentBlockHeight) // if we can't check our utxos, we assume the worst
case MempoolTxMonitor.TxInMempool(_, currentBlockHeight, parentConfirmed) =>
val shouldRbf = cmd.txInfo match {
// Our commit tx was confirmed on its own, so there's no need to increase fees on the anchor tx.
case _: Transactions.ClaimLocalAnchorOutputTx if parentConfirmed => false
case _ => true
}
if (shouldRbf) {
context.pipeToSelf(hasEnoughSafeUtxos(nodeParams.onChainFeeConf.feeTargets.safeUtxosThreshold)) {
case Success(isSafe) => CheckUtxosResult(isSafe, currentBlockHeight)
case Failure(_) => CheckUtxosResult(isSafe = false, currentBlockHeight) // if we can't check our utxos, we assume the worst
}
}
Behaviors.same
case MempoolTxMonitor.TxRecentlyConfirmed(_, _) => Behaviors.same // just wait for the tx to be deeply buried
Expand Down
2 changes: 1 addition & 1 deletion eclair-core/src/main/scala/fr/acinq/eclair/io/Peer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ class Peer(val nodeParams: NodeParams, remoteNodeId: PublicKey, wallet: OnChainA
}

override def mdc(currentMessage: Any): MDC = {
Logs.mdc(LogCategory(currentMessage), Some(remoteNodeId), Logs.channelId(currentMessage))
Logs.mdc(LogCategory(currentMessage), Some(remoteNodeId), Logs.channelId(currentMessage), nodeAlias_opt = Some(nodeParams.alias))
}

}
Expand Down
15 changes: 13 additions & 2 deletions eclair-core/src/main/scala/fr/acinq/eclair/io/PeerConnection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package fr.acinq.eclair.io

import akka.actor.{ActorRef, FSM, OneForOneStrategy, PoisonPill, Props, SupervisorStrategy, Terminated}
import akka.actor.{ActorRef, FSM, OneForOneStrategy, PoisonPill, Props, Stash, SupervisorStrategy, Terminated}
import akka.event.Logging.MDC
import fr.acinq.bitcoin.scalacompat.ByteVector32
import fr.acinq.bitcoin.scalacompat.Crypto.PublicKey
Expand Down Expand Up @@ -56,7 +56,7 @@ import scala.util.Random
*
* Created by PM on 11/03/2020.
*/
class PeerConnection(keyPair: KeyPair, conf: PeerConnection.Conf, switchboard: ActorRef, router: ActorRef) extends FSMDiagnosticActorLogging[PeerConnection.State, PeerConnection.Data] {
class PeerConnection(keyPair: KeyPair, conf: PeerConnection.Conf, switchboard: ActorRef, router: ActorRef) extends FSMDiagnosticActorLogging[PeerConnection.State, PeerConnection.Data] with Stash {

import PeerConnection._

Expand Down Expand Up @@ -95,6 +95,11 @@ class PeerConnection(keyPair: KeyPair, conf: PeerConnection.Conf, switchboard: A
log.warning(s"authentication timed out after ${conf.authTimeout}")
d.pendingAuth.origin_opt.foreach(_ ! ConnectionResult.AuthenticationFailed("authentication timed out"))
stop(FSM.Normal)

case Event(_: protocol.Init, _) =>
log.debug("stashing remote init")
stash()
stay()
}

when(BEFORE_INIT) {
Expand All @@ -108,7 +113,13 @@ class PeerConnection(keyPair: KeyPair, conf: PeerConnection.Conf, switchboard: A
}
d.transport ! localInit
startSingleTimer(INIT_TIMER, InitTimeout, conf.initTimeout)
unstashAll() // unstash remote init if it already arrived
goto(INITIALIZING) using InitializingData(chainHash, d.pendingAuth, d.remoteNodeId, d.transport, peer, localInit, doSync, d.isPersistent)

case Event(_: protocol.Init, _) =>
log.debug("stashing remote init")
stash()
stay()
}

when(INITIALIZING) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class ReconnectionTask(nodeParams: NodeParams, remoteNodeId: PublicKey) extends
}

override def mdc(currentMessage: Any): MDC = {
Logs.mdc(Some(LogCategory.CONNECTION), Some(remoteNodeId))
Logs.mdc(Some(LogCategory.CONNECTION), Some(remoteNodeId), nodeAlias_opt = Some(nodeParams.alias))
}

}
Expand Down
11 changes: 6 additions & 5 deletions eclair-core/src/main/scala/fr/acinq/eclair/router/Router.scala
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,13 @@ class Router(val nodeParams: NodeParams, watcher: typed.ActorRef[ZmqWatcher.Comm

override def mdc(currentMessage: Any): MDC = {
val category_opt = LogCategory(currentMessage)
currentMessage match {
case s: SendChannelQuery => Logs.mdc(category_opt, remoteNodeId_opt = Some(s.remoteNodeId))
case prm: PeerRoutingMessage => Logs.mdc(category_opt, remoteNodeId_opt = Some(prm.remoteNodeId))
case lcu: LocalChannelUpdate => Logs.mdc(category_opt, remoteNodeId_opt = Some(lcu.remoteNodeId))
case _ => Logs.mdc(category_opt)
val remoteNodeId_opt = currentMessage match {
case s: SendChannelQuery => Some(s.remoteNodeId)
case prm: PeerRoutingMessage => Some(prm.remoteNodeId)
case lcu: LocalChannelUpdate => Some(lcu.remoteNodeId)
case _ => None
}
Logs.mdc(category_opt, remoteNodeId_opt = remoteNodeId_opt, nodeAlias_opt = Some(nodeParams.alias))
}
}

Expand Down
2 changes: 1 addition & 1 deletion eclair-core/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<target>System.out</target>
<encoder>
<pattern>%date{HH:mm:ss.SSS} %highlight(%-5level) %replace(%logger{24}){'\$.*',''}%X{category}%X{nodeId}%X{channelId}%X{paymentHash}%.-11X{parentPaymentId}%.-11X{paymentId}%.-11X{txPublishId} - %msg%ex{12}%n</pattern>
<pattern>%date{HH:mm:ss.SSS} %highlight(%-5level) %replace(%logger{24}){'\$.*',''}%X{category}%.-9X{nodeId}%.-11X{channelId}%.-11X{paymentHash}%.-11X{parentPaymentId}%.-11X{paymentId}%.-11X{txPublishId}%.-11X{nodeAlias} - %msg%ex{12}%n</pattern>
</encoder>
</appender>

Expand Down
22 changes: 11 additions & 11 deletions eclair-core/src/test/scala/fr/acinq/eclair/CltvExpirySpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class CltvExpirySpec extends AnyFunSuite with ParallelTestExecution {

test("cltv expiry delta") {
val d = CltvExpiryDelta(561)
assert(d.toInt === 561)
assert(d.toInt == 561)

// add
assert(d + 5 === CltvExpiryDelta(566))
assert(d + CltvExpiryDelta(5) === CltvExpiryDelta(566))
assert(d + 5 == CltvExpiryDelta(566))
assert(d + CltvExpiryDelta(5) == CltvExpiryDelta(566))

// subtract
assert(d - CltvExpiryDelta(5) === CltvExpiryDelta(556))
assert(d - CltvExpiryDelta(562) === CltvExpiryDelta(-1))
assert(d - CltvExpiryDelta(5) == CltvExpiryDelta(556))
assert(d - CltvExpiryDelta(562) == CltvExpiryDelta(-1))

// compare
assert(d <= CltvExpiryDelta(561))
Expand All @@ -44,18 +44,18 @@ class CltvExpirySpec extends AnyFunSuite with ParallelTestExecution {
assert(d > CltvExpiryDelta(560))

// convert to cltv expiry
assert(d.toCltvExpiry(currentBlockHeight = BlockHeight(1105)) === CltvExpiry(1666))
assert(d.toCltvExpiry(currentBlockHeight = BlockHeight(1106)) === CltvExpiry(1667))
assert(d.toCltvExpiry(currentBlockHeight = BlockHeight(1105)) == CltvExpiry(1666))
assert(d.toCltvExpiry(currentBlockHeight = BlockHeight(1106)) == CltvExpiry(1667))
}

test("cltv expiry") {
val e = CltvExpiry(1105)
assert(e.toLong === 1105)
assert(e.toLong == 1105)

// add
assert(e + CltvExpiryDelta(561) === CltvExpiry(1666))
assert(e - CltvExpiryDelta(561) === CltvExpiry(544))
assert(e - CltvExpiry(561) === CltvExpiryDelta(544))
assert(e + CltvExpiryDelta(561) == CltvExpiry(1666))
assert(e - CltvExpiryDelta(561) == CltvExpiry(544))
assert(e - CltvExpiry(561) == CltvExpiryDelta(544))

// compare
assert(e <= CltvExpiry(1105))
Expand Down
Loading

0 comments on commit 52f8182

Please sign in to comment.