Matt Corallo [Sat, 28 Jul 2018 23:15:45 +0000 (19:15 -0400)]
Add pending-HTLC-failure to and unify force_shutdown() handling
This patch got a bit bigger than I'd intended, but primarily this
unifies force_shutdown() handling so all the callsites at least
look similar. It also fails backwards any HTLCs which were
completely pending (ie hadn't been committed to) and ensures we
broadcast our local commitment transaction. It also adds a
force_close_channel method to ChannelManager to expose
force-closure.
Matt Corallo [Thu, 26 Jul 2018 21:53:10 +0000 (17:53 -0400)]
Fix force_shutdown() bug where we lose knowledge of a preimage
In case we are in AwaitingRemoteRevoke and we go to claim an HTLC
(at which point we've already given up the money to the next hop in
the payment) we just write it to holding_cell_htlc_updates.
However, we should be ensuring we *also* write it to our
channel_monitor as we need to make sure we can still claim it after
a force_shutdown() or otherwise after hitting the chain.
Matt Corallo [Thu, 26 Jul 2018 19:44:27 +0000 (15:44 -0400)]
Handle duplicate payment_hash send_payment()s
We don't bother doing anything smart, we just return an Err in
case we have a pending outbound HTLC with the payment_hash provided
for the send.
This doesn't resolve the TODO as users can still send duplicative
payments that have the same payment_hash as was already sent,
though the docs are updated and hopefully users do so on their own.
Matt Corallo [Thu, 26 Jul 2018 18:33:01 +0000 (14:33 -0400)]
Properly calculate Channel::announce_publicly
For some reason we were only setting "announce_publicly" when
Channel::new_from_req had announce_publicly set to true and the
open_channel message had the relevant flag set. However, this
resulted in us rejecting peers for sending unsolicited
announcement_signatures messages, despite them having indicated,
and us having accepted, their announce-bit-set open_channel.
1. Implements sorting of transactoin inputs.
- BIP says to use "reversed byte-order" for the `prev_hash`. I interpreted this as: little-endian.
- TODO need to add tests
2. Re: improve sorting of TxOut's script_pubkey to use lexicographic ordering, and not length.
From the test-cases i've included it seems that the current code already does lexicographic ordering (and not length based). Am i missing something?
Antoine Riard [Mon, 23 Jul 2018 01:06:45 +0000 (01:06 +0000)]
Add DisconnectPeer events
Add test for DisconnectPeer event
Update DisconnectPeer with optional ErrorMessage
Manage error for funding_transaction_generated
Add disconnect_socket to SocketDescriptor trait
[msgs::ChannelReestablish] implement encoding and decoding
Summary:
Implementing these, taking inspiration from the surrounding code since i'm a rust n00b.
Test Plan:
```
cargo build
cargo test channel_reestablish
```
output:
```
running 3 tests
test ln::msgs::tests::encoding_channel_reestablish_with_secret ... ok
test ln::msgs::tests::decode_channel_reestablish_bad_length ... ok
test ln::msgs::tests::encoding_channel_reestablish_no_secret ... ok
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 14 filtered out
```
add two methods for the issue #56
peer_handler::get_peer_node_ids() get connected peers' node_id
router::get_addresses() to get network addresses by node_id
[fuzz] remove \L in sed regex for filenames in gen_target.sh
Summary:
on `master` branch, if i ran `gen_target.sh` i would get the following output:
https://gist.github.com/savil/2b3114eaf34c3ef8499b65005e374841
Without it, I get the files generated that are already checked-in (as expected).
Looking at the sed docs (https://www.gnu.org/software/sed/manual/html_node/Regular-Expressions.html) i don't see an explanation for what `\L` may do in whatever regex sed follows. Does this look correct? cc @yuntai
this was a TODO and also briefly discussed in https://github.com/rust-bitcoin/rust-lightning/pull/43#pullrequestreview-135649551
I'm not fully sure how to remove the `Option`, and make it completely required. Would love suggestions. So, have omitted that for now. Plus, better to make smaller, incremental changes.
Matt Corallo [Thu, 19 Jul 2018 21:17:06 +0000 (17:17 -0400)]
Fix various spec bugs, can now open channels with real nodes!
* commitment transaction number, as used in locktime/sequence
fields is actually different from commitment transaction number,
as used for revocation state. This is confusing and never stated
in the spec, so we have to do the conversion.
* max_htlc_value_in_flight is never constrained in the spec, but
we were requiring it be <= channel size. Instead just clamp the
values the peer sends us when storing.
* channel_id calculation was incorrect, we now do some crazy
conversion hops, which we shouldn't, but will need to change our
types to fix.
* Our channel_reserve_satoshis value was too low, just change the
constant and leave the TODO to figure out what it really should
be for now.