mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-23 17:59:41 +02:00
lnwire+htlcswitch: change NewInvalidBlinding to use array instead of slice
This commit is contained in:
committed by
Oliver Gugger
parent
e4497b4f45
commit
9904af5d96
@@ -3468,11 +3468,6 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
|
|||||||
// or are able to settle it (and it adheres to our fee related
|
// or are able to settle it (and it adheres to our fee related
|
||||||
// constraints).
|
// constraints).
|
||||||
|
|
||||||
// Fetch the onion blob that was included within this processed
|
|
||||||
// payment descriptor.
|
|
||||||
var onionBlob [lnwire.OnionPacketSize]byte
|
|
||||||
copy(onionBlob[:], pd.OnionBlob[:])
|
|
||||||
|
|
||||||
// Before adding the new htlc to the state machine, parse the
|
// Before adding the new htlc to the state machine, parse the
|
||||||
// onion object in order to obtain the routing information with
|
// onion object in order to obtain the routing information with
|
||||||
// DecodeHopIterator function which process the Sphinx packet.
|
// DecodeHopIterator function which process the Sphinx packet.
|
||||||
@@ -3581,7 +3576,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg,
|
|||||||
l.cfg.DisallowRouteBlinding {
|
l.cfg.DisallowRouteBlinding {
|
||||||
|
|
||||||
failure := lnwire.NewInvalidBlinding(
|
failure := lnwire.NewInvalidBlinding(
|
||||||
onionBlob[:],
|
fn.Some(pd.OnionBlob),
|
||||||
)
|
)
|
||||||
l.sendHTLCError(
|
l.sendHTLCError(
|
||||||
pd, NewLinkError(failure), obfuscator, false,
|
pd, NewLinkError(failure), obfuscator, false,
|
||||||
@@ -4027,7 +4022,9 @@ func (l *channelLink) sendIncomingHTLCFailureMsg(htlcIndex uint64,
|
|||||||
|
|
||||||
// The specification does not require that we set the onion
|
// The specification does not require that we set the onion
|
||||||
// blob.
|
// blob.
|
||||||
failureMsg := lnwire.NewInvalidBlinding(nil)
|
failureMsg := lnwire.NewInvalidBlinding(
|
||||||
|
fn.None[[lnwire.OnionPacketSize]byte](),
|
||||||
|
)
|
||||||
reason, err := e.EncryptFirstHop(failureMsg)
|
reason, err := e.EncryptFirstHop(failureMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
"github.com/lightningnetwork/lnd/tlv"
|
"github.com/lightningnetwork/lnd/tlv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1271,14 +1272,19 @@ func (f *FailInvalidBlinding) Encode(w *bytes.Buffer, _ uint32) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewInvalidBlinding creates new instance of FailInvalidBlinding.
|
// NewInvalidBlinding creates new instance of FailInvalidBlinding.
|
||||||
func NewInvalidBlinding(onion []byte) *FailInvalidBlinding {
|
func NewInvalidBlinding(
|
||||||
|
onion fn.Option[[OnionPacketSize]byte]) *FailInvalidBlinding {
|
||||||
// The spec allows empty onion hashes for invalid blinding, so we only
|
// The spec allows empty onion hashes for invalid blinding, so we only
|
||||||
// include our onion hash if it's provided.
|
// include our onion hash if it's provided.
|
||||||
if onion == nil {
|
if onion.IsNone() {
|
||||||
return &FailInvalidBlinding{}
|
return &FailInvalidBlinding{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &FailInvalidBlinding{OnionSHA256: sha256.Sum256(onion)}
|
shaSum := fn.MapOptionZ(onion, func(o [OnionPacketSize]byte) [32]byte {
|
||||||
|
return sha256.Sum256(o[:])
|
||||||
|
})
|
||||||
|
|
||||||
|
return &FailInvalidBlinding{OnionSHA256: shaSum}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecodeFailure decodes, validates, and parses the lnwire onion failure, for
|
// DecodeFailure decodes, validates, and parses the lnwire onion failure, for
|
||||||
|
@@ -9,11 +9,12 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
testOnionHash = []byte{}
|
testOnionHash = [OnionPacketSize]byte{}
|
||||||
testAmount = MilliSatoshi(1)
|
testAmount = MilliSatoshi(1)
|
||||||
testCtlvExpiry = uint32(2)
|
testCtlvExpiry = uint32(2)
|
||||||
testFlags = uint16(2)
|
testFlags = uint16(2)
|
||||||
@@ -43,9 +44,9 @@ var onionFailures = []FailureMessage{
|
|||||||
&FailMPPTimeout{},
|
&FailMPPTimeout{},
|
||||||
|
|
||||||
NewFailIncorrectDetails(99, 100),
|
NewFailIncorrectDetails(99, 100),
|
||||||
NewInvalidOnionVersion(testOnionHash),
|
NewInvalidOnionVersion(testOnionHash[:]),
|
||||||
NewInvalidOnionHmac(testOnionHash),
|
NewInvalidOnionHmac(testOnionHash[:]),
|
||||||
NewInvalidOnionKey(testOnionHash),
|
NewInvalidOnionKey(testOnionHash[:]),
|
||||||
NewTemporaryChannelFailure(&testChannelUpdate),
|
NewTemporaryChannelFailure(&testChannelUpdate),
|
||||||
NewTemporaryChannelFailure(nil),
|
NewTemporaryChannelFailure(nil),
|
||||||
NewAmountBelowMinimum(testAmount, testChannelUpdate),
|
NewAmountBelowMinimum(testAmount, testChannelUpdate),
|
||||||
@@ -56,7 +57,7 @@ var onionFailures = []FailureMessage{
|
|||||||
NewFinalIncorrectCltvExpiry(testCtlvExpiry),
|
NewFinalIncorrectCltvExpiry(testCtlvExpiry),
|
||||||
NewFinalIncorrectHtlcAmount(testAmount),
|
NewFinalIncorrectHtlcAmount(testAmount),
|
||||||
NewInvalidOnionPayload(testType, testOffset),
|
NewInvalidOnionPayload(testType, testOffset),
|
||||||
NewInvalidBlinding(testOnionHash),
|
NewInvalidBlinding(fn.Some(testOnionHash)),
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestEncodeDecodeCode tests the ability of onion errors to be properly encoded
|
// TestEncodeDecodeCode tests the ability of onion errors to be properly encoded
|
||||||
|
Reference in New Issue
Block a user