htlcswitch/link: integrate persistence changes to lnwallet APIs

This commit is contained in:
Conner Fromknecht 2018-02-23 22:40:55 -08:00
parent d420266911
commit 1fe7c6d431
No known key found for this signature in database
GPG Key ID: 39DE78FBE6ACB0EF

@ -503,7 +503,7 @@ func (l *channelLink) syncChanStates() error {
// We've just received a ChnSync message from the remote party, // We've just received a ChnSync message from the remote party,
// so we'll process the message in order to determine if we // so we'll process the message in order to determine if we
// need to re-transmit any messages to the remote party. // need to re-transmit any messages to the remote party.
msgsToReSend, err = l.channel.ProcessChanSyncMsg(remoteChanSyncMsg) msgsToReSend, _, _, err = l.channel.ProcessChanSyncMsg(remoteChanSyncMsg)
if err != nil { if err != nil {
// TODO(roasbeef): check concrete type of error, act // TODO(roasbeef): check concrete type of error, act
// accordingly // accordingly
@ -580,7 +580,7 @@ func (l *channelLink) syncChanStates() error {
// remote party. // remote party.
var p [32]byte var p [32]byte
copy(p[:], preimage) copy(p[:], preimage)
err := l.channel.SettleHTLC(p, htlc.HtlcIndex) err := l.channel.SettleHTLC(p, htlc.HtlcIndex, nil, nil, nil)
if err != nil { if err != nil {
l.fail("unable to settle htlc: %v", err) l.fail("unable to settle htlc: %v", err)
return err return err
@ -819,7 +819,7 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
// so we add the new HTLC to our local log, then update the // so we add the new HTLC to our local log, then update the
// commitment chains. // commitment chains.
htlc.ChanID = l.ChanID() htlc.ChanID = l.ChanID()
index, err := l.channel.AddHTLC(htlc) index, err := l.channel.AddHTLC(htlc, nil)
if err != nil { if err != nil {
switch err { switch err {
@ -910,7 +910,13 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
// An HTLC we forward to the switch has just settled somewhere // An HTLC we forward to the switch has just settled somewhere
// upstream. Therefore we settle the HTLC within the our local // upstream. Therefore we settle the HTLC within the our local
// state machine. // state machine.
err := l.channel.SettleHTLC(htlc.PaymentPreimage, pkt.incomingHTLCID) err := l.channel.SettleHTLC(
htlc.PaymentPreimage,
pkt.incomingHTLCID,
nil,
nil,
nil,
)
if err != nil { if err != nil {
// TODO(roasbeef): broadcast on-chain // TODO(roasbeef): broadcast on-chain
l.fail("unable to settle incoming HTLC: %v", err) l.fail("unable to settle incoming HTLC: %v", err)
@ -931,7 +937,13 @@ func (l *channelLink) handleDownStreamPkt(pkt *htlcPacket, isReProcess bool) {
case *lnwire.UpdateFailHTLC: case *lnwire.UpdateFailHTLC:
// An HTLC cancellation has been triggered somewhere upstream, // An HTLC cancellation has been triggered somewhere upstream,
// we'll remove then HTLC from our local state machine. // we'll remove then HTLC from our local state machine.
err := l.channel.FailHTLC(pkt.incomingHTLCID, htlc.Reason) err := l.channel.FailHTLC(
pkt.incomingHTLCID,
htlc.Reason,
nil,
nil,
nil,
)
if err != nil { if err != nil {
log.Errorf("unable to cancel HTLC: %v", err) log.Errorf("unable to cancel HTLC: %v", err)
return return
@ -1129,7 +1141,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
// We've received a revocation from the remote chain, if valid, // We've received a revocation from the remote chain, if valid,
// this moves the remote chain forward, and expands our // this moves the remote chain forward, and expands our
// revocation window. // revocation window.
htlcs, err := l.channel.ReceiveRevocation(msg) _, adds, settleFails, err := l.channel.ReceiveRevocation(msg)
if err != nil { if err != nil {
l.fail("unable to accept revocation: %v", err) l.fail("unable to accept revocation: %v", err)
return return
@ -1139,6 +1151,7 @@ func (l *channelLink) handleUpstreamMsg(msg lnwire.Message) {
// commitment transactions they might be safely propagated over // commitment transactions they might be safely propagated over
// htlc switch or settled if our node was last node in htlc // htlc switch or settled if our node was last node in htlc
// path. // path.
htlcs := append(settleFails, adds...)
htlcsToForward := l.processLockedInHtlcs(htlcs) htlcsToForward := l.processLockedInHtlcs(htlcs)
go func() { go func() {
log.Debugf("ChannelPoint(%v) forwarding %v HTLC's", log.Debugf("ChannelPoint(%v) forwarding %v HTLC's",
@ -1646,7 +1659,7 @@ func (l *channelLink) processLockedInHtlcs(
} }
preimage := invoice.Terms.PaymentPreimage preimage := invoice.Terms.PaymentPreimage
err = l.channel.SettleHTLC(preimage, pd.HtlcIndex) err = l.channel.SettleHTLC(preimage, pd.HtlcIndex, nil, nil, nil)
if err != nil { if err != nil {
l.fail("unable to settle htlc: %v", err) l.fail("unable to settle htlc: %v", err)
return nil return nil
@ -1868,7 +1881,7 @@ func (l *channelLink) sendHTLCError(htlcIndex uint64,
return return
} }
err = l.channel.FailHTLC(htlcIndex, reason) err = l.channel.FailHTLC(htlcIndex, reason, nil, nil, nil)
if err != nil { if err != nil {
log.Errorf("unable cancel htlc: %v", err) log.Errorf("unable cancel htlc: %v", err)
return return
@ -1887,7 +1900,7 @@ func (l *channelLink) sendMalformedHTLCError(htlcIndex uint64,
code lnwire.FailCode, onionBlob []byte) { code lnwire.FailCode, onionBlob []byte) {
shaOnionBlob := sha256.Sum256(onionBlob) shaOnionBlob := sha256.Sum256(onionBlob)
err := l.channel.MalformedFailHTLC(htlcIndex, code, shaOnionBlob) err := l.channel.MalformedFailHTLC(htlcIndex, code, shaOnionBlob, nil)
if err != nil { if err != nil {
log.Errorf("unable cancel htlc: %v", err) log.Errorf("unable cancel htlc: %v", err)
return return