-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[anchor commitment] Make the anchor commitment type spec compliant #4558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
517fcd6
724f439
07a57ae
09a126b
a48c369
bf18929
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -663,6 +663,47 @@ func CreateCommitTx(chanType channeldb.ChannelType, | |
| return commitTx, nil | ||
| } | ||
|
|
||
| // CoopCloseBalance returns the final balances that should be used to create | ||
| // the cooperative close tx, given the channel type and transaction fee. | ||
| func CoopCloseBalance(chanType channeldb.ChannelType, isInitiator bool, | ||
| coopCloseFee btcutil.Amount, localCommit channeldb.ChannelCommitment) ( | ||
| btcutil.Amount, btcutil.Amount, error) { | ||
|
|
||
| // Get both parties' balances from the latest commitment. | ||
| ourBalance := localCommit.LocalBalance.ToSatoshis() | ||
| theirBalance := localCommit.RemoteBalance.ToSatoshis() | ||
|
|
||
| // We'll make sure we account for the complete balance by adding the | ||
| // current dangling commitment fee to the balance of the initiator. | ||
| initiatorDelta := localCommit.CommitFee | ||
|
|
||
| // Since the initiator's balance also is stored after subtracting the | ||
| // anchor values, add that back in case this was an anchor commitment. | ||
| if chanType.HasAnchors() { | ||
| initiatorDelta += 2 * anchorSize | ||
| } | ||
|
|
||
| // The initiator will pay the full coop close fee, subtract that value | ||
| // from their balance. | ||
| initiatorDelta -= coopCloseFee | ||
|
|
||
| if isInitiator { | ||
| ourBalance += initiatorDelta | ||
| } else { | ||
| theirBalance += initiatorDelta | ||
| } | ||
|
|
||
| // During fee negotiation it should always be verified that the | ||
| // initiator can pay the proposed fee, but we do a sanity check just to | ||
| // be sure here. | ||
| if ourBalance < 0 || theirBalance < 0 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make clear in a comment that this is a sanity check and not supposed to be hit?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. narrator: it was hit |
||
| return 0, 0, fmt.Errorf("initiator cannot afford proposed " + | ||
| "coop close fee") | ||
| } | ||
|
|
||
| return ourBalance, theirBalance, nil | ||
| } | ||
|
|
||
| // genHtlcScript generates the proper P2WSH public key scripts for the HTLC | ||
| // output modified by two-bits denoting if this is an incoming HTLC, and if the | ||
| // HTLC is being applied to their commitment transaction or ours. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.