Commit graph

350 commits

Author SHA1 Message Date
Matt Corallo
cd3748cd9d Add missing unwrap() in tests introduced in 4abfd515e5 2020-03-11 16:10:01 -04:00
Matt Corallo
d6b1825186
Merge pull request #513 from ariard/2020-02-fix-zero-msat-htlc
BOLT2: Check we don't send and accept 0-msat HTLC
2020-03-11 19:57:38 +00:00
Antoine Riard
dd9c476a58 Add test_override_0msat_htlc_minimum 2020-03-11 14:28:22 -04:00
Antoine Riard
9e03d2bc7a Make htlc_minimum_msat configurable
Enforce a minimum htlc_minimum_msat of 1.

Instead of computing dynamically htlc_minimum_msat based on feerate,
relies on user-provided configuration value. This let user compute
an economical-driven channel parameter according to network dynamics.
2020-03-11 14:28:20 -04:00
Matt Corallo
d27e9e1c6a
Merge pull request #472 from TheBlueMatt/2020-01-net-async-await
Rewrite lightning-net-tokio using async/await and tokio 0.2
2020-03-11 17:41:57 +00:00
Valentine Wallace
40a1aef322
Add test cases for feature messages from other lightning clients. 2020-03-11 12:55:00 -04:00
Valentine Wallace
658b681772
Fix blanking out non-node-context feature flags when pulling features from init context.
Fixes bug introduced in 912f877
2020-03-11 12:54:14 -04:00
Antoine Riard
4abfd515e5 Add test_update_add_htlc_bolt2_receiver_zero_value_msat 2020-03-10 13:05:30 -04:00
Antoine Riard
d1c6f235f9 BOLT2: Check we don't send and accept 0-msat HTLC
Failing this requirement at sending means a strict receiver would
fail our channel while processing a HTLC routed from a third-party.

Fix by enforcing check on both sender and receiver side.
2020-03-10 13:05:30 -04:00
Matt Corallo
6f06858304 Swap read_event read type for a slice isntead of a Vec
It looks like we don't currently use the Vec as a Vec, and can
happily take a slice, which makes things easier on the calling
side.
2020-03-10 11:52:12 -04:00
Matt Corallo
4f06d7a83c Update pre-HTLC DataLossProtect to match new spec changes
This was the way DataLossProtect was originally written, however it
didn't match other implementations at the time during testing. It
turns out, other implementations didn't agree with each other
anyway (depending on the exact timeline), so the spec was clarified
somewhat in https://github.com/lightningnetwork/lightning-rfc/pull/550
. This updates us to be in line with the new guidance and appears
to solve out-of-sync issues in testing.
2020-03-05 21:16:47 -05:00
Matt Corallo
78c48f76d4 Use block timestamps as the min for generated update messages.
Fixes issue #493 and should resolve some issues where other nodes
(incorrectly) reject channel_update/node_announcement messages
which have a serial number that is not a relatively recent
timestamp.
2020-03-05 20:59:43 -05:00
Matt Corallo
c2ca6d3cdc Further document the initial routing table send.
As requested by Arik at https://github.com/rust-bitcoin/rust-lightning/pull/435#discussion_r378093821
2020-03-05 20:59:43 -05:00
Matt Corallo
a8114a70cb Add ability to broadcast our own node_announcement.
This is a somewhat-obvious oversight in the capabilities of
rust-lightning, though not a particularly interesting one until we
start relying on node_features (eg for variable-length-onions and
Base AMP).

Sadly its not fully automated as we don't really want to store the
list of available addresses from the user. However, with a simple
call to ChannelManager::broadcast_node_announcement and a sensible
peer_handler, the announcement is made.
2020-03-05 20:59:43 -05:00
Matt Corallo
107da97cd0 Allow more than one address per type in node_announcement messages
lnd has been blatantly ignoring this line in the spec forever, so
its somewhat of a lost cause trying to enforce it.
2020-03-05 18:42:49 -05:00
Matt Corallo
fd08529d59 Allow node_announcement timestamps of 0 in accordance with BOLT 7
Unlike channel_update messages, node_announcement messages have no
requirement that the timestamp is greater than 0.
2020-03-05 18:30:50 -05:00
Matt Corallo
6abce8165e Take multiple spent-txn to check_spends! in functional_tests
This reintroduces a check_spends!() removed in 3d640da5c3
due to check_spends not being able to check a transaction which
spends multiple other transactions.

