-
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] pluggable anchor commitments #3821
[anchor] pluggable anchor commitments #3821
Conversation
lnwallet/commitment.go
Outdated
theirBalance -= commitFeeMSat | ||
} | ||
|
||
// If the commitment has anchors, we must also subtract the anchor |
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.
This is a bit awkward, but is a result of that the balances we store in the db has had their commit fee subtracted. should we do a db migration to change this?
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.
You want instead to store the balance on disk with the anchor output size already subtracted?
lnwallet/commitment.go
Outdated
// and commitment point. The keys are derived differently depending on the type | ||
// of channel, and whether the commitment transaction is ours or the remote | ||
// peer's. | ||
func DeriveCommitmentKeys(commitPoint *btcec.PublicKey, |
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.
Separate move from change in two commits, for easier review.
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.
This look pretty good. The word anchor disappeared completely from lnwallet.Channel
. I also see that there may be more to encapsulate, but the commitment building is probably the most important thing.
I still have that ideal in mind where there is a CommitmentBuilder
interface and a separate instance for the anchor commit format. Those instances would be thin and build on a lot of shared building blocks. It is probably too much for now and this is already a good step in that direction.
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.
Quick skim, cool pr :)
5f89aad
to
819a5dd
Compare
b55825f
to
0bb5f08
Compare
0bb5f08
to
62fe01f
Compare
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.
Some drive-by comments
lnwallet/commitment.go
Outdated
@@ -229,6 +229,18 @@ func CommitScriptToRemote(chanType channeldb.ChannelType, csvTimeout uint32, | |||
}, nil | |||
} | |||
|
|||
func InitiatorFee(chanType channeldb.ChannelType, commitWeight int64, |
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.
Would there be a better term for miner_fee + anchors
then "fee"? To prevent introducing a second definition of fee. Cost, overhead, ..?
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.
I like cost
perhaps?
lnwallet/channel.go
Outdated
} | ||
|
||
// Not found. | ||
return nil |
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.
Could make this stricter and return an error if the channel type says there must be anchors.
3661f7e
to
d17272b
Compare
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.
Solid PR! We're soo close 🤗
The one thing that seems to be missing from my run through is ensuring that we re-account for the value that we deducted for anchors each time we go to create a new commitment.
lnwallet/commitment.go
Outdated
remoteBalance = theirBalance.ToSatoshis() | ||
) | ||
if cb.chanState.ChanType.HasAnchors() { | ||
anchors := 2 * anchorSize |
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.
totalAnchorValue
?
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.
Also could very well just be lifted into a constant of its own.
lnwallet/commitment.go
Outdated
theirBalance -= commitFeeMSat | ||
} | ||
|
||
// If the commitment has anchors, we must also subtract the anchor |
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.
You want instead to store the balance on disk with the anchor output size already subtracted?
// genSweepTx generates a swepp of the senderCommitTx, and sets the | ||
// sequence if locktime is true. | ||
genSweepTx := func(locktime bool) { | ||
prevOut := &wire.OutPoint{ |
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.
A worthy follow up PR would be also testing second-level HTLC aggregation.
@@ -213,6 +219,16 @@ func NewChannelReservation(capacity, localFundingAmt btcutil.Amount, | |||
) | |||
} | |||
|
|||
// Similarly we ensure their balance is reasonable if we are not the | |||
// initiator. | |||
if !initiator && theirBalance.ToSatoshis() <= 2*DefaultDustLimit() { |
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.
Where does this requirement come from?
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.
It is not a new requirement, it was just something I noticed wasn't checked. Made it a separate commit.
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.
Why 2 times the dust limit?
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.
From 10 lines above
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.
Isn't 10 lines above 2 times the anchor size?
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.
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.
this is likely wrong for LTC, but so are most of these checks...
c472925
to
fa13a63
Compare
fa13a63
to
72f257a
Compare
72f257a
to
9df54e7
Compare
We also increase the witness size for these types to account for the 3 extra bytes. The size won't be correct in all cases, but it is just an upper bound in any case.
With this commitment type, we'll add extra anchor outputs to the commitment transaction if the anchor channel type is active.
…witness script We use the fact that we can tell whether the commit is local or remote by inspecting the witness script. We cannot use the maturity delay anymore, as we can have delayed to_remote outputs also now. Co-authored-by: Joost Jager <[email protected]>
… type Based on the channel type, the commitment weight will be calculated.
If we are the initiator, we check that our starting balance after subtracting fees are not less than two times the default dust limit. This commit adds a similar check for the non-initiator case, checking that the remote party has a starting balance of reasonable size.
To prepare for adding more commit types to test for basic channel funding, we make the commit type an enum that gets its own set of subtests.
Since we are also going to use it for experimental new features.
Defaults to disabled.
If both nodes are signalling the feature, make all opened channels using this type.
00aa935
to
b7885db
Compare
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 📯
Excellent work @halseth and @joostjager!
We should also extend the integration tests to cover breach retribution for all the existing commitment types. This can be done as a follow up PR. I'll also put together a small follow up PR to enable SCB support as well.
// AnchorsRequired is a required feature bit that signals that the node | ||
// requires channels to be made using commitments having anchor | ||
// outputs. | ||
AnchorsRequired FeatureBit = 1336 |
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.
Rather it should be resolved before we cut a release with this included. Feature bits are easy to change after the fact.
// HtlcConfirmedScriptOverhead is the extra length of an HTLC script | ||
// that requires confirmation before it can be spent. These extra bytes | ||
// is a result of the extra CSV check. | ||
HtlcConfirmedScriptOverhead = 3 |
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.
👍
Missing from end-to-end anchors working:
to_remote
outputTODO:
Long term:
Builds on #3829