Skip to content

Commit 801de79

Browse files
authored
Merge pull request #10476 from ziggie1984/fix-endorsement-testcases
itest: fix endorsement itests
2 parents ac006d7 + 5f30797 commit 801de79

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

itest/lnd_experimental_endorsement.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,32 @@ func testEndorsement(ht *lntest.HarnessTest, aliceEndorse bool) {
5757
FeeLimitMsat: math.MaxInt64,
5858
}
5959

60-
expectedValue := []byte{lnwire.ExperimentalUnendorsed}
61-
if aliceEndorse {
62-
expectedValue = []byte{lnwire.ExperimentalEndorsed}
63-
t := uint64(lnwire.ExperimentalEndorsementType)
64-
sendReq.FirstHopCustomRecords = map[uint64][]byte{
65-
t: expectedValue,
60+
var expectedValue []byte
61+
hasEndorsement := lntest.ExperimentalEndorsementActive()
62+
63+
if hasEndorsement {
64+
if aliceEndorse {
65+
expectedValue = []byte{lnwire.ExperimentalEndorsed}
66+
t := uint64(lnwire.ExperimentalEndorsementType)
67+
sendReq.FirstHopCustomRecords = map[uint64][]byte{
68+
t: expectedValue,
69+
}
70+
} else {
71+
expectedValue = []byte{lnwire.ExperimentalUnendorsed}
6672
}
6773
}
6874

6975
_ = alice.RPC.SendPayment(sendReq)
7076

7177
// Validate that our signal (positive or zero) propagates until carol
7278
// and then is dropped because she has disabled the feature.
73-
validateEndorsedAndResume(ht, bobIntercept, true, expectedValue)
74-
validateEndorsedAndResume(ht, carolIntercept, true, expectedValue)
79+
// When the endorsement experiment is not active, no signal is sent.
80+
validateEndorsedAndResume(
81+
ht, bobIntercept, hasEndorsement, expectedValue,
82+
)
83+
validateEndorsedAndResume(
84+
ht, carolIntercept, hasEndorsement, expectedValue,
85+
)
7586
validateEndorsedAndResume(ht, daveIntercept, false, nil)
7687

7788
var preimage lntypes.Preimage

itest/lnd_forward_interceptor_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,25 @@ func testForwardInterceptorRestart(ht *lntest.HarnessTest) {
432432
// We should get another notification about the held HTLC.
433433
packet = ht.ReceiveHtlcInterceptor(bobInterceptor)
434434

435-
require.Len(ht, packet.InWireCustomRecords, 2)
435+
// Check the expected number of custom records based on whether the
436+
// endorsement experiment is still active.
437+
expectedLen := 1
438+
if lntest.ExperimentalEndorsementActive() {
439+
expectedLen = 2
440+
}
441+
require.Len(ht, packet.InWireCustomRecords, expectedLen)
436442
require.Equal(ht, lntest.CustomRecordsWithUnendorsed(customRecords),
437443
packet.InWireCustomRecords)
438444

439445
// And now we forward the payment at Carol, expecting only an
440-
// endorsement signal in our incoming custom records.
446+
// endorsement signal in our incoming custom records (if the experiment
447+
// is still active).
441448
packet = ht.ReceiveHtlcInterceptor(carolInterceptor)
442-
require.Len(ht, packet.InWireCustomRecords, 1)
449+
expectedCarolLen := 0
450+
if lntest.ExperimentalEndorsementActive() {
451+
expectedCarolLen = 1
452+
}
453+
require.Len(ht, packet.InWireCustomRecords, expectedCarolLen)
443454
err = carolInterceptor.Send(&routerrpc.ForwardHtlcInterceptResponse{
444455
IncomingCircuitKey: packet.IncomingCircuitKey,
445456
Action: actionResume,

lntest/utils.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import (
77
"os"
88
"strconv"
99
"strings"
10+
"time"
1011

1112
"github.com/btcsuite/btcd/btcutil"
1213
"github.com/btcsuite/btcd/wire"
14+
"github.com/lightningnetwork/lnd"
1315
"github.com/lightningnetwork/lnd/input"
1416
"github.com/lightningnetwork/lnd/lnrpc"
1517
"github.com/lightningnetwork/lnd/lntest/wait"
@@ -288,13 +290,28 @@ func CalcStaticFeeBuffer(c lnrpc.CommitmentType, numHTLCs int) btcutil.Amount {
288290
func CustomRecordsWithUnendorsed(
289291
originalRecords lnwire.CustomRecords) map[uint64][]byte {
290292

293+
if !ExperimentalEndorsementActive() {
294+
// Return nil if there are no records, to match wire encoding.
295+
if len(originalRecords) == 0 {
296+
return nil
297+
}
298+
299+
return originalRecords.Copy()
300+
}
301+
291302
return originalRecords.MergedCopy(map[uint64][]byte{
292303
uint64(lnwire.ExperimentalEndorsementType): {
293304
lnwire.ExperimentalUnendorsed,
294305
}},
295306
)
296307
}
297308

309+
// ExperimentalEndorsementActive returns true if the experimental endorsement
310+
// window is still open.
311+
func ExperimentalEndorsementActive() bool {
312+
return time.Now().Before(lnd.EndorsementExperimentEnd)
313+
}
314+
298315
// LnrpcOutpointToStr returns a string representation of an lnrpc.OutPoint.
299316
func LnrpcOutpointToStr(outpoint *lnrpc.OutPoint) string {
300317
return fmt.Sprintf("%s:%d", outpoint.TxidStr, outpoint.OutputIndex)

0 commit comments

Comments
 (0)