Skip to content

Commit

Permalink
Clarify commitTxFeeMsat
Browse files Browse the repository at this point in the history
It's a bit counter-intuitive that we deduce anchor amounts in this function,
because it's not technically a fee.
  • Loading branch information
t-bast committed Feb 24, 2021
1 parent 5d88187 commit d1542c5
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,16 @@ object Transactions {
def commitTxFeeMsat(dustLimit: Satoshi, spec: CommitmentSpec, commitmentFormat: CommitmentFormat): MilliSatoshi = {
val trimmedOfferedHtlcs = trimOfferedHtlcs(dustLimit, spec, commitmentFormat)
val trimmedReceivedHtlcs = trimReceivedHtlcs(dustLimit, spec, commitmentFormat)
val weight = commitmentFormat.commitWeight + commitmentFormat.htlcOutputWeight * (trimmedOfferedHtlcs.size + trimmedReceivedHtlcs.size)
val fee = weight2feeMsat(spec.feeratePerKw, weight)
// When using anchor outputs, the funder pays for *both* anchors all the time, even if only one anchor is present.
// This is not technically a fee (it doesn't go to miners) but it has to be deduced from the funder's main output,
// so for simplicity we deduce it here.
val anchorsCost = commitmentFormat match {
case DefaultCommitmentFormat => Satoshi(0)
// the funder pays for both anchors all the time, even if only one anchor is present
case AnchorOutputsCommitmentFormat => AnchorOutputsCommitmentFormat.anchorAmount * 2
}
val weight = commitmentFormat.commitWeight + commitmentFormat.htlcOutputWeight * (trimmedOfferedHtlcs.size + trimmedReceivedHtlcs.size)
weight2feeMsat(spec.feeratePerKw, weight) + anchorsCost
fee + anchorsCost
}

def commitTxFee(dustLimit: Satoshi, spec: CommitmentSpec, commitmentFormat: CommitmentFormat): Satoshi = commitTxFeeMsat(dustLimit, spec, commitmentFormat).truncateToSatoshi
Expand Down

0 comments on commit d1542c5

Please sign in to comment.