Commit graph

1333 commits

Author SHA1 Message Date
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
3f229052ea Bump dependencies to bitcoin 0.27 and bech32 0.8 2021-07-31 18:29:07 +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
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
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
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
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
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
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
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
Matt Corallo
dac8b7b399 Update ChannelConfig serialization to be TLV-based
This was missed prior to 0.0.98, so requires a
backwards-compatibility wrapper inside the `Channel` serialization
logic, but it's not very complicated to do so.
2021-07-09 00:50:30 +00:00
Matt Corallo
12253e5331
Merge pull request #988 from TheBlueMatt/2021-07-chan-details-usability
Improve ChannelDetails readability significantly.
2021-07-08 17:25:53 +00:00
Matt Corallo
2b08a47e88 Improve ChannelDetails readability significantly.
After the merge of #984, Jeff pointed out that `ChannelDetails` has
become a bit of a "bag of variables", and that a few of the variable
names in #984 were more confusing than necessary in context.

This addresses several issues by:
 * Splitting counterparty parameters into a separate
   `ChannelCounterpartyParameters` struct,
 * using the name `unspendable_punishment_reserve` for both outbound
   and inbound channel reserves, differentiating them based on their
   position in the counterparty parameters struct or not,
 * Using the name `force_close_spend_delay` instead of
   `spend_csv_on_our_commitment_funds` to better communicate what
   is occurring.
2021-07-08 16:46:57 +00:00
Matt Corallo
96a738aa53
Merge pull request #961 from TheBlueMatt/2021-06-workaround-broken-cln
Use the query start block for ReplyChannelRange response messages
2021-07-08 14:51:47 +00:00
Matt Corallo
42f6a8f111 Use the query start block for ReplyChannelRange response messages
C-Lightning versions prior to 0.10 (incorrectly) enforce that the
reply_channel_range first_blocknum field is set to at least the
value they sent in their query_channel_range message. Sending a 0
results in them responding with an Error message, closing open
channels spuriously.

Further, C-Lightning versions prior to 0.10 require that the
reply_channel_range first_blocknum is either the same block implied
as the last block of the previous reply_channel_range or one
greater. This is not only a creative interpretation of the spec,
but a perfectly reasonable implementation might still receive an
Error message in the case of replies split by an empty block.

This code is extracted and modified from a previous version of
the original query_channel_range PR in commit
44ba52ccf1. The original commit is by
`bmancini55 <bmancini@gmail.com>`.
2021-07-08 14:05:32 +00:00
Matt Corallo
99938455f7
Merge pull request #949 from TheBlueMatt/2021-06-send-priv-update
Send channel_update messages to direct peers on private channels
2021-07-07 20:17:10 +00:00
Matt Corallo
ba600db793 Ignore our own gossip if it is sent to us from our counterparty
If our channel party sends us our own channel_update message, we'll
erroneously use the information in that message to update our view
of the forwarding parameters our counterparty requires of us,
ultimately generating invoices with bogus forwarding information.

This fixes that behavior by checking the channel_update's
directionality before handling it.
2021-07-07 19:45:33 +00:00
Matt Corallo
11594c37a1 Fix spelling in ChannelManager comment 2021-07-07 19:45:33 +00:00
Matt Corallo
e3968e0993 Send channel_update messages to direct peers on private channels
If we are a public node and have a private channel, our
counterparty needs to know the fees which we will charge to forward
payments to them. Without sending them a channel_update, they have
no way to learn that information, resulting in the channel being
effectively useless for outbound-from-us payments.

This commit fixes our lack of channel_update messages to private
channel counterparties, ensuring we always send them a
channel_update after the channel funding is confirmed.
2021-07-07 19:45:33 +00:00
Matt Corallo
431f807907
Merge pull request #984 from TheBlueMatt/2021-06-more-chan-data
Expose More Information about Channels and structs
2021-07-06 00:53:12 +00:00
Matt Corallo
46c3ba4968 Tweak documentation in BestBlock to be a bit more clear 2021-07-06 00:18:27 +00:00