Commit graph

223 commits

Author SHA1 Message Date
Matt Corallo
d22650c0cf
Merge pull request #319 from TheBlueMatt/2019-03-htlc-sorting
Fix HTLC-output-in-commitment sorting for duplicate-HTLCs
2019-03-25 13:26:31 -04:00
Matt Corallo
054530cfb9 Fix potential overflow bug introduced in channel reserve check fix
Found by chanmon_fail_consistency fuzz test.
2019-03-22 17:43:32 -04:00
Matt Corallo
c86657ea6c Fix inbound channel reserve check for removed-outbound-HTLCs
Found by chanmon_fail_consistency fuzzer.
2019-03-22 17:43:32 -04:00
Matt Corallo
bb094f1e30
Merge pull request #314 from TheBlueMatt/2019-03-chan-cleanup
Two simple Channel cleanups
2019-03-22 17:16:08 -04:00
Matt Corallo
d990f72f9a Fix HTLC-output-in-commitment sorting for duplicate-HTLCs
This resolves both an issue that hits fuzzing due to hash
collisions as well as implements an update to the BOLT spec.
2019-03-07 13:56:01 -05:00
Tamas Blummer
02b541607b migration to rust-bitcoin 0.17
typedef Sha256dHash with bitcoin_hashes::sha256d::Hash
SecretKey -> PrivateKey.key
assume compressed public keys
2019-03-07 18:50:02 +01:00
Matt Corallo
8d9b1af8c3 Add a useful log_trace before we release holding cell. 2019-03-03 14:23:52 -05:00
Matt Corallo
29ed3e227f Move fail_reason into OutboundHTLCState states
This should probably have happened when we moved most state into
the state enums themselves, but specifically forcing awareness of
the removed/not removed state would have prevented me from
introducing a bug in the first version of an upcoming reserve-value
patch.
2019-03-03 14:23:52 -05:00
Matt Corallo
5f4bb593b8 Log information about channel freeze/restore from monitor updates 2019-01-25 12:04:39 -05:00
Matt Corallo
e5fa4f270a log_trace HTLC changes in Channel::get_update_fulfill_htlc 2019-01-25 12:04:39 -05:00
Matt Corallo
f0bcb7dba0 log_trace HTLC transitions in RAA handling (best reviewed with -b) 2019-01-25 12:04:39 -05:00
Matt Corallo
b2252fb1e4 log_trace information about commitment txn as they're being built 2019-01-25 12:04:39 -05:00
Matt Corallo
bf26056c8a Fix holding cell freeing in case we fail to add some HTLC
Previously, if we went to free the holding cell HTLC updates, and
adding one failed as we hit our outbound HTLC limit (or in-flight
value limit), we would not send a commitment_signed, leaving us in
an invalid state. We first fix that bug, and then refuse to add
things to our holding cell once we reach our limits considering the
holding cell, as we shouldn't have multiple commitment dance rounds
worth of HTLCs in the holding cell anyway.
2019-01-24 21:53:49 -05:00
Matt Corallo
a6f0281017
Merge pull request #288 from TheBlueMatt/2019-01-test-split-raa-flag-fix
Fix several more monitor-update-failed cases
2019-01-24 13:16:33 -05:00
Dimitris Apostolou
ab10b05075
Fix typos 2019-01-24 19:07:08 +02:00
Matt Corallo
658e558fd0 Fix responding to RAAs when monitor updating had already failed 2019-01-23 17:51:46 -05:00
Matt Corallo
98f264372e Remove incorrect debug_assert!() from reestablish handling and test 2019-01-23 17:43:45 -05:00
Matt Corallo
985688852b Fix AwaitingRAA on RAA receipt when monitor updating had failed
This fixes a rather subtle case handling RAAs when we don't
generate a response due to a previous monitor update failure, but
would otherwise send a CS response. We need to still set
AwaitingRemoteRevoke on the channl in question, but previously did
not. Found by chanmon_fail_consistency fuzz test with the failing
test converted and added manually.
2019-01-23 17:43:45 -05:00
Yuko Roodt
4d77e9d752 Added tests to check the bolt 2 specs for Sending Node Channel 2019-01-23 14:54:10 -05:00
Matt Corallo
7a77c9f1d2
Merge pull request #298 from TheBlueMatt/2019-01-271-cleanup
Implement serialize/deserialize for Router
2019-01-23 14:48:13 -05:00
Antoine Riard
70d06b4610 Implement Writeable/Readable for Option<T>
Add OptionalField in OpenChannel, AcceptChannel
ChannelReestablish to avoid serialization implementation
conflicts
2019-01-23 11:31:26 -05:00
Matt Corallo
4cceb58f91 Rewrite monitor_update_failed as it didn't capture all the options
Primarily this fixes the case where we receive an RAA which does
not require a response, allowing us to call monitor_update_failed
without generating pending messages.
2019-01-22 14:34:18 -05:00
Matt Corallo
8678bda576 Ensure Message always unwraps in fuzztarget
Hashes cant be all-0s, so we can normally unwrap, but fuzztarget
can generate all-0 hashes, so we have to handle it and swap for
something else.
2019-01-22 13:49:15 -05:00
Matt Corallo
12d25576c1 Upgrade to secp256k1 v12, bitcoin v16, and crates bitcoin_hashes 2019-01-22 13:49:15 -05:00
Philip Robinson
a48fb848d9 Wrote test to explicitly test BOLT 2 requirements for update_add_htlc
(minor tweaks by @TheBlueMatt)
2019-01-22 12:22:14 -05:00
Matt Corallo
92424ebbfe Merge tracking of HTLCs-in-commitment with outbound-HTLCs
This simplifies a few things, deduplicates a some small memory
overhead, and, most importantly, is a first step to fixing
would_broadcast_at_height.
2019-01-13 12:59:19 -05:00
Matt Corallo
09919d2af0 Make HTLCOutputInCommitment::transaction_output_index an Option
We really shouldn't have split out the with-source HTLCs from the
in-transaction HTLCs when we added back-failing, and will need
almost all of the info in HTLCOutputInCommitment for each HTLC to
fix would_broadcast_at_height, so this is a first step at
recombining them.
2019-01-11 16:03:40 -05:00
Matt Corallo
608cf1c89d Fail HTLC backwards on unrevoked remote commitment tx broadcast 2018-12-31 19:56:32 -05:00
Matt Corallo
044edd6e86 Fail HTLCs backwards asynchronously 2018-12-21 15:17:42 -05:00
Matt Corallo
c220a5c5cf Add an enum option to pending forwards to fail backwards 2018-12-20 22:56:32 -05:00
Matt Corallo
8e07259326 Use bitcoin_hashes' Ripemd160/Hash160 from rust-crypto+rust-bitcoin
Note that this requires rewriting full_stack_target tests, which
sucks, but it does let the fuzzer hit more stuff since the real
ripemd160 isn't ever actually called anymore.
2018-12-19 20:02:36 -05:00
Matt Corallo
f1e400f142 Switch Sha256 to using bitcoin_hashes and our own HKDF 2018-12-19 17:13:25 -05:00
Antoine Riard
7a483e597c Typify payment_hash and payment_preimage
Fix variable name as payment_hash instead of txid for index
of remote_hash_commitment_number in ChannelMonitor reader
2018-12-14 17:00:50 -05:00
Antoine Riard
b1e313f26d Add const ACCEPTED_HTLC_SCRIPT_WEIGHT and OFFERED_HTLC_SCRIPT_WEIGHT to
ease readability

