From ec099bf5ddb0c5148e5f3867ecf20bd44b9219fe Mon Sep 17 00:00:00 2001 From: carla Date: Tue, 14 Jan 2020 15:07:42 +0200 Subject: [PATCH] htlcswitch: remove extramsg string from ForwardingError Remove the extramsg field in ForwardingError because it has been replaced with detailed link errors. --- htlcswitch/failure.go | 17 ++++------------- htlcswitch/mock.go | 2 +- routing/router_test.go | 24 ++++++++++++------------ 3 files changed, 17 insertions(+), 26 deletions(-) diff --git a/htlcswitch/failure.go b/htlcswitch/failure.go index f3aa6ad2..35d78590 100644 --- a/htlcswitch/failure.go +++ b/htlcswitch/failure.go @@ -88,10 +88,6 @@ type ForwardingError struct { // 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. - ExtraMsg string - // msg is the wire message associated with the error. This value may // be nil in the case where we fail to decode failure message sent by // a peer. @@ -112,24 +108,19 @@ func (f *ForwardingError) WireMessage() lnwire.FailureMessage { // the switch or any callers to insert additional context to the error message // returned. func (f *ForwardingError) Error() string { - if f.ExtraMsg == "" { - return fmt.Sprintf("%v@%v", f.msg, f.FailureSourceIdx) - } - return fmt.Sprintf( - "%v@%v: %v", f.msg, f.FailureSourceIdx, f.ExtraMsg, + "%v@%v", f.msg, f.FailureSourceIdx, ) } // NewForwardingError creates a new payment error which wraps a wire error // with additional metadata. -func NewForwardingError(failure lnwire.FailureMessage, index int, - extraMsg string) *ForwardingError { +func NewForwardingError(failure lnwire.FailureMessage, + index int) *ForwardingError { return &ForwardingError{ FailureSourceIdx: index, msg: failure, - ExtraMsg: extraMsg, } } @@ -199,7 +190,7 @@ func (s *SphinxErrorDecrypter) DecryptError(reason lnwire.OpaqueReason) ( return NewUnknownForwardingError(failure.SenderIdx), nil } - return NewForwardingError(failureMsg, failure.SenderIdx, ""), nil + return NewForwardingError(failureMsg, failure.SenderIdx), nil } // A compile time check to ensure ErrorDecrypter implements the Deobfuscator diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index e39c6073..02737a71 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.go @@ -400,7 +400,7 @@ func (o *mockDeobfuscator) DecryptError(reason lnwire.OpaqueReason) (*Forwarding return nil, err } - return NewForwardingError(failure, 1, ""), nil + return NewForwardingError(failure, 1), nil } var _ ErrorDecrypter = (*mockDeobfuscator)(nil) diff --git a/routing/router_test.go b/routing/router_test.go index 53eaee8f..169557cc 100644 --- a/routing/router_test.go +++ b/routing/router_test.go @@ -292,7 +292,7 @@ func TestSendPaymentRouteFailureFallback(t *testing.T) { // TODO(roasbeef): temp node failure // should be? &lnwire.FailTemporaryChannelFailure{}, - 1, "", + 1, ) } @@ -425,7 +425,7 @@ func TestChannelUpdateValidation(t *testing.T) { &lnwire.FailFeeInsufficient{ Update: errChanUpdate, }, - 1, "", + 1, ) }) @@ -550,7 +550,7 @@ func TestSendPaymentErrorRepeatedFeeInsufficient(t *testing.T) { // node/channel. &lnwire.FailFeeInsufficient{ Update: errChanUpdate, - }, 1, "", + }, 1, ) } @@ -649,7 +649,7 @@ func TestSendPaymentErrorNonFinalTimeLockErrors(t *testing.T) { return [32]byte{}, htlcswitch.NewForwardingError( &lnwire.FailExpiryTooSoon{ Update: errChanUpdate, - }, 1, "", + }, 1, ) } @@ -702,7 +702,7 @@ func TestSendPaymentErrorNonFinalTimeLockErrors(t *testing.T) { return [32]byte{}, htlcswitch.NewForwardingError( &lnwire.FailIncorrectCltvExpiry{ Update: errChanUpdate, - }, 1, "", + }, 1, ) } @@ -763,7 +763,7 @@ func TestSendPaymentErrorPathPruning(t *testing.T) { // sophon not having enough capacity. return [32]byte{}, htlcswitch.NewForwardingError( &lnwire.FailTemporaryChannelFailure{}, - 1, "", + 1, ) } @@ -772,7 +772,7 @@ func TestSendPaymentErrorPathPruning(t *testing.T) { // which should prune out the rest of the routes. if firstHop == roasbeefPhanNuwen { return [32]byte{}, htlcswitch.NewForwardingError( - &lnwire.FailUnknownNextPeer{}, 1, "", + &lnwire.FailUnknownNextPeer{}, 1, ) } @@ -803,7 +803,7 @@ func TestSendPaymentErrorPathPruning(t *testing.T) { if firstHop == roasbeefSongoku { failure := htlcswitch.NewForwardingError( - &lnwire.FailUnknownNextPeer{}, 1, "", + &lnwire.FailUnknownNextPeer{}, 1, ) return [32]byte{}, failure } @@ -850,7 +850,7 @@ func TestSendPaymentErrorPathPruning(t *testing.T) { // roasbeef not having enough capacity. return [32]byte{}, htlcswitch.NewForwardingError( &lnwire.FailTemporaryChannelFailure{}, - 1, "", + 1, ) } return preImage, nil @@ -3102,7 +3102,7 @@ func TestRouterPaymentStateMachine(t *testing.T) { select { case sendResult <- htlcswitch.NewForwardingError( &lnwire.FailTemporaryChannelFailure{}, - 1, "", + 1, ): case <-time.After(1 * time.Second): t.Fatalf("unable to send result") @@ -3126,7 +3126,7 @@ func TestRouterPaymentStateMachine(t *testing.T) { case getPaymentResultFailure: failure := htlcswitch.NewForwardingError( &lnwire.FailTemporaryChannelFailure{}, - 1, "", + 1, ) select { @@ -3302,7 +3302,7 @@ func TestSendToRouteStructuredError(t *testing.T) { return [32]byte{}, htlcswitch.NewForwardingError( &lnwire.FailFeeInsufficient{ Update: lnwire.ChannelUpdate{}, - }, 1, "", + }, 1, ) })