Commit graph

133 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
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
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
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
42da58c0c1 Expand comment on ChannelMonitorUpdateErr::PermanentFailure a bit 2018-12-11 13:17:45 -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
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
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
3af20fd507 Check P2WPKH script against expected before gen'ing an output event
This fixes a bug in 3518f1f85d where
we may generate an output event for a P2WPKH output which is not
ours if the transaction has a sequence/lock_time combination which
false-positives our remote tx detection.

Also note that the TODO is removed as this should already be
covered without issue if the client properly replays the chain on
restart.
2018-11-20 19:03:57 -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
3155890766 Create simple ChannelMonitor-specific Err type 2018-11-20 16:31:41 -05:00
Antoine Riard
394b11c7b5 Add key_storage selection in ChannelMonitor insert_combine
Based on commitment_number
2018-11-19 20:42:55 -05:00
Antoine Riard
1255885a80 Add check_spend_closing_transaction ChannelMonitor
Aims to send back closing output descriptor to user wallet
2018-11-19 20:40:07 -05:00
Antoine Riard
3518f1f85d Add test_static_spendable_outputs_preimage_tx
Aims to covered both keysinterace preimage tx case and
detection of second remote commitment tx

Split DynamicDescriptor between *P2WSH and *P2WKH
2018-11-19 20:39:38 -05:00
Antoine Riard
1b33064554 Split provide_their_next_commitment_point from provide_secret
We needed it to be able to track remote_per_commitment_point
after channel opening and funds locking
2018-11-15 19:08:27 -05:00
Antoine Riard
f88f826b28 Add TxOut in DynamicOutput 2018-11-15 19:07:34 -05:00
Antoine Riard
04e6be9f00 Implement spendable output to_local output on local commitment tx 2018-11-15 19:07:34 -05:00
Steven Roose
7ff7561f2d Update to rust-bitcoin v0.15 2018-11-14 11:43:54 +00:00
Matt Corallo
64bd2eaa7f Give ManyChannelMonitor a logger and trace add_update events 2018-10-29 14:26:05 -04:00
Matt Corallo
a2fb3ccc08 Implement and document Channel/ChannelManager (de)serialization 2018-10-27 09:58:10 -04:00
Matt Corallo
b2bd64d2eb Store+expose bits of Channel[Monitor] to figure out local state 2018-10-27 09:42:04 -04:00
Matt Corallo
6f08779b04 Track ChannelMonitor-watched-outpoints (+ remove now-uesless Mutex) 2018-10-27 09:42:04 -04:00
Matt Corallo
56513f2927 Track last_block_hash in ChannelMonitor and expose it on deser
Also make block_connected take a &mut self to ensure serialized
state will always be self-consistent.
2018-10-27 09:42:04 -04:00
Matt Corallo
612e2801f8 Redo ChannelMonitor deserialization to avoid read_to_end()
This slightly changes the serialization format, but we're still
early enough that that's OK.
2018-10-27 09:42:04 -04:00
Matt Corallo
47fe673c57 Give ChannelMonitor a logger via new ReadableArgs trait 2018-10-27 09:42:04 -04:00
Antoine Riard
8c235d9e28 Generate Events from ChannelMonitor to indicate spendable ouputs
Extend KeyStorage with delayed_payment_base_key and per_commitment_point
to derive local_delayed private key
2018-10-27 09:34:28 -04:00
Matt Corallo
497643a65b Add basic sanity testing for channel monitor update failure handle 2018-10-23 16:03:30 -04:00
Matt Corallo
267b9a44df ChannelManager support for monitor update failure in one place 2018-10-23 16:03:30 -04:00
Matt Corallo
d318184c9e Avoid needless on-chain channel failing for timing-out HTLCs
See new comments in code for more details
2018-10-22 11:49:57 -04:00
Antoine Riard
09831934d1 Test htlc outputs single tx claim due to timeout case 2018-09-29 20:28:15 -04:00
Matt Corallo
ae8bd1ba48 Fix and test simple remote-revoked-commitment-output claiming 2018-09-29 20:27:05 -04:00
Matt Corallo
ea8a1f3506 Narrow check_spend_remote_htlc input/output count check.
This fixes a crash found by fuzztester where a 0-output tx causes a
[] panic (though this shouldn't happen in the real-world as
0-output txn should never be able to be mined).
2018-09-26 11:06:28 -04:00
Matt Corallo
6e1318b0e2 Make docs look nicer by adding explicit spacing 2018-09-20 12:58:10 -04:00
Matt Corallo
79a0a0c959 Migrate ChannelMonitor serialization to new ser framework(ish)
Sadly we can't straight up use the new serialization framework as
we have a few different serialization variants, but that's OK, it
looks identical and is just missing the Writeable impl
2018-09-20 10:46:13 -04:00
Matt Corallo
28d0d44e44 Move ChannelMonitor deserialization to new ser framework 2018-09-20 10:46:13 -04:00
Matt Corallo
3aeec96470 Add module and all-pub-things docs and deny missing docs 2018-09-19 23:07:02 -04:00
Matt Corallo
9373c5993f Make message fields pub(crate) and hide a few internal fns 2018-09-19 23:07:02 -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
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
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
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