Conditionnal compilation for weight of second one to handle test special
cltv values
2018-12-14 17:00:22 -05:00
Antoine Riard
96d17ee737 Add is_resolving_output in ChannelMonitor
Called in ChannelMonitor block_connected, returning
HTLCUpdate upstream via ManyChannelMonitor to
link htlcs between monitors. Used by ChannelManager to
fulfill/fail htlcs backwards accordingly

If spurrious HTLCUpdate are generated due to block re-scan
and htlc are already LocalRemoved, discard them in
channel get_update_*_htlc
2018-12-13 11:53:44 -05:00
Matt Corallo
3b7ef49ef6 Return refs from build_commitment_transaction, removing clone()s 2018-12-13 11:12:07 -05:00
Antoine Riard
160d63dba0 Track HTLCSource in ChannelMonitor
Insert it in current_local_signed_tx, prev_local_signed_tx,
remote_claimable_outpoints. For so get it provided by
Channel calls to provide_latest_{local,remote}_tx
2018-12-13 11:12:07 -05:00
Matt Corallo
302f1314e5
Merge pull request #266 from TheBlueMatt/2018-12-closing_signed-3-leg-commitment
Remove check which makes us sometimes never send closing_signed
2018-12-11 16:40:22 -05:00
Matt Corallo
787644d795 Handle monitor update failures in msg-recv functions
This adds a few TODOs around further message rebroadcasting which
needs to be implemented as well as some loss of tracking of HTLCs
on permanent channel failure which needs to get transferred over to
the appropriate in-memory ChannelMonitor.
2018-12-11 13:17:45 -05:00
Matt Corallo
a2df43d525 Remove check which makes us sometimes never send closing_signed
This is the case pointed out by nayuta-gondo at
https://github.com/lightningnetwork/lightning-rfc/issues/499#issuecomment-438623208
though this doesn't actually solve the issue of ensuring we have a
consistent fee view when we start shutdown processing. There isn't
a clear solution to that however without adding additional state
tracking in Channel.

