Commit graph

3728 commits

Author SHA1 Message Date
Matt Corallo
625cda108c Construct all ChannelMonitor mutexes in the same function
When we add lockorder detection based on mutex construction site
rather than mutex instance in the next commit, ChannelMonitor's
PartialEq implementation causes spurious failures. This is caused
by the lockorder detection logic considering the ChannelMonitor
inner mutex to be two distinct mutexes - one when monitors are
deserialized and one when monitors are created fresh. Instead, we
attempt to tell the lockorder detection logic that they are the
same by ensuring they're constructed in the same place - in this
case a util method.
2022-07-20 22:08:59 +00:00
Matt Corallo
0627c0c88a Fix some test theoretical lock inversions
In the next commit we add lockorder testing based on the line each
mutex was created on rather than the particular mutex instance.
This causes some additional test failure because of lockorder
inversions for the same mutex across different tests, which is
fixed here.
2022-07-13 19:28:29 +00:00
Matt Corallo
2a3bf03f0c
Merge pull request #1552 from dunxen/2022-06-checkminrelayfee
Add min feerate checks
2022-07-13 16:49:16 +00:00
Duncan Dean
7bc6d0e606
Make all internal signatures accept LowerBoundedFeeEstimator 2022-07-13 15:00:51 +02:00
Duncan Dean
9c0c3b0c95
Add LowerBoundedFeeEstimator to set FeeEstimator min rates
`LowerBoundedFeeEstimator` is a wrapper for `Deref`s to `FeeEstimator`s
that limits the get_est_sat_per_1000_weight() method to no less than 253
sats/kW.
2022-07-13 15:00:50 +02:00
Matt Corallo
fda3819699
Merge pull request #1542 from ViktorTigerstrom/2022-06-prepare-maps-for-channels-per-peer
Preparations for storing channels per peer
2022-07-12 18:03:11 -07:00
Viktor Tigerström
fa7f170a73 Add ChannelManager:id_to_peer map coverage test 2022-07-12 17:47:08 +02:00
Viktor Tigerström
4058861730 Add id_to_peer map 2022-07-12 17:47:08 +02:00
Matt Corallo
5c06d1d9c8
Merge pull request #1603 from TheBlueMatt/2022-07-no-backwards-time
Avoid panicking on wallclock time going backwards across restart
2022-07-11 14:07:18 -07:00
Jeffrey Czyz
29e34c8a10
Merge pull request #1596 from jurvis/jurvis/give-chanmon-counterparty-id
Make ChannelMonitor aware of counterparty's node id
2022-07-11 13:51:55 -05:00
Matt Corallo
497fd65ae9 Avoid panicking on wallclock time going backwards across restart
Because we serialize `Instant`s using wallclock time in
`ProbabilisticScorer`, if time goes backwards across restarts we
may end up with `Instant`s in the future, which causes rustc prior
to 1.60 to panic when calculating durations. Here we simply avoid
this by setting the time to `now` if we get a time in the future.
2022-07-11 18:49:22 +00:00
jurvis
2d493364db
Add counterparty_node_id to ChannelMonitor 2022-07-09 12:47:29 -07:00
Jeffrey Czyz
c726b4e561
Merge pull request #1602 from TheBlueMatt/2022-07-109-rel-missing-force-close
Add missing note about renaming force-close methods in 109 changelog
2022-07-08 14:34:13 -05:00
Matt Corallo
ad2e92a3fb
Merge pull request #1592 from tnull/2022-07-manual-penalty
Allow to set manual node penalties
2022-07-08 12:29:25 -07:00
Matt Corallo
469adbd7df Add missing note about renaming force-close methods in 109 changelog 2022-07-08 14:15:46 +00:00
Jeffrey Czyz
4e5f74a6f3
Merge pull request #1567 from tnull/2022-06-send-probe
Add simple probing API
2022-07-07 09:27:14 -05:00
Viktor Tigerström
872c0378f7 Rename short_to_id map to short_to_chan_info
As the map values are no longer only `channel_id`s, but also a
`counterparty_node_id`s, the map is renamed to better correspond to
whats actually stored in the map.
2022-07-07 13:38:31 +02:00
Viktor Tigerström
908e898dcd Add counterparty_node_id to short_to_id map 2022-07-07 13:34:18 +02:00
Elias Rohrer
eb8bce0d16 Add send_probe and introduce probing cookies
When we send payment probes, we generate the [`PaymentHash`] based on a
probing cookie secret and a random [`PaymentId`]. This allows us to
discern probes from real payments, without keeping additional state.
2022-07-07 09:02:29 +02:00
Matt Corallo
e254912a20
Merge pull request #1599 from TheBlueMatt/2022-07-fuzz-warns
Drop unused imports in fuzzing test cases
2022-07-06 12:26:14 -07:00
Matt Corallo
f58f2eb0fa Drop unused imports in fuzzing test cases 2022-07-06 16:18:30 +00:00
Elias Rohrer
790abc540d Refactor max_mpp_path_count to max_path_count
Using this field just for MPP doesn't make sense when it could
intuitively also be used to indicate single-path payments. We therefore
rename `max_mpp_path_count` to `max_path_count` and make sure that a
value of 1 ensures MPP is not even tried.
2022-07-06 08:06:35 +02:00
Matt Corallo
e403999ffd
Merge pull request #1588 from TheBlueMatt/2022-06-ffs-dumb-ser
Do not execute the default_value expr until we need it in TLV deser
2022-07-05 13:46:43 -07:00
Matt Corallo
f1b9bd34b8 Do not execute the default_value expr until we need it in TLV deser
This fixes an insta-panic in `ChannelMonitor` deserialization where
we always `unwrap` a previous value to determine the default value
of a later field. However, because we always ran the `unwrap`
before the previous field is read, we'd always panic.

