mirror of
https://github.com/ACINQ/eclair.git
synced 2025-02-23 06:35:11 +01:00
Define channelReserve()
methods in ChannelParams
(#2653)
So it can be called from `InteractiveTx` for new commitments.
This commit is contained in:
parent
7bf2e8c67f
commit
9beccce300
2 changed files with 17 additions and 11 deletions
|
@ -101,6 +101,20 @@ case class ChannelParams(channelId: ByteVector32,
|
||||||
*/
|
*/
|
||||||
def minDepthDualFunding(defaultMinDepth: Int, sharedTx: SharedTransaction): Option[Long] = minDepthDualFunding(defaultMinDepth, sharedTx.sharedOutput.amount, Some(sharedTx.remoteInputs.nonEmpty))
|
def minDepthDualFunding(defaultMinDepth: Int, sharedTx: SharedTransaction): Option[Long] = minDepthDualFunding(defaultMinDepth, sharedTx.sharedOutput.amount, Some(sharedTx.remoteInputs.nonEmpty))
|
||||||
|
|
||||||
|
/** Channel reserve that applies to our funds. */
|
||||||
|
def localChannelReserveForCapacity(capacity: Satoshi): Satoshi = if (channelFeatures.hasFeature(Features.DualFunding)) {
|
||||||
|
(capacity / 100).max(remoteParams.dustLimit)
|
||||||
|
} else {
|
||||||
|
remoteParams.requestedChannelReserve_opt.get // this is guarded by a require() in Params
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Channel reserve that applies to our peer's funds. */
|
||||||
|
def remoteChannelReserveForCapacity(capacity: Satoshi): Satoshi = if (channelFeatures.hasFeature(Features.DualFunding)) {
|
||||||
|
(capacity / 100).max(localParams.dustLimit)
|
||||||
|
} else {
|
||||||
|
localParams.requestedChannelReserve_opt.get // this is guarded by a require() in Params
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param localScriptPubKey local script pubkey (provided in CMD_CLOSE, as an upfront shutdown script, or set to the current final onchain script)
|
* @param localScriptPubKey local script pubkey (provided in CMD_CLOSE, as an upfront shutdown script, or set to the current final onchain script)
|
||||||
|
@ -248,18 +262,10 @@ case class Commitment(fundingTxIndex: Long,
|
||||||
val capacity: Satoshi = commitInput.txOut.amount
|
val capacity: Satoshi = commitInput.txOut.amount
|
||||||
|
|
||||||
/** Channel reserve that applies to our funds. */
|
/** Channel reserve that applies to our funds. */
|
||||||
def localChannelReserve(params: ChannelParams): Satoshi = if (params.channelFeatures.hasFeature(Features.DualFunding)) {
|
def localChannelReserve(params: ChannelParams): Satoshi = params.localChannelReserveForCapacity(capacity)
|
||||||
(capacity / 100).max(params.remoteParams.dustLimit)
|
|
||||||
} else {
|
|
||||||
params.remoteParams.requestedChannelReserve_opt.get // this is guarded by a require() in Params
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Channel reserve that applies to our peer's funds. */
|
/** Channel reserve that applies to our peer's funds. */
|
||||||
def remoteChannelReserve(params: ChannelParams): Satoshi = if (params.channelFeatures.hasFeature(Features.DualFunding)) {
|
def remoteChannelReserve(params: ChannelParams): Satoshi = params.remoteChannelReserveForCapacity(capacity)
|
||||||
(capacity / 100).max(params.localParams.dustLimit)
|
|
||||||
} else {
|
|
||||||
params.localParams.requestedChannelReserve_opt.get // this is guarded by a require() in Params
|
|
||||||
}
|
|
||||||
|
|
||||||
// NB: when computing availableBalanceForSend and availableBalanceForReceive, the initiator keeps an extra buffer on
|
// NB: when computing availableBalanceForSend and availableBalanceForReceive, the initiator keeps an extra buffer on
|
||||||
// top of its usual channel reserve to avoid getting channels stuck in case the on-chain feerate increases (see
|
// top of its usual channel reserve to avoid getting channels stuck in case the on-chain feerate increases (see
|
||||||
|
|
|
@ -649,7 +649,7 @@ private class InteractiveTxBuilder(replyTo: ActorRef[InteractiveTxBuilder.Respon
|
||||||
}
|
}
|
||||||
|
|
||||||
val sharedInput_opt = fundingParams.sharedInput_opt.map(_ => {
|
val sharedInput_opt = fundingParams.sharedInput_opt.map(_ => {
|
||||||
val remoteReserve = (fundingParams.fundingAmount / 100).max(channelParams.localParams.dustLimit)
|
val remoteReserve = channelParams.remoteChannelReserveForCapacity(fundingParams.fundingAmount)
|
||||||
// We ignore the reserve requirement if we are splicing funds into the channel, which increases the size of the reserve.
|
// We ignore the reserve requirement if we are splicing funds into the channel, which increases the size of the reserve.
|
||||||
if (sharedOutput.remoteAmount < remoteReserve && remoteOutputs.nonEmpty && localInputs.isEmpty) {
|
if (sharedOutput.remoteAmount < remoteReserve && remoteOutputs.nonEmpty && localInputs.isEmpty) {
|
||||||
log.warn("invalid interactive tx: peer takes too much funds out and falls below the channel reserve ({} < {})", sharedOutput.remoteAmount, remoteReserve)
|
log.warn("invalid interactive tx: peer takes too much funds out and falls below the channel reserve ({} < {})", sharedOutput.remoteAmount, remoteReserve)
|
||||||
|
|
Loading…
Add table
Reference in a new issue