Skip to content
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

Allow holder commitment and HTLC signature requests to fail #2816

Merged
merged 3 commits into from
Feb 13, 2024

Conversation

wpaulino
Copy link
Contributor

@wpaulino wpaulino commented Jan 8, 2024

As part of the ongoing async signer work, our holder signatures must also be capable of being obtained asynchronously. We rely on our existing ChainMonitor::rebroadcast_pending_claims method to retry pending onchain claims by re-signing and rebroadcasting transactions. Unfortunately, we cannot retry said claims without them being registered first, so if we're not able to obtain the signature synchronously, we must return the transaction as unsigned and ensure it is not broadcast.

Fixes #2520.

@codecov-commenter
Copy link

codecov-commenter commented Jan 8, 2024

Codecov Report

Attention: 86 lines in your changes are missing coverage. Please review.

Comparison is base (e0323ec) 89.13% compared to head (e38dcca) 89.08%.

Files Patch % Lines
lightning/src/ln/functional_test_utils.rs 0.00% 25 Missing ⚠️
lightning/src/chain/channelmonitor.rs 50.00% 18 Missing and 1 partial ⚠️
lightning/src/chain/chainmonitor.rs 0.00% 13 Missing ⚠️
lightning/src/chain/onchaintx.rs 76.47% 5 Missing and 7 partials ⚠️
lightning/src/chain/package.rs 83.33% 6 Missing and 1 partial ⚠️
lightning/src/util/test_channel_signer.rs 66.66% 5 Missing ⚠️
lightning/src/util/test_utils.rs 42.85% 2 Missing and 2 partials ⚠️
lightning/src/chain/transaction.rs 75.00% 0 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2816      +/-   ##
==========================================
- Coverage   89.13%   89.08%   -0.06%     
==========================================
  Files         115      115              
  Lines       93544    93617      +73     
  Branches    93544    93617      +73     
==========================================
+ Hits        83380    83395      +15     
- Misses       7634     7682      +48     
- Partials     2530     2540      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

coderabbitai bot commented Jan 22, 2024

Walkthrough

The recent updates to the codebase focus on enhancing error handling, introducing more flexible fee rate strategies, and improving the signing process for on-chain transactions. Key changes include modifications to the ChannelMonitor and ChannelSigner to better manage errors and asynchronous signing, adjustments in fee rate strategy handling across various components, and conditional compilation tweaks for testing. These updates aim to increase the robustness and flexibility of the system, particularly in handling edge cases and optimizing transaction fee rates.

Changes

Files Summary
.../channelmonitor.rs, .../ecdsa.rs, .../test_channel_signer.rs, .../test_utils.rs Enhanced error handling and retry logic for signing processes, including adjustments for asynchronous signing.
.../onchaintx.rs, .../package.rs Introduced FeerateStrategy enum and adjusted methods to include feerate_strategy parameter for on-chain transaction fee rate optimization.
.../ln/async_signer_tests.rs, .../ln/channel.rs, .../ln/channelmanager.rs, .../ln/functional_test_utils.rs, .../ln/monitor_tests.rs Various adjustments including conditional compilation tweaks, method renaming, and parameter additions to improve testing and functionality.

Assessment against linked issues

Objective Addressed Explanation
#2520: Ensure no panic occurs in OnChainTxHandler when ChannelSigner::sign_holder_commitment_and_htlcs returns Err

Poem

In the realm of code where rabbits hop,
Changes bloom like flowers non-stop.
🌼 With each commit, the garden grows,
Under moonlight, the blockchain flows.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a 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: 10

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 15c9f5b and ac4f174.
Files selected for processing (7)
  • lightning/src/chain/channelmonitor.rs (6 hunks)
  • lightning/src/chain/onchaintx.rs (8 hunks)
  • lightning/src/chain/package.rs (1 hunks)
  • lightning/src/ln/async_signer_tests.rs (11 hunks)
  • lightning/src/ln/functional_test_utils.rs (1 hunks)
  • lightning/src/util/test_channel_signer.rs (2 hunks)
  • lightning/src/util/test_utils.rs (4 hunks)
Additional comments: 27
lightning/src/util/test_channel_signer.rs (1)
  • 223-225: The sign_holder_htlc_transaction method now includes a check for signer availability, returning an error if the signer is unavailable. This change aligns with the PR's objective to support asynchronous signing.
lightning/src/ln/async_signer_tests.rs (11)
  • 45-45: The set_channel_signer_available method is used to simulate the signer's unavailability. This is a critical part of testing the asynchronous signing feature. Ensure that the rest of the test suite accounts for this new behavior to avoid false negatives in tests.
  • 59-59: The set_channel_signer_available method is correctly used to simulate the signer becoming available again, which should trigger the retry mechanism. This is a good test case for the asynchronous signing feature.
  • 100-100: The set_channel_signer_available method is used to simulate the signer's unavailability during the funding_created handling. This is consistent with the PR's objectives and should be reflected in all relevant tests.
  • 113-113: The set_channel_signer_available method is used to simulate the signer becoming available again, which should trigger the retry mechanism for the funding_signed message. This is a good test case for the asynchronous signing feature.
  • 154-154: The set_channel_signer_available method is used to simulate the signer's unavailability during the commitment_signed handling. This is consistent with the PR's objectives and should be reflected in all relevant tests.
  • 161-161: The set_channel_signer_available method is used to simulate the signer becoming available again, which should trigger the retry mechanism for the commitment_signed message. This is a good test case for the asynchronous signing feature.
  • 217-217: The set_channel_signer_available method is used to simulate the signer's unavailability during the funding_created handling for a zero-conf channel. This is consistent with the PR's objectives and should be reflected in all relevant tests.
  • 232-232: The set_channel_signer_available method is used to simulate the signer becoming available again, which should trigger the retry mechanism for the funding_signed message in a zero-conf channel. This is a good test case for the asynchronous signing feature.
  • 301-301: The set_channel_signer_available method is used to simulate the signer's unavailability during the commitment_signed handling after a peer disconnect. This is consistent with the PR's objectives and should be reflected in all relevant tests.
  • 316-316: The set_channel_signer_available method is used to simulate the signer becoming available again after a peer reconnect, which should trigger the retry mechanism for the commitment_signed message. This is a good test case for the asynchronous signing feature.
  • 330-433: The new test function do_test_async_holder_signatures is added to test the asynchronous signing of holder signatures. It simulates the signer's unavailability and subsequent availability, ensuring that the system can handle asynchronous operations. This is a comprehensive test that covers the new functionality introduced in the PR.