The fix is rather simple - use a `OptionDeserWrapper` for
`default_value` fields and only fill in the default value if no
value was read while walking the TLV stream.

The only complexity comes from our desire to support
`read_tlv_field` calls that use an explicit field rather than an
`Option` of some sort, which requires some statement which can
assign both an `OptionDeserWrapper<T>` variable and a `T` variable.
We settle on `x = t.into()` and implement `From<T> for
OptionDeserWrapper<T>` which works, though it requires users to
specify types explicitly due to Rust determining expression types
prior to macro execution, completely guessing with no knowlege for
integer expressions (see
https://github.com/rust-lang/rust/issues/91369).
2022-07-05 17:32:21 +00:00
Matt Corallo
a3f181af2d
Merge pull request #1586 from TheBlueMatt/2022-06-0.0.109
Fix date on 0.0.109 release notes
2022-07-05 10:30:26 -07:00
Matt Corallo
dcc445fa85
Merge pull request #1589 from TheBlueMatt/2022-07-sec-policy
Add security policy with PGP keys
2022-07-05 10:30:17 -07:00
Elias Rohrer
1ddc6f1089 Allow to set manual node penalties
A user might want to explicitly penalize or prioritize a particular
node. We now allow them to do so by specifying a manual penalty
override for a given node that is then returned by the scorer.
2022-07-05 16:39:53 +02:00
Matt Corallo
92919c8f37 Add security policy with PGP keys
Closes #1246.
2022-07-05 14:25:51 +00:00
Matt Corallo
daeb5a6291
Merge pull request #1553 from wvanlint/dns_hostname
Adds DNS hostname to NetAddress
2022-07-05 07:24:17 -07:00
Willem Van Lint
c30dcf183c Adds DNS hostname to NetAddress 2022-07-04 10:19:16 -07:00
Matt Corallo
d246e61379 [fuzz] Update auto-generated target list 2022-07-01 20:55:26 +00:00
Matt Corallo
c9a52d6ecf [fuzz] Add a ChannelDetails msg target 2022-07-01 20:55:26 +00:00
Matt Corallo
cee1feb165 [fuzz] Take a full struct path in msg gen_target.sh 2022-07-01 20:55:26 +00:00
Matt Corallo
321f1d4896 Fix date on 0.0.109 release notes
We slipped by a day and the PR didn't get updated. NBD, though,
the git tag has the correct date.
2022-07-01 17:40:44 +00:00
Matt Corallo
f3d5b945c3
Merge pull request #1582 from TheBlueMatt/2022-06-0.0.109
Cut 0.0.109
2022-07-01 10:37:17 -07:00
Matt Corallo
156cc77753 Bump crate versions to 0.0.109/invoice 0.17 2022-07-01 16:05:33 +00:00
Matt Corallo
261d6fe1ec Update contributor list for 0.0.107 to be consistent with 0.0.109 2022-07-01 16:05:33 +00:00
Matt Corallo
39cba073eb Add 0.0.109 CHANGELOG entry. 2022-07-01 16:05:33 +00:00
Matt Corallo
d9ba7ce8bf
Merge pull request #1585 from TheBlueMatt/2022-06-copy_from_slice-sucks
Fix spurious panic on bogus funding txn that confirm and are spent
2022-07-01 09:05:02 -07:00
Matt Corallo
6c480ae887 Fix spurious panic on bogus funding txn that confirm and are spent
In c02b6a3807 we moved the
`payment_preimage` copy from inside the macro which only runs if we
are spending an output we know is an HTLC output to doing it for
any script that matches our expected length. This can panic if an
inbound channel is created with a bogus funding transaction that
has a witness program of the HTLC-Success/-Offered length but which
does not have a second-to-last witness element which is 32 bytes.

Luckily this panic is relatively simple for downstream users to
work around - if an invalid-length-copy panic occurs, simply remove
the ChannelMonitor from the bogus channel on startup and run
without it. Because the channel must be funded by a bogus script in
order to reach this panic, the channel will already have closed by
the time the funding transaction is spent, and there can be no
local funds in such a channel, so removing the `ChannelMonitor`
wholesale is completely safe.

In order to test this we have to disable an in-line assertion that
checks that our transactions match expected scripts which we do by
checking for the specific bogus script that we now use in
`test_invalid_funding_tx`.

Thanks to Eugene Siegel for reporting this issue.
2022-07-01 14:47:17 +00:00
Matt Corallo
8a97e58933
Merge pull request #1583 from TheBlueMatt/2022-06-no-ro-graph
Have `find_route` take a `NetworkGraph` instead of a `ReadOnly` one
2022-06-29 12:57:51 -07:00
Matt Corallo
87a6e013f7 Have find_route take a NetworkGraph instead of a ReadOnly one
Because downstream languages are often garbage-collected, having
the user directly allocate a `ReadOnlyNetworkGraph` and pass a
reference to it to `find_route` often results in holding a read
lock long in excess of the `find_route` call. Worse, some languages
(like JavaScript) tend to only garbage collect when other code is
not running, possibly leading to deadlocks.
2022-06-29 17:45:49 +00:00
Matt Corallo
a600eee87c
Merge pull request #1564 from TheBlueMatt/2022-06-panic-on-behind
Panic if we're running with outdated state instead of force-closing
2022-06-27 09:34:26 -07:00
valentinewallace
92ca7ff129
Merge pull request #1555 from tnull/2022-06-prefer-small-htlc-max
Add anti-probing penalty to `ProbabilisticScorer`
2022-06-27 11:37:05 -04:00
Elias Rohrer
800ccec0ed Add anti-probing penalty to ProbabilisticScorer
Currently, channel balances may be rather easily discovered through
probing. This however poses a privacy risk, since the analysis of
balance changes over adjacent channels could in the worst case empower an adversary to
mount an end-to-end deanonymization attack, i.e., track who payed whom.

The penalty added here is applied so we prefer nodes with a smaller `htlc_maximum_msat`, which makes
balance discovery attacks harder to execute. As this improves privacy network-wide, we
treat such nodes preferentially and hence create an incentive to restrict
`htlc_maximum_msat`.
2022-06-25 20:06:04 +02:00
Matt Corallo
caa2a9a55b Panic if we're running with outdated state instead of force-closing
When we receive a `channel_reestablish` with a `data_loss_protect`
that proves we're running with a stale state, instead of
force-closing the channel, we immediately panic. This lines up with
our refusal to run if we find a `ChannelMonitor` which is stale
compared to our `ChannelManager` during `ChannelManager`
deserialization. Ultimately both are an indication of the same
thing - that the API requirements on `chain::Watch` were violated.

In the "running with outdated state but ChannelMonitor(s) and
ChannelManager lined up" case specifically its likely we're running
off of an old backup, in which case connecting to peers with
channels still live is explicitly dangerous. That said, because
this could be an operator error that is correctable, panicing
instead of force-closing may allow for normal operation again in
the future (cc #1207).

In any case, we provide instructions in the panic message for how
to force-close channels prior to peer connection, as well as a note
on how to broadcast the latest state if users are willing to take
the risk.

Note that this is still somewhat unsafe until we resolve #1563.
2022-06-25 02:25:32 +00:00
Matt Corallo
5ed3f25b21 Add ChannelManager methods to force close without broadcasting
If a user restores from a backup that they know is stale, they'd
like to force-close all of their channels (or at least the ones
they know are stale) *without* broadcasting the latest state,
asking their peers to do so instead. This simply adds methods to do
so, renaming the existing `force_close_channel` and
`force_close_all_channels` methods to disambiguate further.
2022-06-25 02:25:32 +00:00
Matt Corallo
79e2af9497
Merge pull request #1550 from tnull/2022-06-scorer-banlist
Allow nodes to be avoided during pathfinding
2022-06-24 08:39:12 -07:00
Elias Rohrer
57d8257a0b Allow nodes to be avoided during pathfinding
Users may want to - for whatever reasons - prevent payments to be routed
over certain nodes. This change therefore allows to add `NodeId`s to a
list of banned nodes, which then will be avoided during path finding.
2022-06-24 08:31:41 +02:00
Matt Corallo
3676a056c8
Merge pull request #1518 from valentinewallace/2022-06-OMs-prefactor
Onion messages v1 pre-refactor
2022-06-21 16:13:37 -07:00