Commit graph

2603 commits

Author SHA1 Message Date
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
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
Valentine Wallace
2d94401cca
Implement sending keysend payments (to public nodes) 2021-07-27 15:15:24 -04:00
Valentine Wallace
d32052fbf6
test utils: add optional PaymentPreimage param to pass_along_path
This will allow keysend tests to assert that the PaymentReceived payment preimage is
as expected in upcoming commits.
2021-07-27 15:15:24 -04:00
Valentine Wallace
5a42be07a0
Implement receiving keysend payments 2021-07-27 15:15:24 -04:00
Valentine Wallace
d1e8d9ced5
Refactor PaymentReceived event for keysend receives 2021-07-27 15:15:23 -04:00
Valentine Wallace
f60a65fec3
Add PendingHTLCRouting variant for receiving keysend payments 2021-07-27 15:15:23 -04:00
Valentine Wallace
a8d5c6e451
Fix indentation in decode_update_add_htlc_onion 2021-07-27 15:15:23 -04:00
Valentine Wallace
288b93b3da
Advertise keysend feature
C-Lightning requires us to advertise this feature before they'll
attempt a keysend payment to us.
2021-07-27 15:15:23 -04:00
Valentine Wallace
99b0e7e59a
Parse keysend TLV field in onion.
This doesn't yet use the field, but it will be used in upcoming commits.
2021-07-27 15:15:21 -04:00
Matt Corallo
d37b1dd673
Merge pull request #998 from TheBlueMatt/2021-07-fix-chan-reserve-msat-sat
Fix channel reserve calculation on the sending side
2021-07-26 16:03:22 +00:00
Matt Corallo
99ecd02f7d
Merge pull request #986 from TheBlueMatt/2021-07-route-lasthop-value
[router] Use the invoice value for last-hop hint channel capacity
2021-07-26 16:02:41 +00:00
Matt Corallo
41d8d4d6b2
Merge pull request #1008 from lightning-signer/2021-07-sync-no-std
Dummy sync implementation for no_std
2021-07-22 14:17:09 +00:00
Matt Corallo
ef4bfdca3c
Merge pull request #1010 from sr-gi/enforce_signature_length 2021-07-20 23:25:40 +00:00
Devrandom
2e8f4fef2f Test no_std instead of just hashbrown 2021-07-20 20:59:18 +02:00
Devrandom
a0a3a6b204 Implement dummy Mutex, Condvar and RwLock 2021-07-20 20:59:18 +02:00
Sergi Delgado Segura
8a1c538f88
Enforces sig_rec length in message_signing 2021-07-20 11:41:38 +02:00
Devrandom
002a5db5b0 Collect all lightning std::sync imports under crate::sync
in preparation for no-std sync dummies
2021-07-19 15:01:58 +02:00
Jeffrey Czyz
4f05db6af8
Stop BackgroundProcessor's thread on drop
Without stopping the thread when BackgroundProcessor is dropped, it will
run free. In the context of language bindings, it is difficult to know
how long references held by the thread should live. Implement Drop to
stop the thread just as is done when explicitly calling stop().
2021-07-18 13:11:01 -05:00
Jeffrey Czyz
d9fa8f1c38
Correctly assert BackgroundProcessor error
The specific error from the ChannelManager persister is not asserted for
in test_persist_error. Rather, any error will do. Update the test to use
BackgroundProcessor::stop and assert for the expected value.
2021-07-18 12:59:27 -05:00
Matt Corallo
1f1d7c6890
Merge pull request #1003 from jkczyz/2021-known-features-mask
Expand tests for Features::to_context
2021-07-15 20:14:35 +00:00
Matt Corallo
ccd7b6c554
Merge pull request #1002 from valentinewallace/2021-07-fix-features-index-bounds 2021-07-15 12:59:45 +00:00
Jeffrey Czyz
87233488cc
Test index-out-of-bounds in Features::to_context
When there are fewer known `from` feature bytes than known `to` feature
bytes, an index-out-of-bounds error can occur if the `from` features
have unknown features set in a byte past the greatest known `from`
feature byte.
2021-07-14 20:34:13 -05:00
Jeffrey Czyz
06ecbecd6d
Remove unnecessary feature test-only methods 2021-07-14 16:26:08 -07:00
Valentine Wallace
7497ed2402
Fix crash due to index-out-of-bounds in feature translation
This was reported by a user when trying to send a payment using the LDK
sample (specifically during route generation when translating a Features
from one context to another)

