Commit graph

2394 commits

Author SHA1 Message Date
Jeffrey Czyz
ff4b4c4d36
Remove block_connected de-duplication logic
Calling block_connected for the same block was necessary when clients
were expected to re-fetch filtered blocks with relevant transactions. At
the time, all listeners were notified of the connected block again for
re-scanning. Thus, de-duplication logic was put in place.

However, this requirement is no longer applicable for ChannelManager as
of commit bd39b20f64, so remove this
logic.
2021-03-05 15:45:12 -08:00
Jeffrey Czyz
d28fa54edb
Parameterize ChannelManager::new with a block hash
When ChannelMonitors are persisted, they need to store the most recent
block hash seen. However, for newly created channels the default block
hash is used. If persisted before a block is connected, the funding
output may be missed when syncing after a restart. Instead, initialize
ChannelManager with a "birthday" hash so it can be used later when
creating channels.
2021-03-05 15:44:54 -08:00
bmancini55
44ba52ccf1 Handle query_channel_range message from peer
Initial implementation of handling query_channel_range messages in
NetGraphMsgHandler.  Enqueues a sequence of reply message in the pending
message events buffer.
2021-03-05 17:14:35 -05:00
Matt Corallo
af49a60e2d
Update docs with correct hash type
Co-authored-by: Matt Corallo <git@bluematt.me>
Co-authored-by: Jeffrey Czyz <jkczyz@gmail.com>
2021-03-05 13:40:26 -08:00
Jeffrey Czyz
4cd2e4e94b
Revert "Merge pull request #819 from TheBlueMatt/2021-03-810-rebased"
This reverts commit 793de5fe69, reversing
changes made to 03a5189651.
2021-03-05 13:35:07 -08:00
Matt Corallo
1a8b9be5e4
Merge pull request #808 from TheBlueMatt/2021-02-791-order-fix
Process monitor update events in block_[dis]connected asynchronously
2021-03-05 12:16:21 -08:00
bmancini55
0b14e97c49 Create short_channel_id utils
Util converts parts into u64 SCID
Util extracts block height from u64 SCID

Both will be used when processing gossip_query messages.
2021-03-05 15:09:51 -05:00
bmancini55
8ec5429f0f Add end_blocknum method to query_channel_range
Overflow safe calculation of the ending block number for a query. Can
be used when processing the query.
2021-03-05 15:09:51 -05:00
bmancini55
feca062072 Add SendReplyChannelRange message event
Creates a MessageSendEvent for sending a reply_channel_range message.
This event will be fired when handling inbound query_channel_range
messages in the NetGraphMessageHandler.
2021-03-05 15:09:42 -05:00
Matt Corallo
93a75726a1 Clarify ChannelManager docs somewhat around full blocks
As suggested by Val.
2021-03-05 14:46:29 -05:00
Matt Corallo
5351f9fa03 Expand tests to cover serialization with pending background events 2021-03-05 14:46:29 -05:00
Matt Corallo
d4810087c1 Process monitor update events in block_[dis]connected asynchronously
The instructions for `ChannelManagerReadArgs` indicate that you need
to connect blocks on a newly-deserialized `ChannelManager` in a
separate pass from the newly-deserialized `ChannelMontiors` as the
`ChannelManager` assumes the ability to update the monitors during
block [dis]connected events, saying that users need to:
```
4) Reconnect blocks on your ChannelMonitors
5) Move the ChannelMonitors into your local chain::Watch.
6) Disconnect/connect blocks on the ChannelManager.
```

This is fine for `ChannelManager`'s purpose, but is very awkward
for users. Notably, our new `lightning-block-sync` implemented
on-load reconnection in the most obvious (and performant) way -
connecting the blocks all at once, violating the
`ChannelManagerReadArgs` API.

Luckily, the events in question really don't need to be processed
with the same urgency as most channel monitor updates. The only two
monitor updates which can occur in block_[dis]connected is either
a) in block_connected, we identify a now-confirmed commitment
   transaction, closing one of our channels, or
b) in block_disconnected, the funding transaction is reorganized
   out of the chain, making our channel no longer funded.
In the case of (a), sending a monitor update which broadcasts a
conflicting holder commitment transaction is far from
time-critical, though we should still ensure we do it. In the case
of (b), we should try to broadcast our holder commitment transaction
when we can, but within a few minutes is fine on the scale of
block mining anyway.

Note that in both cases cannot simply move the logic to
ChannelMonitor::block[dis]_connected, as this could result in us
broadcasting a commitment transaction from ChannelMonitor, then
revoking the now-broadcasted state, and only then receiving the
block_[dis]connected event in the ChannelManager.

Thus, we move both events into an internal invent queue and process
them in timer_chan_freshness_every_min().
2021-03-05 14:46:29 -05:00
Matt Corallo
1efc0c85eb
Merge pull request #825 from jkczyz/2021-03-client-visibility
Expose RpcClient and RestClient interfaces as pub
2021-03-05 09:44:28 -08:00
Matt Corallo
27276695fa
Merge pull request #821 from jkczyz/2021-03-fix-build-warnings
Fix build warnings
2021-03-05 09:44:21 -08:00
Jeffrey Czyz
f48e273560
Expose RpcClient and RestClient interfaces as pub
Useful for use outside of the BlockSource context, e.g., when
implementing fee estimation or transaction broadcasting.
2021-03-03 17:32:39 -08:00
Jeffrey Czyz
a571ecccbc
Fix build warnings 2021-03-02 21:30:34 -08:00
Matt Corallo
ba6eee24e4 Change ShutdownResult type to better capture the possibilites
The return value from Channel::force_shutdown previously always
returned a `ChannelMonitorUpdate`, but expected it to only be
applied in the case that it *also* returned a Some for the funding
transaction output.

This is confusing, instead we move the `ChannelMontiorUpdate`
inside the Option, making it hold a tuple instead.
2021-03-02 20:40:29 -05:00
Matt Corallo
280de80298 Add a few notes about deserializing stale ChannelManagers
See diff for more details
2021-03-02 20:40:29 -05:00
Matt Corallo
23c3278b9d Fix indentation in test_htlc_no_detection 2021-03-02 20:40:29 -05:00
Matt Corallo
89026766a3 Move functional tests involving reorgs to reorg_test
functional_tests.rs is huge, so anything we can do to split it up
some is helpful. This also exposes a somewhat glaring lack of
reorgs in our existing tests.
2021-03-02 20:40:29 -05:00
Matt Corallo
4894d52d30 Merge pull request #646 from naumenkogs/2020-06-router-mpp
MPP on the router side
2021-03-02 20:33:08 -05:00
Matt Corallo
793de5fe69
Merge pull request #819 from TheBlueMatt/2021-03-810-rebased
Change ChannelManager deserialization to return an optional blockhash
2021-03-02 16:04:23 -08:00
Matt Corallo
03a5189651
Merge pull request #818 from jkczyz/2021-03-validate-best-block-header
Add validate_best_block_header utility
2021-03-02 16:03:42 -08:00
Matt Corallo
7caadd446b
Merge pull request #816 from valentinewallace/remove-simple-outer-arcs
Remove simple outer arcs
2021-03-02 16:02:44 -08:00
Gleb Naumenko
e0600e5b1e Don't underpay htlc_min due to path contribution
We could have possibly constructed a slightly inconsistent
path: since we reduce value being transferred all the way, we
could have violated htlc_minimum_msat on some channels
we already passed (assuming dest->source direction). Here,
we recompute the fees again, so that if that's the case, we
match the currently underpaid htlc_minimum_msat with fees.
2021-03-02 21:40:08 +02:00
Matt Corallo
8550bd43d3 Update docs to use the new deserialization requirements 2021-03-02 14:30:56 -05:00
Valentine Wallace
7c8e740b6e Change ChannelMonitor deserialization to return an optional blockhash.
See previous commit msg for details.
2021-03-02 14:30:56 -05:00
Valentine Wallace
ee995a3a55 Change ChannelManager deserialization to return an optional blockhash
If the ChannelManager never receives any blocks, it'll return a default blockhash
on deserialization. It's preferable for this to be an Option instead.
2021-03-02 14:30:56 -05:00
Gleb Naumenko
18c7730040 Mind htlc_minimum_msat when truncating overpaid value
At truncating the overpaid value, if we fall below
htlc_minimum_msat, reach it by increasing fees.
2021-03-02 21:19:58 +02:00
Gleb Naumenko
ef12ceb8dd Use outbound_capacity_msat from first_hops for routing 2021-03-02 21:09:50 +02:00
Gleb Naumenko
db4721f3a7 Implement finding paths for MPP 2021-03-02 21:09:49 +02:00
Jeffrey Czyz
60f4daf2c2
Add validate_best_block_header utility
Refactor synchronize_listeners by pulling out a function returning the
validated block header of a BlockSource's best chain tip. This is needed
when a node is started from scratch and has no listeners to sync.
2021-03-02 10:03:11 -08:00
Matt Corallo
81c6bdc953
Merge pull request #814 from TheBlueMatt/2021-03-optional-handlers
Provide Dummy routing and channel message handlers for users
2021-03-02 07:00:46 -08:00
Matt Corallo
e241ca4339
Merge pull request #813 from jkczyz/2021-02-channel-monitor-mutex
Use interior mutability in ChannelMonitor
2021-03-02 07:00:20 -08:00
Jeffrey Czyz
e8ea0d9f04
Implement chain::Listen without using RefCell
The implementation of chain::Listen for ChannelMonitor required using a
RefCell since its block_connected method required a mutable borrow. This
is no longer the case since ChannelMonitor now uses interior mutability
via a Mutex. So the RefCell is no longer needed.
2021-03-01 22:12:26 -08:00
Jeffrey Czyz
389c4ad6fa
Change Mutex to RwLock in ChainMonitor
Now that ChannelMonitor uses an internal Mutex to support interior
mutability, ChainMonitor can use a RwLock to manage its ChannelMonitor
map. This allows parallelization of update_channel operations since an
exclusive lock only needs to be held when adding to the map in
watch_channel.
2021-03-01 22:12:26 -08:00
Jeffrey Czyz
8e558feb4b
Use consistent variable naming in ChainMonitor 2021-03-01 22:12:26 -08:00
Jeffrey Czyz
b0978a86be
Move ChannelMonitor state behind a Mutex
ChainMonitor accesses a set of ChannelMonitors behind a single Mutex.
As a result, update_channel operations cannot be parallelized. It also
requires using a RefCell around a ChannelMonitor when implementing
chain::Listen.

Moving the Mutex into ChannelMonitor avoids these problems and aligns it
better with other interfaces. Note, however, that get_funding_txo and
get_outputs_to_watch now clone the underlying data rather than returning
references.
2021-03-01 22:12:26 -08:00
Matt Corallo
d95f14568b Add utility constructors to PeerHandler to use a dummy handler 2021-03-01 20:23:54 -05:00
Matt Corallo
825a238a2c Provide Dummy routing and channel message handlers for users
We currently "support" not having a router or channel in memory by
forcing users to implement the same, but its trivial to provide our
own dummy implementations.
2021-03-01 20:23:54 -05:00
Matt Corallo
59d2040c74
Merge pull request #811 from TheBlueMatt/2021-02-bindings-rust-bump
Update bindings for new Listen interface
2021-03-01 15:35:35 -08:00
Matt Corallo
ee9ceb42b1 Add simple README about our C bindings generation stuff 2021-03-01 18:07:29 -05:00
Matt Corallo
f2e4f8a229 [bindings] Build a wasm32-wasi library in genbindings.sh
This will switch to use the clang/C WASM ABI instead of the
wasm_bindgen WASM ABI as of rustc 1.51 (or nightly since [1]),
allowing us to link C and Rust code in a single wasm binary.

[1] https://github.com/rust-lang/rust/pull/79998
2021-03-01 18:07:29 -05:00
Matt Corallo
808db58578 Update auto-generated bindings 2021-02-28 19:44:45 -05:00
Matt Corallo
6dd9c2e97c [bindings] Be explicit when calling trait methods in generated code
For ChannelManager, at least, we have two separate functions called
block_connected, one in the Listen trait, one in the struct, we
need to be explicit with which one we're trying to call.
2021-02-28 19:44:45 -05:00
Matt Corallo
c21b866c60 Fix doc typo introduced in the ChannelKeys->Sign renaming 2021-02-28 19:44:45 -05:00
Matt Corallo
cd0b212e4d [bindings] Use global context for secp256k1
Note that this uses https://github.com/rust-bitcoin/rust-secp256k1/pull/279
2021-02-28 19:44:45 -05:00
Matt Corallo
9fba7c92ad
Merge pull request #802 from TheBlueMatt/2021-01-update-rust-bitcoin
Update rust-bitcoin and add secp256k1 context randomization
2021-02-28 16:43:08 -08:00
Matt Corallo
beb88e69a9
Merge pull request #806 from valentinewallace/monitor-data-persistence-path
persist: Persist ChannelMonitors in their own directory.
2021-02-27 16:34:54 -08:00
Matt Corallo
ea48a5a089 Rebuild full_stack_target test vector for new secp256k1 fuzz req 2021-02-26 23:47:03 -05:00