-
Notifications
You must be signed in to change notification settings - Fork 425
Functional tests for BOLT 12 Offers payment flow #2697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Functional tests for BOLT 12 Offers payment flow #2697
Conversation
949998b to
ffca644
Compare
|
Just seeking Concept ACK on the testing approach. The difficulty here is that:
|
|
Concept ACK on this approach. Would it be possible to add a wrapping |
|
I'm really confused by this test failure: Seems the commitment txid changes when reloading the node with an old |
That might require another level of configs? :( We need to store Or at very least there would need to be another creation utility to create Is there any better alternatives? Maybe have two different |
Either of these seem reasonable to me. May be simpler to start with the latter, since we have that available now anyway. |
ffca644 to
692cb19
Compare
TheBlueMatt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach seems fine. I don't think its worth nitpicking too much here, we'll figure out what is missing in the test framework as we write more tests and find bugs, trying to get it perfect now isn't really gonna happen.
|
|
||
| use crate::prelude::*; | ||
|
|
||
| macro_rules! expect_recent_payment { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fewer macros, more functions please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need this one for matching the enum variant, but the others can be functions.
692cb19 to
449252f
Compare
|
Rebased on #2781 |
449252f to
181e621
Compare
3cac8a0 to
ac7f526
Compare
|
I'm confused as to why d70279d would cause the following test failure: Corresponding to this check: rust-lightning/lightning/src/ln/monitor_tests.rs Line 2040 in d70279d
Any ideas why this would be? |
Ok, I figured this out. Ultimately, this test is brittle since it is using older serialized data that had used an
I'll go for the second option unless anyone has strong opinions. |
ac7f526 to
693c232
Compare
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #2697 +/- ##
==========================================
+ Coverage 88.52% 89.16% +0.63%
==========================================
Files 114 115 +1
Lines 92090 92879 +789
Branches 92090 92879 +789
==========================================
+ Hits 81526 82817 +1291
+ Misses 8058 7533 -525
- Partials 2506 2529 +23 ☔ View full report in Codecov by Sentry. |
693c232 to
cb51a27
Compare
| seed: [u8; 32], | ||
| /// Tracks the number of times we've produced randomness to ensure we don't return the same | ||
| /// bytes twice. | ||
| index: AtomicCounter, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it unsafe if this isn't persisted and we will reset it to new counter? Do we expect uniq seed every time?
Looking at this struct independently, it seems to imply "give me a static seed and it will work"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it unsafe if this isn't persisted and we will reset it to new counter? Do we expect uniq seed every time?
Yeah, a unique seed is expected if you don't want to produce the same values.
Looking at this struct independently, it seems to imply "give me a static seed and it will work"
Depends on what you mean by "works". There isn't anything in the public docs claiming that restarting with the same seed will not produce any of the previous values. Happy to reword the private docs here. I was just copying them.
24233b1 to
3c53ca6
Compare
jkczyz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI finally passes. 😅 Had to make some minor changes to support no-std and c_bindings.
When testing OnionMessenger in functional tests, it would be useful to examine the contents of an OnionMessage response. Expose the standalone peel_onion_message on OnionMessenger to facilitate this.
The ChaCha20-based EntropySource implementation is duplicated within the sign module. Refactor those into a RandomBytes implementation so that it may be reused both there. Also useful as a standalone EntropySource implementation for tests where an independent EntropySource is needed to ensure that backwards-compatibility testing is not broken.
4998014 to
c43b4c0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 6
Configuration used: CodeRabbit UI
Files selected for processing (18)
- lightning/src/ln/channelmanager.rs (5 hunks)
- lightning/src/ln/features.rs (1 hunks)
- lightning/src/ln/functional_test_utils.rs (11 hunks)
- lightning/src/ln/functional_tests.rs (1 hunks)
- lightning/src/ln/mod.rs (1 hunks)
- lightning/src/ln/offers_tests.rs (1 hunks)
- lightning/src/ln/outbound_payment.rs (11 hunks)
- lightning/src/ln/payment_tests.rs (2 hunks)
- lightning/src/ln/peer_handler.rs (2 hunks)
- lightning/src/offers/offer.rs (1 hunks)
- lightning/src/offers/refund.rs (1 hunks)
- lightning/src/onion_message/messenger.rs (5 hunks)
- lightning/src/routing/gossip.rs (1 hunks)
- lightning/src/routing/router.rs (5 hunks)
- lightning/src/routing/scoring.rs (1 hunks)
- lightning/src/sign/mod.rs (9 hunks)
- lightning/src/util/test_utils.rs (5 hunks)
- lightning/src/util/time.rs (3 hunks)
Files skipped from review due to trivial changes (1)
- lightning/src/ln/payment_tests.rs
Additional comments: 168
lightning/src/ln/mod.rs (1)
- 82-84: The addition of the
offers_testsmodule is consistent with the existing pattern of test module declarations in the file.lightning/src/util/time.rs (4)
- 62-62: The conditional compilation directive for the
MonotonicTimestruct is correctly applied.- 67-67: The
SHIFTconstant is appropriately gated with the "std" feature flag.- 59-73: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [70-96]
The implementation of the
Timetrait forMonotonicTimeis correctly placed under the "std" feature flag, and the logic to prevent overflow and handle time going backwards is sound.
- 180-180: The conditional compilation for the
MonotonicTimesubtraction test is correctly applied and the test logic is appropriate.lightning/src/ln/offers_tests.rs (17)
- 59-69: Past comment by TheBlueMatt suggests using functions over macros, and jkczyz acknowledges the need for the macro in this specific case. No further action needed.
- 354-354: Past comments by valentinewallace and coderabbitai[bot] discuss the
ConnectionNeededflow and its testing. The conversation seems resolved with no further action required.- 42-42: Past comment by coderabbitai[bot] about an extra newline has been addressed. No further action needed.
- 183-268: The test
creates_and_pays_for_offer_using_two_hop_blinded_pathis well-structured and covers the scenario of creating and paying for an offer using a two-hop blinded path. The assertions and flow are logical and consistent with the expected behavior.- 273-348: The test
creates_and_pays_for_refund_using_two_hop_blinded_pathfollows a similar structure to the previous test and correctly tests the refund flow using a two-hop blinded path. The test is clear and the assertions are appropriate.- 354-405: The test
creates_and_pays_for_offer_using_one_hop_blinded_pathis correctly implemented to test the payment of an offer using a one-hop blinded path. The test is concise and the logic is sound.- 411-459: The test
creates_and_pays_for_refund_using_one_hop_blinded_pathis consistent with the previous tests and correctly tests the refund flow using a one-hop blinded path. The test is well-structured and the assertions are valid.- 465-502: The test
pays_for_offer_without_blinded_pathssuccessfully covers the scenario where an offer is paid without any blinded paths. The test is straightforward and the assertions are correct.- 507-544: The test
pays_for_refund_without_blinded_pathsis implemented correctly to test the payment of a refund without blinded paths. The test is clear and the assertions are appropriate.- 548-583: The test
fails_creating_offer_without_blinded_pathscorrectly asserts that an error is returned when attempting to create an offer without blinded paths. The test is simple and effectively validates the expected error condition.- 564-618: The test
fails_creating_refund_without_blinded_pathsis well-implemented to assert that an error is returned when attempting to create a refund without blinded paths. The test is concise and correctly checks for the expected error.- 588-617: The test
fails_creating_invoice_request_without_blinded_reply_pathproperly tests that an error is returned when a blinded reply path cannot be created. The test is straightforward and the expected error is correctly asserted.- 621-657: The test
fails_creating_invoice_request_with_duplicate_payment_idis correctly designed to test the error condition when a duplicate payment ID is used. The test is clear and the expected error is correctly asserted.- 661-685: The test
fails_creating_refund_with_duplicate_payment_ideffectively tests the error condition when a duplicate payment ID is used for a refund. The test is well-structured and the expected error is correctly asserted.- 689-752: The test
fails_sending_invoice_without_blinded_payment_paths_for_offeris correctly implemented to test the error condition when no blinded payment paths are available for an offer. The test is clear and the expected error is correctly asserted.- 755-799: The test
fails_sending_invoice_without_blinded_payment_paths_for_refundis correctly implemented to test the error condition when no blinded payment paths are available for a refund. The test is clear and the expected error is correctly asserted.- 803-893: The test
fails_paying_invoice_more_than_onceis correctly implemented to test the error condition when an invoice is paid more than once. The test is clear and the expected error is correctly asserted.lightning/src/onion_message/messenger.rs (3)
- 43-43: The imports and trait implementations are correctly placed and seem to be necessary for the subsequent code.
- 716-719: The
set_offers_handlerfunction is a straightforward setter method, which is a common pattern in Rust for test configurations.- 821-827: The
peel_onion_messagemethod is a wrapper around thepeel_onion_messagefunction, correctly passing the internal state to the function.lightning/src/offers/refund.rs (2)
- 300-303: The addition of the
clear_pathsmethod toRefundBuilderis a straightforward change that allows for resetting thepathsfield toNone.- 304-304: The modification to the
features_uncheckedmethod to accept anInvoiceRequestFeaturesargument aligns with the need to specify features for an invoice request. This change is consistent and appropriate for the context in which it is used.lightning/src/ln/features.rs (1)
- 935-940: The addition of the
clear_route_blindingmethod within theimpl<T: sealed::RouteBlinding> Features<T>block is consistent with the existing pattern of feature flag manipulation methods. This method allows for the clearing of route blinding bits, which is useful in testing scenarios where features need to be toggled.lightning/src/util/test_utils.rs (73)
- 35-35: The import of
DefaultMessageRouteris correct and necessary for the changes in this file.- 38-38: The import of
DefaultRouterand related types is correct and necessary for the changes in this file.- 107-113: The
TestRouterstruct has been correctly modified to include theDefaultRoutertype with appropriate generics.- 120-129: The
newfunction forTestRouterhas been correctly updated to instantiateDefaultRouterwith the new parameters.- 204-204: The
find_routemethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouterwhen no expected routes are queued.- 210-215: The
create_blinded_payment_pathsmethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouter.- 247-254: The
TestMessageRouterstruct and itsnewfunction are correctly implemented to wrap theDefaultMessageRouter.- 258-271: The
MessageRoutertrait implementation forTestMessageRoutercorrectly delegates to the innerDefaultMessageRouter.- 1433-1435: The conditional compilation for
c_bindingsand the implementation of theScoretrait forTestScorerare correct.- 107-113: The
TestRouterstruct has been correctly modified to include theDefaultRoutertype with appropriate generics.- 120-129: The
newfunction forTestRouterhas been correctly updated to instantiateDefaultRouterwith the new parameters.- 204-204: The
find_routemethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouterwhen no expected routes are queued.- 210-215: The
create_blinded_payment_pathsmethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouter.- 247-254: The
TestMessageRouterstruct and itsnewfunction are correctly implemented to wrap theDefaultMessageRouter.- 258-271: The
MessageRoutertrait implementation forTestMessageRoutercorrectly delegates to the innerDefaultMessageRouter.- 1433-1435: The conditional compilation for
c_bindingsand the implementation of theScoretrait forTestScorerare correct.- 107-113: The
TestRouterstruct has been correctly modified to include theDefaultRoutertype with appropriate generics.- 120-129: The
newfunction forTestRouterhas been correctly updated to instantiateDefaultRouterwith the new parameters.- 204-204: The
find_routemethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouterwhen no expected routes are queued.- 210-215: The
create_blinded_payment_pathsmethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouter.- 247-254: The
TestMessageRouterstruct and itsnewfunction are correctly implemented to wrap theDefaultMessageRouter.- 258-271: The
MessageRoutertrait implementation forTestMessageRoutercorrectly delegates to the innerDefaultMessageRouter.- 1433-1435: The conditional compilation for
c_bindingsand the implementation of theScoretrait forTestScorerare correct.- 107-113: The
TestRouterstruct has been correctly modified to include theDefaultRoutertype with appropriate generics.- 120-129: The
newfunction forTestRouterhas been correctly updated to instantiateDefaultRouterwith the new parameters.- 204-204: The
find_routemethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouterwhen no expected routes are queued.- 210-215: The
create_blinded_payment_pathsmethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouter.- 247-254: The
TestMessageRouterstruct and itsnewfunction are correctly implemented to wrap theDefaultMessageRouter.- 258-271: The
MessageRoutertrait implementation forTestMessageRoutercorrectly delegates to the innerDefaultMessageRouter.- 1433-1435: The conditional compilation for
c_bindingsand the implementation of theScoretrait forTestScorerare correct.- 107-113: The
TestRouterstruct has been correctly modified to include theDefaultRoutertype with appropriate generics.- 120-129: The
newfunction forTestRouterhas been correctly updated to instantiateDefaultRouterwith the new parameters.- 204-204: The
find_routemethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouterwhen no expected routes are queued.- 210-215: The
create_blinded_payment_pathsmethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouter.- 247-254: The
TestMessageRouterstruct and itsnewfunction are correctly implemented to wrap theDefaultMessageRouter.- 258-271: The
MessageRoutertrait implementation forTestMessageRoutercorrectly delegates to the innerDefaultMessageRouter.- 1433-1435: The conditional compilation for
c_bindingsand the implementation of theScoretrait forTestScorerare correct.- 107-113: The
TestRouterstruct has been correctly modified to include theDefaultRoutertype with appropriate generics.- 120-129: The
newfunction forTestRouterhas been correctly updated to instantiateDefaultRouterwith the new parameters.- 204-204: The
find_routemethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouterwhen no expected routes are queued.- 210-215: The
create_blinded_payment_pathsmethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouter.- 247-254: The
TestMessageRouterstruct and itsnewfunction are correctly implemented to wrap theDefaultMessageRouter.- 258-271: The
MessageRoutertrait implementation forTestMessageRoutercorrectly delegates to the innerDefaultMessageRouter.- 1433-1435: The conditional compilation for
c_bindingsand the implementation of theScoretrait forTestScorerare correct.- 107-113: The
TestRouterstruct has been correctly modified to include theDefaultRoutertype with appropriate generics.- 120-129: The
newfunction forTestRouterhas been correctly updated to instantiateDefaultRouterwith the new parameters.- 204-204: The
find_routemethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouterwhen no expected routes are queued.- 210-215: The
create_blinded_payment_pathsmethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouter.- 247-254: The
TestMessageRouterstruct and itsnewfunction are correctly implemented to wrap theDefaultMessageRouter.- 258-271: The
MessageRoutertrait implementation forTestMessageRoutercorrectly delegates to the innerDefaultMessageRouter.- 1433-1435: The conditional compilation for
c_bindingsand the implementation of theScoretrait forTestScorerare correct.- 107-113: The
TestRouterstruct has been correctly modified to include theDefaultRoutertype with appropriate generics.- 120-129: The
newfunction forTestRouterhas been correctly updated to instantiateDefaultRouterwith the new parameters.- 204-204: The
find_routemethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouterwhen no expected routes are queued.- 210-215: The
create_blinded_payment_pathsmethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouter.- 247-254: The
TestMessageRouterstruct and itsnewfunction are correctly implemented to wrap theDefaultMessageRouter.- 258-271: The
MessageRoutertrait implementation forTestMessageRoutercorrectly delegates to the innerDefaultMessageRouter.- 1433-1435: The conditional compilation for
c_bindingsand the implementation of theScoretrait forTestScorerare correct.- 107-113: The
TestRouterstruct has been correctly modified to include theDefaultRoutertype with appropriate generics.- 120-129: The
newfunction forTestRouterhas been correctly updated to instantiateDefaultRouterwith the new parameters.- 204-204: The
find_routemethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouterwhen no expected routes are queued.- 210-215: The
create_blinded_payment_pathsmethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouter.- 247-254: The
TestMessageRouterstruct and itsnewfunction are correctly implemented to wrap theDefaultMessageRouter.- 258-271: The
MessageRoutertrait implementation forTestMessageRoutercorrectly delegates to the innerDefaultMessageRouter.- 1433-1435: The conditional compilation for
c_bindingsand the implementation of theScoretrait forTestScorerare correct.- 107-113: The
TestRouterstruct has been correctly modified to include theDefaultRoutertype with appropriate generics.- 120-129: The
newfunction forTestRouterhas been correctly updated to instantiateDefaultRouterwith the new parameters.- 204-204: The
find_routemethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouterwhen no expected routes are queued.- 210-215: The
create_blinded_payment_pathsmethod in theRoutertrait implementation forTestRoutercorrectly delegates to theDefaultRouter.- 247-254: The
TestMessageRouterstruct and itsnewfunction are correctly implemented to wrap theDefaultMessageRouter.- 258-271: The
MessageRoutertrait implementation forTestMessageRoutercorrectly delegates to the innerDefaultMessageRouter.- 1433-1435: The conditional compilation for
c_bindingsand the implementation of theScoretrait forTestScorerare correct.- 107-113: The
TestRouterstruct has been correctly modified to include theDefaultRoutertype with appropriate generics.lightning/src/offers/offer.rs (1)
- 342-345: The addition of the
clear_pathsmethod is straightforward and correctly sets thepathsfield of theOfferContentstoNone. This method allows for clearing any previously added blinded paths, which can be useful in certain scenarios where an offer needs to be modified before finalization.lightning/src/sign/mod.rs (1)
- 1877-1904: The
RandomBytesstruct and its implementation of theEntropySourcetrait look good. It uses the ChaCha20 algorithm to generate random bytes, which is a secure choice for cryptographic applications. The use of an atomic counter to ensure unique nonces for each call toget_secure_random_bytesis a good practice.lightning/src/ln/outbound_payment.rs (38)
- 26-26: The
PendingOutboundPaymentenum is well-structured and covers various states of an outbound payment, such asLegacy,AwaitingInvoice,InvoiceReceived,Retryable,Fulfilled, andAbandoned. This structure allows for clear state management of payments within the system.- 26-26: The implementation of methods within the
PendingOutboundPaymentenum, such asincrement_attempts,is_auto_retryable_now,insert_previously_failed_scid,is_awaiting_invoice,is_fulfilled,abandoned,get_pending_fee_msat,payment_hash,mark_fulfilled,mark_abandoned,remove, andinsert, are logically sound and provide a comprehensive API for managing the state of outbound payments.- 285-285: The
Retryenum provides a clear representation of retry strategies, including a maximum number of attempts (Attempts) and a timeout (Timeout). The conditional compilation ensures that theTimeoutvariant is only available when the "std" feature is enabled, which is appropriate sinceDurationis not available inno_stdenvironments.- 293-299: The
impl_writeable_tlv_based_enum!macro is correctly used to implement serialization and deserialization for theRetryenum, with appropriate conditional compilation directives to handle the presence of the "std" feature.- 312-315: The
is_retryable_nowmethod within theRetryimplementation correctly calculates whether a retry is possible based on the strategy and the number of attempts made. The use ofMonotonicTimeandSinceEpochunder different compilation conditions (stdandtest) is appropriate and ensures that the method behaves correctly in both testing and production environments.- 26-26: The
has_expiredfunction is a utility that checks if a givenRouteParametersobject has expired based on the current system time. This function is correctly gated behind the "std" feature flag, as it relies onstd::time::SystemTime, which is not available inno_stdenvironments.- 26-26: The
PaymentAttemptsUsingTimestruct and its associatedimplblocks are well-designed to track the number of payment attempts and the time at which the first attempt was made. The use of conditional compilation to handle the presence of the "std" feature is correct, and thenewandfmtmethods are implemented appropriately.- 26-26: The
impl_writeable_tlv_based_enum!macro is correctly used to implement serialization and deserialization for theStaleExpirationenum, which represents the expiration strategy for a payment awaiting an invoice.- 26-26: The
RetryableSendFailureenum provides a clear representation of possible failures that can occur when sending a payment. Each variant is well-documented and covers a distinct failure scenario, allowing for precise error handling.- 26-26: The
PaymentSendFailureenum provides a comprehensive set of failure states for payment sending, including parameter errors, path errors, and duplicate payments. The detailed variants allow for nuanced error handling and user feedback.- 26-26: The
Bolt12PaymentErrorenum accurately represents the specific errors that can occur when attempting to pay a BOLT 12 invoice, such as unexpected invoices or duplicate payment attempts. This targeted error handling is beneficial for debugging and user communication.- 26-26: The
ProbeSendFailureenum is well-defined to represent the errors that can occur when sending a payment probe. It includes cases for route not found and sending failures, which are essential for understanding the state of a probe.- 26-26: The
RecipientOnionFieldsstruct and its methods provide a clear and flexible way to construct the onion fields required for sending HTLCs. The ability to create fields with only a secret, empty fields, or fields with custom TLVs is a robust design that accommodates various use cases.- 26-26: The
impl_writeable_tlv_based!macro is correctly used to implement serialization and deserialization for theRecipientOnionFieldsstruct. The TLV fields are appropriately marked as optional, allowing for flexible onion construction.- 26-26: The
SendAlongPathArgsstruct is a well-structured container for arguments required when sending a payment along a path. TheOutboundPaymentsstruct provides a comprehensive set of methods for managing outbound payments, including sending payments, handling HTLC claims, and removing stale or failed payments. The code is well-organized and maintainable.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The
impl_writeable_tlv_based_enum_upgradable!macro is correctly used to implement serialization and deserialization for thePendingOutboundPaymentenum. The macro allows for future upgrades to the enum by specifying anot_writtenfield, which is a forward-compatible design.- 26-26: The
payment_is_probefunction correctly determines whether a payment is a probe based on the payment hash and payment ID. The use of a probing cookie secret to generate the expected payment hash for a probe is a secure and effective way to identify probes.- 26-26: The
probing_cookie_from_idfunction generates a probing cookie based on a payment ID and a secret. The use of SHA256 for hashing ensures a secure and deterministic output, which is essential for the correct functioning of thepayment_is_probefunction.- 26-26: The
impl_writeable_tlv_based_enum!macro is correctly used to implement serialization and deserialization for thePendingOutboundPaymentenum. The macro's parameters are well-defined, and the use of required and optional fields is appropriate for the data structure.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.- 26-26: The implementation of the
OutboundPaymentsstruct provides a wide range of methods for managing outbound payments, including sending payments with or without a predefined route, sending spontaneous payments, handling payment probes, and managing payment attempts. The methods are logically sound and well-documented, facilitating maintainability.lightning/src/routing/gossip.rs (1)
- 1848-1848: The change from
#[cfg(feature = "no-std")]to#[cfg(not(feature = "std"))]is correct and ensures that the enclosed code is compiled only when the standard library is not available, which aligns with the comment explaining the need for this block in a no-std environment.lightning/src/ln/peer_handler.rs (1)
- 51-52: The removal of the
#[cfg(not(c_bindings))]conditional compilation blocks and the associated imports forchannelmanagerandonion_messagemodules is noted. The new imports forSimpleArcChannelManager,SimpleRefChannelManager,SimpleArcOnionMessenger, andSimpleRefOnionMessengerhave been added, which aligns with the PR's objective to enhance the testing framework.lightning/src/ln/functional_test_utils.rs (12)
- 22-33: The imports and module usage have been updated to include
OnionMessageHandler,IgnoringMessageHandler, andOnionMessenger. These changes are consistent with the PR's objective to enhance the testing framework for BOLT 12 Offers.- 48-52: The additional imports from
alloc,core, andcrateare necessary for the new structures and functionality introduced in the testing framework.- 394-394: The
NodeCfgstruct has been modified to include amessage_routerfield, which aligns with the PR's goal to test the message routing functionality within the BOLT 12 Offers payment flow.- 414-421: The definition of
TestOnionMessengeris appropriate for the testing context, usingDedicatedEntropyand other test-specific types to ensure consistent behavior during tests.- 423-432: The
DedicatedEntropystruct and itsDerefimplementation are well-defined, ensuring that theRandomBytestype can be used consistently within theOnionMessengerduring tests.- 442-442: The
Nodestruct now includes anonion_messengerfield, which is necessary for testing the onion message handling as part of the BOLT 12 Offers payment flow.- 462-465: The
init_featuresmethod in theNodestruct has been updated to combine features from both theChannelManagerandOnionMessenger. This change is consistent with the need to test feature negotiation in the context of BOLT 12 Offers.- 635-635: The
NodeCfgstruct is correctly modified to include themessage_routerfield during the creation of aNode, which is necessary for the new testing framework.- 1090-1090: The macro
reload_node!has been updated to set the offers handler on theonion_messenger. This is a necessary change to ensure that theOnionMessengeris correctly configured after a node is reloaded in the test environment.- 2934-2935: The
create_networkfunction now initializes themessage_routerwith a new instance ofTestMessageRouter. This change is necessary to support the testing of message routing within the BOLT 12 Offers payment flow.- 2989-3001: The loop for creating nodes in the network now includes the initialization of
OnionMessengerwithDedicatedEntropy. This is consistent with the PR's objective to test the onion message handling and ensure deterministic behavior in the test environment.- 3016-3033: The connection setup between nodes now includes the initialization of features and the connection of the
OnionMessenger. This is necessary to test the interaction between nodes in the context of BOLT 12 Offers and onion message handling.lightning/src/routing/scoring.rs (1)
- 254-254: The conditional compilation directive correctly includes the
RwLock<T>implementation ofLockableScorewhen not compiling forc_bindings, or when the_test_utilsortestfeatures are enabled.lightning/src/routing/router.rs (5)
- 6905-6905: The change from
#[cfg(not(feature = "no-std"))]to#[cfg(feature = "std")]is consistent with the PR objectives to update conditional compilation directives.- 6915-6915: The update to the conditional compilation attribute for the
generate_routestest function is correct and aligns with the standard Rust feature flags.- 6936-6936: The conditional compilation attribute for the
generate_routes_mpptest function has been correctly updated to#[cfg(feature = "std")].- 6957-6957: The change in the conditional compilation attribute for the
generate_large_mpp_routestest function is appropriate and follows the Rust conventions.- 8293-8293: The modification of the conditional compilation attribute for the
bench_utilsmodule is consistent with the changes made in other parts of the file and adheres to the intended feature flag usage.lightning/src/ln/functional_tests.rs (2)
- 5536-5538: The instantiation of
TestRouterandTestMessageRouterand their inclusion in theNodeCfgstruct are consistent with the PR's objective to enhance the testing framework.- 5538-5538: The
NodeCfgstruct is correctly instantiated with the newmessage_routerfield, ensuring that the new testing components are integrated into the node configuration.lightning/src/ln/channelmanager.rs (5)
- 7782-7790: The conditional compilation directives here ensure that the correct version of
respond_using_derived_keysis called based on the "std" feature flag. This is a good practice to maintain compatibility with different environments.- 9227-9237: Similar to the previous hunk, the conditional compilation directives are used to handle the presence of the "std" feature. The code correctly uses a timestamp from
highest_seen_timestampwhen the "std" feature is not present, ensuring consistent behavior across environments.- 9246-9248: Again, the use of conditional compilation directives here is appropriate. The code ensures that the correct method is called for responding to an invoice request based on the compilation environment.
- 12490-12490: The import statements for Bitcoin types and synchronization primitives are correctly placed and are necessary for the subsequent code.
- 12530-12530: The initialization of
TestRouterwith a newNetworkGraphinstance and the configuration ofmax_dust_htlc_exposureare done correctly. These changes are likely related to setting up the environment for the new tests.
| match peel_onion_message( | ||
| msg, &self.secp_ctx, &*self.node_signer, &*self.logger, &*self.custom_handler | ||
| ) { | ||
| match self.peel_onion_message(msg) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The handle_onion_message method does not check if _peer_node_id matches next_node_id before forwarding the onion message. This could potentially lead to forwarding a message to an incorrect peer.
if next_node_id != *_peer_node_id {
log_trace!(self.logger, "Received onion message intended for another peer: {}", next_node_id);
return;
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... no, _peer_node_id is that node that sent the message, whereas next_node_id is where the message should be forwarded to next.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jkczyz Thank you for the clarification. I understand now that _peer_node_id is the sender of the message and next_node_id is the intended recipient for forwarding. No further action is required regarding the comparison between these two IDs.
| /// A source of random bytes. | ||
| entropy_source: RandomBytes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The RandomBytes struct is introduced to provide an entropy source, but it's not clear how the index is used to ensure uniqueness. The index should be incremented on each call to get_secure_random_bytes to ensure different values are produced each time. Please clarify the usage or ensure the implementation guarantees unique random values for each call.
| channel_keys_id: self.channel_keys_id, | ||
| rand_bytes_unique_start: self.get_secure_random_bytes(), | ||
| rand_bytes_index: AtomicCounter::new(), | ||
| entropy_source: RandomBytes::new(self.get_secure_random_bytes()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clone method for InMemorySigner is using RandomBytes::new(self.get_secure_random_bytes()), which seems to be using the output of get_secure_random_bytes as a new seed. This could potentially lead to predictable randomness if the get_secure_random_bytes method does not guarantee a unique seed on each invocation. Please ensure that the seed used for RandomBytes is unique and unpredictable.
| channel_keys_id, | ||
| rand_bytes_unique_start, | ||
| rand_bytes_index: AtomicCounter::new(), | ||
| entropy_source: RandomBytes::new(rand_bytes_unique_start), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new method for InMemorySigner is also using RandomBytes::new(rand_bytes_unique_start), where rand_bytes_unique_start is derived from various parameters. It's crucial to ensure that this results in a unique and unpredictable seed for the RandomBytes instance. If there's any doubt about the uniqueness or randomness of this seed, it should be addressed to prevent potential security issues.
| let mut nonce = [0u8; 16]; | ||
| nonce[..8].copy_from_slice(&index.to_be_bytes()); | ||
| ChaCha20::get_single_block(&self.rand_bytes_unique_start, &nonce) | ||
| self.entropy_source.get_secure_random_bytes() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The get_secure_random_bytes method in InMemorySigner is directly calling self.entropy_source.get_secure_random_bytes(). It's important to verify that entropy_source is indeed providing secure, random bytes and that the index is being handled correctly to avoid any reuse of random values.
| use crate::util::logger::Logger; | ||
| use crate::util::time::Time; | ||
| #[cfg(all(not(feature = "no-std"), test))] | ||
| #[cfg(all(feature = "std", test))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conditional compilation directive #[cfg(all(feature = "std", test))] is used to include SinceEpoch only when both the "std" feature and testing are enabled. This may lead to compilation errors or unexpected behavior when running tests without the "std" feature. Consider whether this is the intended behavior or if the directive should be adjusted to #[cfg(any(feature = "std", test))] to include SinceEpoch for either case.
| IgnoringMessageHandler, | ||
| >; | ||
|
|
||
| /// For use with [`OnionMessenger`] otherwise `test_restored_packages_retry` will fail. This is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kinda unfortunate how brittle that test is. Opened #2827.
OnionMessenger is needed to write functional tests for ChannelManager's OffersMessageHandler implementation. Also adds a TestMessageRouter, which simply wraps DefaultMessageRouter for now.
TestRouter checks route and scoring expectations before delegating to the standalone find_route function. Refactor it to wrap DefaultRouter and delegate to it instead. This allows TestRouter to implement create_blinded_payment_paths by delegating to DefaultRouter.
An upcoming rust-bitcoin release will remove the "no-std" feature. Replace "no-std" in feature checks with "std", negating as needed. Using a single feature flag makes the checks more consistent across modules.
ChannelManager provides utilities to create offers and refunds along with utilities to initiate and request payment for them, respectively. It also manages the payment flow via implementing OffersMessageHandler. Test that functionality, including the resulting event generation.
c43b4c0 to
4532fb5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (18)
- lightning/src/ln/channelmanager.rs (5 hunks)
- lightning/src/ln/features.rs (1 hunks)
- lightning/src/ln/functional_test_utils.rs (11 hunks)
- lightning/src/ln/functional_tests.rs (1 hunks)
- lightning/src/ln/mod.rs (1 hunks)
- lightning/src/ln/offers_tests.rs (1 hunks)
- lightning/src/ln/outbound_payment.rs (11 hunks)
- lightning/src/ln/payment_tests.rs (2 hunks)
- lightning/src/ln/peer_handler.rs (2 hunks)
- lightning/src/offers/offer.rs (1 hunks)
- lightning/src/offers/refund.rs (1 hunks)
- lightning/src/onion_message/messenger.rs (5 hunks)
- lightning/src/routing/gossip.rs (1 hunks)
- lightning/src/routing/router.rs (5 hunks)
- lightning/src/routing/scoring.rs (1 hunks)
- lightning/src/sign/mod.rs (9 hunks)
- lightning/src/util/test_utils.rs (5 hunks)
- lightning/src/util/time.rs (3 hunks)
Files skipped from review as they are similar to previous changes (18)
- lightning/src/ln/channelmanager.rs
- lightning/src/ln/features.rs
- lightning/src/ln/functional_test_utils.rs
- lightning/src/ln/functional_tests.rs
- lightning/src/ln/mod.rs
- lightning/src/ln/offers_tests.rs
- lightning/src/ln/outbound_payment.rs
- lightning/src/ln/payment_tests.rs
- lightning/src/ln/peer_handler.rs
- lightning/src/offers/offer.rs
- lightning/src/offers/refund.rs
- lightning/src/onion_message/messenger.rs
- lightning/src/routing/gossip.rs
- lightning/src/routing/router.rs
- lightning/src/routing/scoring.rs
- lightning/src/sign/mod.rs
- lightning/src/util/test_utils.rs
- lightning/src/util/time.rs
|
LGTM, only did a quick glance at the overall changes, didn't really review the tests themselves, I'll leave that to @valentinewallace. |
ChannelManagerprovides utilities to createOffers andRefunds along with utilities to initiate and request payment for them, respectively. It also manages the payment flow via implementingOffersMessageHandler. Test that functionality, including the resultingEventgeneration.