itest: fix endorsement itests

Due to the signaling period expiring tests had to be adopted bc
they were not taking the activation time period into account.
This commit is contained in:
ziggie committed 2026-01-05 14:28:14 +01:00
1 parent 013f5c93ed
commit 5f30797738
3 files changed
+50 -11

No files matched your search

+19 -8
View File
@@ -57,12 +57,18 @@ func testEndorsement(ht *lntest.HarnessTest, aliceEndorse bool) {
FeeLimitMsat: math.MaxInt64, FeeLimitMsat: math.MaxInt64,
} }
expectedValue := []byte{lnwire.ExperimentalUnendorsed} var expectedValue []byte
if aliceEndorse { hasEndorsement := lntest.ExperimentalEndorsementActive()
expectedValue = []byte{lnwire.ExperimentalEndorsed}
t := uint64(lnwire.ExperimentalEndorsementType) if hasEndorsement {
sendReq.FirstHopCustomRecords = map[uint64][]byte{ if aliceEndorse {
t: expectedValue, expectedValue = []byte{lnwire.ExperimentalEndorsed}
t := uint64(lnwire.ExperimentalEndorsementType)
sendReq.FirstHopCustomRecords = map[uint64][]byte{
t: expectedValue,
}
} else {
expectedValue = []byte{lnwire.ExperimentalUnendorsed}
} }
} }
@@ -70,8 +76,13 @@ func testEndorsement(ht *lntest.HarnessTest, aliceEndorse bool) {
// Validate that our signal (positive or zero) propagates until carol // Validate that our signal (positive or zero) propagates until carol
// and then is dropped because she has disabled the feature. // and then is dropped because she has disabled the feature.
validateEndorsedAndResume(ht, bobIntercept, true, expectedValue) // When the endorsement experiment is not active, no signal is sent.
validateEndorsedAndResume(ht, carolIntercept, true, expectedValue) validateEndorsedAndResume(
ht, bobIntercept, hasEndorsement, expectedValue,
)
validateEndorsedAndResume(
ht, carolIntercept, hasEndorsement, expectedValue,
)
validateEndorsedAndResume(ht, daveIntercept, false, nil) validateEndorsedAndResume(ht, daveIntercept, false, nil)
var preimage lntypes.Preimage var preimage lntypes.Preimage
+14 -3
View File
@@ -432,14 +432,25 @@ func testForwardInterceptorRestart(ht *lntest.HarnessTest) {
// We should get another notification about the held HTLC. // We should get another notification about the held HTLC.
packet = ht.ReceiveHtlcInterceptor(bobInterceptor) 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), require.Equal(ht, lntest.CustomRecordsWithUnendorsed(customRecords),
packet.InWireCustomRecords) packet.InWireCustomRecords)
// And now we forward the payment at Carol, expecting only an // 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) 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{ err = carolInterceptor.Send(&routerrpc.ForwardHtlcInterceptResponse{
IncomingCircuitKey: packet.IncomingCircuitKey, IncomingCircuitKey: packet.IncomingCircuitKey,
Action: actionResume, Action: actionResume,
+17
View File
@@ -7,9 +7,11 @@ import (
"os" "os"
"strconv" "strconv"
"strings" "strings"
"time"
"github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/wire" "github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lntest/wait" "github.com/lightningnetwork/lnd/lntest/wait"
@@ -288,6 +290,15 @@ func CalcStaticFeeBuffer(c lnrpc.CommitmentType, numHTLCs int) btcutil.Amount {
func CustomRecordsWithUnendorsed( func CustomRecordsWithUnendorsed(
originalRecords lnwire.CustomRecords) map[uint64][]byte { 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{ return originalRecords.MergedCopy(map[uint64][]byte{
uint64(lnwire.ExperimentalEndorsementType): { uint64(lnwire.ExperimentalEndorsementType): {
lnwire.ExperimentalUnendorsed, lnwire.ExperimentalUnendorsed,
@@ -295,6 +306,12 @@ func CustomRecordsWithUnendorsed(
) )
} }
// 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. // LnrpcOutpointToStr returns a string representation of an lnrpc.OutPoint.
func LnrpcOutpointToStr(outpoint *lnrpc.OutPoint) string { func LnrpcOutpointToStr(outpoint *lnrpc.OutPoint) string {
return fmt.Sprintf("%s:%d", outpoint.TxidStr, outpoint.OutputIndex) return fmt.Sprintf("%s:%d", outpoint.TxidStr, outpoint.OutputIndex)