Commit graph

1184 commits

Author SHA1 Message Date
Jeffrey Czyz
ba2c00b3f8
EventHandler for applying NetworkUpdate
PaymentFailed events contain an optional NetworkUpdate describing
changes to the NetworkGraph as conveyed by a node along a failed payment
path according to BOLT 4. An EventHandler should apply the update to the
graph so that future routing decisions can account for it.

Implement EventHandler for NetGraphMsgHandler to update NetworkGraph.
Previously, NetGraphMsgHandler::handle_htlc_fail_channel_update
implemented this behavior.
2021-09-15 11:50:31 -05:00
Jeffrey Czyz
eff9a47075
Refactor PaymentFailureNetworkUpdate event
MessageSendEvent::PaymentFailureNetworkUpdate served as a hack to pass
an HTLCFailChannelUpdate from ChannelManager to NetGraphMsgHandler via
PeerManager. Instead, remove the event entirely and move the contained
data (renamed NetworkUpdate) to Event::PaymentFailed to be processed by
an event handler.
2021-09-15 11:50:27 -05:00
Jeffrey Czyz
bd3ee0ab3d
Fail with PERM|8 (permanent_channel_failure)
This affects the htlc_fail_async_shutdown test.
2021-09-09 23:11:12 -05:00
Jeffrey Czyz
a6749d582d
Remove test_invalid_channel_announcement
It doesn't seem to be testing anything useful that isn't covered
elsewhere.
2021-09-09 23:11:12 -05:00
Jeffrey Czyz
798cf6ea83
Add a read-only view of NetworkGraph
Hide the internal locking of NetworkGraph by providing a read-only
view. This way the locking order is handled internally.
2021-09-09 23:11:12 -05:00
Jeffrey Czyz
16ad7f17a1
Remove RwLock from around NetworkGraph
Now that NetworkGraph uses interior mutability, the RwLock used around
it in NetGraphMsgHandler is no longer needed. This allows for shared
ownership without a lock.
2021-09-09 23:11:09 -05:00
Jeffrey Czyz
777661ae52
Individually lock NetworkGraph fields
In preparation for giving NetworkGraph shared ownership, wrap individual
fields in RwLock. This allows removing the outer RwLock used in
NetGraphMsgHandler.
2021-09-09 23:01:28 -05:00
Jeffrey Czyz
a6e650630d
Pass Event by reference to EventHandler
Passing an Event by reference rather and by move gives more flexibility
for composing event handlers without needing to clone events.
2021-09-09 22:57:51 -05:00
Matt Corallo
423f1b1803
Merge pull request #1064 from lightning-signer/2021-08-closing-tx-phase2 2021-09-09 19:31:47 +00:00
Devrandom
eebc0a921e Use ClosingTransaction in BaseSign 2021-09-09 20:49:24 +02:00
Devrandom
54907a0f4a Introduce ClosingTransaction 2021-09-09 20:49:24 +02:00
Matt Corallo
b3be420cfb
Merge pull request #1047 from TheBlueMatt/2021-08-985-followups 2021-09-09 09:23:08 +00:00
Matt Corallo
623da4da7a Add further comments around fee update handling in channel
These were suggested to clarify behavior in post-merge review of #985.
2021-09-09 08:37:59 +00:00
Matt Corallo
fc35aa745a Update docs for pending_update_fee and holding_cell_update_fee
The docs were left stale after the logic was updated in #985 as
pointed out in post-merge review.
2021-09-09 08:37:59 +00:00
Devrandom
3dd99ebda6 Factor out low-level build_closing_transaction 2021-09-03 13:57:21 +02:00
Matt Corallo
4c4d99b291
Merge pull request #1055 from lightning-signer/2021-08-anchor-tx 2021-09-02 21:54:11 +00:00
Devrandom
8275698f3a Add anchor outputs pair in CommitmentTransaction
The anchor ouputs pair is added if there are pending HTLCs. Or a
a per-party anchor is added if the party has a pending balance.
2021-09-02 09:13:46 +02:00
Matt Corallo
6bd1af4f9f
Merge pull request #1057 from TheBlueMatt/2021-08-invoice-fails
Fix and modernize lightning-invoice API
2021-08-31 22:11:22 +00:00
Matt Corallo
75f7af64f3 Implement core:#️⃣:Hash more incl invoice::RawTaggedField 2021-08-31 21:29:51 +00:00
Matt Corallo
a4a54ed9df Check if invoices contain unknown required features
This adds the final missing BOLT 11 failure test, checking for
unknown required feature flags before accepting an invoice.
2021-08-31 21:29:51 +00:00
Matt Corallo
a265f1e97a
Merge pull request #1040 from abhik-99/Issue#945
Multi-Hop Route Hint now considered. Added in unit tests for same.
2021-08-31 17:50:14 +00:00
abhik-99
fd4d3bf3b7 Multi-Hop Route Hint as per Bolt 12 now considered
Bolt 12 details the process of picking up route hints from payee
using the lightning invoice. This PR brings the changes to use
multiple route hints from payee picked from the invoice.

