Commit graph

677 commits

Author SHA1 Message Date
bmancini55
f4adb9f013 Use constant MAX_REPLY_SCID
Modifies NetGraphMsgHandler::handle_query_channel_range to use a constant
max value in replies. Modifies tests to generate 8000 channels instead
of making this value configurable.
2021-03-13 14:51:36 -05:00
bmancini55
1809ef199e Use constant in QueryChannelRange::end_blocknum
Clarifies u32 max value used as the default.
2021-03-10 06:46:44 -05:00
bmancini55
deffb4a3d8 Clean up iteration in handle_query_channel_range
Refactor to use an enumerator in NetGraphMsgHandler::handle_query_channel_range
2021-03-09 16:30:52 -05:00
bmancini55
dd0bb25694 Use scid_from_parts in Channel::block_connected
Refactors validation and short_channel_id construction to use
the new scid_from_parts function.
2021-03-09 15:42:45 -05:00
bmancini55
d5fd8d96e1 Improve short_channel_id utils
Modifies scid_from_parts to use u64 inputs allowing untruncated
validation. Adds public constants for limits.
2021-03-09 15:34:52 -05: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
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
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
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
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
c21b866c60 Fix doc typo introduced in the ChannelKeys->Sign renaming 2021-02-28 19:44:45 -05:00
Matt Corallo
c5c0abb88d Log full signed remote commitment transaction hex in channel
This is useful when rebuilding the full_stack_target test vector
2021-02-26 23:47:03 -05:00
Matt Corallo
1521633ca2 Randomize secp contexts for marginally better sidechannel resistance 2021-02-26 23:47:03 -05:00
Valentine Wallace
a2d9fca9d5
SimpleArcPeerManager type: remove outer Arc for flexibility 2021-02-26 17:58:56 -05:00
Valentine Wallace
eecc3b7223
SimpleArcChannelManager type: remove outer Arc for flexibility 2021-02-26 17:56:53 -05:00
Matt Corallo
a51d5cef58 Update rust-bitcoin 2021-02-26 15:15:18 -05:00
Matt Corallo
e77b16049b
Merge pull request #791 from jkczyz/2021-01-spv-client
SPV client utility for syncing a lightning node
2021-02-26 07:54:01 -08:00
Jeffrey Czyz
8bfdfdc9e4
Utility for syncing a set of chain listeners
Add a utility for syncing a set of chain listeners to a common chain
tip. Required to use before creating an SpvClient when the chain
listener used with the client is actually a set of listeners each of
which may have had left off at a different block. This would occur when
the listeners had been persisted individually at different frequencies
(e.g., a ChainMonitor's individual ChannelMonitors).
2021-02-26 00:54:43 -06:00
Galder Zamarreño
24ed1dc2ec Add support for opt_shutdown_anysegwit feature #780
* Implemented protocol.
* Made feature optional.
* Verify that the default value is true.
* Verify that on shutdown,
if Channel.supports_shutdown_anysegwit is enabled,
the script can be a witness program.
* Added a test that verifies that a scriptpubkey
for an unreleased segwit version is handled successfully.
* Added a test that verifies that
if node has op_shutdown_anysegwit disabled,
a scriptpubkey with an unreleased segwit version on shutdown
throws an error.
* Added peer InitFeatures to handle_shutdown
* Check if shutdown script is valid when given upfront.
* Added a test to verify that an invalid test results in error.
* Added a test to check that if a segwit script with version 0 is provided,
the updated anysegwit check detects it and returns unsupported.
* An empty script is only allowed when sent as upfront shutdown script,
so make sure that check is only done for accept/open_channel situations.
* Instead of reimplementing a variant of is_witness_script,
just call it and verify that the witness version is not 0.
2021-02-25 14:28:08 +01:00
Matt Corallo
4b04f3ff1e Allow cloning NetworkGraphs 2021-02-22 11:44:22 -05:00
Matt Corallo
8051fb0118 Standardize trait derives in network graph objects
In general, trivial structs that have no inner logic can/should
all derive, at least, `Clone, Debug, PartialEq`.
2021-02-22 11:44:22 -05:00
Matt Corallo
9a5d846c9e Standardize trait derives in network message objects
In general, trivial structs that have no inner logic can/should
all derive, at least, `Clone, Debug, PartialEq`.
2021-02-22 11:44:22 -05:00
Matt Corallo
4b6f0a3b26 Further rename chan_keys variables to signers 2021-02-20 10:06:22 -05:00
Matt Corallo
aa127f55ed Use ChannelSigner instead of ChanSigner for type parameters 2021-02-19 16:04:19 -05:00
Matt Corallo
523fcb6f3f Change Persist's Sign from an associated type to a generic param 2021-02-19 16:04:19 -05:00
Matt Corallo
20a25967ef Use signer instead of keys_storage in OnchainTx to hold Sign 2021-02-19 15:54:43 -05:00
Matt Corallo
ff00f6f886 Rename ChannelKeys -> Sign and generic it consistently
The `ChannelKeys` object really isn't about keys at all anymore,
its all about signing. At the same time, we rename the type aliases
used in traits from both `ChanKeySigner` and `Keys` to just
`Signer` (or, in contexts where Channel isnt clear, `ChanSigner`).
2021-02-19 15:54:41 -05:00
Matt Corallo
ee68ffa5fd
Merge pull request #801 from TheBlueMatt/2021-02-789-bindings
Bindings updates for 789
2021-02-19 12:42:17 -08:00
Valentine Wallace
12c735ab3a
Add PersistenceNotifier to ChannelManager
This will allow the ChannelManager to signal when it has new
updates to persist, and adds a way for ChannelManager persisters
to be notified when they should re-persist the ChannelManager
to disk/backups.

Feature-gate the wait_timeout function because the core
lightning crate shouldn't depend on wallclock time unless
users opt into it.
2021-02-19 15:00:43 -05:00
Valentine Wallace
f41cfb4da9
Make logger macros public
These will be used in upcoming commits for the BackgroundProcessor
to log.
2021-02-19 15:00:41 -05:00
Matt Corallo
1d0645f7e6 Add a no-bindings-map comment to std::io::ErrorKind in DecodeErr 2021-02-19 14:02:46 -05:00
Matt Corallo
2f06b53abf Switch from slice to slice-of-refs for spend_spendable_outputs
Sadly, there's just not really a practical way to map a slice of
objects in our current bindings infrastructure - either we take
ownership of the underlying objects and move them into a Vec, or we
need to leave the original objects in place and have a list of
pointers to the Rust objects. Thus, the only practical mapping is
to create a slice of references using the pointers we have.
2021-02-19 13:58:05 -05:00
Valentine Wallace
1079753f20
Ensure build_commitment_tx and next_local/remote_tx_fee agree on the fee 2021-02-18 13:09:17 -05:00