Skip to content

Commit

Permalink
sphinx: increase NumMaxHops to accomodate for tlv payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
joostjager committed Dec 11, 2019
1 parent 7964cdf commit 20a5267
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
14 changes: 9 additions & 5 deletions path.go
Expand Up @@ -304,11 +304,15 @@ func (hp *HopPayload) HopData() (*HopData, error) {
return &hd, nil
}

// NumMaxHops is the maximum path length. This should be set to an estimate of
// the upper limit of the diameter of the node graph.
//
// TODO(roasbeef): adjust due to var-payloads?
const NumMaxHops = 20
// NumMaxHops is the maximum path length. There is a maximum of 1300 bytes in
// the routing info block. Legacy hop payloads are always 65 bytes, while tlv
// payloads are at least 47 bytes (tlvlen 1, amt 2, timelock 2, nextchan 10,
// hmac 32) for the intermediate hops and 37 bytes (tlvlen 1, amt 2, timelock 2,
// hmac 32) for the exit hop. The maximum path length can therefore only be
// reached by using tlv payloads only. With that, the maximum number of
// intermediate hops is: Floor((1300 - 37) / 47) = 26. Including the exit hop,
// the maximum path length is 27 hops.
const NumMaxHops = 27

// PaymentPath represents a series of hops within the Lightning Network
// starting at a sender and terminating at a receiver. Each hop contains a set
Expand Down
12 changes: 7 additions & 5 deletions sphinx_test.go
Expand Up @@ -86,6 +86,8 @@ var (
"2cf4f0731da13b8546d1d6d4f8d75b9fce6c2341a71b0ea6f780" +
"df54bfdb0dd5cd9855179f602f917265f21f9190c70217774a6f" +
"baaa7d63ad64199f4664813b955cff954949076dcf"

testLegacyRouteNumHops = 20
)

func newTestRoute(numHops int) ([]*Router, *PaymentPath, *[]HopData, *OnionPacket, error) {
Expand Down Expand Up @@ -214,7 +216,7 @@ func TestBolt4Packet(t *testing.T) {
}

func TestSphinxCorrectness(t *testing.T) {
nodes, _, hopDatas, fwdMsg, err := newTestRoute(NumMaxHops)
nodes, _, hopDatas, fwdMsg, err := newTestRoute(testLegacyRouteNumHops)
if err != nil {
t.Fatalf("unable to create random onion packet: %v", err)
}
Expand Down Expand Up @@ -307,7 +309,7 @@ func TestSphinxSingleHop(t *testing.T) {
func TestSphinxNodeRelpay(t *testing.T) {
// We'd like to ensure that the sphinx node itself rejects all replayed
// packets which share the same shared secret.
nodes, _, _, fwdMsg, err := newTestRoute(NumMaxHops)
nodes, _, _, fwdMsg, err := newTestRoute(testLegacyRouteNumHops)
if err != nil {
t.Fatalf("unable to create test route: %v", err)
}
Expand All @@ -332,7 +334,7 @@ func TestSphinxNodeRelpay(t *testing.T) {
func TestSphinxNodeRelpaySameBatch(t *testing.T) {
// We'd like to ensure that the sphinx node itself rejects all replayed
// packets which share the same shared secret.
nodes, _, _, fwdMsg, err := newTestRoute(NumMaxHops)
nodes, _, _, fwdMsg, err := newTestRoute(testLegacyRouteNumHops)
if err != nil {
t.Fatalf("unable to create test route: %v", err)
}
Expand Down Expand Up @@ -378,7 +380,7 @@ func TestSphinxNodeRelpaySameBatch(t *testing.T) {
func TestSphinxNodeRelpayLaterBatch(t *testing.T) {
// We'd like to ensure that the sphinx node itself rejects all replayed
// packets which share the same shared secret.
nodes, _, _, fwdMsg, err := newTestRoute(NumMaxHops)
nodes, _, _, fwdMsg, err := newTestRoute(testLegacyRouteNumHops)
if err != nil {
t.Fatalf("unable to create test route: %v", err)
}
Expand Down Expand Up @@ -423,7 +425,7 @@ func TestSphinxNodeRelpayLaterBatch(t *testing.T) {
func TestSphinxNodeReplayBatchIdempotency(t *testing.T) {
// We'd like to ensure that the sphinx node itself rejects all replayed
// packets which share the same shared secret.
nodes, _, _, fwdMsg, err := newTestRoute(NumMaxHops)
nodes, _, _, fwdMsg, err := newTestRoute(testLegacyRouteNumHops)
if err != nil {
t.Fatalf("unable to create test route: %v", err)
}
Expand Down

0 comments on commit 20a5267

Please sign in to comment.