Commit graph

190 commits

Author SHA1 Message Date
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
Matt Corallo
7efaf2e8ac
Merge pull request #230 from ariard/handle_sizeable_push_msat
Handle sizeable push msat (fix #195) + handle two first per_commitment_point + keys interface tests
2018-11-20 15:51:27 -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
Matt Corallo
b14baa03ab
Merge pull request #253 from TheBlueMatt/2018-11-misc-tweaks
Misc Tweaks
2018-11-16 11:47:50 -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
8c638ffc81 Track local_commitment_tx at funding_created
Goal to claim sizeable push_msat and in event of
local commitment tx being broadcast without htlcs
2018-11-15 19:07:34 -05:00
Matt Corallo
968720344c Panic if funding transaction has non-witness inputs 2018-11-15 12:25:09 -05:00
Matt Corallo
ed006f5e46 Clarify get_update_*_htlc docs and tweak one case slightly 2018-11-15 12:22:16 -05:00
Philip Robinson
a51dbb4a4d Check affordability of new fee during update_fee call #204 2018-11-14 14:14:10 +02:00
Steven Roose
7ff7561f2d Update to rust-bitcoin v0.15 2018-11-14 11:43:54 +00:00
Matt Corallo
224fb05cc5 Rebroadcast shutdown on channel_reestablish (and reprocess them) 2018-11-02 22:26:51 -04:00
Matt Corallo
527d036c1b Delay closing_signed until update_fee exchanges complete
See https://github.com/lightningnetwork/lightning-rfc/issues/499
for a bit more about the ambiguity we're addressing here.

Also drop holding cell update_fee the same way we drop holding
cell update_add_htlcs when sending shutdown, resolving a bug.
2018-11-02 22:26:51 -04:00
Matt Corallo
78232f2aed Fail incoming HTLCs sent after we start shutdown, not the chan 2018-11-02 22:26:51 -04:00
Matt Corallo
a11e27d20e Send closing_signed when appropriate as pending HTLCs clear 2018-11-01 17:08:53 -04:00
Matt Corallo
1993ec0d12 Always send Shutdown resposnes to Shutdown messages
We always require that any changes to Channel state be committed
immediately (within the same lock) so we should never have
uncommitted changes which would prevent us from sending a Shutdown
response.
2018-11-01 17:06:07 -04:00
Matt Corallo
7bb598e525 Refactor out first-closing-sent creation 2018-11-01 17:05:56 -04:00
Matt Corallo
4eb8a4905c Use ChannelError in shutdown handling, clean up, impl err actions 2018-11-01 13:50:03 -04:00
Schalk van Heerden
a0be4d1758 Added config interface to allow users to specify channel limits 2018-10-31 15:45:30 -04:00
Matt Corallo
9189d0e61d Require at least 1k sat for outbound channels and meet BTC's dust 2018-10-31 15:45:30 -04:00
Matt Corallo
55a74b5dab Use non-funder's funding block wait instead of max with ours
This is both required by the protocol and also makes sense - if
we're the funder we don't mind accepting payment on the channel
after one confirmation because we assume we won't double-spend
ourselves.
2018-10-31 15:45:30 -04:00
Matt Corallo
4a51f4f073 fix broken state comparison (thanks @yuntai!) 2018-10-27 09:58:10 -04:00
Matt Corallo
6ed5a829bb Fix + test disconnect/reconnect prior to FundingLocked 2018-10-27 09:58:10 -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
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
47fe673c57 Give ChannelMonitor a logger via new ReadableArgs trait 2018-10-27 09:42:04 -04:00
Matt Corallo
c0c139cdc2 Fix and test update_add_htlc but disconnect pre-commitment_signed 2018-10-27 09:42:04 -04:00
Matt Corallo
e2de49ddc4 Respond to channel_reestablish out-of-band for ordered delivery 2018-10-27 09:42:04 -04:00
Antoine Riard
5180686b1d Integrate destination_script from KeysInterface in ChannelManager/Channel
Drop channel_monitor_claim_key from ChannelKeys
2018-10-27 09:42:04 -04:00
Antoine Riard
32a9378909 Integrate shutdown_pubkey from KeysInterface in ChannelManager/Channel
Drop channel_close_key from ChannelKeys
2018-10-27 09:42:04 -04:00
Antoine Riard
e361fed0f1 Integrate KeysInterface to ChannelManager with Arc 2018-10-27 09:42:04 -04:00
Antoine Riard
d33cb3cca5 Add a KeysInterface which provides keys from user
Move ChannelKeys into keysinterface for generate a set of it from
master_seed and change return type to panic on bogus data
2018-10-27 09:34:45 -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