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:
3 files changed
+50
-11
No files matched your search
@@ -57,12 +57,18 @@ 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
|
||||
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}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,8 +76,13 @@ func testEndorsement(ht *lntest.HarnessTest, aliceEndorse bool) {
|
||||
|
||||
// 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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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"
|
||||
@@ -288,6 +290,15 @@ 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,
|
||||
@@ -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.
|
||||
func LnrpcOutpointToStr(outpoint *lnrpc.OutPoint) string {
|
||||
return fmt.Sprintf("%s:%d", outpoint.TxidStr, outpoint.OutputIndex)
|
||||
|
||||
Reference in new issue
Block a user