The route hints are processed in the following manner:-
 - `get_route()` receives the hints in `last_hops`.
 - Every `RouteHintHop` in `RouteHint` is processed based on
   feasiblity of channel capacity and fees.
 - If a `RouteHintHop` then preceeding `RouteHintHop`s are not
   processed.
 - A direct route is checked from `first_hops_targets` to the
   first `RouteHintHop` if the respective `RouteHint` is
   processed from the payee's end till the first `RouteHintHop`.

`partial_route_hint_test`, `ignores_empty_last_hops_test`,
`multi_hint_last_hops_test` and `last_hops_with_public_channel_test`
test usage of partial route hints for building optimal route,
processing empty route hint hops, complete usage of private route
hints and presence of public channels in route hints respectively.

Resolves: #945
2021-08-31 11:08:06 +05:30
Antoine Riard
97c29cfd34 Add get_anchor_script
This is a script builder to generate anchor output ones. They can be
satisfied either by a signature for the committed funding pubkey or anyone
after CSV delay expiration.

This is used at anchor output addition while generating commitment transaction.
2021-08-28 11:09:42 +02:00
Devrandom
608ed12a5b Allow BaseSign validation functions to return an Err 2021-08-28 11:04:20 +02:00
Devrandom
a016bb1408 Improve documentation for validate_holder_commitment and sign_counterparty_commitment 2021-08-28 11:01:15 +02:00
Devrandom
181d319630 Always use KeysInterface.read_chan_signer for de-serializing EnforcingSigner in tests 2021-08-28 11:01:15 +02:00
Devrandom
285b3faf77 Enforce signing counterparty commitment only after revocation 2021-08-28 11:01:15 +02:00
Devrandom
241e448d37 Enforce that revocation can only occur after we validated a new commitment 2021-08-28 11:01:15 +02:00
Devrandom
50966e25ba Introduce EnforcementState for EnforcingSigner
as we add more enforcement state variables, we want to keep track of them under a single structure
2021-08-28 11:01:15 +02:00
Matt Corallo
4368b56eb6
Merge pull request #1060 from JosephGoulden/function_test_utils_logs
tests: use origin node logger instead of creating new TestLogger
2021-08-27 02:37:00 +00:00
Matt Corallo
45853b3a95
Merge pull request #1031 from p2pderivatives/dlc-version-generic
Dlc version generic
2021-08-25 17:22:20 +00:00
Jeffrey Czyz
eb46f477f4 Remove wire::MessageType in favor of u16
With custom messages, wire::Type was introduced. wire::MessageType is a
bit redundant, so use u16 instead and move is_even to wire::Message.
2021-08-25 13:22:09 +09:00
Tibo-lg
2e5e40e0b2 Add custom message handler to peer manager 2021-08-25 13:22:09 +09:00
Joseph Goulden
02c95eefd4 tests: use origin node logger instead of creating new TestLogger in functional_test_utils 2021-08-24 16:53:29 +01:00
Matt Corallo
cb7faf8951 Fix trailing semicolon warnings on latest rustc nightly
Latest rustc nightly compiles are filled with warnings like the
following, which we fix here:

```
warning: trailing semicolon in macro used in expression position
   --> lightning/src/util/macro_logger.rs:163:114
    |
163 |         $logger.log(&$crate::util::logger::Record::new($lvl, format_args!($($arg)+), module_path!(), file!(), line!()));
    |                                                                                                                        ^
    |
   ::: lightning/src/chain/chainmonitor.rs:165:9
    |
165 |         log_debug!(self.logger, "New best block {} at height {} provided via block_connected", header.block_hash(), height);
    |         -------------------------------------------------------------------------------------------------------------------- in this macro invocation
    |
    = note: `#[warn(semicolon_in_expressions_from_macros)]` on by default
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #79813 <https://github.com/rust-lang/rust/issues/79813>
    = note: this warning originates in the macro `log_internal` (in Nightly builds, run with -Z macro-backtrace for more info)
