htlcswitch+server: pass onion error to ChannelRouter
This commit is contained in:
parent
492f7fa52f
commit
54c4fc4559
@ -57,11 +57,7 @@ func newMockServer(t *testing.T, name string) *mockServer {
|
||||
messages: make(chan lnwire.Message, 3000),
|
||||
quit: make(chan bool),
|
||||
registry: newMockRegistry(),
|
||||
htlcSwitch: New(Config{
|
||||
UpdateTopology: func(msg *lnwire.ChannelUpdate) error {
|
||||
return nil
|
||||
},
|
||||
}),
|
||||
htlcSwitch: New(Config{}),
|
||||
recordFuncs: make([]func(lnwire.Message), 0),
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user