Commit graph

659 commits

Author SHA1 Message Date
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
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
46c3ba4968 Tweak documentation in BestBlock to be a bit more clear 2021-07-06 00:18:27 +00:00
Matt Corallo
da298e498f Expose the current best chain tip from ChannelManager + Monitors
Fixes #979
2021-07-06 00:18:27 +00:00
Matt Corallo
412cc9f01a Clean up get_broadcasted_holder_claims confirmation height param use 2021-07-02 17:16:12 +00:00
Matt Corallo
1905570358 Clarify when height is the *current* vs a *confirmation* height 2021-07-02 17:16:12 +00:00
Matt Corallo
496eb4526b Create SpendableOutputs events no matter the chain::Confirm order
We had a user who pointed out that we weren't creating
`SpendableOutputs` events when we should have been after they
called `ChannelMonitor::best_block_updated` with a block well
after a CSV locktime and then called
`ChannelMonitor::transactions_confirmed` with the transaction which
we should have been spending (with a block height/hash a ways in
the past).

This was due to `ChannelMonitor::transactions_confirmed` only
calling `ChannelMonitor::block_confirmed` with the height at which
the transactions were confirmed, resulting in all checks being done
against that, not the current height.

Further, in the same scenario, we also would not fail-back and HTLC
where the HTLC-Timeout transaction was confirmed more than
ANTI_REORG_DELAY blocks ago.

To address this, we use the best block height for confirmation
threshold checks in `ChannelMonitor::block_confirmed` and pass both
the confirmation and current heights through to
`OnchainTx::update_claims_view`, using each as appropriate.

Fixes #962.
2021-07-02 17:16:12 +00:00
Matt Corallo
599c74cd42 Update ChannelMonitor::best_block before calling block_confirmed
No matter the context, if we're told about a block which is
guaranteed by our API semantics to be on the best chain, and it has
a higher height than our current understanding of the best chain,
we should update our understanding. This avoids complexity
in `block_confirmed` by never having a height set which is *higher*
than our current best chain, potentially avoiding some bugs in the
rather-complicated code.

It also requires a minor test tweak as we in some cases now no
longer broadcast a conflicting transaction after the original has
reached the ANTI_REORG_DELAY.
2021-07-02 17:16:12 +00:00
Matt Corallo
697033342e Avoid calling OnchainTx::block_disconnected if no block was discon'd
There are no visible effects of this, but it seems like good code
hygiene to not call a disconnect function in a different file if no
disconnect happened.
2021-07-02 17:16:12 +00:00
Matt Corallo
f4729075cb
Merge pull request #965 from TheBlueMatt/2021-06-log-cleanups
Cleanup logging
2021-06-29 20:13:50 +00:00
Matt Corallo
6d98aedaf5 Add debug log when we stop tracking confirmed on-chain packages 2021-06-29 19:36:47 +00:00
Matt Corallo
74717d390c Increase the log level of several channelmonitor/onchain logs.
ChannelMonitor and related log entries can generally lean towards
being higher log levels than they necessarily need to be, as they
should be exceedingly rare, if only because they require
confirmation of an on-chain transaction.
2021-06-29 19:36:47 +00:00
Valentine Wallace
40959b74b7
Fix TLV serialization to work with large types.
Previous to this PR, TLV serialization involved iterating from 0 to the highest
given TLV type. This worked until we decided to implement keysend, which has a
TLV type of ~5.48 billion.

