Commit graph

442 commits

Author SHA1 Message Date
Devrandom
f60026387e make LocalCommitmentTransaction constructor public
Allows calling of InMemoryChannelKeys methods
2020-08-11 09:23:31 +02:00
Devrandom
31b4d89cde make SimpleManyChannelMonitor.monitors public 2020-08-11 09:23:31 +02:00
Devrandom
ce0cecd50a export "unsafe_revoked_tx_signing" feature
Allows unsafe signing in dev code, such as functional testing of
justice transactions outside our crate.
2020-08-11 09:23:31 +02:00
Matt Corallo
4395b92cc8 Relicense as dual Apache-2.0 + MIT
This changes the LICENSE file and adds license headers to most files
to relicense under dual Apache-2.0 and MIT. This is helpful in that
we retain the patent grant issued under Apache-2.0-licensed work,
avoiding some sticky patent issues, while still allowing users who
are more comfortable with the simpler MIT license to use that.

See https://github.com/rust-bitcoin/rust-lightning/issues/659 for
relicensing statements from code authors.
2020-08-10 21:12:44 -04:00
Matt Corallo
093fcaba68
Merge pull request #664 from lightning-signer/tx-creation-keys
Wrap transaction creation keys
2020-08-10 13:25:03 -07:00
Devrandom
8058202c4c nit 2020-08-10 22:09:03 +02:00
Devrandom
6f635c6bc3 Expose TxCreationKeys in LocalCommitmentTransaction via a method
This makes it obvious to signer implementers that the pre-derived keys are a local cache and should not be trusted in a validating signer.
2020-08-10 20:22:01 +02:00
Devrandom
d2e6f2ac18 Make TxCreationKeys public and wrap it in PreCalculatedTxCreationKeys
Allows calling of InMemoryChannelKeys methods.

The wrapping makes it obvious to signer implementers that the pre-derived keys are a local cache and should not be trusted in a validating signer.
2020-08-10 20:21:07 +02:00
Valentine Wallace
523cab8ef7
Holding cell: if we fail to free an HTLC, fail it backwards
Plus add a test.
2020-08-08 16:32:15 -04:00
Devrandom
48d73b3264 ChannelKeys - provide to_self_delay alongside the remote channel pubkeys
In the phase 2 signer, we will construct the commitment transaction inside the signer.
In preparation, provide needed channel related data.
2020-07-29 20:43:39 +02:00
Matt Corallo
779ff6721b
Merge pull request #651 from naumenkogs/2020-06-routing-data-improvements
Routing improvements
2020-07-27 10:18:13 -07:00
Gleb Naumenko
dd0e4f4034 Check htlc_maximum_msat on channel update 2020-07-27 14:06:20 +03:00
Gleb Naumenko
3a57cfc7c6 Store channel capacity if available 2020-07-27 14:06:20 +03:00
Gleb Naumenko
8b4f6e8861 Add htlc_maximum_msat field 2020-07-27 14:06:16 +03:00
Devrandom
b19d4475cb ChannelKeys - separate commitment revocation from getting the per-commitment point
The commitment secret is sensitive - it can be used by an attacker to
steal funds if the node also signs the same transaction. Therefore,
only release the secret from ChannelKeys when we are revoking a
transaction.
2020-07-22 11:47:10 -07:00
Gleb Naumenko
a66b8017c0 Improve routing announcement test 2020-07-22 16:21:04 +03:00
Gleb Naumenko
430d57c610 Fix formatting 2020-07-22 16:21:04 +03:00
Gleb Naumenko
5309197150 Use constant for max msats 2020-07-22 16:21:04 +03:00
Gleb Naumenko
7838727a5c Update get_route comment to reflect new parameters 2020-07-22 16:20:19 +03:00
Matt Corallo
50df4cf464
Merge pull request #644 from joemphilips/improve_error_message
Improve error message.
2020-07-21 20:04:44 -07:00
joe.miyamoto
407e306a99
slightly refactor internal_announcement_signatures
For making debugging easy.
If the user gives a different node_secret for transport
layer (`PeerManager`) and for routing msg, internal_announcement_signatures
is the first place it causes an error.
By giving a detailed error message, user will be able to
fix the bug quickly.
2020-07-22 10:34:47 +09:00
joe.miyamoto
1fc6d6b5ee
Improve error message.
... for ChannelError and APIMisuseError
Before this commit, When rl returns error, we don't know
The actual parameter which caused the error.
By returning parameterised `String` instead of predefined `&'static str`,
We can give a caller improved error message.

