Commit graph

2787 commits

Author SHA1 Message Date
Jeffrey Czyz
2833786084
Clean up and add shutdown script functional tests 2021-08-09 15:55:25 -05:00
Matt Corallo
03537cc346
Merge pull request #1035 from TheBlueMatt/2021-08-faster-pings
Suggest faster ping in `PeerManager::timer_tick_occurred` docs
2021-08-09 18:52:25 +00:00
Matt Corallo
0f1a3b1698 Handle being asleep for more than double our ping time gracefully
If we've been asleep for double our ping time, for whatever reason,
disconnect all open sockets.
2021-08-09 18:11:19 +00:00
Matt Corallo
a00eec1865 Update lightning-background-processor to ping every five seconds
This updates lightning-background-processor calls to
PeerManager::timer_tick_occurred to match the new suggested rate in
the documentation.
2021-08-09 18:11:19 +00:00
Matt Corallo
70653d0ccb Suggest faster ping in PeerManager::timer_tick_occurred docs
This clarifies the docs for `PeerManager::timer_tick_occurred` to
note that the call rate is entirely up to the user, and also
suggests a faster ping rate of "once every five to ten seconds"
instead of "every 30 seconds". There isn't a lot of reason to want
to ping less often, and faster ping means we detect disconnects
sooner, which is important.
2021-08-09 18:11:19 +00:00
Matt Corallo
6bfab9d30a Correctly detect missing HTLCs when a local commitment tx was broadcast
If we forward an HTLC to our counterparty, but we force-closed the
channel before our counterparty provides us an updated commitment
transaction, we'll end up with a commitment transaction that does
not contain the HTLC which we attempted to forward. In this case,
we need to wait `ANTI_REORG_DELAY` blocks and then fail back the
HTLC as there is no way for us to learn the preimage and the
confirmed commitment transaction paid us the value of the HTLC.

However, check_spend_holder_transaction did not do this - it
instead only looked for dust HTLCs in the confirmed commitment
transaction, paying no attention to what other HTLCs may exist that
are missed.

This will eventually lead to channel force-closure as the channel
on which we received the inbound HTLC to forward will be closed in
time for the initial sender to claim the HTLC on-chain.
2021-08-09 16:12:53 +00:00
Matt Corallo
925e64228f DRY HTLC failure code in check_spend_counterparty_transaction
This extracts the HTLC-not-in-broadcasted-commitment-transaction
code from check_spend_counterparty_transaction and moves it to a
global macro, DRYing up the two very similar codepaths (fixing
some minor logging inconsistencies) in the process.

This macro will be used for local commitment transaction HTLC
failure as well in the next commit.

This commit has no functional change outside of logging.
2021-08-09 16:12:24 +00:00
Valentine Wallace
929259e546
Update keysend docs 2021-08-08 14:10:21 -04:00
Matt Corallo
853007800e
Merge pull request #1029 from TheBlueMatt/2021-07-log-channel-close
Log when a channel is closed on startup due to stale ChannelManager
2021-08-05 21:05:43 +00:00
Matt Corallo
5307b5e8ce Make BackgroundProcessor #[must_use] to avoid dropping immediately
It is easy for users to have a bug where they drop a
`BackgroundProcessor` immediately, causing it to start and then
immediately stop. Instead, add a `#[must_use]` tag to provide a
compiler warning for such instances.
2021-08-05 20:24:21 +00:00
Matt Corallo
cab2ca8eeb Log when a channel is closed on startup due to stale ChannelManager
This is one of the riskiest parts of our API from the perspective
of accidental force-closes - if users delay persisting the
ChannelManager much at all after a ChannelMonitor we may hit a
force-close after restart.

The fact that we don't log at all when this happens is criminal.
2021-08-05 20:24:21 +00:00
Matt Corallo
01bdc15fe6 Add additional TLV serialization type of (default_value, N)
This allows TLV serialization macros to read non-Option-wrapped
types but allow them to be missing, filling them in with the
provided default value as needed.
2021-08-05 12:34:06 -04:00
Matt Corallo
69ee486084
Merge pull request #1004 from TheBlueMatt/2021-07-forward-event
Add a `PaymentForwarded` Event
2021-08-04 22:58:14 +00:00
Matt Corallo
50f47ecc05 Change return value of claim_funds to ignore duplicate claims
While we should never reach `ClaimFundsFromHop::DuplicateClaim` in
most cases, if we do, it likely indicates the HTLC was timed out
some time ago and is no longer available to be claimed. Thus, it
does not make sense to imply that we `claimed_any_htlcs`.
2021-08-04 21:48:21 +00:00
Matt Corallo
2024c5e104 Generate a PaymentForwarded event when a forwarded HTLC is claimed
It is useful for accounting and informational reasons for users to
be informed when a payment has been successfully forwarded. Thus,
when an HTLC which represents a forwarded leg is claimed, we
generate a new `PaymentForwarded` event.

