8000 Make verifyAttempt more robust by ziggie1984 · Pull Request #10257 · lightningnetwork/lnd · GitHub
[go: up one dir, main page]

Skip to content

Conversation

ziggie1984
Copy link
Collaborator
@ziggie1984 ziggie1984 commented Sep 30, 2025

We now return an error when blinded and non blinded attempts are
combined. This was theoretically possible to register a legacy
attempt in combination with a blinded payment. This would have
been prevented by other checks in the code because legacy payments
are not split into shards.

resulted from #9147 (comment)

@ziggie1984 ziggie1984 self-assigned this Sep 30, 2025
@ziggie1984 ziggie1984 added payments Related to invoices/payments code health Related to code commenting, refactoring, and other non-behaviour improvements labels Sep 30, 2025
@ziggie1984 ziggie1984 added this to v0.21 Sep 30, 2025
@ziggie1984 ziggie1984 force-pushed the make-verifyAttempt-robust branch from 2941b9e to 3ec398f Compare September 30, 2025 09:03
@ziggie1984 ziggie1984 marked this pull request as ready for review September 30, 2025 09:03
@ziggie1984 ziggie1984 force-pushed the make-verifyAttempt-robust branch from 3ec398f to db23434 Compare September 30, 2025 09:08
We now return an error when blinded and non blinded attempts are
combined. This was theoretically possible to register a legacy
attempt in combination with a blinded payment. This would have
been prevented by other checks in the code because legacy payments
are not split into shards.
@ziggie1984
Copy link
Collaborator Author

/gemini review

@ziggie1984 ziggie1984 added this to the v0.21.0 milestone Sep 30, 2025
Copy link
@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the robustness of payment attempt verification by adding a check to prevent mixing blinded and non-blinded attempts within the same payment. The implementation is straightforward and correct, introducing a new error and the corresponding validation logic in verifyAttempt. The changes are well-supported by an extensive suite of new unit tests, which significantly improves confidence in the payment verification logic. I've added one suggestion to further improve test coverage for the new validation.

verifyAttempt(payment, &full),
ErrMixedBlindedAndNonBlindedPayments,
)
}

Choose a reason for hiding this comment

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

medium

This test covers adding a non-blinded attempt to a payment that already has a blinded attempt. For completeness, it would be beneficial to also test the reverse scenario: adding a blinded attempt to a payment that already has a non-blinded attempt.

	)

	// Now test the other direction: a payment with a non-blinded attempt
	// should not accept a blinded attempt.
	nonBlindedExisting := makeLastHopAttemptInfo(
		4, lastHopArgs{amt: 2000, mpp: record.NewMPP(total, testHash)},
	)
	paymentWithNonBlinded := makePayment(
		total,
		HTLCAttempt{HTLCAttemptInfo: nonBlindedExisting},
	)

	blindedAttempt := makeLastHopAttemptInfo(
		5, lastHopArgs{amt: 2000, total: total, encrypted: []byte{1}},
	)
	require.ErrorIs(
		t,
		verifyAttempt(paymentWithNonBlinded, &blindedAttempt),
		ErrMixedBlindedAndNonBlindedPayments,
	)
}

@saubyk saubyk moved this to In review in v0.21 Sep 30, 2025
Copy link
Collaborator
@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

lgtm!

@ziggie1984 ziggie1984 changed the base branch from master to 0-21-0-staging October 6, 2025 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code health Related to code commenting, refactoring, and other non-behaviour improvements no-changelog payments Related to invoices/payments
Projects
Status: In review
Development

Successfully merging this pull request may close these issues.

2 participants
0