lnwallet+htlcswitch: add NewCommitState struct, modify send/recv sig to accept

In this commit, we add a new NewCommitState struct. This preps us for
the future change wherein a partial signature is also added to the mix.
All related tests and type signatures have also been updated
accordingly.
This commit is contained in:
Olaoluwa Osuntokun committed 2023-08-22 16:31:18 -07:00
1 parent 72d41ae408
commit 11c62e3951
9 files changed
+342 -322

No files matched your search

+9 -6
View File
@@ -1899,7 +1899,10 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
// We just received a new updates to our local commitment
// chain, validate this new commitment, closing the link if
// invalid.
err = l.channel.ReceiveNewCommitment(msg.CommitSig, msg.HtlcSigs)
err = l.channel.ReceiveNewCommitment(&lnwallet.CommitSigs{
CommitSig: msg.CommitSig,
HtlcSigs: msg.HtlcSigs,
})
if err != nil {
// If we were unable to reconstruct their proposed
// commitment, then we'll examine the type of error. If
@@ -2215,7 +2218,7 @@ func (l *channelLink) updateCommitTx() error {
return nil
}
theirCommitSig, htlcSigs, pendingHTLCs, err := l.channel.SignNextCommitment()
newCommit, err := l.channel.SignNextCommitment()
if err == lnwallet.ErrNoWindow {
l.cfg.PendingCommitTicker.Resume()
l.log.Trace("PendingCommitTicker resumed")
@@ -2247,7 +2250,7 @@ func (l *channelLink) updateCommitTx() error {
// pending).
newUpdate := &contractcourt.ContractUpdate{
HtlcKey: contractcourt.RemotePendingHtlcSet,
Htlcs: pendingHTLCs,
Htlcs: newCommit.PendingHTLCs,
}
err = l.cfg.NotifyContractUpdate(newUpdate)
if err != nil {
@@ -2262,9 +2265,9 @@ func (l *channelLink) updateCommitTx() error {
}
commitSig := &lnwire.CommitSig{
ChanID: l.ChanID(),
CommitSig: theirCommitSig,
HtlcSigs: htlcSigs,
ChanID: l.ChanID(),
CommitSig: newCommit.CommitSig,
HtlcSigs: newCommit.HtlcSigs,
}
l.cfg.Peer.SendMessage(false, commitSig)
+7 -6
View File
@@ -93,14 +93,14 @@ func (l *linkTestContext) receiveHtlcAliceToBob() {
func (l *linkTestContext) sendCommitSigBobToAlice(expHtlcs int) {
l.t.Helper()
sig, htlcSigs, _, err := l.bobChannel.SignNextCommitment()
sigs, err := l.bobChannel.SignNextCommitment()
if err != nil {
l.t.Fatalf("error signing commitment: %v", err)
}
commitSig := &lnwire.CommitSig{
CommitSig: sig,
HtlcSigs: htlcSigs,
CommitSig: sigs.CommitSig,
HtlcSigs: sigs.HtlcSigs,
}
if len(commitSig.HtlcSigs) != expHtlcs {
@@ -141,9 +141,10 @@ func (l *linkTestContext) receiveCommitSigAliceToBob(expHtlcs int) {
comSig := l.receiveCommitSigAlice(expHtlcs)
err := l.bobChannel.ReceiveNewCommitment(
comSig.CommitSig, comSig.HtlcSigs,
)
err := l.bobChannel.ReceiveNewCommitment(&lnwallet.CommitSigs{
CommitSig: comSig.CommitSig,
HtlcSigs: comSig.HtlcSigs,
})
if err != nil {
l.t.Fatalf("bob failed receiving commitment: %v", err)
}
+28 -22
View File
@@ -2062,8 +2062,10 @@ func handleStateUpdate(link *channelLink,
// Let the remote channel receive the commit sig, and
// respond with a revocation + commitsig.
err := remoteChannel.ReceiveNewCommitment(
commitSig.CommitSig, commitSig.HtlcSigs)
err := remoteChannel.ReceiveNewCommitment(&lnwallet.CommitSigs{
CommitSig: commitSig.CommitSig,
HtlcSigs: commitSig.HtlcSigs,
})
if err != nil {
return err
}
@@ -2074,13 +2076,13 @@ func handleStateUpdate(link *channelLink,
}
link.HandleChannelUpdate(remoteRev)
remoteSig, remoteHtlcSigs, _, err := remoteChannel.SignNextCommitment()
remoteSigs, err := remoteChannel.SignNextCommitment()
if err != nil {
return err
}
commitSig = &lnwire.CommitSig{
CommitSig: remoteSig,
HtlcSigs: remoteHtlcSigs,
CommitSig: remoteSigs.CommitSig,
HtlcSigs: remoteSigs.HtlcSigs,
}
link.HandleChannelUpdate(commitSig)
@@ -2125,14 +2127,14 @@ func updateState(batchTick chan time.Time, link *channelLink,
// The remote is triggering the state update, emulate this by
// signing and sending CommitSig to the link.
remoteSig, remoteHtlcSigs, _, err := remoteChannel.SignNextCommitment()
remoteSigs, err := remoteChannel.SignNextCommitment()
if err != nil {
return err
}
commitSig := &lnwire.CommitSig{
CommitSig: remoteSig,
HtlcSigs: remoteHtlcSigs,
CommitSig: remoteSigs.CommitSig,
HtlcSigs: remoteSigs.HtlcSigs,
}
link.HandleChannelUpdate(commitSig)
@@ -2165,8 +2167,10 @@ func updateState(batchTick chan time.Time, link *channelLink,
return fmt.Errorf("expected CommitSig, got %T", msg)
}
err = remoteChannel.ReceiveNewCommitment(
commitSig.CommitSig, commitSig.HtlcSigs)
err = remoteChannel.ReceiveNewCommitment(&lnwallet.CommitSigs{
CommitSig: commitSig.CommitSig,
HtlcSigs: commitSig.HtlcSigs,
})
if err != nil {
return err
}
@@ -3239,7 +3243,10 @@ func TestChannelLinkTrimCircuitsRemoteCommit(t *testing.T) {
t.Fatalf("alice did not send commitment signature")
}
err := bobChan.ReceiveNewCommitment(sig.CommitSig, sig.HtlcSigs)
err := bobChan.ReceiveNewCommitment(&lnwallet.CommitSigs{
CommitSig: sig.CommitSig,
HtlcSigs: sig.HtlcSigs,
})
if err != nil {
t.Fatalf("unable to receive new commitment: %v", err)
}
@@ -4839,9 +4846,10 @@ func TestChannelLinkNoEmptySig(t *testing.T) {
ctx.sendCommitSigBobToAlice(1)
// Now send Bob the signature from Alice covering both htlcs.
err = bobChannel.ReceiveNewCommitment(
commitSigAlice.CommitSig, commitSigAlice.HtlcSigs,
)
err = bobChannel.ReceiveNewCommitment(&lnwallet.CommitSigs{
CommitSig: commitSigAlice.CommitSig,
HtlcSigs: commitSigAlice.HtlcSigs,
})
require.NoError(t, err, "bob failed receiving commitment")
// Both Alice and Bob revoke their previous commitment txes.
@@ -5443,8 +5451,7 @@ func TestChannelLinkFail(t *testing.T) {
// Sign a commitment that will include
// signature for the HTLC just sent.
sig, htlcSigs, _, err :=
remoteChannel.SignNextCommitment()
sigs, err := remoteChannel.SignNextCommitment()
if err != nil {
t.Fatalf("error signing commitment: %v",
err)
@@ -5453,8 +5460,8 @@ func TestChannelLinkFail(t *testing.T) {
// Remove the HTLC sig, such that the commit
// sig will be invalid.
commitSig := &lnwire.CommitSig{
CommitSig: sig,
HtlcSigs: htlcSigs[1:],
CommitSig: sigs.CommitSig,
HtlcSigs: sigs.HtlcSigs[1:],
}
c.HandleChannelUpdate(commitSig)
@@ -5485,8 +5492,7 @@ func TestChannelLinkFail(t *testing.T) {
// Sign a commitment that will include
// signature for the HTLC just sent.
sig, htlcSigs, _, err :=
remoteChannel.SignNextCommitment()
sigs, err := remoteChannel.SignNextCommitment()
if err != nil {
t.Fatalf("error signing commitment: %v",
err)
@@ -5494,7 +5500,7 @@ func TestChannelLinkFail(t *testing.T) {
// Flip a bit on the signature, rendering it
// invalid.
sigCopy := sig.Copy()
sigCopy := sigs.CommitSig.Copy()
copyBytes := sigCopy.RawBytes()
copyBytes[19] ^= 1
modifiedSig, err := lnwire.NewSigFromWireECDSA(
@@ -5503,7 +5509,7 @@ func TestChannelLinkFail(t *testing.T) {
require.NoError(t, err)
commitSig := &lnwire.CommitSig{
CommitSig: modifiedSig,
HtlcSigs: htlcSigs,
HtlcSigs: sigs.HtlcSigs,
}
c.HandleChannelUpdate(commitSig)