TestLogger now has two additional methods
1. `assert_log_contains` which checks the logged messsage
  has how many entry which includes the specified string as a substring.
2. `aasert_log_regex` mostly the same with `assert_log_contains`
  but it is more flexible that caller specifies regex which has
  to be satisfied instead of just a substring.
For regex, tests now includes `regex` as dev-dependency.
2020-07-22 10:34:47 +09:00
Dr. Maxim Orlovsky
4bb5955be9 Moving LN_MAX_MSG_LEN const to the actual use place 2020-07-21 18:53:55 +02:00
Dr. Maxim Orlovsky
0e5dfadf64 Removing spec quotation from LN_MAX_MSG_LEN definition 2020-07-21 18:10:58 +02:00
Dr. Maxim Orlovsky
eae748a7b2 Removing duplicated code in message decryption test cases 2020-07-21 18:10:58 +02:00
Dr. Maxim Orlovsky
caed31a1e6 Test cases for message encryption/decryption size limits 2020-07-21 18:10:58 +02:00
Dr. Maxim Orlovsky
bcb50a65ae Fixing panic messages for decryption procedures 2020-07-21 18:10:58 +02:00
Dr. Maxim Orlovsky
eb8bcaae87 Making message size limit an exportable constant 2020-07-21 18:10:58 +02:00
Devrandom
1d37f56f8a ChannelKeys provides individual commitment secrets 2020-07-01 11:54:56 -07:00
Matt Corallo
4ed148a64d Fix unused-parentheses warnings newer rustcs have added 2020-06-28 13:21:45 -04:00
Matt Corallo
94c37c6c0e Fix silent merge conflict between bcd65bed7b and 940d7ac8d8 2020-06-28 13:19:40 -04:00
Matt Corallo
0133739e9e
Merge pull request #647 from valentinewallace/test-remote-fee-spike-buffer-violation
Test remote fee spike buffer violation
2020-06-27 00:41:35 +00:00
Matt Corallo
5c370232eb Use usize for transaction-position-in-block values
We use them largely as indexes into a Vec<Transaction> so there's
little reason for them to be u32s. Instead, use them as usize
everywhere.

We also take this opportunity to add range checks before
short_channel_id calculation, as we could otherwise end up with a
bogus short_channel_id due to an output index out of range.
2020-06-23 16:12:55 -04:00
Matt Corallo
bcd65bed7b Take &NetworkGraph as input in get_route, not a NetGraphMsgHandler
This was just an oversight when route calculation was split up into
parts - it makes no sense for get_route to require that we have a
full route message handler, only a network graph (which can always
be accessed from a NetGraphMsgHandler anyway).
2020-06-23 16:12:55 -04:00
Matt Corallo
882db714de Make ChainWatchInterface::filter_block return only idxes, not refs
Instead of making the filter_block fn in the ChainWatchInterface
trait return both a list of indexes of transaction positions within
the block and references to the transactions themselves, return
only the list of indexes and then build the reference list at the
callsite.

While this may be slightly less effecient from a memory locality
perspective, it shouldn't be materially different.