lightning/src/chain/onchaintx.rs (3)
  • 643-644: The debug logging for the pre-signed commitment transaction is correct and provides useful information.
  • 1126-1129: The method get_maybe_signed_holder_tx attempts to sign the holder commitment transaction and falls back to returning an unsigned transaction if signing fails. This change aligns with the PR's objective to handle cases where signatures are not immediately available.
  • 1163-1173: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1138-1170]

The method get_maybe_signed_htlc_tx has been updated to handle potentially unsigned HTLC transactions. It correctly attempts to sign the transaction and adds the necessary witness data if successful. If signing fails, it does not add any witness data, leaving the transaction unsigned.

lightning/src/util/test_utils.rs (8)
  • 1127-1127: The addition of the unavailable_signers field to TestKeysInterface is intended to simulate the behavior of unavailable signers in tests.
  • 1186-1190: The logic within derive_channel_signer checks if the channel_keys_id is in the unavailable_signers set and sets the signer's availability accordingly. This is a good use of the new field to control the signer's behavior in tests.
  • 1242-1242: The derive_channel_keys method is a wrapper around derive_channel_signer that simplifies its usage by not requiring the caller to pass a reference to the channel_keys_id. This is a convenience method that maintains the existing functionality.
  • 1242-1242: The derive_channel_keys method is a thin wrapper that does not add any new logic. It's a simple pass-through to derive_channel_signer. This is acceptable as it's meant to simplify the interface for the caller.
  • 1228-1228: The unavailable_signers field is initialized as an empty HashSet, which is appropriate for its intended use in testing scenarios where signers may be unavailable.
  • 1127-1127: The unavailable_signers field is a Mutex<HashSet<[u8; 32]>>, which is thread-safe. This is appropriate since the TestKeysInterface may be used in a multi-threaded context during testing.
  • 1186-1190: The check for signer availability is done by looking up the channel_keys_id in the unavailable_signers set. This is a simple and effective way to simulate signer unavailability.
  • 1242-1242: The derive_channel_keys method provides a convenient way to derive channel keys without having to specify the channel_keys_id explicitly. This is useful for tests that do not need to control the channel_keys_id.
lightning/src/chain/channelmonitor.rs (4)
  • 1399-1400: The trait bounds for F and L in the load_outputs_to_watch function have been refined. This change is appropriate and aligns with Rust's idiomatic use of trait bounds for generic parameters.
  • 1787-1792: The do_signer_call function is a test utility that allows for the invocation of a closure with the signer as a parameter. This change seems to be in line with the PR's objectives to facilitate testing of asynchronous signing functionality.
  • 3495-3506: The logic for adding HTLC transactions to the holder transactions list has been updated to check for non-empty witness data. This ensures that only signed transactions are included. The change is consistent with the PR's goal of handling unsigned transactions properly. However, the same recommendation about using a more descriptive error type applies here as well.
  • 3531-3536: This hunk is a duplicate of the logic reviewed in hunk 5. It appears to be part of the same function and is likely included due to the way the diff was generated. Since the same logic has been reviewed and approved in hunk 5, no additional comments are necessary for this hunk.

lightning/src/chain/onchaintx.rs Outdated Show resolved Hide resolved
lightning/src/chain/onchaintx.rs Outdated Show resolved Hide resolved
lightning/src/chain/onchaintx.rs Outdated Show resolved Hide resolved
lightning/src/chain/package.rs Outdated Show resolved Hide resolved
lightning/src/chain/package.rs Show resolved Hide resolved
lightning/src/ln/functional_test_utils.rs Outdated Show resolved Hide resolved
lightning/src/chain/channelmonitor.rs Outdated Show resolved Hide resolved
lightning/src/chain/channelmonitor.rs Outdated Show resolved Hide resolved
lightning/src/util/test_utils.rs Show resolved Hide resolved
lightning/src/util/test_utils.rs Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 51d9ee3 and 8945f62.
Files selected for processing (7)
  • lightning/src/chain/channelmonitor.rs (5 hunks)
  • lightning/src/chain/onchaintx.rs (8 hunks)
  • lightning/src/chain/package.rs (1 hunks)
  • lightning/src/ln/async_signer_tests.rs (11 hunks)
  • lightning/src/ln/functional_test_utils.rs (1 hunks)
  • lightning/src/util/test_channel_signer.rs (2 hunks)
  • lightning/src/util/test_utils.rs (4 hunks)
Files skipped from review as they are similar to previous changes (6)
  • lightning/src/chain/onchaintx.rs
  • lightning/src/chain/package.rs
  • lightning/src/ln/async_signer_tests.rs
  • lightning/src/ln/functional_test_utils.rs
  • lightning/src/util/test_channel_signer.rs
  • lightning/src/util/test_utils.rs
Additional comments: 4
lightning/src/chain/channelmonitor.rs (4)
  • 1399-1400: The trait bounds for F and L in the load_outputs_to_watch function have been refined. This change is straightforward and does not appear to introduce any issues.
  • 1545-1561: The get_latest_holder_commitment_txn function has been renamed to broadcast_latest_holder_commitment_txn and now takes additional parameters for broadcaster and fee_estimator. This change aligns with the PR's objective to enable asynchronous signer functionality. Ensure that all calls to the old function name have been updated to the new name and signature.
  • 1794-1799: The do_signer_call function is a test utility that allows for the invocation of a closure with the Signer. This change seems to be a utility for testing and does not affect production code.
  • 3493-3498: The logic within the if let Some(htlc_tx) block checks if the HTLC transaction is signed before pushing it to holder_transactions. This is a critical change that supports the PR's goal of handling transactions that may be unsigned. Ensure that the logic correctly handles the case where the transaction is not yet signed.
