diff --git a/itest/lnd_experimental_endorsement.go b/itest/lnd_experimental_endorsement.go index 43e29c2be..7b0fc21a0 100644 --- a/itest/lnd_experimental_endorsement.go +++ b/itest/lnd_experimental_endorsement.go @@ -76,7 +76,7 @@ func testEndorsement(ht *lntest.HarnessTest, aliceEndorse bool) { var preimage lntypes.Preimage copy(preimage[:], invoice.RPreimage) - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED) } func validateEndorsedAndResume(ht *lntest.HarnessTest, diff --git a/itest/lnd_forward_interceptor_test.go b/itest/lnd_forward_interceptor_test.go index 7e43e6a24..7b25ffe12 100644 --- a/itest/lnd_forward_interceptor_test.go +++ b/itest/lnd_forward_interceptor_test.go @@ -122,7 +122,7 @@ func testForwardInterceptorDedupHtlc(ht *lntest.HarnessTest) { // We expect one in flight payment since we held the htlcs. var preimage lntypes.Preimage copy(preimage[:], invoice.RPreimage) - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT) // At this point if we have more than one held htlcs then we should // fail. This means we hold the same htlc twice which is a risk we want @@ -275,7 +275,7 @@ func testForwardInterceptorBasic(ht *lntest.HarnessTest) { copy(preimage[:], testCase.invoice.RPreimage) payment := ht.AssertPaymentStatus( - alice, preimage, lnrpc.Payment_IN_FLIGHT, + alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT, ) expectedAmt := testCase.invoice.ValueMsat require.Equal(ht, expectedAmt, payment.ValueMsat, @@ -408,7 +408,7 @@ func testForwardInterceptorRestart(ht *lntest.HarnessTest) { // The payment should now be in flight. var preimage lntypes.Preimage copy(preimage[:], invoice.RPreimage) - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT) // We don't resume the payment on Carol, so it should be held there. // We now restart first Bob, then Alice, so we can make sure we've @@ -456,7 +456,7 @@ func testForwardInterceptorRestart(ht *lntest.HarnessTest) { // Assert that the payment was successful. ht.AssertPaymentStatus( - alice, preimage, lnrpc.Payment_SUCCEEDED, + alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED, func(p *lnrpc.Payment) error { recordsEqual := reflect.DeepEqual( lntest.CustomRecordsWithUnendorsed( diff --git a/itest/lnd_hold_persistence_test.go b/itest/lnd_hold_persistence_test.go index 3554a5593..f024453eb 100644 --- a/itest/lnd_hold_persistence_test.go +++ b/itest/lnd_hold_persistence_test.go @@ -185,9 +185,7 @@ func testHoldInvoicePersistence(ht *lntest.HarnessTest) { payStream := alice.RPC.TrackPaymentV2(hash[:]) ht.ReceiveTrackPayment(payStream) - ht.AssertPaymentStatus( - alice, preimg, lnrpc.Payment_IN_FLIGHT, - ) + ht.AssertPaymentStatus(alice, hash, lnrpc.Payment_IN_FLIGHT) } // Settle invoices half the invoices, cancel the rest. @@ -211,11 +209,11 @@ func testHoldInvoicePersistence(ht *lntest.HarnessTest) { for i, preimg := range preimages { if i%2 == 0 { ht.AssertPaymentStatus( - alice, preimg, lnrpc.Payment_SUCCEEDED, + alice, preimg.Hash(), lnrpc.Payment_SUCCEEDED, ) } else { payment := ht.AssertPaymentStatus( - alice, preimg, lnrpc.Payment_FAILED, + alice, preimg.Hash(), lnrpc.Payment_FAILED, ) require.Equal(ht, reason, payment.FailureReason, "wrong failure reason") diff --git a/itest/lnd_htlc_timeout_resolver_test.go b/itest/lnd_htlc_timeout_resolver_test.go index 88114384f..3ce3026eb 100644 --- a/itest/lnd_htlc_timeout_resolver_test.go +++ b/itest/lnd_htlc_timeout_resolver_test.go @@ -197,7 +197,7 @@ func testHtlcTimeoutResolverExtractPreimageRemote(ht *lntest.HarnessTest) { // Finally, check that the Alice's payment is marked as succeeded as // Bob has settled the htlc using the preimage extracted from Carol's // 2nd level success tx. - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED) // Mine a block to clean the mempool. ht.MineBlocksAndAssertNumTxes(1, 2) @@ -371,7 +371,7 @@ func testHtlcTimeoutResolverExtractPreimageLocal(ht *lntest.HarnessTest) { // Finally, check that the Alice's payment is marked as succeeded as // Bob has settled the htlc using the preimage extracted from Carol's // direct spend tx. - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED) // NOTE: for non-standby nodes there's no need to clean up the force // close as long as the mempool is cleaned. diff --git a/itest/lnd_mpp_test.go b/itest/lnd_mpp_test.go index fd368f7c1..abc61e298 100644 --- a/itest/lnd_mpp_test.go +++ b/itest/lnd_mpp_test.go @@ -200,7 +200,7 @@ func testSendToRouteMultiPath(ht *lntest.HarnessTest) { copy(preimage[:], invoices[0].RPreimage) payment := ht.AssertPaymentStatus( - hn, preimage, lnrpc.Payment_SUCCEEDED, + hn, preimage.Hash(), lnrpc.Payment_SUCCEEDED, ) htlcs := payment.Htlcs diff --git a/itest/lnd_multi-hop_force_close_test.go b/itest/lnd_multi-hop_force_close_test.go index da760a289..befaf3447 100644 --- a/itest/lnd_multi-hop_force_close_test.go +++ b/itest/lnd_multi-hop_force_close_test.go @@ -894,7 +894,7 @@ func runMultiHopReceiverPreimageClaim(ht *lntest.HarnessTest, ht.AssertNumActiveHtlcs(alice, 0) // Check that the Alice's payment is correctly marked succeeded. - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED) // Carol's pending channel report should now show two outputs under // limbo: her commitment output, as well as the second-layer claim @@ -1918,7 +1918,7 @@ func runLocalClaimIncomingHTLC(ht *lntest.HarnessTest, // Finally, check that the Alice's payment is correctly marked // succeeded. - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED) } // testLocalClaimIncomingHTLCLeasedZeroConf tests @@ -2221,7 +2221,7 @@ func runLocalClaimIncomingHTLCLeased(ht *lntest.HarnessTest, // Finally, check that the Alice's payment is correctly marked // succeeded. - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED) } // testLocalPreimageClaimAnchorZeroConf tests `runLocalPreimageClaim` with @@ -2575,7 +2575,7 @@ func runLocalPreimageClaim(ht *lntest.HarnessTest, // Finally, check that the Alice's payment is correctly marked // succeeded. - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED) } // testLocalPreimageClaimLeasedZeroConf tests `runLocalPreimageClaim` with @@ -2839,7 +2839,7 @@ func runLocalPreimageClaimLeased(ht *lntest.HarnessTest, ht.AssertInvoiceState(stream, lnrpc.Invoice_SETTLED) // Check that the Alice's payment is correctly marked succeeded. - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED) // With the script-enforced lease commitment type, Alice and Bob still // haven't been able to sweep their respective commit outputs due to diff --git a/itest/lnd_payment_test.go b/itest/lnd_payment_test.go index a362b3209..0b220cd1b 100644 --- a/itest/lnd_payment_test.go +++ b/itest/lnd_payment_test.go @@ -98,8 +98,10 @@ func testPaymentSucceededHTLCRemoteSwept(ht *lntest.HarnessTest) { // We also check the payments are marked as IN_FLIGHT in Alice's // database. - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT) - ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_IN_FLIGHT) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT) + ht.AssertPaymentStatus( + alice, dustPreimage.Hash(), lnrpc.Payment_IN_FLIGHT, + ) // Bob should have two incoming HTLC. ht.AssertIncomingHTLCActive(bob, chanPoint, payHash[:]) @@ -166,12 +168,12 @@ func testPaymentSucceededHTLCRemoteSwept(ht *lntest.HarnessTest) { dustPayStream := alice.RPC.TrackPaymentV2(dustPayHash[:]) // Check that the dust payment is failed in both the stream and DB. - ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_FAILED) + ht.AssertPaymentStatus(alice, dustPreimage.Hash(), lnrpc.Payment_FAILED) ht.AssertPaymentStatusFromStream(dustPayStream, lnrpc.Payment_FAILED) // We expect the non-dust payment to marked as succeeded in Alice's // database and also from her stream. - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_SUCCEEDED) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_SUCCEEDED) ht.AssertPaymentStatusFromStream(payStream, lnrpc.Payment_SUCCEEDED) } @@ -263,8 +265,10 @@ func runTestPaymentHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) { // We also check the payments are marked as IN_FLIGHT in Alice's // database. - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT) - ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_IN_FLIGHT) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT) + ht.AssertPaymentStatus( + alice, dustPreimage.Hash(), lnrpc.Payment_IN_FLIGHT, + ) // Bob should have two incoming HTLC. ht.AssertIncomingHTLCActive(bob, chanPoint, payHash[:]) @@ -310,14 +314,14 @@ func runTestPaymentHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) { // mark the non-dust payment as succeeded. // // Check that the dust payment is failed in both the stream and DB. - ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_FAILED) + ht.AssertPaymentStatus(alice, dustPreimage.Hash(), lnrpc.Payment_FAILED) ht.AssertPaymentStatusFromStream(dustPayStream, lnrpc.Payment_FAILED) // Check that the non-dust payment is still in-flight. // // NOTE: we don't check the payment status from the stream here as // there's no new status being sent. - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT) // We now have two possible cases for the non-dust payment: // - Bob stays offline, and Alice will sweep her outgoing HTLC, which @@ -335,7 +339,7 @@ func runTestPaymentHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) { // We expect the non-dust payment to marked as failed in Alice's // database and also from her stream. - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_FAILED) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_FAILED) ht.AssertPaymentStatusFromStream(payStream, lnrpc.Payment_FAILED) } @@ -1114,7 +1118,7 @@ func sendPaymentInterceptAndCancel(ht *lntest.HarnessTest, var preimage lntypes.Preimage copy(preimage[:], invoice.RPreimage) payment := ht.AssertPaymentStatus( - alice, preimage, lnrpc.Payment_IN_FLIGHT, + alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT, ) reasonNone := lnrpc.PaymentFailureReason_FAILURE_REASON_NONE require.Equal(ht, reasonNone, payment.FailureReason) @@ -1127,7 +1131,7 @@ func sendPaymentInterceptAndCancel(ht *lntest.HarnessTest, require.NoError(ht, err, "failed to send request") // Assert that the payment status is as expected. - ht.AssertPaymentStatus(alice, preimage, expectedPaymentStatus) + ht.AssertPaymentStatus(alice, preimage.Hash(), expectedPaymentStatus) // Since the payment context was cancelled, no further payment attempts // should've been made, and we observe FAILURE_REASON_CANCELED. @@ -1245,7 +1249,7 @@ func runSendToRouteFailHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) { }() // Check that the payment is in-flight. - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT) // Construct a route to send the dust payment. go func() { @@ -1281,7 +1285,9 @@ func runSendToRouteFailHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) { }() // Check that the dust payment is in-flight. - ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_IN_FLIGHT) + ht.AssertPaymentStatus( + alice, dustPreimage.Hash(), lnrpc.Payment_IN_FLIGHT, + ) // Bob should have two incoming HTLC. ht.AssertIncomingHTLCActive(bob, chanPoint, payHash[:]) @@ -1323,14 +1329,14 @@ func runSendToRouteFailHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) { // HTLC is resolved onchain. // // Check that the dust payment is failed in both the stream and DB. - ht.AssertPaymentStatus(alice, dustPreimage, lnrpc.Payment_FAILED) + ht.AssertPaymentStatus(alice, dustPreimage.Hash(), lnrpc.Payment_FAILED) ht.AssertPaymentStatusFromStream(dustPayStream, lnrpc.Payment_FAILED) // Check that the non-dust payment is still in-flight. // // NOTE: we don't check the payment status from the stream here as // there's no new status being sent. - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_IN_FLIGHT) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_IN_FLIGHT) // We now have two possible cases for the non-dust payment: // - Bob stays offline, and Alice will sweep her outgoing HTLC, which @@ -1348,6 +1354,6 @@ func runSendToRouteFailHTLCTimeout(ht *lntest.HarnessTest, restartAlice bool) { // We expect the non-dust payment to marked as failed in Alice's // database and also from her stream. - ht.AssertPaymentStatus(alice, preimage, lnrpc.Payment_FAILED) + ht.AssertPaymentStatus(alice, preimage.Hash(), lnrpc.Payment_FAILED) ht.AssertPaymentStatusFromStream(payStream, lnrpc.Payment_FAILED) } diff --git a/itest/lnd_route_blinding_test.go b/itest/lnd_route_blinding_test.go index a2f68ef71..072788dec 100644 --- a/itest/lnd_route_blinding_test.go +++ b/itest/lnd_route_blinding_test.go @@ -509,7 +509,7 @@ func (b *blindedForwardTest) sendToRoute(route *lnrpc.Route, require.NoError(b.ht, err) pmt := b.ht.AssertPaymentStatus( - b.alice, preimage, lnrpc.Payment_FAILED, + b.alice, preimage.Hash(), lnrpc.Payment_FAILED, ) require.Len(b.ht, pmt.Htlcs, 1) diff --git a/lntest/harness_assertion.go b/lntest/harness_assertion.go index 9af81a7cd..fb5b03990 100644 --- a/lntest/harness_assertion.go +++ b/lntest/harness_assertion.go @@ -1550,16 +1550,15 @@ func (h *HarnessTest) findPayment(hn *node.HarnessNode, // PaymentCheck is a function that checks a payment for a specific condition. type PaymentCheck func(*lnrpc.Payment) error -// AssertPaymentStatus asserts that the given node list a payment with the -// given preimage has the expected status. It also checks that the payment has -// the expected preimage, which is empty when it's not settled and matches the -// given preimage when it's succeeded. +// AssertPaymentStatus asserts that the given node list a payment with the given +// payment hash has the expected status. It also checks that the payment has the +// expected preimage, which is empty when it's not settled and matches the given +// preimage when it's succeeded. func (h *HarnessTest) AssertPaymentStatus(hn *node.HarnessNode, - preimage lntypes.Preimage, status lnrpc.Payment_PaymentStatus, + payHash lntypes.Hash, status lnrpc.Payment_PaymentStatus, checks ...PaymentCheck) *lnrpc.Payment { var target *lnrpc.Payment - payHash := preimage.Hash() err := wait.NoError(func() error { p, err := h.findPayment(hn, payHash.String()) @@ -1581,8 +1580,11 @@ func (h *HarnessTest) AssertPaymentStatus(hn *node.HarnessNode, // If this expected status is SUCCEEDED, we expect the final // preimage. case lnrpc.Payment_SUCCEEDED: - require.Equal(h, preimage.String(), target.PaymentPreimage, - "preimage not match") + preimage, err := lntypes.MakePreimageFromStr( + target.PaymentPreimage, + ) + require.NoError(h, err, "fail to make preimage") + require.Equal(h, payHash, preimage.Hash(), "preimage not match") // Otherwise we expect an all-zero preimage. default: