Commit graph

720 commits

Author SHA1 Message Date
Matt Corallo
f5ccd4b4ef Add additional log traces in channelmonitor/manager 2018-12-14 17:01:12 -05:00
Antoine Riard
ea6e9a7880 Add logging of HTLC outputs resolved by remote peer justice tx
In case of broadcast of revoked local commitment tx, we may be
interested that we've screwed up
2018-12-14 17:00:51 -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
Matt Corallo
cdbd2ef5a2 Add bigger test for failing HTLCs claimed through revocation 2018-12-14 17:00:22 -05:00
Antoine Riard
0e9ac1144b Add test for failing/fulfilling HTLCs from on-chain actions
Including detection of timeout claims, fulfill claims, and
failing all current HTLCs in case of revoked-commitment broadcast.
2018-12-14 17:00:22 -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
Matt Corallo
badda94022 Generate PaymentFailed events for outbound payments we fail 2018-12-14 17:00:22 -05:00
Matt Corallo
221bfa6bd4 Move monitor-generated HTLC event handling to manager event-getters
This is somewhat awkward, but prevents a slew of duplicate events.
Really this should probably be more explicit, but would be easy to
move that along with a slew of block_connected-event-processing
refactors, see-also GH #80.

This affects full_stack_target only on accident cause the demo test
didn't continue onwards with another block connection.
2018-12-14 17:00:22 -05:00
Matt Corallo
b9c609eb6a Fail all pending HTLCs if the remote broadcasts a revoked tx 2018-12-14 16:46:27 -05:00
Antoine Riard
7499a4bf9b Detect onchain timeout of a HTLC in ChannelManager block_connected
Pass failure backward
2018-12-13 11:53:44 -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
Antoine Riard
664ae42257 Track outputs fron local commitment tx
Aims to detect onchain resolution of channel

Modify in consequence test_txn_broadcast to still pass
channel_monitor_network_test

Modify some tests due to block re-scan caused by
detections extensions
2018-12-11 16:47:02 -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
0bf783ee4a
Merge pull request #263 from TheBlueMatt/2018-12-monitor-fail-2
Handle monitor update failures in msg-recv functions
2018-12-11 14:55:16 -05:00
Matt Corallo
42da58c0c1 Expand comment on ChannelMonitorUpdateErr::PermanentFailure a bit 2018-12-11 13:17:45 -05:00
Matt Corallo
aa0a37cc4b Add test for monitor update failure on CS/RAA/CR handling 2018-12-11 13:17:45 -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
788dd738a8 Swap handle_monitor_update_fail for a macro ala try_chan_entry
This resolves an API bug where send_payment may return a
MonitorUpdateFailed Err both when the payment will not be sent and
when the HTLC will be retried automatically when monitor updating
is restored. This makes it impossible for a client to know when
they should retry a payment and when they should not.
2018-12-11 13:10:02 -05:00
Matt Corallo
16df97d988
Merge pull request #268 from TheBlueMatt/2015-12-fuzz-fix-output-idx
Check tx output matches monitor output data (and is sufficient len)
2018-12-10 15:39:37 -05:00
Matt Corallo
79c0f98c1f Check tx output matches monitor output data (and is sufficient len)
Fixes a panic found by fuzzer in case the monitor per-commitment
data is garbage. We had a similar check for revoked commitment tx
but didn't copy it down to non-revoked commitment tx, so do that
now.
2018-12-10 15:06:35 -05:00
Matt Corallo
33553d7436
Merge pull request #264 from TheBlueMatt/2018-12-198-first-commit
Refactor KeyStorage as Storage
2018-12-04 14:01:22 -05:00
Matt Corallo
823497d5a3 Unify the update pattern in provide_latest_local_commitment_tx_info 2018-12-04 11:24:20 -05:00
Matt Corallo
35bd8c31e8 Simplify ChannelMonitor Storage updates a bit 2018-12-04 11:24:20 -05:00
Matt Corallo
90d2ca37e7 Simplify insert_combine by unimplemented!()ing unimplemented things 2018-12-04 11:24:20 -05:00
Antoine Riard
e86e10b87d Refactor KeyStorage as Storage
Move PrivMode as Local, SigsMode as Watchtower

