From f32a7a28abe881c7f821fa3d237a87ed2fb38cea Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 12 Sep 2017 18:10:30 +0200 Subject: [PATCH] htlcswitch: if we fail to parse and onion error, return the proper lnwire.FailCode --- htlcswitch/iterator.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/htlcswitch/iterator.go b/htlcswitch/iterator.go index 16191134..f34507a1 100644 --- a/htlcswitch/iterator.go +++ b/htlcswitch/iterator.go @@ -160,9 +160,17 @@ func NewOnionProcessor(router *sphinx.Router) *OnionProcessor { // MACs during the decoding process. func (p *OnionProcessor) DecodeHopIterator(r io.Reader, rHash []byte) (HopIterator, lnwire.FailCode) { + onionPkt := &sphinx.OnionPacket{} if err := onionPkt.Decode(r); err != nil { - return nil, lnwire.CodeTemporaryChannelFailure + switch err { + case sphinx.ErrInvalidOnionVersion: + return nil, lnwire.CodeInvalidOnionVersion + case sphinx.ErrInvalidOnionKey: + return nil, lnwire.CodeInvalidOnionKey + default: + return nil, lnwire.CodeTemporaryChannelFailure + } } // Attempt to process the Sphinx packet. We include the payment hash of @@ -197,7 +205,14 @@ func (p *OnionProcessor) DecodeHopIterator(r io.Reader, rHash []byte) (HopIterat func (p *OnionProcessor) DecodeOnionObfuscator(r io.Reader) (Obfuscator, lnwire.FailCode) { onionPkt := &sphinx.OnionPacket{} if err := onionPkt.Decode(r); err != nil { - return nil, lnwire.CodeTemporaryChannelFailure + switch err { + case sphinx.ErrInvalidOnionVersion: + return nil, lnwire.CodeInvalidOnionVersion + case sphinx.ErrInvalidOnionKey: + return nil, lnwire.CodeInvalidOnionKey + default: + return nil, lnwire.CodeTemporaryChannelFailure + } } onionObfuscator, err := sphinx.NewOnionObfuscator(p.router,