This also removes an associated test that tests for the correct
behavior (but didn't consider the bug) as we no longer behave
correctly. This should be fine as we'll be removing all the
update_fee garbage with option_simplified_commitment anyway.
2018-12-03 17:04:19 -05:00
Matt Corallo
23c2cef5f4 Fix channel_reestablish generation/handling around next_remote. 2018-12-02 17:26:16 -05:00
Matt Corallo
26a7192689
Merge pull request #260 from yuntai/201811-sessionkey
Add a method to get session secret for onion packet to KeysInterface
2018-11-26 22:09:42 -05:00
Yuntai Kyong
7e59e1e392 Add a method to get session secret for onion packet to KeysInterface 2018-11-27 10:44:51 +09:00
Matt Corallo
fe3d706d5b Remove MsgHandleErrInternal::from_chan_maybe_close as it's useless
Technically funding_transaction_generated was fine using it, but
calling force_shutdown on an empty Channel inside the channel_state
lock isn't a big deal and almost any other use of it would be
unsafe.
2018-11-22 23:57:54 -05:00
Matt Corallo
bac091cdb9 Stop needlessly returning &HTLCSource out of Channel.
This moves a clone() inside Channel from ChannelManager making
references simpler for the coming refactors.
2018-11-22 23:57:54 -05:00
Matt Corallo
6032099469 Remove remaining uses of HandleError in Channel Err return values
This converts block_connected failures to returning the
ErrorMessage that needs to be sent directly, since it always
results in channel closure and never results in needing to call
force_shutdown. It also converts update_add_htlc and closing_signed
handlers to ChannelError as the rest of the message handlers.
2018-11-22 23:57:54 -05:00
Matt Corallo
90b0ed937e Provide commitment point to monitor with the remote txn update
This extends 1b33064554 by
re-simplifying the ChannelMonitor <-> Channel interface a bit as we
never have any use for the latest remote commitment point until we
have knowledge of a remote transaction generated using it.
2018-11-20 19:03:57 -05:00
Matt Corallo
90816dd9d8 Move a ton of Channel functions to ChannelError from HandleError
This is a big patch, but its all very mechanical, everything here
should be pretty obvious, and it all has to happen at once due to a
few common utility functions all having the same return type.

Note that this exposes a race in channel closure where we may
access a channel via some non-peer-specific mechanism like
forwarding an HTLC or sending a payment during the time between
the channel gave us a Close error and expected us to never call it
again and the time we actually removed it from the channel_state
set outside of the internal_* handler.
2018-11-20 16:33:32 -05:00
Matt Corallo
3155890766 Create simple ChannelMonitor-specific Err type 2018-11-20 16:31:41 -05:00
Matt Corallo
86944d34a1
Merge pull request #231 from philipr-za/philip-204-check-commitment-transaction-fee
Check funder can afford commitment transaction fee when receiving update_fee
2018-11-20 16:29:21 -05:00