Cut funnding_txo from ChannelMonitor, move it inside Local

Rename log_funding_option as log_funding_info
2018-12-04 11:24:19 -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
dfbc6c60a7
Merge pull request #265 from TheBlueMatt/2018-12-fuzz-fix-no-witness
Fix crash on no-witness tx in ChannelMonitor found by fuzzer
2018-12-03 14:38:56 -05:00
Matt Corallo
4f9b0fbd3f Avoid writing to stdout during fuzz tests 2018-12-03 13:58:50 -05:00
Matt Corallo
7e94d3a617 Remove unused import in full_stack_target 2018-12-03 13:30:38 -05:00
Matt Corallo
f9c945e17f Fix crash on no-witness tx in ChannelMonitor found by fuzzer
Tehnically we can't currently hit this, but a theoretical future
watchtower could, and full_stack_target crashes on it.
2018-12-03 13:21:20 -05:00
Matt Corallo
0d7156ffc1
Merge pull request #261 from TheBlueMatt/2018-11-reestablish-fix
Fix channel_reestablish generation/handling around next_remote.
2018-12-03 13:17:54 -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
5e9e199279
Merge pull request #258 from TheBlueMatt/2018-11-close-locked
Simplify + document the ChannelManager Err flow, fix close-outside-lock race, finish ChannelError conversion
2018-11-26 10:56:18 -05:00
Matt Corallo
6969fc997b
Merge pull request #259 from TheBlueMatt/2018-11-256-redux
Add test_claim_on_remote_revoked_sizeable_push_msat
2018-11-23 15:21:35 -05:00
Antoine Riard
ab9a98ff5d Add test_claim_on_remote_revoked_sizeable_push_msat 2018-11-23 14:38:02 -05:00
Antoine Riard
546bd37c19 Refactor check spendable outputs macros into one
In consequence, harden spendable outputs tests

Fix vocabulary abuse
2018-11-23 14:38:02 -05:00
Matt Corallo
466d0f61cf Simplify + document the ChannelManager Err flow a bit
This removes all the channel-closure stuff from handle_error!() and
MsgHandleErrInternal, making all the Err handling consistent by
closing the channel before releasing the channel_state lock and
then calling handle_error!() outside of the lock.
2018-11-22 23:57:54 -05: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
032f20275b Properly handle ChannelError::Close results in update_fee.
Best reviewed with -b
2018-11-22 23:57:54 -05:00
Matt Corallo
9fdc349573 Properly handle ChannelError::Close results in send_payment.
Best reviewed with -b
2018-11-22 23:57:54 -05:00
Matt Corallo
31ec11f446 Close channels on Err returns inside the same channel_state lock
If we never accessed channels for a peer outside of a message
handler for that peer then this wouldn't be a problem since message
handlers are required to be serialized per-peer. However, that
isn't the world we live in - we may want to forward payments or we
may get a send_payment call.
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
dfbcacfe0e Split channel_reserve_test so we don't rely on unfilled Err actions
Currently channel_reserve_test sends a garbage update_add_htlc
message and then relies on it being silently ignored to continue
using the channel. This shouldn't be the case, so take the easy
way out and split the test in two, at first not delivering the
bogus update_add_htlc and then delivering it, but not running the
rest of the test.
2018-11-22 23:57:54 -05:00
Matt Corallo
dae97a4858
Merge pull request #257 from TheBlueMatt/2018-11-007-bump
Bump to 0.0.7 for API rev
2018-11-21 16:45:17 -05:00
Matt Corallo
bde921ea20 Bump to 0.0.7 for API rev 2018-11-21 16:18:18 -05:00