multi: explicitly signal final hop in pack hop payload

Previously, we'd use the value of nextChanID to infer whether a payload
was for the final hop in a route. This commit updates our packing logic
to explicitly signal to account for blinded routes, which allow zero
value nextChanID in intermediate hops. This is a preparatory commit
that allows us to more thoroughly validate payloads.
This commit is contained in:
Carla Kirk-Cohen
2023-11-01 10:46:48 -04:00
parent b5afd905d1
commit 585f28c5f5
3 changed files with 20 additions and 15 deletions

View File

@@ -105,7 +105,7 @@ func TestMPPHop(t *testing.T) {
// Encoding an MPP record to an intermediate hop should result in a
// failure.
var b bytes.Buffer
err := hop.PackHopPayload(&b, 2)
err := hop.PackHopPayload(&b, 2, false)
if err != ErrIntermediateMPPHop {
t.Fatalf("expected err: %v, got: %v",
ErrIntermediateMPPHop, err)
@@ -113,7 +113,7 @@ func TestMPPHop(t *testing.T) {
// Encoding an MPP record to a final hop should be successful.
b.Reset()
err = hop.PackHopPayload(&b, 0)
err = hop.PackHopPayload(&b, 0, true)
if err != nil {
t.Fatalf("expected err: %v, got: %v", nil, err)
}
@@ -135,7 +135,7 @@ func TestAMPHop(t *testing.T) {
// Encoding an AMP record to an intermediate hop w/o an MPP record
// should result in a failure.
var b bytes.Buffer
err := hop.PackHopPayload(&b, 2)
err := hop.PackHopPayload(&b, 2, false)
if err != ErrAMPMissingMPP {
t.Fatalf("expected err: %v, got: %v",
ErrAMPMissingMPP, err)
@@ -144,7 +144,7 @@ func TestAMPHop(t *testing.T) {
// Encoding an AMP record to a final hop w/o an MPP record should result
// in a failure.
b.Reset()
err = hop.PackHopPayload(&b, 0)
err = hop.PackHopPayload(&b, 0, true)
if err != ErrAMPMissingMPP {
t.Fatalf("expected err: %v, got: %v",
ErrAMPMissingMPP, err)
@@ -154,7 +154,7 @@ func TestAMPHop(t *testing.T) {
// successful.
hop.MPP = record.NewMPP(testAmt, testAddr)
b.Reset()
err = hop.PackHopPayload(&b, 0)
err = hop.PackHopPayload(&b, 0, true)
if err != nil {
t.Fatalf("expected err: %v, got: %v", nil, err)
}
@@ -170,7 +170,7 @@ func TestNoForwardingParams(t *testing.T) {
}
var b bytes.Buffer
err := hop.PackHopPayload(&b, 2)
err := hop.PackHopPayload(&b, 2, false)
require.NoError(t, err)
}