htlcswitch: if we fail to parse and onion error, return the proper lnwire.FailCode

This commit is contained in:
Olaoluwa Osuntokun 2017-09-12 18:10:30 +02:00
parent 3d95efdc0f
commit f32a7a28ab
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -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,