It also simplifies a few calls in claim_htlc_outputs_single_tx by
using check_spends!().
2020-03-04 21:06:58 -05:00
Matt Corallo
f554c59463 Drop redundant .clone() in check_spends calls.
The API to rust-bitcoin to check a transaction correctly spends
another changed some time ago, but we still have a lot of needless
.clone()s in our tests.
2020-03-04 21:06:57 -05:00
Matt Corallo
9de9288100 Correct comment in onchaintx.rs
This comment was stale and referred to a previous implementation
of #462, which changed before it was merged.
2020-03-04 21:06:57 -05:00
Matt Corallo
4c3533d017 Flatten Vec passed from channelmonitor to onchaintx block_connected
Instead of passing a Vec of Vecs drop them into one as we go in
ChannelMonitor, hopefully avoiding a bit of memory fragmentation
and improving readability.
2020-03-04 17:57:22 -05:00
Antoine Riard
a4a5e01437 Rename InputMaterial script to witness_script 2020-03-04 16:06:31 -05:00
Antoine Riard
e8cb076267 Comment better get_height_timer logic.
Height timer as an important component of a more-secure, fee-sensitive
claiming of time-constrained LN outputs, therefore document assumptions.
2020-03-04 16:06:31 -05:00
Antoine Riard
d86423c366 Remove TestBroadcaster temporary dedup buffer 2020-03-04 16:06:31 -05:00
Antoine Riard
14335358d0 Structurify claim request handed between detection/reaction 2020-03-04 16:06:31 -05:00
Antoine Riard
3d640da5c3 Introduce OnchainTxHandler, move bumping and tracking logic
Encapsulates tracking and bumping of in-flight transactions in
its own component. This component may be latter abstracted
to reuse tracking and RBF for new features (e.g dual-funding,
splicing)

Build all transactions generation in one place. Also as fees
and signatures are closely tied, what keys do you have determine
what bumping mode you can use.
2020-03-04 16:06:29 -05:00
Matt Corallo
5f3986d047 Test Router serialization round-trip in functional_tests.
This tests Router serialization round-trip at the end of each
functional test in the same way we do ChannelMonitors and
ChannelManagers to catch any cases where we were able to get into
a state which would have prevented reading a Router back off disk.

We further walk all of the announcements which both the original
and deserialized Routers would send to peers requesting initial
sync to ensure they match.
2020-03-04 14:29:06 -05:00
Matt Corallo
b80d3d9d29 Change Option<T> serialization format to include length
This is a cheap way to fix an error in Router serialization
roundtrip due to us calling read_to_end during the read of
channel/node announcement/updates. During normal message reading,
we only have limited bytes to read (specifically the message buffer)
so this is fine, however when we read them inside Router, we have
more data from other fields of the Router available as well. Thus,
we end up reading the entire rest of the Router into one message
field, and failing to deserialize.

Because such fields are always stored in Option<>s, we can simply
use a LengthLimitingStream in the Option<> serialization format and
make only the correct number of bytes available.

By using a variable-length integer for the new field, we avoid
wasting space compared to the existing serialization format.
2020-03-04 14:29:06 -05:00
Matt Corallo
32ca8ec13e Make Readable::read a templated on the stream, not Readable itself
This makes Readable symmetric with Writeable and makes sense -
something which is Readable should be Readable for any stream which
implements std::io::Read, not only for a stream type it decides on.

This solves some lifetime-compatibility issues in trying to read()
from a LengthLimitingReader in arbitrary Readable impls.
2020-03-04 14:29:06 -05:00
Matt Corallo
39b62335b7 Impl ReadableArgs for Arc<ChannelManager>, not just ChannelManager.
This provides a simple wrapper for deserializing right into an
Arc<ChannelManager>, which improves UX a tiny bit when working with
SimpleArcChannelManager types.
2020-03-04 14:29:06 -05:00
Christopher Coverdale
53c894bcaa Add an override optional UserConfig per new outbound channel 2020-02-28 22:58:26 +00:00
Matt Corallo
9ff6f29074 Add comment noting that ChannelMonitor events are serialized 2020-02-28 14:36:02 -05:00
Matt Corallo
0ebf70d6a2 Drop stale doc comment + TODO describing MessageSendEvents 2020-02-28 14:36:02 -05:00
Matt Corallo
26008bbc0b Move events into ChannelMonitor from ManyChannelMonitor
This is the next step after "Move pending-HTLC-updated ChannelMonitor
from ManyChannelMonitor", moving our events into ChannelMonitor as
well and leaving only new-outputs-to-watch in the return value for
ChannelMonitor::block_connected (which is fine as those are
duplicatively tracked in the ChannelMonitor directly, so
losing/replaying them is acceptable).
2020-02-28 14:36:02 -05:00
Matt Corallo
bfd4ac4995 Implement Readable/Writeable for Events
As noted in the docs, Events don't round-trip fully, but round-trip
in a way that is useful for ChannelManagers, specifically some events
don't make sense anymore after a restart.
2020-02-28 14:36:02 -05:00
Matt Corallo
8829d1b80f
Merge pull request #522 from valentinewallace/chanmgr-fee-est-arc-to-deref
Update ChannelManager's FeeEstimator from Arc to Deref.
2020-02-28 19:08:43 +00:00
Matt Corallo
de24150203 Dont treat a timer tick as no_connection_possible and log
In testing, due to other patches, I managed to flood the send queue
with messages and cause us not to be able to send pings, thus
getting a peer disconnected for ping timeout. To my surprise, this
also force-closed all of my channels with that peeer.

