Commit graph

609 commits

Author SHA1 Message Date
Matt Corallo
28c5f6f309 Track peer-disconnection in Channel and handle channel_reestablish 2018-09-15 10:53:16 -04:00
Matt Corallo
ca712dfa36 Add a Disconnected ChannelState and check/handle it everywhere
Setting/removing it comes next
2018-09-15 10:53:16 -04:00
Matt Corallo
12a50627a3 Add channel_reestablish + peer_connected events to channel handler 2018-09-15 10:53:16 -04:00
Matt Corallo
4bcf00e5b8 Clarify update_fail/fulfill_htlc holding cell allowed Errs
Specifically, there really should be no Errs, but in case there is
some case where duplicate HTLC removes are possible, return
IgnoreError and debug_assert to see if fuzzing can find them.
2018-09-15 10:53:16 -04:00
Matt Corallo
5fe598c073 Drop channels on disconnection if we haven't funded them yet 2018-09-15 10:53:16 -04:00
Matt Corallo
f55f055b4e Remove/fail uncommitted HTLCs upon peer disconnection 2018-09-15 10:53:16 -04:00
Matt Corallo
2be7eda3b5
Merge pull request #179 from TheBlueMatt/2018-09-pre-178-cleanups
Pre-reconnect ChannelManager test cleanups
2018-09-15 10:50:57 -04:00
Matt Corallo
ed71995f15
Merge pull request #183 from yuntai/201809-unwrap-getopenchannel
unwrap channel.get_open_channel
2018-09-15 10:48:54 -04:00
Yuntai Kyong
4e4fa56e2b unwrap channel.get_open_channel 2018-09-15 07:33:20 +09:00
Matt Corallo
5737b32424 Split claim and fail payment functions to be able to skip one hop 2018-09-14 16:24:30 -04:00
Matt Corallo
4f36f379e7 Move all-events check into framework instead of per-test 2018-09-14 16:24:30 -04:00
Matt Corallo
adee6719c4 Split up send_commitment into a const and non-const version 2018-09-14 16:24:30 -04:00
Matt Corallo
9252ddbb1d Remove unused import and uneccessary mut 2018-09-14 16:24:30 -04:00
Matt Corallo
1e3d875be0
Merge pull request #180 from TheBlueMatt/2018-09-htlc-tx-unwrap-fix
Ignore HTLC txn we dont know how to claim instead of unwrap()ing and Do not fail-backwards LocalAnnounced HTLCs upon force-close.
2018-09-14 16:19:38 -04:00
Matt Corallo
aa17defa04 Tweak + extend full_stack_target sample to incl HTLC tx broadcasts 2018-09-14 15:27:54 -04:00
Matt Corallo
68be3c0353 Test that we do not fail-backwards HTLCs that the remote on-chained 2018-09-14 15:27:54 -04:00
Matt Corallo
f48fe4bd8c Make the commitment signed dance a macro in ChannelManager tests 2018-09-14 15:27:53 -04:00
Matt Corallo
5ef88cea34 Do not fail-backwards LocalAnnounced HTLCs upon force-close.
This is completely unsafe as we have provided the remote side with
a commitment_signed which they can broadcast, including the HTLC
transaction, and then could claim it on-chain after we've failed it
backwards!
2018-09-14 15:27:53 -04:00
Matt Corallo
a55355e641 Ignore HTLC txn we dont know how to claim instead of unwrap()ing
This fixes a crash introduced in 3e149b1fb6
and introduces a test which will tickle the bug.
2018-09-14 15:27:39 -04:00
Matt Corallo
e323c13a59
Merge pull request #177 from TheBlueMatt/2018-09-163-cleanups
Optimize some ChannelMonitor stuff after #163
2018-09-13 20:18:21 -04:00
Matt Corallo
66d5d764aa Clean up and clarify tx broadcast checks in channelmonitor tests
This effecitlvey reverts the refactors in 383bd90a48,
however keeps the actully new test code.