This requires some additional plumbing to return HTLC values from
`OnchainEvent`s. Further, when we have to go on-chain to claim the
inbound side of the payment, we do not inform the user of the fee
reward, as we cannot calculate it until we see what is confirmed
on-chain.

Substantial code structure rewrites by:
Valentine Wallace <vwallace@protonmail.com>
2021-08-04 21:48:21 +00:00
Matt Corallo
09e1670195
Merge pull request #1022 from TheBlueMatt/2021-07-to-remote-reorg
Fix to_remote SpendableOutputs generation in rare reorg cases
2021-08-04 03:08:53 +00:00
Matt Corallo
ad4459080e Fix to_remote SpendableOutputs generation in rare reorg cases
If we first see a local commitment transaction, and then a reorg
causes the confirmed channel close transaction to instead be a
remote commitment transaction, we would fail a spurious `if else`
check, resulting in us not generating the correct `SpendableOutput`
event for the to_remote output now confirmed on chain.

This resolves the incorrect logic and adds a regression test.
2021-08-04 02:34:57 +00:00
Matt Corallo
57feb26307
Merge pull request #1028 from lightning-signer/2021-08-no-std
Actual no_std support
2021-08-03 17:06:59 +00:00
Devrandom
32d13a2ff8 Rename no_std feature to no-std
matches rust-bitcoin
2021-08-03 18:53:33 +02:00
Matt Corallo
75f77a5708
Merge pull request #1033 from TheBlueMatt/2021-07-fix-beta
Fix lightning-persister tests for upcoming rustc changes
2021-08-03 14:41:35 +00:00
Devrandom
0dfcacd22c Actual no_std support 2021-08-03 09:34:56 +02:00
Matt Corallo
84909447e9 Check IO errors in test using raw_os_error() instead of kind()
std::io::ErrorKind is a `#[non_exhaustive]` enum as more specific
error types are to be added in the future. It was unclear in the
docs until very recently, however, that this is to be done by
re-defining `ErrorKind::Other` errors to new enum variants. Thus,
our tests which check explicitly for `ErrorKind::Other` as a
result of trying to access a directory as a file were incorrect.
Sadly, these generated no meaningful feedback from rustc at all,
except that they're suddenly failing in rustc beta!

After some back-and-forth, it seems rustc is moving forward
breaking existing code in future versions, so we move to the
"correct" check here, which is to check the raw IO error.

See rust-lang/rust#86442 and rust-lang/rust#85746 for more info.
2021-08-02 18:50:00 +00:00
Matt Corallo
7dfa886c67
Merge pull request #1032 from jkczyz/2021-08-clippy 2021-08-02 16:28:14 +00:00
Jeffrey Czyz
b4c3a33f29
Fail linter on #[warn(clippy::try_err)]
Some heavily used macros are using ? directly on an Err. Using a return
is easier to read and removes hundreds of linter warnings.