```
2021-08-18 00:34:13 +00:00
Matt Corallo
803d8041f1
Merge pull request #1048 from TheBlueMatt/2021-08-no-net-print
Remove explicit print in lightning-net-tokio, reduce redundant block connection logging
2021-08-18 00:31:28 +00:00
Matt Corallo
35d0b7aae7 Clarify docs on ShutdownScript::new_witness_program somewhat
This is especially important for C or other language bindings
clients as the `version` field may be exported as a `u8`.
2021-08-17 21:12:06 +00:00
Matt Corallo
1e7d4798eb Log chain calls in ChainMonitor, reducing logs in ChannelMonitor
For users with many ChannelMonitors, we log a large volume per
block simply because each ChannelMonitor lots several times per
block. Instead, we move to log only once at the TRACE level per
block call in ChannelMonitors, relying instead on a DEBUG level
log in ChainMonitor before we call any ChannelMonitor functions.

For most users, this will reduce redundant logging and also log at
the DEBUG level for block events, which is appropriate.

Fixes #980.
2021-08-17 21:03:14 +00:00
Matt Corallo
2e02aa7dab Ensure we always at least log at TRACE when a peer disconnects 2021-08-17 21:03:14 +00:00
Matt Corallo
11f78798d3 Update versions to 0.0.100 and lightning-invoice to 0.8 2021-08-17 18:55:07 +00:00
Matt Corallo
6f16453275
Merge pull request #1011 from TheBlueMatt/2021-07-new-closing-fee
Clean up existing and add range-based closing_signed negotiation
2021-08-17 17:53:21 +00:00
Matt Corallo
82e7df1c0b Add relatively simple tests of the legacy and target closing fee
This doesn't exhaustively test closing fee negotiation at all, but
ensures that it is at least basically able to come to consensus and
sign cooperative closing transactions.
2021-08-17 02:16:01 +00:00
Matt Corallo
0b481e91d5 Slightly clarify the closing_signed error msg on fee mismatch 2021-08-17 02:16:01 +00:00
Matt Corallo
dcb0832b76 Add a test for shutdown negotiaion funder restart and timeout 2021-08-17 02:16:01 +00:00
Matt Corallo
d63b024eff Force-close if finish closing_signed negotiation takes a full minute 2021-08-17 02:16:01 +00:00
Matt Corallo
5712de2da0 Move shutdown-related tests into a new module
Because ln::functional_tests if over 9000 LoC long, its useful to
move tests into new modules as we can. Here we move all
cooperative shutdown related tests into a new module entitled
`shutdown_tests`
2021-08-17 02:16:01 +00:00
Matt Corallo
177810b152 Clean up existing and add range-based closing_signed negotiation
This adds the new range-based closing_signed negotiation specified
in https://github.com/lightningnetwork/lightning-rfc/pull/847 as
well as cleans up the existing closing_signed negotiation to unify
the new codepaths and the old ones.

Note that because the new range-based closing_signed negotiation
allows the channel fundee to ultimately select the fee out of a
range specified by the funder, which we, of course, always select
the highest allowed amount from. Thus, we've added an extra round
of closing_signed in the common case as we will not simply accept
the first fee we see, always preferring to make the funder pay as
much as they're willing to.
2021-08-17 02:16:01 +00:00
Matt Corallo
67ddd46aed Send initial closing_signed message asynchronously and handle errs
When we added the support for external signing, many of the
signing functions were allowed to return an error, closing the
channel in such a case. `sign_closing_transaction` is one such
function which can now return an error, except instead of handling
it properly we'd simply never send a `closing_signed` message,
hanging the channel until users intervene and force-close it.

Piping the channel-closing error back through the various callsites
(several of which already have pending results by the time they
call `maybe_propose_first_closing_signed`) may be rather
complicated, so instead we simply attempt to propose the initial
`closing_signed` in `get_and_clear_pending_msg_events` like we do
for holding-cell freeing.

Further, since we now (possibly) generate a `ChannelMonitorUpdate`
on `shutdown`, we may need to wait for monitor updating to complete
before we can send a `closing_signed`, meaning we need to handle
the send asynchronously anyway.

This simplifies a few function interfaces and has no impact on
behavior, aside from a few message-ordering edge-cases, as seen in
the two small test changes required.
2021-08-17 02:16:01 +00:00
Matt Corallo
ee43975bf8 Migrate OnchainEvent serialization to be MaybeReadable.
This adds a new TLV-based enum serialization macro entitled
`impl_writeable_tlv_based_enum_upgradable`. As the name implies,
the new macro allows us to ignore odd-numbered variant entries.
Because the new macro implements only `MaybeReadable` and not
`Readable`, it is not applicable in many contexts, here only being
added for the two `OnchainEvent` structs.
2021-08-16 17:35:35 +00:00
Matt Corallo
45490d537e Implement VecReadWrapper for MaybeReadable
This makes it much simpler to deal with `MaybeReadable` types in
`Vec`s in TLVs as we can transparently deal with them as `vec`,
with the wrapper doing the Right Thing.

This requires we implement `MaybeReadable` for all `Readable` which
has some downstream implications, but nothing too bad.
2021-08-16 17:35:35 +00:00