-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add Experimental Endorsement Signalling #8390
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
Merged
ellemouton
merged 5 commits into
lightningnetwork:master
from
carlaKC:7883-experimental-endorsement
Nov 26, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
774bfa7
htlcswitch: relay experimental endorsement signal with update_add_htlc
carlaKC 4bb5b0c
lnrpc: set a zero value endorsement signal on sender outgoing htlc
carlaKC f02bb58
multi: add experimental endorsement feature bit and disable option
carlaKC 7a876e8
itest: add coverage for experimental endorsement
carlaKC a8c159b
docs: add experimental endorsement
carlaKC 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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| package itest | ||
|
|
||
| import ( | ||
| "math" | ||
|
|
||
| "github.com/btcsuite/btcd/btcutil" | ||
| "github.com/lightningnetwork/lnd/lnrpc" | ||
| "github.com/lightningnetwork/lnd/lnrpc/routerrpc" | ||
| "github.com/lightningnetwork/lnd/lntest" | ||
| "github.com/lightningnetwork/lnd/lntest/rpc" | ||
| "github.com/lightningnetwork/lnd/lntest/wait" | ||
| "github.com/lightningnetwork/lnd/lntypes" | ||
| "github.com/lightningnetwork/lnd/lnwire" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // testExperimentalEndorsement tests setting of positive and negative | ||
| // experimental endorsement signals. | ||
| func testExperimentalEndorsement(ht *lntest.HarnessTest) { | ||
|
carlaKC marked this conversation as resolved.
|
||
| testEndorsement(ht, true) | ||
| testEndorsement(ht, false) | ||
| } | ||
|
|
||
| // testEndorsement sets up a 5 hop network and tests propagation of | ||
| // experimental endorsement signals. | ||
| func testEndorsement(ht *lntest.HarnessTest, aliceEndorse bool) { | ||
| alice, bob := ht.Alice, ht.Bob | ||
| carol := ht.NewNode( | ||
| "carol", []string{"--protocol.no-experimental-endorsement"}, | ||
| ) | ||
| dave := ht.NewNode("dave", nil) | ||
| eve := ht.NewNode("eve", nil) | ||
|
|
||
| ht.EnsureConnected(alice, bob) | ||
| ht.EnsureConnected(bob, carol) | ||
| ht.EnsureConnected(carol, dave) | ||
| ht.EnsureConnected(dave, eve) | ||
|
|
||
| ht.FundCoins(btcutil.SatoshiPerBitcoin, carol) | ||
| ht.FundCoins(btcutil.SatoshiPerBitcoin, dave) | ||
| // Open and wait for channels. | ||
| const chanAmt = btcutil.Amount(300000) | ||
| p := lntest.OpenChannelParams{Amt: chanAmt} | ||
| reqs := []*lntest.OpenChannelRequest{ | ||
| {Local: alice, Remote: bob, Param: p}, | ||
| {Local: bob, Remote: carol, Param: p}, | ||
| {Local: carol, Remote: dave, Param: p}, | ||
| {Local: dave, Remote: eve, Param: p}, | ||
| } | ||
| resp := ht.OpenMultiChannelsAsync(reqs) | ||
| cpAB, cpBC, cpCD, cpDE := resp[0], resp[1], resp[2], resp[3] | ||
|
|
||
| // Make sure Alice is aware of Bob=>Carol=>Dave=>Eve channels. | ||
| ht.AssertChannelInGraph(alice, cpBC) | ||
| ht.AssertChannelInGraph(alice, cpCD) | ||
| ht.AssertChannelInGraph(alice, cpDE) | ||
|
|
||
| bobIntercept, cancelBob := bob.RPC.HtlcInterceptor() | ||
| defer cancelBob() | ||
|
|
||
| carolIntercept, cancelCarol := carol.RPC.HtlcInterceptor() | ||
| defer cancelCarol() | ||
|
|
||
| daveIntercept, cancelDave := dave.RPC.HtlcInterceptor() | ||
| defer cancelDave() | ||
|
|
||
| req := &lnrpc.Invoice{ValueMsat: 1000} | ||
| addResponse := eve.RPC.AddInvoice(req) | ||
| invoice := eve.RPC.LookupInvoice(addResponse.RHash) | ||
|
|
||
| sendReq := &routerrpc.SendPaymentRequest{ | ||
| PaymentRequest: invoice.PaymentRequest, | ||
| TimeoutSeconds: int32(wait.PaymentTimeout.Seconds()), | ||
| FeeLimitMsat: math.MaxInt64, | ||
| } | ||
|
|
||
| expectedValue := []byte{lnwire.ExperimentalUnendorsed} | ||
| if aliceEndorse { | ||
| expectedValue = []byte{lnwire.ExperimentalEndorsed} | ||
| t := uint64(lnwire.ExperimentalEndorsementType) | ||
| sendReq.FirstHopCustomRecords = map[uint64][]byte{ | ||
| t: expectedValue, | ||
| } | ||
| } | ||
|
|
||
| _ = alice.RPC.SendPayment(sendReq) | ||
|
|
||
| // Validate that our signal (positive or zero) propagates until carol | ||
| // and then is dropped because she has disabled the feature. | ||
| validateEndorsedAndResume(ht, bobIntercept, true, expectedValue) | ||
| validateEndorsedAndResume(ht, carolIntercept, true, expectedValue) | ||
| validateEndorsedAndResume(ht, daveIntercept, false, nil) | ||
|
|
||
| var preimage lntypes.Preimage | ||
| copy(preimage[:], invoice.RPreimage) | ||
| ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) | ||
|
|
||
| ht.CloseChannel(alice, cpAB) | ||
| ht.CloseChannel(bob, cpBC) | ||
| ht.CloseChannel(carol, cpCD) | ||
| ht.CloseChannel(dave, cpDE) | ||
| } | ||
|
|
||
| func validateEndorsedAndResume(ht *lntest.HarnessTest, | ||
| interceptor rpc.InterceptorClient, hasEndorsement bool, | ||
| expectedValue []byte) { | ||
|
|
||
| packet := ht.ReceiveHtlcInterceptor(interceptor) | ||
|
|
||
| var expectedRecords map[uint64][]byte | ||
| if hasEndorsement { | ||
| u64Type := uint64(lnwire.ExperimentalEndorsementType) | ||
| expectedRecords = map[uint64][]byte{ | ||
| u64Type: expectedValue, | ||
| } | ||
| } | ||
| require.Equal(ht, expectedRecords, packet.InWireCustomRecords) | ||
|
|
||
| err := interceptor.Send(&routerrpc.ForwardHtlcInterceptResponse{ | ||
| IncomingCircuitKey: packet.IncomingCircuitKey, | ||
| Action: routerrpc.ResolveHoldForwardAction_RESUME, | ||
| }) | ||
| require.NoError(ht, err) | ||
| } | ||
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.