This should make it more practical to generate bindings for
filter_block as it no longer needs to reference Rust Transaction
objects that are contained in a Rust Block object (which we'd
otherwise just pass over the FFI in fully-serialized form).
2020-06-23 16:12:55 -04:00
Matt Corallo
ee6dd7f1bb Avoid references to primitives and add NetworkGraph::new()
non-mut references to primitives are only excess overhead, so
there's not much reason to ever have them. As a nice bonus, it also
is one less thing to worry about when generating C bindings
2020-06-23 16:12:55 -04:00
Matt Corallo
922fc8e9ee Avoid use std and use std::fmt and fmt:: instead in network_graph
This is more consistent with the way we use std::cmp over the
codebase and avoids `use std`, which is only actually needed to
support older rustcs, so feels a bit awkward.
2020-06-22 17:42:35 -04:00
Valentine Wallace
940d7ac8d8
Add test for remote fee spike buffer violations.
HTLCs that violate the remote's fee spike buffer should be failed.
2020-06-22 15:52:57 -04:00
Valentine Wallace
118d191a5a
Log fee spike buffer violations. 2020-06-22 15:30:41 -04:00
Matt Corallo
c33a444267 Reduce RwLock usage in public interface of NetworkGraph
This isn't a big difference in the API, but it avoids needing to
wrap a given NetworkGraph in a RwLock before passing it, which
makes it much easier to generate C bindings for.
2020-06-22 13:42:28 -04:00
Matt Corallo
9e5800927a Drop a useless import of std::result::Result since its always there 2020-06-22 13:42:28 -04:00
Matt Corallo
aa14fe5830 Drop some unnecessary lifetime specifiers in return type definitions
In general, we don't need an explicit lifetime when doing something
like:
fn get_thing(&self) -> &Thing { &self.thing }.

This also makes it easier to reason about what's going on in the
bindings generation.
2020-06-22 13:42:28 -04:00
Matt Corallo
775a5adfb9 ChannelMonitor::get_funding_txo returns both the txid and scriptPK
... instead of only the txid.

This is another instance of it not being possible to fully
re-implement SimpleManyChannelMonitor using only public methods. In
this case you couldn't properly register outpoints for monitoring
so that the funding transaction would be matched.
2020-06-22 13:42:28 -04:00
Jeffrey Czyz
43eed8dd8b
Make test output deterministic
Tests use sources of randomness to produce seeds, preimages, secrets,
and ephemeral data. However, this makes comparing logs between different
test runs difficult. Remove uses of random number generators and the
current time in favor of fixed values in order to make the test output
deterministic.
2020-06-18 19:28:50 -07:00
Valentine Wallace
f91718722a
Switch all feerate u64's to u32's.
The protocol only allows a u32, so if we received or sent something
larger it would be an issue (though it's unlikely).
2020-06-15 21:52:52 -04:00
Valentine Wallace
4c655b2281
Use our actual feerate in open_channel messages, not a new one
When we were sending an open_channel messages we were asking the
feerate estimator for a new value instead of using the one we had.
If the feerate estimator gave a different value than the one it did
when we created the Channel struct, we'd start out-of-sync with our
counterparty and blow up on funding_signed. Even worse, the
ConfirmationTarget used was different, so its highly likely they
would disagree.

Also remove newly unused fee estimator parameter from get_open-channel
API.

Co-authored-by: Matt Corallo <git@bluematt.me>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
2020-06-15 18:22:33 -04:00
Matt Corallo
c1c9b1175b
Merge pull request #577 from valentinewallace/fix-onchain-fee-check-htlcs
Incl tx fee when calcing inbound+outbound HTLC limits on channels
2020-06-15 20:17:03 +00:00
Valentine Wallace
c9926b9500
Add fee spike buffer + incl commit tx fee in chan reserve calculation
When we receive an inbound HTLC from a peer on an inbound channel,
make sure the funder can still cover the additional on-chain cost
of the HTLC while maintaining their channel reserve.

When we're sending an outbound HTLC, make sure the funder can still
cover the additional on-chain cost of the HTLC while maintaining
their channel reserve.

+ implement fee spike buffer for channel initiators sending payments.
Also add an additional spec-deviating fee spike buffer on the
receiving side (but don't close the channel if this reserve is
violated, just fail the HTLC).
From lightning-rfc PR #740.

Co-authored-by: Matt Corallo <git@bluematt.me>
Co-authored-by: Valentine Wallace <vwallace@protonmail.com>
2020-06-15 15:51:09 -04:00
Matt Corallo
9be497cad4
Merge pull request #634 from valentinewallace/improve-inbound-htlc-docs
Improve documentation for InboundHTLCState enum states.
2020-06-11 18:59:07 +00:00
Valentine Wallace
96daffaf63
Improve documentation for InboundHTLCState enum states. 2020-06-11 14:40:29 -04:00