https://rust-lang.github.io/rust-clippy/master/index.html#try_err
2021-08-02 10:32:02 -05:00
Jeffrey Czyz
58a4dc0ef4
Fix #[warn(clippy::try_err)] in ser_macros.rs 2021-08-02 10:31:16 -05:00
Matt Corallo
0fa18658cd Add CI runs on rustc beta on Windows and MacOS
This should catch any platform-specific behavior changes in rustc
before they land in stable.
2021-08-02 14:52:35 +00:00
Matt Corallo
bee9a1e403
Merge pull request #1012 from TheBlueMatt/2021-07-bump-deps
Bump dependencies to bitcoin 0.27 and bech32 0.8
2021-07-31 20:42:59 +00:00
Matt Corallo
0671ca6a17 Add a #[macro_use] on the alloc import for format!() 2021-07-31 18:36:16 +00:00
Matt Corallo
8c16225557 Fix no_std warnings due to unused includes 2021-07-31 18:36:08 +00:00
Matt Corallo
24ae779652 Drop MSRV for no_std to 1.47 as that's what Ubuntu LTS ships with
...but disable it for now given core2 is broken (it claims an MSRV
of 1.47 but does not build).
2021-07-31 18:31:16 +00:00
Matt Corallo
3f229052ea Bump dependencies to bitcoin 0.27 and bech32 0.8 2021-07-31 18:29:07 +00:00
Matt Corallo
fe4b0b86db
Merge pull request #1024 from TheBlueMatt/2021-07-always-connect-in-tests
Connect peers on startup in tests
2021-07-30 20:53:30 +00:00
Matt Corallo
2745bd5ac7 Connect peers on startup in tests
This avoids `ChannelManager` ever being confused by the fact that
it received a message from a peer which it didn't think it was
connected to.
2021-07-30 18:48:29 +00:00
Matt Corallo
e26c9b051a
Merge pull request #1021 from TheBlueMatt/2021-07-broken-beta
Disable fast-fail to let CI actually run even though beta is broken
2021-07-29 18:06:05 +00:00
Matt Corallo
6b0a97be21
Merge pull request #1007 from jkczyz/2021-07-stop-drop-shutem-down
Stop BackgroundProcessor's thread on drop
2021-07-29 17:49:05 +00:00
Matt Corallo
a7934d7ece Disable fast-fail to let CI actually run even though beta is broken 2021-07-29 17:40:42 +00:00
Matt Corallo
f3b63e4dab
Merge pull request #1020 from TheBlueMatt/2021-07-log-features-more
Macroize feature printing to ensure we don't miss new flags
2021-07-28 21:58:31 +00:00
Jeffrey Czyz
e260cfcd9b
Add join method to BackgroundProcessor
The previous commit wraps the background thread's JoinHandle in an
Option. Providing a dedicated method to join hides this implementation
detail from users.
2021-07-28 16:30:51 -05:00
Matt Corallo
1f013c9cc2 Macroize feature printing to ensure we don't miss new flags 2021-07-28 21:06:49 +00:00
Matt Corallo
f438778715 Test preimages are learned instantly in test_onchain_to_onchain_claim
test_onchain_to_onchain_claim was connecting additional blocks in
order to reach HTLC timeout and broadcast an HTLC-Timeout
transaction, resulting in it not testing whether HTLC preimages are
learned instantly in response to HTLC-Success transactions.
2021-07-28 17:35:09 +00:00
Matt Corallo
8ffc2d1742 Ignore unknown Events serialized with an odd type value.
This should provide some additional future extensibility, allowing
for new informational events which can be safely ignored to be
ignored by older versions.
2021-07-28 17:35:09 +00:00
Matt Corallo
49ab8c2f9a Drop single-use macro from check_spend_holder_transaction
The wait_threshold_conf!() macro in check_spend_holder_transaction
was only used once, making it a good candidate for inlining at the
callsite. Further, it incorrectly always logged that we were
failing HTLCs from the "latest" commitment transaction, when it is
sometimes actually failing HTLCs from the previous commitment
transaction.
2021-07-28 17:35:09 +00:00
Matt Corallo
1bb9e64ebc
Merge pull request #977 from TheBlueMatt/2021-06-fix-double-claim-close
Handle double-HTLC-claims without failing the backwards channel
2021-07-28 01:24:27 +00:00
Matt Corallo
f06f9d1136 Fail channel if we can't sign a new commitment tx during HTLC claim
Previously, we could fail to generate a new commitment transaction
but it simply indicated we had gone to doule-claim an HTLC. Now
that double-claims are returned instead as Ok(None), we should
handle the error case and fail the channel, as the only way to hit
the error case is if key derivation failed or the user refused to
sign the new commitment transaction.

This also resolves an issue where we wouldn't inform our
ChannelMonitor of the new payment preimage in case we failed to
fetch a signature for the new commitment transaction.
2021-07-28 00:34:53 +00:00
Matt Corallo
c09104f46e Simplify call graph of get_update_fulfill_htlc since it can't Err. 2021-07-28 00:34:53 +00:00
Matt Corallo
7e78fa660c Handle double-HTLC-claims without failing the backwards channel
When receiving an update_fulfill_htlc message, we immediately
forward the claim backwards along the payment path before waiting
for a full commitment_signed dance. This is great, but can cause
duplicative claims if a node sends an update_fulfill_htlc message,
disconnects, reconnects, and then has to re-send its
update_fulfill_htlc message again.

While there was code to handle this, it treated it as a channel
error on the inbound channel, which is incorrect - this is an
expected, albeit incredibly rare, condition. Instead, we handle
these double-claims correctly, simply ignoring them.

With debug_assertions enabled, we also check that the previous
close of the same HTLC was a fulfill, and that we are not moving
from a HTLC failure to an HTLC claim after its too late.

A test is also added, which hits all three failure cases in
`Channel::get_update_fulfill_htlc`.

Found by the chanmon_consistency fuzzer.
2021-07-28 00:34:53 +00:00
Matt Corallo
0b4079df9a
Merge pull request #967 from valentinewallace/2021-06-keysend
Keysend
2021-07-28 00:32:27 +00:00
Valentine Wallace
6dd6289d38
Clarify decode_update_add_htlc_onion comment
Clearer phrasing
2021-07-27 15:18:25 -04:00
Valentine Wallace
47bcc1823b
tests: make PaymentSecret optional in pass_along path
and use it to make more keysend tests
2021-07-27 15:18:25 -04:00
Valentine Wallace
0328be32f7
Implement utilities for keysending to private nodes 2021-07-27 15:18:23 -04:00