Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions itest/lnd_experimental_endorsement.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,32 @@ func testEndorsement(ht *lntest.HarnessTest, aliceEndorse bool) {
FeeLimitMsat: math.MaxInt64,
}

expectedValue := []byte{lnwire.ExperimentalUnendorsed}
if aliceEndorse {
expectedValue = []byte{lnwire.ExperimentalEndorsed}
t := uint64(lnwire.ExperimentalEndorsementType)
sendReq.FirstHopCustomRecords = map[uint64][]byte{
t: expectedValue,
var expectedValue []byte
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could do a var-block

hasEndorsement := lntest.ExperimentalEndorsementActive()

if hasEndorsement {
if aliceEndorse {
expectedValue = []byte{lnwire.ExperimentalEndorsed}
t := uint64(lnwire.ExperimentalEndorsementType)
sendReq.FirstHopCustomRecords = map[uint64][]byte{
t: expectedValue,
}
} else {
expectedValue = []byte{lnwire.ExperimentalUnendorsed}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this else if we initialize expectedValue with []byte{lnwire.ExperimentalUnendorsed}.

}
}

_ = 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)
// When the endorsement experiment is not active, no signal is sent.
validateEndorsedAndResume(
ht, bobIntercept, hasEndorsement, expectedValue,
)
validateEndorsedAndResume(
ht, carolIntercept, hasEndorsement, expectedValue,
)
validateEndorsedAndResume(ht, daveIntercept, false, nil)

var preimage lntypes.Preimage
Expand Down
17 changes: 14 additions & 3 deletions itest/lnd_forward_interceptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,25 @@ func testForwardInterceptorRestart(ht *lntest.HarnessTest) {
// We should get another notification about the held HTLC.
packet = ht.ReceiveHtlcInterceptor(bobInterceptor)

require.Len(ht, packet.InWireCustomRecords, 2)
// Check the expected number of custom records based on whether the
// endorsement experiment is still active.
expectedLen := 1
if lntest.ExperimentalEndorsementActive() {
expectedLen = 2
}
require.Len(ht, packet.InWireCustomRecords, expectedLen)
require.Equal(ht, lntest.CustomRecordsWithUnendorsed(customRecords),
packet.InWireCustomRecords)

// And now we forward the payment at Carol, expecting only an
// endorsement signal in our incoming custom records.
// endorsement signal in our incoming custom records (if the experiment
// is still active).
packet = ht.ReceiveHtlcInterceptor(carolInterceptor)
require.Len(ht, packet.InWireCustomRecords, 1)
expectedCarolLen := 0
if lntest.ExperimentalEndorsementActive() {
expectedCarolLen = 1
}
require.Len(ht, packet.InWireCustomRecords, expectedCarolLen)
err = carolInterceptor.Send(&routerrpc.ForwardHtlcInterceptResponse{
IncomingCircuitKey: packet.IncomingCircuitKey,
Action: actionResume,
Expand Down
17 changes: 17 additions & 0 deletions lntest/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
"os"
"strconv"
"strings"
"time"

"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lntest/wait"
Expand Down Expand Up @@ -288,13 +290,28 @@ func CalcStaticFeeBuffer(c lnrpc.CommitmentType, numHTLCs int) btcutil.Amount {
func CustomRecordsWithUnendorsed(
originalRecords lnwire.CustomRecords) map[uint64][]byte {

if !ExperimentalEndorsementActive() {
// Return nil if there are no records, to match wire encoding.
if len(originalRecords) == 0 {
return nil
}

return originalRecords.Copy()
}

return originalRecords.MergedCopy(map[uint64][]byte{
uint64(lnwire.ExperimentalEndorsementType): {
lnwire.ExperimentalUnendorsed,
}},
)
}

// ExperimentalEndorsementActive returns true if the experimental endorsement
// window is still open.
func ExperimentalEndorsementActive() bool {
return time.Now().Before(lnd.EndorsementExperimentEnd)
}

// LnrpcOutpointToStr returns a string representation of an lnrpc.OutPoint.
func LnrpcOutpointToStr(outpoint *lnrpc.OutPoint) string {
return fmt.Sprintf("%s:%d", outpoint.TxidStr, outpoint.OutputIndex)
Expand Down
Loading