Skip to content

Commit

Permalink
Nits (#2773)
Browse files Browse the repository at this point in the history
* remove old arg doc

* reorg methods in Helper

* cleanup imports
  • Loading branch information
pm47 authored Nov 8, 2023
1 parent 73a2578 commit 5fa7d4b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 23 additions & 23 deletions eclair-core/src/main/scala/fr/acinq/eclair/channel/Helpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5fa7d4b

Please sign in to comment.