Obviously a ping timeout does not indicate that no future connection
with said peer will be possible, and we shouldn't be force-closing
channels as a result.

This also logs when a peer is disconnected to ping timeout to make
debug easier.
2020-02-27 15:46:52 -05:00
Matt Corallo
440129c6b6 Add logging on receipt of unknown message types.
This should make peer disconnection easier to debug.
2020-02-27 15:46:31 -05:00
Valentine Wallace
f5b5bf2acb
Update ChannelManager's FeeEstimator from Arc to Deref. 2020-02-27 15:27:58 -05:00
Valentine Wallace
bff9982299
multi: update ChannelManager's keys manager from Arc to Deref 2020-02-27 11:55:18 -05:00
Matt Corallo
08db88c673 Drop TODO which was implemented long ago 2020-02-26 19:15:32 -05:00
Matt Corallo
ab7a0a5431 Drop Clone from ChannelMonitor.
This removes the somewhat-easy-to-misuse Clone from ChannelMonitors,
opening us up to being able to track Events in ChannelMonitors with
less risk of misuse.

Sadly it doesn't remove the Clone requirement for ChannelKeys,
though gets us much closer - we now just need to request a second
copy once when we go to create the ChannelMonitors.
2020-02-26 19:15:32 -05:00
Matt Corallo
3e26bd7a1d Rm ChannelMonitor merge capabilities in favor of explicit add/update
This removes the ability to merge ChannelMonitors in favor of
explicit ChannelMonitorUpdates. It further removes
ChannelManager::test_restore_channel_monitor in favor of the new
ChannelManager::channel_monitor_updated method, which explicitly
confirms a set of updates instead of providing the latest copy of
each ChannelMonitor to the user.

This removes almost all need for Channels to have the latest
channel_monitor, except for broadcasting the latest local state.
2020-02-26 19:15:32 -05:00
Matt Corallo
6caed7df7c Create ChannelMonitors with basic_channel_info and funding_info set
This removes most of the reliance on ChannelMonitor Clone, creating
them in Channel only at the time when we need to start monitoring
the chain.
2020-02-26 19:15:32 -05:00
Matt Corallo
f930fc1886 Use ChannelMonitorUpdate in fallen-behind handling during reestablish
This is a rather huge diff, almost entirely due to removing the
type parameter from ChannelError which was added in
c20e930b31 due to holding the
ChannelKeys in ChannelMonitors.
2020-02-26 19:15:32 -05:00
Matt Corallo
537bd357f9 Set ChannelMonitor basic_channel_info on funding, not on accept
This prepares for only creating the ChannelMonitor on funding by
removing any channel_monitor calls from Channel open/accept-time to
funding-signed time.
2020-02-26 19:15:32 -05:00
Matt Corallo
df5053d396 Use ChannelMonitorUpdates in commitment signing fns in Channel
This is a rather big step towards using the new ChannelMonitorUpdate
flow, using it in the various commitment signing and commitment
update message processing functions in Channel. Becase they all
often call each other, they all have to be updated as a group,
resulting in the somewhat large diff in this commit.

In order to keep the update_ids strictly increasing by one for
ease of use on the user end, we have to play some games with the
latest_monitor_update_id field, though its generally still pretty
readable, and the pattern of "get an update_id at the start, and
use the one we got at the start when returning, irrespective of
what other calls into the Channel during that time did" is
relatively straightforward.
2020-02-26 19:15:32 -05:00
Matt Corallo
569f9038be Impl (de)serialization for bitcoin::Transaction.
There is little risk of misusing this as there's not much in the
way of other ways you may want to serialize bitcoin::Transaction
2020-02-26 19:15:32 -05:00
Matt Corallo
8c69bb11b8 Update Channel::funding_signed to use ChannelMonitorUpdate
This is the first of several steps to update ChannelMonitor updates
to use the new ChannelMonitorUpdate objects, demonstrating how the
new flow works in Channel.
2020-02-26 19:15:32 -05:00
Matt Corallo
3b277cc394 Add types for updating ChannelMonitors without copying them.
This is the first step in migrating ChannelMonitor updating logic
to use incremental Update objects instead of copying the
ChannelMonitors themselves and insert_combine()ing them.

This adds most of the scaffolding and updates relevant comments to
refer to the new architecture, without changing how any actual
updates occur.
2020-02-26 19:15:32 -05:00
Matt Corallo
d271d74bc7 Use Channel::funding_txo instead of its channel_monitor.funding_txo
Currently Channel relies on its own internal channel_monitor copy
to keep track of funding_txo information, which is both a bit
awkward and not ideal if we want to get rid of the ChannelMonitor
copy in Channel.

Instead, just duplicate it (its small) and keep it directly in
Channel, allowing us to remove the (super awkward)
ChannelMonitor::unset_funding_txo().
2020-02-26 17:48:31 -05:00