htlcswitch+routing+routerrpc: return error source as index
This commit is contained in:
11 files changed
+245
-310
No files matched your search
+10
-9
@@ -6,17 +6,18 @@ import (
|
||||
"io"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/lightningnetwork/lightning-onion"
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
// ForwardingError wraps an lnwire.FailureMessage in a struct that also
|
||||
// includes the source of the error.
|
||||
type ForwardingError struct {
|
||||
// ErrorSource is the public key of the node that sent the error. With
|
||||
// this information, the dispatcher of a payment can modify their set
|
||||
// of candidate routes in response to the type of error extracted.
|
||||
ErrorSource *btcec.PublicKey
|
||||
// FailureSourceIdx is the index of the node that sent the failure. With
|
||||
// this information, the dispatcher of a payment can modify their set of
|
||||
// candidate routes in response to the type of failure extracted. Index
|
||||
// zero is the self node.
|
||||
FailureSourceIdx int
|
||||
|
||||
// ExtraMsg is an additional error message that callers can provide in
|
||||
// order to provide context specific error details.
|
||||
@@ -256,20 +257,20 @@ type SphinxErrorDecrypter struct {
|
||||
// NOTE: Part of the ErrorDecrypter interface.
|
||||
func (s *SphinxErrorDecrypter) DecryptError(reason lnwire.OpaqueReason) (*ForwardingError, error) {
|
||||
|
||||
source, failureData, err := s.OnionErrorDecrypter.DecryptError(reason)
|
||||
failure, err := s.OnionErrorDecrypter.DecryptError(reason)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r := bytes.NewReader(failureData)
|
||||
r := bytes.NewReader(failure.Message)
|
||||
failureMsg, err := lnwire.DecodeFailure(r, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ForwardingError{
|
||||
ErrorSource: source,
|
||||
FailureMessage: failureMsg,
|
||||
FailureSourceIdx: failure.SenderIdx,
|
||||
FailureMessage: failureMsg,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
+2
-8
@@ -163,10 +163,7 @@ func initSwitchWithDB(startingHeight uint32, db *channeldb.DB) (*Switch, error)
|
||||
}
|
||||
}
|
||||
|
||||
priv, _ := btcec.NewPrivateKey(btcec.S256())
|
||||
pubkey := priv.PubKey()
|
||||
cfg := Config{
|
||||
SelfKey: pubkey,
|
||||
DB: db,
|
||||
SwitchPackager: channeldb.NewSwitchPackager(),
|
||||
FwdingLog: &mockForwardingLog{
|
||||
@@ -393,12 +390,9 @@ func (o *mockDeobfuscator) DecryptError(reason lnwire.OpaqueReason) (*Forwarding
|
||||
return nil, err
|
||||
}
|
||||
|
||||
priv, _ := btcec.NewPrivateKey(btcec.S256())
|
||||
pubkey := priv.PubKey()
|
||||
|
||||
return &ForwardingError{
|
||||
ErrorSource: pubkey,
|
||||
FailureMessage: failure,
|
||||
FailureSourceIdx: 1,
|
||||
FailureMessage: failure,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
+19
-25
@@ -9,7 +9,6 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/coreos/bbolt"
|
||||
@@ -112,11 +111,6 @@ type ChanClose struct {
|
||||
// Config defines the configuration for the service. ALL elements within the
|
||||
// configuration MUST be non-nil for the service to carry out its duties.
|
||||
type Config struct {
|
||||
// SelfKey is the key of the backing Lightning node. This key is used
|
||||
// to properly craft failure messages, such that the Layer 3 router can
|
||||
// properly route around link./vertex failures.
|
||||
SelfKey *btcec.PublicKey
|
||||
|
||||
// FwdingLog is an interface that will be used by the switch to log
|
||||
// forwarding events. A forwarding event happens each time a payment
|
||||
// circuit is successfully completed. So when we forward an HTLC, and a
|
||||
@@ -776,8 +770,8 @@ func (s *Switch) handleLocalDispatch(pkt *htlcPacket) error {
|
||||
if err != nil {
|
||||
log.Errorf("Link %v not found", pkt.outgoingChanID)
|
||||
return &ForwardingError{
|
||||
ErrorSource: s.cfg.SelfKey,
|
||||
FailureMessage: &lnwire.FailUnknownNextPeer{},
|
||||
FailureSourceIdx: 0,
|
||||
FailureMessage: &lnwire.FailUnknownNextPeer{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -790,9 +784,9 @@ func (s *Switch) handleLocalDispatch(pkt *htlcPacket) error {
|
||||
// will be returned back to the router.
|
||||
htlcErr := lnwire.NewTemporaryChannelFailure(nil)
|
||||
return &ForwardingError{
|
||||
ErrorSource: s.cfg.SelfKey,
|
||||
ExtraMsg: err.Error(),
|
||||
FailureMessage: htlcErr,
|
||||
FailureSourceIdx: 0,
|
||||
ExtraMsg: err.Error(),
|
||||
FailureMessage: htlcErr,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -808,8 +802,8 @@ func (s *Switch) handleLocalDispatch(pkt *htlcPacket) error {
|
||||
"satisfied", pkt.outgoingChanID)
|
||||
|
||||
return &ForwardingError{
|
||||
ErrorSource: s.cfg.SelfKey,
|
||||
FailureMessage: htlcErr,
|
||||
FailureSourceIdx: 0,
|
||||
FailureMessage: htlcErr,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -823,9 +817,9 @@ func (s *Switch) handleLocalDispatch(pkt *htlcPacket) error {
|
||||
// will be returned back to the router.
|
||||
htlcErr := lnwire.NewTemporaryChannelFailure(nil)
|
||||
return &ForwardingError{
|
||||
ErrorSource: s.cfg.SelfKey,
|
||||
ExtraMsg: err.Error(),
|
||||
FailureMessage: htlcErr,
|
||||
FailureSourceIdx: 0,
|
||||
ExtraMsg: err.Error(),
|
||||
FailureMessage: htlcErr,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -967,9 +961,9 @@ func (s *Switch) parseFailedPayment(deobfuscator ErrorDecrypter,
|
||||
failureMsg = lnwire.NewTemporaryChannelFailure(nil)
|
||||
}
|
||||
failure = &ForwardingError{
|
||||
ErrorSource: s.cfg.SelfKey,
|
||||
ExtraMsg: userErr,
|
||||
FailureMessage: failureMsg,
|
||||
FailureSourceIdx: 0,
|
||||
ExtraMsg: userErr,
|
||||
FailureMessage: failureMsg,
|
||||
}
|
||||
|
||||
// A payment had to be timed out on chain before it got past
|
||||
@@ -981,9 +975,9 @@ func (s *Switch) parseFailedPayment(deobfuscator ErrorDecrypter,
|
||||
"on-chain, then cancelled back (hash=%v, pid=%d)",
|
||||
paymentHash, paymentID)
|
||||
failure = &ForwardingError{
|
||||
ErrorSource: s.cfg.SelfKey,
|
||||
ExtraMsg: userErr,
|
||||
FailureMessage: lnwire.FailPermanentChannelFailure{},
|
||||
FailureSourceIdx: 0,
|
||||
ExtraMsg: userErr,
|
||||
FailureMessage: lnwire.FailPermanentChannelFailure{},
|
||||
}
|
||||
|
||||
// A regular multi-hop payment error that we'll need to
|
||||
@@ -999,9 +993,9 @@ func (s *Switch) parseFailedPayment(deobfuscator ErrorDecrypter,
|
||||
paymentHash, paymentID, err)
|
||||
log.Error(userErr)
|
||||
failure = &ForwardingError{
|
||||
ErrorSource: s.cfg.SelfKey,
|
||||
ExtraMsg: userErr,
|
||||
FailureMessage: lnwire.NewTemporaryChannelFailure(nil),
|
||||
FailureSourceIdx: 0,
|
||||
ExtraMsg: userErr,
|
||||
FailureMessage: lnwire.NewTemporaryChannelFailure(nil),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user