-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Enforce MPP/AMP records in QueryRoutes and SendToRoute #10467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kartikangiras
wants to merge
4
commits into
lightningnetwork:master
Choose a base branch
from
kartikangiras:mpp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5a59ecd
lnrpc: add payment_addr and amp_record fields
kartikangiras 8a115a6
routing: add PaymentAddr and AMP support
kartikangiras 5af2c4a
routerrpc: enforce MPP/AMP records in routes
kartikangiras 14c16e9
multi: update tests for MPP/AMP enforcement
kartikangiras File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| package routerrpc | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/lightningnetwork/lnd/lnrpc" | ||
| "github.com/lightningnetwork/lnd/routing/route" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestUnmarshallRouteMPPValidation tests that UnmarshallRoute correctly | ||
| // enforces the MPP/AMP record validation on incoming routes. | ||
| func TestUnmarshallRouteMPPValidation(t *testing.T) { | ||
| t.Parallel() | ||
| backend := &RouterBackend{ | ||
| SelfNode: route.Vertex{1, 2, 3}, | ||
| } | ||
|
|
||
| // Test case 1: Route with no MPP or AMP record should succeed with | ||
| // a deprecation warning. | ||
| t.Run("no_mpp_or_amp", func(t *testing.T) { | ||
| rpcRoute := &lnrpc.Route{ | ||
| TotalTimeLock: 100, | ||
| TotalAmtMsat: 1000, | ||
| Hops: []*lnrpc.Hop{ | ||
| { | ||
| PubKey: "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", | ||
| ChanId: 12345, | ||
| AmtToForwardMsat: 1000, | ||
| Expiry: 100, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| // Should succeed with deprecation warning logged. | ||
| _, err := backend.UnmarshallRoute(rpcRoute) | ||
| require.NoError(t, err) | ||
| }) | ||
|
|
||
| // Test case 2: Route with MPP record should succeed. | ||
| t.Run("with_mpp", func(t *testing.T) { | ||
| paymentAddr := make([]byte, 32) | ||
| paymentAddr[0] = 1 | ||
|
|
||
| rpcRoute := &lnrpc.Route{ | ||
| TotalTimeLock: 100, | ||
| TotalAmtMsat: 1000, | ||
| Hops: []*lnrpc.Hop{ | ||
| { | ||
| PubKey: "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", | ||
| ChanId: 12345, | ||
| AmtToForwardMsat: 1000, | ||
| Expiry: 100, | ||
| MppRecord: &lnrpc.MPPRecord{ | ||
| PaymentAddr: paymentAddr, | ||
| TotalAmtMsat: 1000, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| _, err := backend.UnmarshallRoute(rpcRoute) | ||
| require.NoError(t, err) | ||
| }) | ||
|
|
||
| // Test case 3: Route with AMP record should succeed. | ||
| t.Run("with_amp", func(t *testing.T) { | ||
| rootShare := make([]byte, 32) | ||
| setID := make([]byte, 32) | ||
| rootShare[0] = 1 | ||
| setID[0] = 2 | ||
|
|
||
| rpcRoute := &lnrpc.Route{ | ||
| TotalTimeLock: 100, | ||
| TotalAmtMsat: 1000, | ||
| Hops: []*lnrpc.Hop{ | ||
| { | ||
| PubKey: "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", | ||
| ChanId: 12345, | ||
| AmtToForwardMsat: 1000, | ||
| Expiry: 100, | ||
| AmpRecord: &lnrpc.AMPRecord{ | ||
| RootShare: rootShare, | ||
| SetId: setID, | ||
| ChildIndex: 0, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| _, err := backend.UnmarshallRoute(rpcRoute) | ||
| require.NoError(t, err) | ||
| }) | ||
|
|
||
| // Test case 4: Route with both MPP and AMP records should fail. | ||
| t.Run("both_mpp_and_amp", func(t *testing.T) { | ||
| paymentAddr := make([]byte, 32) | ||
| rootShare := make([]byte, 32) | ||
| setID := make([]byte, 32) | ||
| paymentAddr[0] = 1 | ||
| rootShare[0] = 1 | ||
| setID[0] = 2 | ||
|
|
||
| rpcRoute := &lnrpc.Route{ | ||
| TotalTimeLock: 100, | ||
| TotalAmtMsat: 1000, | ||
| Hops: []*lnrpc.Hop{ | ||
| { | ||
| PubKey: "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", | ||
| ChanId: 12345, | ||
| AmtToForwardMsat: 1000, | ||
| Expiry: 100, | ||
| MppRecord: &lnrpc.MPPRecord{ | ||
| PaymentAddr: paymentAddr, | ||
| TotalAmtMsat: 1000, | ||
| }, | ||
| AmpRecord: &lnrpc.AMPRecord{ | ||
| RootShare: rootShare, | ||
| SetId: setID, | ||
| ChildIndex: 0, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| _, err := backend.UnmarshallRoute(rpcRoute) | ||
| require.Error(t, err) | ||
| require.Contains(t, err.Error(), "cannot have both MPP and AMP") | ||
| }) | ||
|
|
||
| // Test case 5: Blinded route should not require MPP/AMP. | ||
| t.Run("blinded_no_mpp", func(t *testing.T) { | ||
| blindingPoint := []byte{ | ||
| 0x02, 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, | ||
| 0xac, 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b, | ||
| 0x07, 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, 0x28, | ||
| 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, | ||
| 0x98, | ||
| } | ||
|
|
||
| rpcRoute := &lnrpc.Route{ | ||
| TotalTimeLock: 100, | ||
| TotalAmtMsat: 1000, | ||
| Hops: []*lnrpc.Hop{ | ||
| { | ||
| PubKey: "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", | ||
| ChanId: 12345, | ||
| AmtToForwardMsat: 1000, | ||
| Expiry: 100, | ||
| BlindingPoint: blindingPoint, | ||
| EncryptedData: []byte{1, 2, 3}, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| _, err := backend.UnmarshallRoute(rpcRoute) | ||
| require.NoError(t, err) | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.