-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[anchor commitment] Make the anchor commitment type spec compliant #4558
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first pass looks good
lnwallet/commitment.go
Outdated
} | ||
|
||
if isInitiator { | ||
ourBalance = ourBalance - coopCloseFee + commitFee + anchorValue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possible underflow, here and below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-existing, but I think it is safe to add the extra check: ca22db6
lnwallet/commitment.go
Outdated
if isInitiator { | ||
ourBalance = ourBalance - coopCloseFee + commitFee + anchorValue | ||
} else { | ||
theirBalance = theirBalance - coopCloseFee + commitFee + anchorValue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be simplified with +=
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe coopCloseFee + commitFee + anchorValue
can be extracted to prevent a future bug where only one is updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extracted into initiatorDelta
: a8ec11a
lncfg/protocol.go
Outdated
|
||
// Anchors should be set if we want to support opening or accepting | ||
// channels having the anchor commitment type. | ||
Anchors bool `long:"anchors" description:"enable support for anchor commitments (won't work with watchtowers)"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preexisting: help message is a little misleading. it will work with watchtowers, but state updates for anchor channels won't be backed up. this should change before 0.12 though with anchor tower support in the works
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated: 83fe313
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Tested on regtest and inspected coop close tx. Anchor value is indeed added back to the initiator balance. Two questions:
- Did you (manually) test coop closing an old-format anchor channel?
- Is the itest coop closing with anchors anywhere?
lnwallet/commitment.go
Outdated
if isInitiator { | ||
ourBalance = ourBalance - coopCloseFee + commitFee + anchorValue | ||
} else { | ||
theirBalance = theirBalance - coopCloseFee + commitFee + anchorValue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe coopCloseFee + commitFee + anchorValue
can be extracted to prevent a future bug where only one is updated
Do you mean one node running the updated code, one node running the old code? If yes, then I tried this in one of the integration tests, and closing expectedly failed.
Yes, most tests using anchors are closing the channel at the end, most notably the |
@halseth looks good, can squash now |
@@ -693,7 +693,12 @@ func CoopCloseBalance(chanType channeldb.ChannelType, isInitiator bool, | |||
theirBalance += initiatorDelta | |||
} | |||
|
|||
return ourBalance, theirBalance | |||
if ourBalance < 0 || theirBalance < 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
narrator: it was hit
Squashed and rebased. Removed the commit making anchors non-experimental as discussed, such that they are still behind a build tag. |
@halseth appears related to newly added underflow check
|
Fixed! |
|
@cfromknecht Should be good now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🤓
To be spec compliant, we require the initiator to not pay the anchor values into fees on coop close. We extract the balance calculation into commitment.go, and add back the value of the anchors to the initiator's balance.
Also modify the test to check for this condition.
1ea3da2
to
bf18929
Compare
This PR makes the necessary changes to the anchor commitment type to make it compliant with the final spec version as defined in lightning/bolts#688
There are two changes needed:
20/21
. This means that we now require this bit to be advertised to signal anchor support. The old bit will be ignored by new nodes.NOTE: Watchtowers are still not supported for anchor commitment types, and anchor support is not advertised by default but must be enabled through the
--protocol.anchors
option.