So instead, we now specify the type of whatever is being (de)serialized (which
can be an Option, a Vec type, or a non-Option (specified in the serialization macros as "required").
2021-06-24 16:25:31 -04:00
Gene Ferneau
da7a851d47
Use hashbrown replacements for std equivalents 2021-06-18 21:54:21 +00:00
Matt Corallo
1d4f9c8dec
Merge pull request #936 from TheBlueMatt/2021-05-spendable-event-locktime-delay
Delay DelayedPaymentOutput spendable events until the CSV delay
2021-06-08 01:53:03 +00:00
Matt Corallo
ed6a69c1cf Add additional derives for a few structs 2021-06-02 16:21:00 +00:00
Matt Corallo
e60ccbb1a8 Delay DelayedPaymentOutput spendable events until the CSV delay 2021-06-01 22:32:56 +00:00
Matt Corallo
c56265d225 Convert SpendableOutputDescriptor to new TLV-based serialization 2021-06-01 21:53:06 +00:00
Matt Corallo
3c93967cd2 Clean up ChannelMonitor object serialization to use TLVs/versions 2021-06-01 21:53:06 +00:00
Matt Corallo
86641ea680 Convert most chain::* inner structs and enums to TLV-based ser macros 2021-06-01 21:53:06 +00:00
Matt Corallo
0e41bba506 Give OnchainEvent::HTLCUpdate individual fields instead of a pair 2021-06-01 16:11:53 +00:00
Matt Corallo
f61676ea15 Dont broadcast HTLC-Timeouts when closing a channel until locktime 2021-05-28 23:58:07 +00:00
Matt Corallo
90e984e797 Track the blocks a node has connected in the TestBroadcaster 2021-05-28 23:56:44 +00:00
Matt Corallo
29a780e9e0 Delay broadcast of PackageTemplate packages until their locktime
This stores transaction templates temporarily until their locktime
is reached, avoiding broadcasting (or RBF bumping) transactions
prior to their locktime. For those broadcasting transactions
(potentially indirectly) via Bitcoin Core RPC, this ensures no
automated rebroadcast of transactions on the client side is
required to get transactions confirmed.
2021-05-28 23:56:44 +00:00
Matt Corallo
79ffc5eac9 Always pass height to OnchainTxHandler::update_claims_view
This simplifies logic somewhat and avoids duplicating the storage
of the current height in OnchainTxHandler.
2021-05-28 23:56:44 +00:00
Matt Corallo
9bd87e9c9d Expose the timelock of transaction packages 2021-05-28 23:56:44 +00:00
Matt Corallo
56491d91bb Simplify HolderHTLCOutput constructor and track CLTV expiry
This allows us to interrogate a PackageTemplate for the CLTV
timelock of the resulting transaction.
2021-05-28 23:56:44 +00:00
Matt Corallo
f492a192ff Add assertions to ensure we don't use an invalid package_amount
This somewhat cleans up the public API of PackageSolvingData to
make it harder to get an invalid amount and use it, adding further
debug assertion to check it at test-time.
2021-05-28 23:56:44 +00:00
Matt Corallo
df829a8526
Merge pull request #928 from TheBlueMatt/2021-05-really-tlv-ser
Migrate some inner structs to TLVs
2021-05-27 23:05:47 +00:00
Matt Corallo
45d86ead64 Migrate packages sub-fields to TLV serialization 2021-05-27 21:41:24 +00:00
Matt Corallo
a7494228c9 Add TLV suffix to PackageTemplate 2021-05-27 21:41:07 +00:00
Matt Corallo
557aa81619 Add dummy OutPoint constructor to be used when reading it in a TLV 2021-05-27 21:41:07 +00:00
Gene Ferneau
12461fcba1
Use alloc for no_std builds
Replace std structs with alloc equivalents to support no_std builds

f use prelude::* credit @devrandom
2021-05-27 17:35:20 +00:00
Antoine Riard
c40ebf18e5 Add package template unit tests 2021-05-25 23:18:56 -04:00
Antoine Riard
881c0f58e1 Move compute_output_value as part of package member functions 2021-05-25 19:59:40 -04:00
Antoine Riard
bb0e33f383 Move get_height_timer out of OnchainTxHandler 2021-05-25 19:59:40 -04:00
Antoine Riard
4363f965d6 Move onchain* to chain/ 2021-05-25 19:59:40 -04:00
Antoine Riard
5ccb07554b Integrate PackageTemplate
This commit replaces InputMaterial in both ChannelMonitor/
OnchainTxHandler.

This doesn't change behavior.
2021-05-25 19:59:40 -04:00
Antoine Riard
0ea7dd8bfc Add package.rs file
Package.rs aims to gather interfaces to communicate between
onchain channel transactions parser (ChannelMonitor) and outputs
claiming logic (OnchainTxHandler). These interfaces are data
structures, generated per-case by ChannelMonitor and consumed
blindly by OnchainTxHandler.
2021-05-25 19:54:57 -04:00
Matt Corallo
5b59178f89 Add version and TLV suffix for more user-facing "major" structs 2021-05-25 20:06:45 +00:00
Matt Corallo
8ee7d841b6 Support serializing TLV fields which may or may not be present 2021-05-25 20:06:45 +00:00
Matt Corallo
a515eb3ba6 Append backwards-compat TLVs to serialization of larger structs
Currently our serialization is very compact, and contains version
numbers to indicate which versions the code can read a given
serialized struct. However, if you want to add a new field without
needlessly breaking the ability of previous versions of the code to
read the struct, there is not a good way to do so.

This adds dummy, currently empty, TLVs to the major structs we
serialize out for users, providing an easy place to put new
optional fields without breaking previous versions.
2021-05-25 20:06:45 +00:00
Jeffrey Czyz
f63fd83fd6
Process ChainMonitor events in the background 2021-05-25 00:28:59 -07:00
Jeffrey Czyz
7c465d69dc
Refactor EventsProvider to take an EventHandler 2021-05-24 14:16:16 -07:00
Gene Ferneau
ec3739b7a2
Use core replacements for std members
In preparation for no_std build support, replace std structs and
functions with core equivalents
2021-05-23 23:48:27 +00:00
Antoine Riard
6319690891 keysinterface: replace Result match with map_err 2021-05-17 22:32:02 -04:00
Antoine Riard
55eccfa7b3 Split sign_justice_transaction in two halves
To avoid caller data struct storing HTLC-related information when
a revokeable output is claimed on top of a commitment/second-stage
HTLC transactions, we split `keysinterface::sign_justice_transaction`
in two new halves `keysinterfaces::sign_justice_revoked_output` and
`keysinterfaces::sign_justice_revoked_htlc`.

Further, this split offers more flexibility to signer policy as a
commitment revokeable output might be of a value far more significant
than HTLC ones.
2021-05-17 22:31:28 -04:00
Matt Corallo
d2955be5cf
Merge pull request #911 from TheBlueMatt/2021-05-fix-cltv-diff 2021-05-06 21:49:24 +00:00
Matt Corallo
71d640a64b Always log_info when we broadcast a transaction, including the txid 2021-05-06 18:49:11 +00:00
Matt Corallo
e84f5edbc5 Increase the CLTV delay required on payments and forwards
This increases the CLTV_CLAIM_BUFFER constant to 18, much better
capturing how long it takes to go on chain to claim payments.
This is also more in line with other clients, and the spec, which
sets the default CLTV delay in invoices to 18.

As a side effect, we have to increase MIN_CLTV_EXPIRY_DELTA as
otherwise as are subject to an attack where someone can hold an
HTLC being forwarded long enough that we *also* close the channel
on which we received the HTLC.
2021-05-05 20:09:11 +00:00