Verification successful
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for the usage of `get_maybe_signed_htlc_tx` to ensure it's being handled correctly.
rg --type rust 'get_maybe_signed_htlc_tx'

Length of output: 431



Script:

#!/bin/bash
# Examine the implementation of `get_maybe_signed_htlc_tx` in `onchaintx.rs`.
rg --type rust --context 10 'fn get_maybe_signed_htlc_tx' lightning/src/chain/onchaintx.rs

# Confirm that the check for a non-empty witness is used elsewhere in the codebase as an indicator of a signed transaction.
rg --type rust 'input.witness.is_empty()' lightning/

Length of output: 1865



Script:

#!/bin/bash
# Retrieve the complete implementation of `get_maybe_signed_htlc_tx` from `onchaintx.rs`.
rg --type rust --context 30 'fn get_maybe_signed_htlc_tx' lightning/src/chain/onchaintx.rs

Length of output: 3053

log_debug!(logger, "Pre-signed {} already has feerate {} sat/kW above required {} sat/kW",
log_tx!(tx), commitment_tx_feerate_sat_per_1000_weight,
log_debug!(logger, "Pre-signed commitment {} already has feerate {} sat/kW above required {} sat/kW",
tx.txid(), commitment_tx_feerate_sat_per_1000_weight,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

log_tx wants input witnesses and we may not have any if the transaction wasn't signed.

lightning/src/chain/channelmonitor.rs Outdated Show resolved Hide resolved
let log_start = if bumped_feerate { "Broadcasting RBF-bumped" } else { "Rebroadcasting" };
log_info!(logger, "{} onchain {}", log_start, log_tx!(tx));
broadcaster.broadcast_transactions(&[&tx]);
if tx.input.iter().any(|input| input.witness.is_empty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens if our fee estimator returns a very slightly different fee every time we call it? If fees are slowly rising, and the estimator is some smoothed thing, we may try to broadcast a new transaction each time with 0.1sat/vB additional fee, which will cause the signer to never succeed, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see how that causes the signer to never succeed. Whenever rebroadcast_pending_claims is called, we'll only try re-signing the most recently used fee.

Copy link
Collaborator

Choose a reason for hiding this comment

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

rebroadcast_pending_claims just calls generate_claim for all the relevant requests, which, for is_malleable packages calls compute_package_feerate, which will return the estimator feerate if its greater than the previous package feerate. In such a case, we'll compute_package_output and finalize_malleable_package on a different-feerate tx than previously.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed this offline and it's been addressed by adding a new ChannelMonitor::signer_unblocked method that will regenerate all claim requests using their most recently used feerate. rebroadcast_pending_claims remains unchanged.

Copy link

@coderabbitai coderabbitai bot left a 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: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 51d9ee3 and 7340531.
Files selected for processing (8)
  • lightning/src/chain/channelmonitor.rs (6 hunks)
  • lightning/src/chain/onchaintx.rs (8 hunks)
  • lightning/src/chain/package.rs (1 hunks)
  • lightning/src/ln/async_signer_tests.rs (11 hunks)
  • lightning/src/ln/functional_test_utils.rs (1 hunks)
  • lightning/src/ln/monitor_tests.rs (2 hunks)
  • lightning/src/util/test_channel_signer.rs (2 hunks)
  • lightning/src/util/test_utils.rs (4 hunks)
Files skipped from review as they are similar to previous changes (6)
  • lightning/src/chain/onchaintx.rs
  • lightning/src/chain/package.rs
  • lightning/src/ln/async_signer_tests.rs
  • lightning/src/ln/functional_test_utils.rs
  • lightning/src/util/test_channel_signer.rs
  • lightning/src/util/test_utils.rs
Additional comments: 5
lightning/src/chain/channelmonitor.rs (5)
  • 1399-1400: The refinement of trait bounds for the F and L parameters in the load_outputs_to_watch function is a good practice for ensuring that the function can only be used with appropriate types. This change enhances type safety and readability.
  • 1545-1561: The introduction of the broadcast_latest_holder_commitment_txn method with additional parameters for broadcaster and fee_estimator is a significant change. It aligns with the PR's objective to enable asynchronous signer functionality. However, the method's documentation should emphasize the conditions under which it is safe to use this function, given its potential risks. Additionally, the use of LowerBoundedFeeEstimator and WithChannelMonitor within this method suggests a thoughtful approach to fee estimation and logging, enhancing the method's robustness.
  • 1794-1799: The do_signer_call method, marked for test configurations, provides a flexible way to interact with the Signer for testing purposes. This utility function is a valuable addition for testing the asynchronous signing functionality, ensuring that the signer can be tested under various conditions without exposing this functionality in the production code.
  • 2846-2846: The logging within this conditional block serves as a critical warning to operators about the potential risks of broadcasting a holder commitment transaction. This is an essential safety measure, but it also underscores the importance of clear documentation and operator education on handling such scenarios safely.
  • 3493-3498: The logic for handling HTLC transactions in this segment is crucial for the asynchronous signing feature. It ensures that only HTLC transactions with non-empty witness data are considered for broadcasting. This check is a necessary part of the transaction validation process, preventing the broadcasting of incomplete transactions. However, it's important to ensure that this logic is thoroughly tested, especially since it directly impacts the safety and reliability of transaction broadcasting.

lightning/src/ln/monitor_tests.rs Show resolved Hide resolved
lightning/src/ln/monitor_tests.rs Show resolved Hide resolved
@TheBlueMatt
Copy link
Collaborator

Oh, also we need to tweak the BP on mobile so that we call the rebroadcast faster on startup. If we're on mobile we're usually not even running for more than a second or two, so we can't rely on the signer to have signatures on rebroadcast in 30 seconds. We should probably do an exponential rebroadcast starting with 500ms and growing to 30s on startup.

@wpaulino
Copy link
Contributor Author

It's already called once on startup, that should suffice?

Copy link

@coderabbitai coderabbitai bot left a 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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 51d9ee3 and 6b16a32.
Files selected for processing (10)
  • lightning/src/chain/channelmonitor.rs (8 hunks)
  • lightning/src/chain/onchaintx.rs (15 hunks)
  • lightning/src/chain/package.rs (6 hunks)
  • lightning/src/ln/async_signer_tests.rs (11 hunks)
  • lightning/src/ln/channelmanager.rs (1 hunks)
  • lightning/src/ln/functional_test_utils.rs (1 hunks)
  • lightning/src/ln/monitor_tests.rs (2 hunks)
  • lightning/src/sign/ecdsa.rs (3 hunks)
  • lightning/src/util/test_channel_signer.rs (2 hunks)
  • lightning/src/util/test_utils.rs (4 hunks)
Files skipped from review due to trivial changes (1)
  • lightning/src/ln/functional_test_utils.rs
Files skipped from review as they are similar to previous changes (5)
  • lightning/src/chain/onchaintx.rs
  • lightning/src/ln/async_signer_tests.rs
  • lightning/src/ln/monitor_tests.rs
  • lightning/src/util/test_channel_signer.rs
  • lightning/src/util/test_utils.rs
Additional comments: 15
lightning/src/sign/ecdsa.rs (3)
  • 55-60: The addition of error handling and retry logic in sign_holder_commitment is a significant improvement. It allows for asynchronous operation by enabling the signer to indicate unavailability and defer signing until later. This change aligns with the PR's objective to enhance the LDK with asynchronous signer functionality. However, ensure that all downstream consumers of this method properly handle the new error case to prevent unhandled errors.
  • 118-125: Similar to the sign_holder_commitment method, the addition of error handling in sign_holder_htlc_transaction is crucial for supporting asynchronous signing operations. This change allows the method to signal when the signer is unavailable, requiring a retry later. It's important to verify that the retry mechanism is implemented wherever this method is called to handle the deferred signing process effectively.
  • 158-163: The changes to sign_holder_anchor_input to include error handling for signer unavailability are consistent with the modifications made to other signing methods in this trait. This consistency is beneficial for the overall design, making the asynchronous signing feature more robust. As with the other methods, it's critical to ensure that the caller implements retry logic correctly to manage the asynchronous nature of the signing process.
lightning/src/chain/package.rs (4)
  • 643-643: The method get_maybe_signed_holder_tx is expected to return an Option<Transaction>, but the return statement is missing the Some wrapper. This issue was previously flagged and remains valid.
  • 966-966: The method compute_package_output now includes a feerate_strategy parameter. Ensure that all calls to this method throughout the codebase have been updated to include this new parameter.
  • 977-977: The use of feerate_bump within compute_package_output introduces a new logic for fee estimation. Verify that this logic aligns with the intended behavior and that the feerate_strategy is correctly applied.
Verification successful

The provided script output reveals the implementation details of compute_package_output within package.rs. This function calculates the output value and the new feerate for a transaction package based on the provided predicted_weight, dust_limit_sats, and feerate_strategy. The logic includes a conditional check on self.feerate_previous to determine whether to use a new fee estimation logic (feerate_bump) or a standard fee calculation (compute_fee_from_spent_amounts).

  • When self.feerate_previous is not 0: It attempts to bump the feerate using the feerate_bump function, which takes into account the predicted_weight, input_amounts, self.feerate_previous, feerate_strategy, fee_estimator, and logger. If successful, it returns the adjusted output value and the new feerate.

  • When self.feerate_previous is 0: It falls back to a standard fee calculation method, compute_fee_from_spent_amounts, to determine the new fee and feerate.

This implementation suggests that the feerate_strategy is indeed considered in the fee estimation process, specifically in the context of fee bumping when self.feerate_previous is not zero. The logic appears to align with the intended behavior of dynamically adjusting the fee based on the current feerate, the previous feerate, and the specified strategy for fee estimation.

Given this analysis, the use of feerate_bump within compute_package_output aligns with the intended behavior of adjusting the transaction fee based on a strategy, and the feerate_strategy is correctly applied as part of this process.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Manual verification needed to ensure the new fee estimation logic in `compute_package_output` aligns with intended behavior.
echo "Review the use of feerate_bump within compute_package_output for correctness and alignment with intended behavior."

Length of output: 238



Script:

#!/bin/bash
# Search for the definition and usage of compute_package_output to understand the application of feerate_bump and feerate_strategy
rg "compute_package_output" -A 30

Length of output: 5089

* 993-993: The addition of the `feerate_strategy` parameter in `compute_package_feerate` method is significant. Ensure that all invocations of this method have been updated accordingly.
lightning/src/chain/channelmonitor.rs (7)
  • 47-47: The imports have been updated to include new traits and structures necessary for the changes in this file. This is a straightforward change and appears correct as it aligns with the PR's objectives to support asynchronous signer functionality.
  • 1399-1400: The load_outputs_to_watch method now specifies refined trait bounds for its parameters, ensuring that the filter argument must implement the chain::Filter trait and the logger must implement the Logger trait. This change improves type safety and clarity in the method's contract.
  • 1545-1561: The broadcast_latest_holder_commitment_txn method has been introduced, replacing the get_latest_holder_commitment_txn method. This change is significant as it directly addresses the PR's objective by enabling the rebroadcasting of transactions when necessary. The method now takes additional parameters for broadcasting and fee estimation, which are essential for handling transactions asynchronously. Ensure that all calls to the old method have been updated to use this new method.
Verification successful

The verification process confirms that the broadcast_latest_holder_commitment_txn method has been introduced and is being used as intended, replacing the get_latest_holder_commitment_txn method for the main operational purposes. The presence of unsafe_get_latest_holder_commitment_txn in the codebase is consistent with a common practice for retaining more sensitive or controlled versions of methods for specific use cases, such as testing or internal operations, which does not conflict with the intent of the original review comment. Therefore, the transition appears to have been handled appropriately.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for old method usage to ensure it's fully replaced.
rg --type rust 'get_latest_holder_commitment_txn'
# Confirm new method is used correctly everywhere.
rg --type rust 'broadcast_latest_holder_commitment_txn'

Length of output: 1324

* 1748-1767: The `signer_unblocked` method is introduced to trigger rebroadcasts of pending claims after a transaction signature generation failure. This method is part of the enhancements to support asynchronous operations within the signer. It's crucial to ensure that this method is called appropriately in scenarios where the signer becomes available after being previously unavailable. The use of `LowerBoundedFeeEstimator` and `WithChannelMonitor` within this method is consistent with the approach taken in other parts of the PR. * 1815-1818: The `do_signer_call` method is a test utility that allows for direct invocation of signer-related operations. While this method is scoped under `#[cfg(test)]`, indicating it's only available for testing purposes, it's essential to ensure that it's used correctly in tests to simulate asynchronous signing behavior accurately. * 2865-2865: The logging statements have been updated to warn about the availability of a potentially-unsafe holder commitment transaction. This change is part of the broader effort to improve error handling and user guidance when dealing with asynchronous signing scenarios. It's important that these logs are clear and provide actionable advice to the node operator. * 3512-3517: The logic for handling HTLC transactions has been updated to include a check for whether the transaction's inputs have witnesses, indicating that the transaction is fully signed. This change is a direct consequence of the move towards asynchronous signing, where transactions may not be immediately signed. It's crucial to ensure that only fully signed transactions are considered for inclusion in `holder_transactions`.
lightning/src/ln/channelmanager.rs (1)
  • 3000-3001: The documentation update for force_close_without_broadcasting_txn correctly reflects the shift towards using ChannelMonitor::broadcast_latest_holder_commitment_txn for broadcasting the latest local transaction(s). This change aligns with the PR's objectives to enhance asynchronous operations within the LDK. Ensure that this method (broadcast_latest_holder_commitment_txn) is indeed the recommended approach and is implemented as described.

@@ -637,10 +637,10 @@ impl PackageSolvingData {
match self {
PackageSolvingData::HolderHTLCOutput(ref outp) => {
debug_assert!(!outp.channel_type_features.supports_anchors_zero_fee_htlc_tx());
return onchain_handler.get_fully_signed_htlc_tx(outpoint, &outp.preimage);
onchain_handler.get_maybe_signed_htlc_tx(outpoint, &outp.preimage)
Copy link

Choose a reason for hiding this comment

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

The method get_maybe_signed_htlc_tx is called without handling its return type correctly. It should handle the Option<Transaction> return type properly.

- onchain_handler.get_maybe_signed_htlc_tx(outpoint, &outp.preimage)
+ return onchain_handler.get_maybe_signed_htlc_tx(outpoint, &outp.preimage);

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
onchain_handler.get_maybe_signed_htlc_tx(outpoint, &outp.preimage)
return onchain_handler.get_maybe_signed_htlc_tx(outpoint, &outp.preimage)

Copy link

@coderabbitai coderabbitai bot left a 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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5bf58f0 and 4dea907.
Files selected for processing (11)
  • lightning/src/chain/channelmonitor.rs (8 hunks)
  • lightning/src/chain/onchaintx.rs (15 hunks)
  • lightning/src/chain/package.rs (6 hunks)
  • lightning/src/ln/async_signer_tests.rs (2 hunks)
  • lightning/src/ln/channel.rs (1 hunks)
  • lightning/src/ln/channelmanager.rs (1 hunks)
  • lightning/src/ln/functional_test_utils.rs (1 hunks)
  • lightning/src/ln/monitor_tests.rs (2 hunks)
  • lightning/src/sign/ecdsa.rs (3 hunks)
  • lightning/src/util/test_channel_signer.rs (2 hunks)
  • lightning/src/util/test_utils.rs (4 hunks)
Files skipped from review as they are similar to previous changes (9)
  • lightning/src/chain/onchaintx.rs
  • lightning/src/chain/package.rs
  • lightning/src/ln/async_signer_tests.rs
  • lightning/src/ln/channelmanager.rs
  • lightning/src/ln/functional_test_utils.rs
  • lightning/src/ln/monitor_tests.rs
  • lightning/src/sign/ecdsa.rs
  • lightning/src/util/test_channel_signer.rs
  • lightning/src/util/test_utils.rs
Additional comments: 7
lightning/src/chain/channelmonitor.rs (6)
  • 47-47: The imports are correctly organized, ensuring that all necessary traits and structures for the ChannelMonitor and related functionality are available. This change aligns with the PR's objective to enhance asynchronous signer functionality.
  • 1419-1420: Refining trait bounds for the F and L parameters in the load_outputs_to_watch function improves type safety and clarity. This change ensures that only appropriate types implementing the chain::Filter and Logger traits can be passed to the function, enhancing maintainability and readability.
  • 1768-1787: The signer_unblocked method, which triggers rebroadcasts of pending claims after a transaction signature generation failure, is a crucial addition for handling asynchronous signing scenarios. This method's implementation, including the use of LowerBoundedFeeEstimator and WithChannelMonitor, is consistent with the PR's objectives. However, ensure that the logic for handling rebroadcasts is thoroughly tested, especially given the complexity of asynchronous operations.
Verification successful

The expanded search for the signer_unblocked method across the entire repository has revealed multiple references to this method in the codebase, including in lightning/src/ln/async_signer_tests.rs. This file contains tests that specifically invoke the signer_unblocked method in various scenarios, indicating that there is indeed test coverage for this method. These findings confirm that the initial review comment's concern about ensuring thorough testing for the signer_unblocked method has been addressed in the codebase.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that tests covering the signer_unblocked method exist.
rg --type rust 'signer_unblocked' tests/

Length of output: 87



Script:

#!/bin/bash
# Broaden the search for tests covering the signer_unblocked method across the entire repository.
rg --type rust 'signer_unblocked'

Length of output: 1916

* 1834-1838: The `do_signer_call` method in the test utilities is a useful addition for simulating asynchronous signing behavior. By allowing a closure to be executed with the `Signer`, it facilitates more flexible testing scenarios. Ensure that this method is used effectively in tests to cover the new asynchronous functionality introduced by the PR. * 2885-2885: Logging a warning when a potentially-unsafe holder commitment transaction is available to broadcast is a good practice. It alerts the operator to the risks involved and suggests consulting the documentation for manual action. This change enhances the robustness of error handling and user awareness. * 3536-3541: The logic for handling HTLC transactions in `unsafe_get_latest_holder_commitment_txn` has been updated to include a check for non-empty witness data before adding a transaction to the `holder_transactions` list. This change is crucial for ensuring that only properly signed transactions are considered, aligning with the PR's goal to handle transactions asynchronously and safely.
lightning/src/ln/channel.rs (1)
  • 1261-1264: The conditional compilation directives are correctly applied to toggle the visibility of channel_keys_id based on the compilation context. This is a common pattern to facilitate testing. However, it would be beneficial to add a comment explaining why this field's visibility is altered for tests, to provide context for future maintainers.

TheBlueMatt
TheBlueMatt previously approved these changes Feb 2, 2024
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

LGTM, small nits but nothing critical.

lightning/src/chain/channelmonitor.rs Show resolved Hide resolved
@@ -637,10 +637,10 @@ impl PackageSolvingData {
match self {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be renamed get_maybe_finalized_tx, then? (and finalize_untractable_package).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, while doing this I also realized we were missing handling of signatures from non-external malleable requests (sign_counterparty_htlc_transaction, sign_justice_revoked_*) as well. Added with test coverage included.

Copy link

@coderabbitai coderabbitai bot left a 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: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e64342a and eb3c4ab.
Files selected for processing (12)
  • lightning/src/chain/chainmonitor.rs (1 hunks)
  • lightning/src/chain/channelmonitor.rs (8 hunks)
  • lightning/src/chain/onchaintx.rs (16 hunks)
  • lightning/src/chain/package.rs (8 hunks)
  • lightning/src/ln/async_signer_tests.rs (2 hunks)
  • lightning/src/ln/channel.rs (1 hunks)
  • lightning/src/ln/channelmanager.rs (1 hunks)
  • lightning/src/ln/functional_test_utils.rs (1 hunks)
  • lightning/src/ln/monitor_tests.rs (2 hunks)
  • lightning/src/sign/ecdsa.rs (3 hunks)
  • lightning/src/util/test_channel_signer.rs (4 hunks)
  • lightning/src/util/test_utils.rs (4 hunks)
Files skipped from review as they are similar to previous changes (10)
  • lightning/src/chain/onchaintx.rs
  • lightning/src/chain/package.rs
  • lightning/src/ln/async_signer_tests.rs
  • lightning/src/ln/channel.rs
  • lightning/src/ln/channelmanager.rs
  • lightning/src/ln/functional_test_utils.rs
  • lightning/src/ln/monitor_tests.rs
  • lightning/src/sign/ecdsa.rs
  • lightning/src/util/test_channel_signer.rs
  • lightning/src/util/test_utils.rs
Additional comments: 6
lightning/src/chain/chainmonitor.rs (1)
  • 639-659: The implementation of signer_unblocked correctly handles the optional OutPoint to selectively trigger rebroadcasts for a specific channel monitor or all monitors if none is specified. This approach aligns with the intended functionality described in the PR objectives. The use of locking mechanisms (self.monitors.read().unwrap()) to access shared state is consistent with the rest of the file, ensuring thread safety. The function iterates over the relevant monitors and calls signer_unblocked on each, which is expected to handle the rebroadcast logic internally. Overall, the changes are logically sound and adhere to the project's coding standards.
lightning/src/chain/channelmonitor.rs (5)
  • 47-47: Imports are added for several types. Ensure these new imports are used within the file to avoid unnecessary dependencies.
  • 1419-1420: The load_outputs_to_watch method now specifies refined trait bounds for its parameters. Verify that these changes do not restrict the method's usability in existing contexts.
  • 1768-1787: The signer_unblocked method triggers rebroadcasts of pending claims with a specific FeerateStrategy. Ensure that the chosen strategy aligns with the intended behavior and that the method's implementation correctly handles all edge cases.
  • 1835-1838: The do_signer_call method is introduced for testing purposes. Confirm that its usage is restricted to test scenarios and does not expose any sensitive operations in production code.
  • 3536-3541: The logic for handling HTLC transactions in unsafe_get_latest_holder_commitment_txn is adjusted. Verify that these changes correctly handle all cases, especially around the signing and inclusion of HTLC transactions.

Comment on lines +1565 to +1581
/// You may use this to broadcast the latest local commitment transaction, either because
/// a monitor update failed or because we've fallen behind (i.e. we've received proof that our
/// counterparty side knows a revocation secret we gave them that they shouldn't know).
///
/// Broadcasting these transactions in the second case is UNSAFE, as they allow counterparty
/// Broadcasting these transactions in this manner is UNSAFE, as they allow counterparty
/// side to punish you. Nevertheless you may want to broadcast them if counterparty doesn't
/// close channel with their commitment transaction after a substantial amount of time. Best
/// may be to contact the other node operator out-of-band to coordinate other options available
/// to you.
///
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
pub fn get_latest_holder_commitment_txn<L: Deref>(&self, logger: &L) -> Vec<Transaction>
where L::Target: Logger {
pub fn broadcast_latest_holder_commitment_txn<B: Deref, F: Deref, L: Deref>(
&self, broadcaster: &B, fee_estimator: &F, logger: &L
)
where
B::Target: BroadcasterInterface,
F::Target: FeeEstimator,
L::Target: Logger
{
Copy link

Choose a reason for hiding this comment

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

The broadcast_latest_holder_commitment_txn method is introduced with detailed documentation on its unsafe nature and intended use. Ensure that all calls to this method are carefully reviewed to prevent misuse, given its potential to cause loss of funds if used incorrectly.

@@ -2855,7 +2882,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
} else if !self.holder_tx_signed {
log_error!(logger, "WARNING: You have a potentially-unsafe holder commitment transaction available to broadcast");
log_error!(logger, " in channel monitor for channel {}!", &self.channel_id());
log_error!(logger, " Read the docs for ChannelMonitor::get_latest_holder_commitment_txn and take manual action!");
log_error!(logger, " Read the docs for ChannelMonitor::broadcast_latest_holder_commitment_txn to take manual action!");
Copy link

Choose a reason for hiding this comment

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

Logging statements are added to warn about the availability of a potentially-unsafe holder commitment transaction. Ensure that these logs provide clear guidance to operators on how to proceed safely.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Needs another reviewer.

) {
assert!(new_feerate != 0);

let transaction = cached_request.finalize_malleable_package(
let transaction = cached_request.maybe_finalize_malleable_package(
cur_height, self, output_value, self.destination_script.clone(), logger
).unwrap();
log_trace!(logger, "...with timer {} and feerate {}", new_timer, new_feerate);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this ...ing from? Is it supposed to be a followon to the now-removed Finalized transaction...ready to broadcast logs?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, please add comment. Also, if we ever add a log statement between this one and the one it is ostensibly continuing from, it will become confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm just going to remove it.

}
log_debug!(logger, "Finalized transaction {} ready to broadcast", bumped_tx.txid());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean, I'm fine removing this, but its not clear to me we have quite the same logs printing the output of what we're doing in generate_claim describing what we've done (though it'll show up when we broadcast eventually, presumably).

Copy link
Contributor

Choose a reason for hiding this comment

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

Or you could leave the log statement if the finalization succeeded.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We already have logs whenever we process the result of generate_claim so I opted to remove this one as it's not very useful anymore.

lightning/src/chain/onchaintx.rs Outdated Show resolved Hide resolved
) {
assert!(new_feerate != 0);

let transaction = cached_request.finalize_malleable_package(
let transaction = cached_request.maybe_finalize_malleable_package(
cur_height, self, output_value, self.destination_script.clone(), logger
).unwrap();
log_trace!(logger, "...with timer {} and feerate {}", new_timer, new_feerate);
Copy link
Contributor

Choose a reason for hiding this comment

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

+1, please add comment. Also, if we ever add a log statement between this one and the one it is ostensibly continuing from, it will become confusing

// so we choose to bump our previous feerate by 25%, making sure we don't use a
// lower feerate or overpay by a large margin by limiting it to 5x the new fee
// estimate.
let previous_feerate = self.feerate_previous.try_into().unwrap_or(u32::max_value());
Copy link
Contributor

Choose a reason for hiding this comment

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

can there ever be a scenario where previous_feerate does become u32::max_value()? Because that could potentially be rather catastrophic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Possibly if we keep bumping 25% on each block connected, but it's very unlikely to happen.

lightning/src/chain/onchaintx.rs Outdated Show resolved Hide resolved
}
log_debug!(logger, "Finalized transaction {} ready to broadcast", bumped_tx.txid());
Copy link
Contributor

Choose a reason for hiding this comment

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

Or you could leave the log statement if the finalization succeeded.

Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between e0323ec and f35adc7.
Files selected for processing (12)
  • lightning/src/chain/chainmonitor.rs (1 hunks)
  • lightning/src/chain/channelmonitor.rs (7 hunks)
  • lightning/src/chain/onchaintx.rs (16 hunks)
  • lightning/src/chain/package.rs (8 hunks)
  • lightning/src/ln/async_signer_tests.rs (2 hunks)
  • lightning/src/ln/channel.rs (1 hunks)
  • lightning/src/ln/channelmanager.rs (1 hunks)
  • lightning/src/ln/functional_test_utils.rs (1 hunks)
  • lightning/src/ln/monitor_tests.rs (2 hunks)
  • lightning/src/sign/ecdsa.rs (6 hunks)
  • lightning/src/util/test_channel_signer.rs (4 hunks)
  • lightning/src/util/test_utils.rs (4 hunks)
Files skipped from review as they are similar to previous changes (11)
  • lightning/src/chain/chainmonitor.rs
  • lightning/src/chain/onchaintx.rs
  • lightning/src/chain/package.rs
  • lightning/src/ln/async_signer_tests.rs
  • lightning/src/ln/channel.rs
  • lightning/src/ln/channelmanager.rs
  • lightning/src/ln/functional_test_utils.rs
  • lightning/src/ln/monitor_tests.rs
  • lightning/src/sign/ecdsa.rs
  • lightning/src/util/test_channel_signer.rs
  • lightning/src/util/test_utils.rs
Additional comments: 6
lightning/src/chain/channelmonitor.rs (6)
  • 47-47: Imports are added for various traits and structs. Ensure these new imports are used in the modified or added code segments within this file to justify their inclusion.
  • 1565-1581: The method broadcast_latest_holder_commitment_txn is introduced with a clear warning about its unsafe nature. Ensure that the documentation and method signature accurately reflect its intended use and the risks involved. Additionally, verify that the trait bounds and parameters (broadcaster, fee_estimator, logger) are correctly utilized within the method body.
  • 1768-1787: The signer_unblocked method is added to trigger rebroadcasts of pending claims. Ensure that the method's implementation correctly uses the provided broadcaster, fee_estimator, and logger parameters, and that the FeerateStrategy::RetryPrevious is appropriately applied.
  • 1835-1838: The do_signer_call test utility method is introduced. Confirm that this method is only available in test configurations and that it correctly invokes the provided closure with the Signer instance.
  • 2885-2885: Logging statements are added to warn about the availability of a potentially-unsafe holder commitment transaction. Ensure that these logs provide clear guidance to operators on how to proceed safely.
  • 3554-3559: The logic for handling HTLC transactions in unsafe_get_latest_holder_commitment_txn is modified. Ensure that the changes correctly identify and include signed HTLC transactions in holder_transactions.

@wpaulino
Copy link
Contributor Author

wpaulino commented Feb 7, 2024

Had to rebase to fix CI.

This method is meant to be used as a last resort when a user is forced
to broadcast the current state, even if it is stale, in an attempt to
claim their funds in the channel. Previously, we'd return the commitment
and HTLC transactions such that they broadcast them themselves. Doing so
required a different code path, one which was not tested, to obtain
these transactions than our usual path when force closing. It's not
worth maintaining both, and it's much simpler for us to broadcast
instead.
This refactors the existing `force_feerate_bump` flag into an enum as we
plan to introduce a new flag/enum variant in a future commit.
As part of the ongoing async signer work, our holder signatures must
also be capable of being obtained asynchronously. We expose a new
`ChannelMonitor::signer_unblocked` method to retry pending onchain
claims by re-signing and rebroadcasting transactions. Unfortunately, we
cannot retry said claims without them being registered first, so if
we're not able to obtain the signature synchronously, we must return the
transaction as unsigned and ensure it is not broadcast.
Copy link

@coderabbitai coderabbitai bot left a 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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e0323ec and e38dcca.
Files selected for processing (13)
  • lightning/src/chain/chainmonitor.rs (1 hunks)
  • lightning/src/chain/channelmonitor.rs (7 hunks)
  • lightning/src/chain/onchaintx.rs (18 hunks)
  • lightning/src/chain/package.rs (8 hunks)
  • lightning/src/chain/transaction.rs (2 hunks)
  • lightning/src/ln/async_signer_tests.rs (2 hunks)
  • lightning/src/ln/channel.rs (1 hunks)
  • lightning/src/ln/channelmanager.rs (1 hunks)
  • lightning/src/ln/functional_test_utils.rs (1 hunks)
  • lightning/src/ln/monitor_tests.rs (2 hunks)
  • lightning/src/sign/ecdsa.rs (6 hunks)
  • lightning/src/util/test_channel_signer.rs (4 hunks)
  • lightning/src/util/test_utils.rs (4 hunks)
Files not reviewed due to errors (1)
  • lightning/src/ln/functional_test_utils.rs (Error: unable to parse review)
Files skipped from review as they are similar to previous changes (10)
  • lightning/src/chain/chainmonitor.rs
  • lightning/src/chain/onchaintx.rs
  • lightning/src/chain/package.rs
  • lightning/src/ln/async_signer_tests.rs
  • lightning/src/ln/channel.rs
  • lightning/src/ln/channelmanager.rs
  • lightning/src/ln/monitor_tests.rs
  • lightning/src/sign/ecdsa.rs
  • lightning/src/util/test_channel_signer.rs
  • lightning/src/util/test_utils.rs
Additional comments: 7
lightning/src/chain/transaction.rs (1)
  • 83-85: The method is_fully_signed correctly checks if all inputs are fully signed by verifying the witness is not empty for each input. This logic is sound for determining the signature status of a transaction in the context of Bitcoin transactions where the presence of witness data is indicative of a signed input.
lightning/src/chain/channelmonitor.rs (6)
  • 47-47: The imports are updated to include new dependencies. Ensure that all newly imported types are used within the file to avoid unnecessary imports.
  • 1565-1581: The method broadcast_latest_holder_commitment_txn is introduced with a detailed explanation of its unsafe nature. Ensure that the method's usage is strictly controlled and documented, especially given its potential consequences. The method signature correctly uses trait bounds for the broadcaster, fee estimator, and logger, promoting flexibility in the implementation.
  • 1768-1787: The signer_unblocked method is introduced for rebroadcasting pending claims after a transaction signature generation failure. The method signature and logic appear correct, using trait bounds for the broadcaster, fee estimator, and logger. The use of LowerBoundedFeeEstimator and WithChannelMonitor wrapper for logging is consistent with the rest of the file. Ensure that the FeerateStrategy::RetryPrevious is the intended strategy for this context.
  • 1835-1838: The do_signer_call method is introduced for testing purposes, allowing a closure to be executed with the Signer as an argument. This method is correctly gated with a #[cfg(test)] attribute, ensuring it's only available during testing. The implementation is straightforward and serves its intended purpose without introducing unnecessary complexity.
  • 2885-2885: Logging statements are added to warn about the availability of a potentially-unsafe holder commitment transaction. This is a critical addition for informing operators of the risks associated with broadcasting such transactions. Ensure that the documentation for ChannelMonitor::broadcast_latest_holder_commitment_txn provides clear guidance on how to proceed safely.
  • 3554-3559: The logic for handling HTLC transactions in the unsafe_get_latest_holder_commitment_txn method is updated. This change appears to correctly handle the retrieval and signing of HTLC transactions. Ensure that the method's usage of is_fully_signed correctly reflects the transaction's signing status and that the handling of the htlc_tx is consistent with the intended logic for dealing with HTLCs.

@@ -76,6 +76,15 @@ impl core::fmt::Display for OutPoint {

impl_writeable!(OutPoint, { txid, index });

#[derive(Debug, Clone)]
pub(crate) struct MaybeSignedTransaction(pub Transaction);
Copy link

Choose a reason for hiding this comment

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

Define the visibility of MaybeSignedTransaction more explicitly if it's intended for use outside of the crate; otherwise, ensure the restricted visibility is intentional.

@@ -633,14 +634,14 @@ impl PackageSolvingData {
}
true
}
fn get_finalized_tx<Signer: WriteableEcdsaChannelSigner>(&self, outpoint: &BitcoinOutPoint, onchain_handler: &mut OnchainTxHandler<Signer>) -> Option<Transaction> {
fn get_maybe_finalized_tx<Signer: WriteableEcdsaChannelSigner>(&self, outpoint: &BitcoinOutPoint, onchain_handler: &mut OnchainTxHandler<Signer>) -> Option<MaybeSignedTransaction> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still kinda hung up on this Option thing. Because there are essentially three states now: None, Some(non-finalized tx), and Some(finalized tx). The nesting feels like it should give way to an enum. Not really worth the refactor imo, but I think it would improve legibility in the future.

@TheBlueMatt TheBlueMatt merged commit f98a652 into lightningdevkit:main Feb 13, 2024
14 of 15 checks passed
@wpaulino wpaulino deleted the retryable-holder-sigs branch February 13, 2024 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ChannelSigner::sign_holder_commitment_and_htlcs causes panic when returning Err
5 participants