routing: only pack amount and cltv if populated

With the addition of blinded routes, we now need to account for the
possibility that intermediate nodes payloads will not have an amount
and expiry set because that information is provided by the recipient
encrypted data blob. This commit updates our payload packing to only
optionally include those fields.
This commit is contained in:
Carla Kirk-Cohen
2022-12-20 14:02:42 -05:00
committed by Olaoluwa Osuntokun
parent fee0e05708
commit 940b491051
2 changed files with 40 additions and 11 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/btcsuite/btcd/btcec/v2"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/record"
"github.com/stretchr/testify/require"
)
var (
@@ -159,6 +160,20 @@ func TestAMPHop(t *testing.T) {
}
}
// TestNoForwardingParams tests packing of a hop payload without an amount or
// expiry height.
func TestNoForwardingParams(t *testing.T) {
t.Parallel()
hop := Hop{
EncryptedData: []byte{1, 2, 3},
}
var b bytes.Buffer
err := hop.PackHopPayload(&b, 2)
require.NoError(t, err)
}
// TestPayloadSize tests the payload size calculation that is provided by Hop
// structs.
func TestPayloadSize(t *testing.T) {