diff --git a/eclair-core/src/main/scala/fr/acinq/eclair/blockchain/fee/OnChainFeeConf.scala b/eclair-core/src/main/scala/fr/acinq/eclair/blockchain/fee/OnChainFeeConf.scala index 9b4a3d9de7..09bb60c884 100644 --- a/eclair-core/src/main/scala/fr/acinq/eclair/blockchain/fee/OnChainFeeConf.scala +++ b/eclair-core/src/main/scala/fr/acinq/eclair/blockchain/fee/OnChainFeeConf.scala @@ -98,7 +98,6 @@ case class OnChainFeeConf(feeTargets: FeeTargets, safeUtxosThreshold: Int, spend * * @param remoteNodeId nodeId of our channel peer * @param commitmentFormat commitment format - * @param currentFeerates_opt if provided, will be used to compute the most up-to-date network fee, otherwise we rely on the fee estimator */ def getCommitmentFeerate(feerates: FeeratesPerKw, remoteNodeId: PublicKey, commitmentFormat: CommitmentFormat, channelCapacity: Satoshi): FeeratePerKw = { val networkFeerate = feerates.fast diff --git a/eclair-core/src/main/scala/fr/acinq/eclair/channel/Helpers.scala b/eclair-core/src/main/scala/fr/acinq/eclair/channel/Helpers.scala index 673f74194d..348be40c6e 100644 --- a/eclair-core/src/main/scala/fr/acinq/eclair/channel/Helpers.scala +++ b/eclair-core/src/main/scala/fr/acinq/eclair/channel/Helpers.scala @@ -244,6 +244,14 @@ object Helpers { extractShutdownScript(accept.temporaryChannelId, localFeatures, remoteFeatures, accept.upfrontShutdownScript_opt).map(script_opt => (channelFeatures, script_opt)) } + /** + * @param remoteFeeratePerKw remote fee rate per kiloweight + * @return true if the remote fee rate is too small + */ + private def isFeeTooSmall(remoteFeeratePerKw: FeeratePerKw): Boolean = { + remoteFeeratePerKw < FeeratePerKw.MinimumFeeratePerKw + } + /** Compute the temporaryChannelId of a dual-funded channel. */ def dualFundedTemporaryChannelId(nodeParams: NodeParams, localParams: LocalParams, channelConfig: ChannelConfig): ByteVector32 = { val channelKeyPath = nodeParams.channelKeyManager.keyPath(localParams, channelConfig) @@ -302,14 +310,24 @@ object Helpers { delay } - /** - * @param remoteFeeratePerKw remote fee rate per kiloweight - * @return true if the remote fee rate is too small + /** Computes a maximum HTLC amount adapted to the current balance to reduce chances that other nodes will try sending payments that we can't relay. */ - private def isFeeTooSmall(remoteFeeratePerKw: FeeratePerKw): Boolean = { - remoteFeeratePerKw < FeeratePerKw.MinimumFeeratePerKw + def maxHtlcAmount(nodeParams: NodeParams, commitments: Commitments): MilliSatoshi = { + if (!commitments.announceChannel) { + // The channel is private, let's not change the channel update needlessly. + return commitments.params.maxHtlcAmount + } + for (balanceThreshold <- nodeParams.channelConf.balanceThresholds) { + if (commitments.availableBalanceForSend <= balanceThreshold.available) { + return balanceThreshold.maxHtlcAmount.toMilliSatoshi.max(commitments.params.remoteParams.htlcMinimum).min(commitments.params.maxHtlcAmount) + } + } + commitments.params.maxHtlcAmount } + def makeChannelUpdate(nodeParams: NodeParams, remoteNodeId: PublicKey, scid: ShortChannelId, commitments: Commitments, relayFees: RelayFees, enable: Boolean = true): ChannelUpdate = + Announcements.makeChannelUpdate(nodeParams.chainHash, nodeParams.privateKey, remoteNodeId, scid, nodeParams.channelConf.expiryDelta, commitments.params.remoteParams.htlcMinimum, relayFees.feeBase, relayFees.feeProportionalMillionths, maxHtlcAmount(nodeParams, commitments), isPrivate = !commitments.announceChannel, enable) + def makeAnnouncementSignatures(nodeParams: NodeParams, channelParams: ChannelParams, remoteFundingPubKey: PublicKey, shortChannelId: RealShortChannelId): AnnouncementSignatures = { val features = Features.empty[Feature] // empty features for now val fundingPubKey = nodeParams.channelKeyManager.fundingPublicKey(channelParams.localParams.fundingKeyPath, fundingTxIndex = 0) // TODO: public announcements are not yet supported with splices @@ -327,29 +345,11 @@ object Helpers { AnnouncementSignatures(channelParams.channelId, shortChannelId, localNodeSig, localBitcoinSig) } - /** Computes a maximum HTLC amount adapted to the current balance to reduce chances that other nodes will try sending payments that we can't relay. - */ - def maxHtlcAmount(nodeParams: NodeParams, commitments: Commitments): MilliSatoshi = { - if (!commitments.announceChannel) { - // The channel is private, let's not change the channel update needlessly. - return commitments.params.maxHtlcAmount - } - for (balanceThreshold <- nodeParams.channelConf.balanceThresholds) { - if (commitments.availableBalanceForSend <= balanceThreshold.available) { - return balanceThreshold.maxHtlcAmount.toMilliSatoshi.max(commitments.params.remoteParams.htlcMinimum).min(commitments.params.maxHtlcAmount) - } - } - commitments.params.maxHtlcAmount - } - def getRelayFees(nodeParams: NodeParams, remoteNodeId: PublicKey, announceChannel: Boolean): RelayFees = { val defaultFees = nodeParams.relayParams.defaultFees(announceChannel) nodeParams.db.peers.getRelayFees(remoteNodeId).getOrElse(defaultFees) } - def makeChannelUpdate(nodeParams: NodeParams, remoteNodeId: PublicKey, scid: ShortChannelId, commitments: Commitments, relayFees: RelayFees, enable: Boolean = true): ChannelUpdate = - Announcements.makeChannelUpdate(nodeParams.chainHash, nodeParams.privateKey, remoteNodeId, scid, nodeParams.channelConf.expiryDelta, commitments.params.remoteParams.htlcMinimum, relayFees.feeBase, relayFees.feeProportionalMillionths, maxHtlcAmount(nodeParams, commitments), isPrivate = !commitments.announceChannel, enable) - object Funding { def makeFundingInputInfo(fundingTxId: ByteVector32, fundingTxOutputIndex: Int, fundingSatoshis: Satoshi, fundingPubkey1: PublicKey, fundingPubkey2: PublicKey): InputInfo = { diff --git a/eclair-core/src/main/scala/fr/acinq/eclair/crypto/keymanager/LocalOnChainKeyManager.scala b/eclair-core/src/main/scala/fr/acinq/eclair/crypto/keymanager/LocalOnChainKeyManager.scala index 38779fdd8d..af21bfd9cf 100644 --- a/eclair-core/src/main/scala/fr/acinq/eclair/crypto/keymanager/LocalOnChainKeyManager.scala +++ b/eclair-core/src/main/scala/fr/acinq/eclair/crypto/keymanager/LocalOnChainKeyManager.scala @@ -22,14 +22,10 @@ import fr.acinq.bitcoin.scalacompat.DeterministicWallet._ import fr.acinq.bitcoin.scalacompat.{Block, ByteVector32, Crypto, DeterministicWallet, MnemonicCode, Satoshi, Script, computeBIP84Address} import fr.acinq.eclair.TimestampSecond import fr.acinq.eclair.blockchain.bitcoind.rpc.BitcoinCoreClient.{Descriptor, Descriptors} -import fr.acinq.eclair.blockchain.bitcoind.rpc.BitcoinJsonRPCClient import grizzled.slf4j.Logging -import org.json4s.{JArray, JBool} import scodec.bits.ByteVector import java.io.File -import scala.concurrent.duration.DurationInt -import scala.concurrent.{ExecutionContext, Future} import scala.jdk.CollectionConverters.{CollectionHasAsScala, MapHasAsScala} import scala.util.{Failure, Success, Try} @@ -69,8 +65,6 @@ object LocalOnChainKeyManager extends Logging { */ class LocalOnChainKeyManager(override val walletName: String, seed: ByteVector, val walletTimestamp: TimestampSecond, chainHash: ByteVector32) extends OnChainKeyManager with Logging { - import LocalOnChainKeyManager._ - // Master key derived from our seed. We use it to generate a BIP84 wallet that can be used: // - to generate a watch-only wallet with any BIP84-compatible bitcoin wallet // - to generate descriptors that can be imported into Bitcoin Core to create a watch-only wallet which can be used diff --git a/eclair-core/src/main/scala/fr/acinq/eclair/crypto/keymanager/OnChainKeyManager.scala b/eclair-core/src/main/scala/fr/acinq/eclair/crypto/keymanager/OnChainKeyManager.scala index 55ba8db41e..9e555f1092 100644 --- a/eclair-core/src/main/scala/fr/acinq/eclair/crypto/keymanager/OnChainKeyManager.scala +++ b/eclair-core/src/main/scala/fr/acinq/eclair/crypto/keymanager/OnChainKeyManager.scala @@ -19,11 +19,8 @@ package fr.acinq.eclair.crypto.keymanager import fr.acinq.bitcoin.psbt.Psbt import fr.acinq.bitcoin.scalacompat.Crypto.PublicKey import fr.acinq.bitcoin.scalacompat.DeterministicWallet.KeyPath -import fr.acinq.eclair.TimestampSecond import fr.acinq.eclair.blockchain.bitcoind.rpc.BitcoinCoreClient.Descriptors -import fr.acinq.eclair.blockchain.bitcoind.rpc.BitcoinJsonRPCClient -import scala.concurrent.{ExecutionContext, Future} import scala.util.Try trait OnChainKeyManager {