From 54c4fc455920e837d7840dc094b0d21eb0e33b20 Mon Sep 17 00:00:00 2001 From: John Griffith Date: Fri, 8 Sep 2017 12:35:37 +0200 Subject: [PATCH] htlcswitch+server: pass onion error to ChannelRouter --- htlcswitch/mock.go | 18 ++++++-------- htlcswitch/switch.go | 49 +-------------------------------------- htlcswitch/switch_test.go | 24 ++++--------------- server.go | 4 ---- 4 files changed, 12 insertions(+), 83 deletions(-) diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index c437cc57..e6758f4d 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -51,17 +51,13 @@ func newMockServer(t *testing.T, name string) *mockServer { copy(id[:], h[:]) return &mockServer{ - t: t, - id: id, - name: name, - messages: make(chan lnwire.Message, 3000), - quit: make(chan bool), - registry: newMockRegistry(), - htlcSwitch: New(Config{ - UpdateTopology: func(msg *lnwire.ChannelUpdate) error { - return nil - }, - }), + t: t, + id: id, + name: name, + messages: make(chan lnwire.Message, 3000), + quit: make(chan bool), + registry: newMockRegistry(), + htlcSwitch: New(Config{}), recordFuncs: make([]func(lnwire.Message), 0), } } diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index f1c99c62..8bd45c6a 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -89,12 +89,6 @@ type Config struct { // or forced unilateral closure of the channel initiated by a local // subsystem. LocalChannelClose func(pubKey []byte, request *ChanClose) - - // UpdateTopology sends the onion error failure topology update to router - // subsystem. - // - // TODO(roasbeef): remove - UpdateTopology func(msg *lnwire.ChannelUpdate) error } // Switch is the central messaging bus for all incoming/outgoing HTLCs. @@ -395,51 +389,10 @@ func (s *Switch) handleLocalDispatch(payment *pendingPayment, packet *htlcPacket "onion failure, htlc with hash(%x): %v", payment.paymentHash[:], err) log.Error(userErr) - } else { - // Process payment failure by updating the lightning - // network topology by using router subsystem handler. - var update *lnwire.ChannelUpdate - - // Only a few error message actually contain a channel - // update message, so we'll filter out for those that - // do. - switch failure := failure.(type) { - case *lnwire.FailTemporaryChannelFailure: - update = failure.Update - case *lnwire.FailAmountBelowMinimum: - update = &failure.Update - case *lnwire.FailFeeInsufficient: - update = &failure.Update - case *lnwire.FailIncorrectCltvExpiry: - update = &failure.Update - case *lnwire.FailExpiryTooSoon: - update = &failure.Update - case *lnwire.FailChannelDisabled: - update = &failure.Update - } - - // If we've been sent an error that includes an update, - // then we'll apply it to the local graph. - // - // TODO(roasbeef): instead, make all onion errors the - // error interface, and handle this within the router. - // Will allow us more flexibility w.r.t how we handle - // the error. - if update != nil { - log.Infof("Received payment failure(%v), "+ - "applying lightning network topology update", - failure.Code()) - - if err := s.cfg.UpdateTopology(update); err != nil { - log.Errorf("unable to update topology: %v", err) - } - } - - userErr = errors.New(failure.Code()) } // Notify user that his payment was discarded. - payment.err <- userErr + payment.err <- failure payment.preimage <- zeroPreimage s.removePendingPayment(payment.amount, payment.paymentHash) diff --git a/htlcswitch/switch_test.go b/htlcswitch/switch_test.go index 4f370324..0b0c20fc 100644 --- a/htlcswitch/switch_test.go +++ b/htlcswitch/switch_test.go @@ -40,11 +40,7 @@ func TestSwitchForward(t *testing.T) { aliceChannelLink := newMockChannelLink(chanID1, aliceChanID, alicePeer) bobChannelLink := newMockChannelLink(chanID2, bobChanID, bobPeer) - s := New(Config{ - UpdateTopology: func(msg *lnwire.ChannelUpdate) error { - return nil - }, - }) + s := New(Config{}) s.Start() if err := s.AddLink(aliceChannelLink); err != nil { t.Fatalf("unable to add alice link: %v", err) @@ -122,11 +118,7 @@ func TestSwitchCancel(t *testing.T) { aliceChannelLink := newMockChannelLink(chanID1, aliceChanID, alicePeer) bobChannelLink := newMockChannelLink(chanID2, bobChanID, bobPeer) - s := New(Config{ - UpdateTopology: func(msg *lnwire.ChannelUpdate) error { - return nil - }, - }) + s := New(Config{}) s.Start() if err := s.AddLink(aliceChannelLink); err != nil { t.Fatalf("unable to add alice link: %v", err) @@ -202,11 +194,7 @@ func TestSwitchAddSamePayment(t *testing.T) { aliceChannelLink := newMockChannelLink(chanID1, aliceChanID, alicePeer) bobChannelLink := newMockChannelLink(chanID2, bobChanID, bobPeer) - s := New(Config{ - UpdateTopology: func(msg *lnwire.ChannelUpdate) error { - return nil - }, - }) + s := New(Config{}) s.Start() if err := s.AddLink(aliceChannelLink); err != nil { t.Fatalf("unable to add alice link: %v", err) @@ -302,11 +290,7 @@ func TestSwitchSendPayment(t *testing.T) { alicePeer := newMockServer(t, "alice") aliceChannelLink := newMockChannelLink(chanID1, aliceChanID, alicePeer) - s := New(Config{ - UpdateTopology: func(msg *lnwire.ChannelUpdate) error { - return nil - }, - }) + s := New(Config{}) s.Start() if err := s.AddLink(aliceChannelLink); err != nil { t.Fatalf("unable to add link: %v", err) diff --git a/server.go b/server.go index 2fd67771..f9ff2a21 100644 --- a/server.go +++ b/server.go @@ -181,10 +181,6 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl, pubKey[:], err) } }, - UpdateTopology: func(msg *lnwire.ChannelUpdate) error { - s.authGossiper.ProcessRemoteAnnouncement(msg, nil) - return nil - }, }) // If external IP addresses have been specified, add those to the list