Commit graph

2908 commits

Author SHA1 Message Date
Matt Corallo
cae2123793 Expand ANTI_REORG_DELAY docs to say its a library-wide assumption 2021-09-15 18:07:34 +00:00
Matt Corallo
a675886e10 Add an accessor to ChainMonitor to get the claimable balances
The common user desire is to get the set of claimable balances for
all non-closed channels. In order to do so, they really want to
just ask their `ChainMonitor` for the set of balances, which they
can do here by passing the `ChannelManager::list_channels` output
to `ChainMonitor::get_claimable_balances`.
2021-09-15 18:07:34 +00:00
Matt Corallo
00906418aa Expose the amount of funds available for claim in ChannelMonitor
In general, we should always allow users to query for how much is
currently in-flight being claimed on-chain at any time.

This does so by examining the confirmed claims on-chain and
breaking down what is left to be claimed into a new
`ClaimableBalance` enum.

Fixes #995.
2021-09-15 18:07:34 +00:00
Matt Corallo
f9febb0351 Fix indentation in ChannelMonitor 2021-09-15 18:07:34 +00:00
Matt Corallo
c02b6a3807 Track how our HTLCs are resolved on-chain persistently
This tracks how any HTLC outputs in broadcast commitment
transactions are resolved on-chain, storing the result of the HTLC
resolution persistently in the ChannelMonitor.

This can be used to determine which outputs may still be available
for claiming on-chain.
2021-09-15 18:07:34 +00:00
Matt Corallo
73ee30d9da Track the tx which spends our funding output in ChannelMonitor
This allows us to easily look up how our channel was closed and
track which balances may be spendable on-chain.
2021-09-15 18:07:34 +00:00
Matt Corallo
cd578b55f3 Rename CounterpartyCommitmentTransaction to Params as it is static 2021-09-15 18:07:34 +00:00
Matt Corallo
44e48679fb Drop unused CounterpartyCommitmentTransaction::per_htlc HashMap 2021-09-15 18:07:34 +00:00
Matt Corallo
aaba0a2ec9 Store to-self value in the current commitment tx in ChannelMonitor 2021-09-15 18:07:34 +00:00
Jeffrey Czyz
992df51001
Update NetworkGraph in BackgroundProcessor
Decorate the user-supplied EventHandler with NetGraphMsgHandler in
the BackgroundProcessor. The resulting handler will intercept
PaymentFailed events in order to update the NetworkGraph in the
background before delegating to the user's event handler.
2021-09-15 11:53:13 -05:00
Jeffrey Czyz
e2f088c371
Expand and format BackgroundProcessor docs 2021-09-15 11:53:12 -05:00
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
Tibo-lg
2c6a078d2c Add node id to custom message callback 2021-09-15 09:29:29 +09:00
Matt Corallo
3f9efe717b Move CounterpartyForwardingInfo from channel to channelmanager
CounterpartyForwardingInfo is public (previously exposed with a
`pub use`), and used inside of ChannelCounterparty in
channelmanager.rs. However, it is defined in channel.rs, away from
where it is used.

This would be fine, except that the bindings generator is somewhat
confused by this - it doesn't currently support interpreting
`pub use` as a struct to expose, instead ignoring it.

Fixes https://github.com/lightningdevkit/ldk-garbagecollected/issues/44
2021-09-13 17:31:59 +00:00
Matt Corallo
de9fba82f2
Merge pull request #1072 from TheBlueMatt/2021-09-tighter-max_fee-constant
Reduce our stated max closing-transaction fee to be the true value
2021-09-13 16:42:36 +00:00
Matt Corallo
ce3a04ba1a
Merge pull request #1073 from gilescope/less-deps 2021-09-13 04:22:26 +00:00
Giles Cope
b74ab25b61
Not needed now. We refer to std::futures. 2021-09-11 20:11:10 +01: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
b348d9cb60 Reduce our stated max closing-transaction fee to be the true value
When communicating the maximum fee we're willing to accept on a
cooperative closing transaction to our peer, we currently tell them
we'll accept `u64::max_value()` if they're the ones who have to pay
it. Spec-wise this is fine - they aren't allowed to try to claim
our balance, and we don't care how much of their own funds they
want to spend on transaction fees.

However, the Eclair folks prefer to check all values on the wire
do not exceed 21 million BTC, which seems like generally good
practice to avoid overflows and such issues. Thus, our close
messages are rejected by Eclair.

Here we simply relax our stated maximum to be the real value - our
counterparty's current balance in satoshis.

Fixes #1071
2021-09-10 00:24:58 +00: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
6879348530 Require payment secrets when building and reading invoices 2021-08-31 21:29:51 +00:00
Matt Corallo
a906c498fb Use new BOLT 11 test vectors with payment_secrets and feature flags
This pulls the BOLT 11 test vectors from
https://github.com/lightningnetwork/lightning-rfc/pull/898,
tweaking our tests to properly handle them.
2021-08-31 21:29:51 +00:00
Matt Corallo
c7cf5011be [invoice] Ignore InvalidLength fields
BOLT 11 states that a reader "MUST skip over...`p`, `h`, `s` or `n`
fields that do NOT have data_lengths of 52, 52, 52 or 53,
respectively." Here we do so by simply ignoring any invalid-length
field.
2021-08-31 21:29:51 +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
0be428eeda Convert the invoice creation API to millisats and req it for parse
The BOLT 11 invalid invoice test vectors suggest failing to parse
invoices which have an amount which is not a whole number of
millisatoshis. lightning-invoice, however, happily parses such
invoices. While we could continue to parse them, failing them makes
for one less check on the user code side, so we might as well.

In order to keep the invoice creation less likely to fail, we also
switch the Builder amount-setting function to use millisatoshis.
2021-08-31 21:29:51 +00:00
Matt Corallo
181cb1103d [invoice] Fix non-recoverable sig handling and bogus SI prefix err
This adds two additional tests from the BOLT 11 invalid invoice
tests, fixing the two errors that broke them. It fixes a panic on
the "nonrecoverable signature" test and makes the error variant
more sensible on the bogus SI prefix test.
2021-08-31 21:29:51 +00:00
Matt Corallo
a80819c9c2 [invoice] Add the BOLT 11 failure unit tests that we already pass 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
Matt Corallo
731773cad2
Merge pull request #1039 from lightning-signer/2021-08-more-enforcement
Introduce EnforcementState, validate release of revocation secret
2021-08-30 02:43:01 +00:00
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