The problem was we didn't check T::KNOWN_FEATURE_MASK vec length before
indexing into it, due likely to the assumption that known feature vec
lengths are the same across contexts, when they may not be
2021-07-14 18:55:17 -04:00
Matt Corallo
fecac81874 Support pending update_fail_htlcs in reconnect_nodes test util 2021-07-14 18:23:32 +00:00
Matt Corallo
306e9a5acf Fix channel reserve calculation on the sending side
As the variable name implies holder_selected_chan_reserve_msat is
intended to be in millisatoshis, but is instead calculated in
satoshis.

We fix that error here and update the relevant tests to more
accurately calculate the expected reserve value and test both
success and failure cases.

Bug discovered by chanmon_consistency fuzz target.
2021-07-13 17:13:58 +00:00
Matt Corallo
afae12ea1e
Merge pull request #990 from TheBlueMatt/2021-07-0.0.99
Cut 0.0.99
2021-07-09 17:29:38 +00:00
Matt Corallo
c9a8b26d58 Bump most crate versions to 0.0.99 and lightning-invoice to 0.7.0 2021-07-09 16:34:46 +00:00
Matt Corallo
230c72bd4c Add documentation for all PRs slated to land for 0.0.99 2021-07-09 16:34:46 +00:00
Matt Corallo
e04a1b3872
Merge pull request #975 from TheBlueMatt/2021-06-fix-fee-calc
Make the base fee configurable in ChannelConfig
2021-07-09 02:11:57 +00:00
Matt Corallo
4cc0d9dfe5 Change serialization backwards compat in Channel to use new version
Instead of interpreting the backwards compatibility data in Channel
serialization, use the serialization version bump present in 0.0.99
as the flag to indicate if a channel should be read in backwards
compatibility.
2021-07-09 01:33:44 +00:00
Matt Corallo
dbfccf045f Add a note clarifying the API guarantees of create_channel 2021-07-09 01:33:44 +00:00
Matt Corallo
520b53eb1c Optionally reject HTLC forwards over priv chans with a new config
Private nodes should never wish to forward HTLCs at all, which we
support here by disabling forwards out over private channels by
default. As private nodes should not have any public channels, this
suffices, without allowing users to disable forwarding over
channels announced in the routing graph already.

Closes #969
2021-07-09 01:33:44 +00:00
Matt Corallo
99953ed8ff Update full_stack_target demo input to match new, fewer, fee gets 2021-07-09 00:50:30 +00:00
Matt Corallo
c620944f16 Make the base fee configurable in ChannelConfig
Currently the base fee we apply is always the expected cost to
claim an HTLC on-chain in case of closure. This results in
significantly higher than market rate fees [1], and doesn't really
match the actual forwarding trust model anyway - as long as
channel counterparties are honest, our HTLCs shouldn't end up
on-chain no matter what the HTLC sender/recipient do.

While some users may wish to use a feerate that implies they will
not lose funds even if they go to chain (assuming no flood-and-loot
style attacks), they should do so by calculating fees themselves;
since they're already charging well above market-rate,
over-estimating some won't have a large impact.

Worse, we current re-calculate fees at forward-time, not based on
the fee we set in the channel_update. This means that the fees
others expect to pay us (and which they calculate their route based
on), is not what we actually want to charge, and that any attempt
to forward through us is inherently race-y.

This commit adds a configuration knob to set the base fee
explicitly, defaulting to 1 sat, which appears to be market-rate
today.

[1] Note that due to an msat-vs-sat bug we currently actually
    charge 1000x *less* than the calculated cost.
2021-07-09 00:50:30 +00:00