It also writes documentation for the super confusing tx test func
and makes it a bit less permissive.
2018-09-13 14:24:37 -04:00
Matt Corallo
e9e27f277a There can only be one input in matched txn in ChannelMonitor
This lets us simplify a few tidbits of loop.
2018-09-13 14:05:08 -04:00
Matt Corallo
27d5a3a94f Optimize check_spend_remote HTLC a tad by avoiding indirections
Instead of hopping a pointer, we're only ever going to return one
Transaction at max, so skip the Vec. Also avoid
re-pubkey-converting the revocation key.
2018-09-13 14:05:08 -04:00
Matt Corallo
01c8e4f56f
Merge pull request #163 from ariard/claim_revoked_htlc_tx
Implement claiming of revoked HTLC transactions by ChannelMonitor
2018-09-13 13:53:47 -04:00
Matt Corallo
77c2622615
Merge pull request #175 from TheBlueMatt/2018-09-173-whitespace-err
raise APIError from send_payment (#173 without whitespace nit)
2018-09-13 13:11:51 -04:00
Yuntai Kyong
ec743351b1 raise APIError from send_payment
add APIError::RouteError
2018-09-13 11:18:03 -04:00
Matt Corallo
84e45f477b
Merge pull request #174 from yuntai/201809-funding_created_sig
verify incoming sig first to fail earlier
2018-09-13 10:31:06 -04:00
Yuntai Kyong
b6cbcc9f40 verify incoming sig first and fail earlier 2018-09-13 22:31:51 +09:00
Antoine Riard
383bd90a48 Add test of claiming HTLC-Timeout outputs based on a revoked commitment
tx
2018-09-12 23:51:02 +00:00
Antoine Riard
3e149b1fb6 Implement claiming of revoked HTLC transactions by ChannelMonitor
Refactor check_spend_remote_transaction in part to check_spend_remote_htlc to
avoid lock mess in block_connected. We need
remote_commitment_txn_on_chain to match remote HTLC tx
2018-09-12 23:50:58 +00:00
Antoine Riard
d84c084df7 Implement set_their_delayed_payment_base_key in ChannelMonitor
Needed to build redeemscript on HTLC-Success/HTLC-Timeout tx from
remote revoked commitment tx
2018-09-12 23:17:20 +00:00
Matt Corallo
648a31b91a
Merge pull request #171 from TheBlueMatt/2018-09-ser-fixes
Correct MAX_BUF_SIZE in serialization
2018-09-12 15:53:14 -04:00
Matt Corallo
d7ed4c63e7 Correct MAX_BUF_SIZE in serialization
I think this might have been my fault due to faulty review
feedback, but fuzzer caught trivial crash here where you try to
send a ping message larger than 16KB (but smaller than the
max-length 64KB) and you crash as message serialization is unwrap()
2018-09-12 13:22:42 -04:00
Matt Corallo
c3e225597d Fix some double-indentation in util/ser 2018-09-12 13:22:42 -04:00
Matt Corallo
f27c74b35c
Merge pull request #167 from TheBlueMatt/2018-09-dup-htlc
Allow duplicate-payment_hash HTLCs for HTLC forwards
2018-09-12 13:07:13 -04:00
Matt Corallo
b2f31c5256
Merge pull request #170 from TheBlueMatt/2018-09-119-rebased
#119 squashed
2018-09-12 11:22:06 -04:00
Matt Corallo
0a65255bd9 Add simple test for duplicate-payment_hash HTLC tracking 2018-09-12 11:15:51 -04:00
Matt Corallo
6b3cc8bb4d Avoid cross-test statics in ChannelManager network tests 2018-09-12 11:15:51 -04:00
Matt Corallo
da5d707f49 Allow duplicate-payment_hash HTLCs for HTLC forwards
This is required by BOLT 2 to ensure that no attacker can simply
relay every public node a duplicate-payment_hash HTLC for each HTLC
it receives to deduce where an HTLC came from.

Note that this makes the claim logic much less incentive-compatible
as we will not claim all available HTLCs with the same payment_hash
even if we know the preimage! This is OK because, most likely, any
attackers trying to map the network will use small-value payments
and, hopefully, we will move away from constant hashes across an
entire payment at some point in the near future.

This further simplifies the payment transition state a bit, so
hopefully at least we got some readability out of all of this
2018-09-12 11:15:47 -04:00
Yuntai Kyong
28a612f9f3 Migrate fuzz router/channel target to Readable
and be more specific about DecodeError::InvalidValue
2018-09-12 10:19:36 -04:00
Yuntai Kyong
3e89106163 migrate peer_handler to use Writeable
added inplace byte_utils
2018-09-12 10:19:36 -04:00
Yuntai Kyong
63cb37d346 Add fuzz targets for Writeable messages/migrate fuzz test 2018-09-12 10:19:36 -04:00
Yuntai Kyong
89475381bb Implement Writeable for messages 2018-09-12 10:18:52 -04:00
Yuntai Kyong
1b8504a3f3 Implement Writer/Reader
with additional variants in DecodeError
2018-09-12 10:18:02 -04:00
Matt Corallo
3b49837862 Split HTLC tracking into separate Inbound/Outbound types
This isnt as simplifying as I'd hoped, but still increases
compile-time checking, which is nice, and removes one of two
panic!()s.
2018-09-11 15:02:10 -04:00
Matt Corallo
bde48b2c15
Merge pull request #165 from TheBlueMatt/2018-09-pre-disconnect-misc
Further minor misc changes from reconnect work
2018-09-11 15:01:35 -04:00
Matt Corallo
a2d4889e32 panic on invalid calls to Channel::send_commitment instead of Err 2018-09-09 11:36:00 -04:00
Matt Corallo
33fa278f33 Do not allow sending HTLCs when the first hop is disconnected 2018-09-09 11:36:00 -04:00
Matt Corallo
8cad2ffa9b Sync get_update_fail_htlc, get_update_fulfill_htlc state err result
Both get_update_fail_htlc and get_update_fulfill_htlc should never
be called before any HTLC could have been accepted (ie
pre-ChannelFunded) nor should they ever be called
post-ShutdownComplete as the Channel object should be destroyed at
that point. Previously get_update_fulfill_htlc would panic, but
get_update_fail_htlc would return an Err. For now make them both
panic but we can revisit this if we want to have fewer panics in
the future.
2018-09-09 11:36:00 -04:00
Matt Corallo
673912e769 Add force_close_channel call command to full_stack_target 2018-09-09 11:36:00 -04:00