htlcswitch: modify channelLink to use new create+verify commitment API

This commit is contained in:
Olaoluwa Osuntokun 2017-07-30 14:08:25 -07:00
parent f7c4237686
commit 2d1a598b66
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -2,7 +2,6 @@ package htlcswitch
import ( import (
"bytes" "bytes"
"fmt"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
@ -14,7 +13,6 @@ import (
"github.com/go-errors/errors" "github.com/go-errors/errors"
"github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/lnwire"
"github.com/roasbeef/btcd/btcec"
"github.com/roasbeef/btcd/chaincfg/chainhash" "github.com/roasbeef/btcd/chaincfg/chainhash"
"github.com/roasbeef/btcd/wire" "github.com/roasbeef/btcd/wire"
"github.com/roasbeef/btcutil" "github.com/roasbeef/btcutil"
@ -291,6 +289,7 @@ out:
// TODO(roasbeef): need to send HTLC outputs to nursery // TODO(roasbeef): need to send HTLC outputs to nursery
// TODO(roasbeef): or let the arb sweep?
l.cfg.SettledContracts <- l.channel.ChannelPoint() l.cfg.SettledContracts <- l.channel.ChannelPoint()
break out break out
@ -630,10 +629,8 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
case *lnwire.CommitSig: case *lnwire.CommitSig:
// We just received a new update to our local commitment chain, // We just received a new update to our local commitment chain,
// validate this new commitment, closing the link if invalid. // validate this new commitment, closing the link if invalid.
// err := l.channel.ReceiveNewCommitment(msg.CommitSig, msg.HtlcSigs)
// TODO(roasbeef): redundant re-serialization if err != nil {
sig := msg.CommitSig.Serialize()
if err := l.channel.ReceiveNewCommitment(sig); err != nil {
l.fail("unable to accept new commitment: %v", err) l.fail("unable to accept new commitment: %v", err)
return return
} }
@ -718,7 +715,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
// commitment to their commitment chain which includes all the latest updates // commitment to their commitment chain which includes all the latest updates
// we've received+processed up to this point. // we've received+processed up to this point.
func (l *channelLink) updateCommitTx() error { func (l *channelLink) updateCommitTx() error {
sigTheirs, err := l.channel.SignNextCommitment() theirCommitSig, htlcSigs, err := l.channel.SignNextCommitment()
if err == lnwallet.ErrNoWindow { if err == lnwallet.ErrNoWindow {
log.Tracef("revocation window exhausted, unable to send %v", log.Tracef("revocation window exhausted, unable to send %v",
l.batchCounter) l.batchCounter)
@ -727,14 +724,10 @@ func (l *channelLink) updateCommitTx() error {
return err return err
} }
parsedSig, err := btcec.ParseSignature(sigTheirs, btcec.S256())
if err != nil {
return fmt.Errorf("unable to parse sig: %v", err)
}
commitSig := &lnwire.CommitSig{ commitSig := &lnwire.CommitSig{
ChanID: l.ChanID(), ChanID: l.ChanID(),
CommitSig: parsedSig, CommitSig: theirCommitSig,
HtlcSigs: htlcSigs,
} }
l.cfg.Peer.SendMessage(commitSig) l.cfg.Peer.SendMessage(commitSig)