Commit graph

1391 commits

Author SHA1 Message Date
Matt Corallo
f0e9524e6d Add a constant and docs for when we should fail an HTLC. 2020-04-24 14:28:20 -04:00
Matt Corallo
86a2607b00
Merge pull request #601 from D4nte/ci-in-github-action
Add GitHub Action to build the project
2020-04-24 18:14:55 +00:00
Franck Royer
06419a2608
Add a pop of colour 2020-04-24 15:06:15 +10:00
Franck Royer
355dbbcde9
Add CI using GitHub Action
Same setup than Travis except for removing
`rm -f target/debug/lightning-*` as I do not believe
such file would exist on a fresh run.

I have not setup caching at this stage. The library is
small so I don't think it'd be that necessary/helpful.

I'd recommend to let both CI run for a bit to compare
performance and stability. The CI setup is straightforward
so I do not foresee any issue with GitHub actions.

Once happy, Travis file can be removed and branch
protection checks can be updated to block on the GitHub
actions.

You can also check the [Coverage report](752a58bc04/lightning/src/chain) to ensure it is as expected.
2020-04-24 14:49:22 +10:00
Matt Corallo
5b24d3e327
Merge pull request #597 from TheBlueMatt/2020-04-more-chanmon-cleanups
Few more ChannelMonitor Cleanups
2020-04-23 18:15:47 +00:00
Matt Corallo
80055d4bb4 De-Option<> current_local_signed_commitment_tx in ChannelMonitor
Since we now are always initialised with an initial local commitment
transaction available now, we might as well take advantage of it and
stop using an Option<> where we don't need to.
2020-04-23 13:34:57 -04:00
Matt Corallo
5d0bfa3834 Delay creating outbound ChannelMonitor until funding_signed rcpt
Previously, we created the initial ChannelMonitor on outbound
channels when we generated the funding_created message. This was
somewhat unnecessary as, at that time, we hadn't yet received
clearance to broadcast our initial funding transaction, and thus
there should never be any use for a ChannelMonitor. It also
complicated ChannelMonitor a bit as, at this point, we didn't have
an initial local commitment transaction.

By moving the creation of the initial ChannelMonitor to when we
receive our counterparty's funding_signed, we can ensure that any
ChannelMonitor will always have both a latest remote commitment tx
and a latest local commitment tx for broadcast.

This also fixes a strange API where we would close a channel
unceremoniously on peer-disconnection if we hadn't yet received the
funding_signed, but we'd already have a ChannelMonitor for that
channel. While it isn't strictly a bug (some potential DoS issues
aside), it is strange that these two definitions of a channel being
open were not in sync.
2020-04-23 13:34:57 -04:00
Matt Corallo
3ea13194e8 Add HTLC/extra data in LocalCommitmentTransaction from construction
1107ab06c3 introduced some additional
metadata, including per-HTLC data in LocalCommitmentTransaction. To
keep diff reasonable it did so in ChannelMonitor after the
LocalCommitmentTransaction had been constructed and passed over the
wall, but there's little reason to do so - we should just be
constructing them with the data from the start, filled in by Channel.

This cleans up some internal interfaces a bit, slightly reduces
some data duplication and moves us one step forward to exposing
the guts of LocalCommitmentTransaction publicly in a sensible way.
2020-04-23 13:34:57 -04:00
Matt Corallo
ba75b3ecd7 Drop redundant parameters in sign_local_commitment_tx
The ChanKeys is created with knowledge of the Channel's value and
funding redeemscript up-front, so we should not be providing it
when making signing requests.
2020-04-23 13:34:57 -04:00
Matt Corallo
ddda194d53 Avoid a few useless clone() calls in onchaintx.rs
3d640da5c3 looped over a new HashMap
new_claims, clone()ing entries out of it right before droppng the
whole thing. This is an obvious candidate for drain(..).
2020-04-23 13:34:57 -04:00
Matt Corallo
71f1eba91f Clarify documentation on deserialization reorg requirements 2020-04-23 13:34:56 -04:00
Franck Royer
e6e69f51b9
Use more generic name as it will be use in GitHub Action too 2020-04-23 09:36:48 +10:00
Matt Corallo
b04219a767 Drop ChannelMonitor::write_for_watchtower
Not only was watchtower mode never implemented, but the bits that
we had were removed some time ago. It doesn't seem likely we'll
move forward with a "watchtower-mode" ChannelMonitor, instead
we'll likely have some other, separate struct for this.
2020-04-22 16:48:13 -04:00
Matt Corallo
99a34e1d17
Merge pull request #602 from murtyjones/test-byte-utils
Add tests to byte_utils.rs
2020-04-22 20:45:04 +00:00
Matt Corallo
82c81357e2
Merge pull request #603 from moneyball/patch-3
fixed typo
2020-04-22 20:43:45 +00:00
Steve Lee
3e2f2b4472
fixed typo 2020-04-22 10:52:32 -07:00
Marty Jones
f5a6796a47
Update lightning/src/util/byte_utils.rs 2020-04-21 20:29:46 -04:00
Marty Jones
09a39725f8 add tests 2020-04-21 20:27:35 -04:00
Matt Corallo
5a2ed03247
Merge pull request #594 from TheBlueMatt/2020-04-cleanups
Trivial Cleanups
2020-04-20 21:54:35 +00:00
Matt Corallo
900d900035
Merge pull request #596 from D4nte/586-update-htlc-error-code-content
Include `height` to `incorrect_or_unknown_payment_details` failure
2020-04-20 05:14:18 +00:00
Franck Royer
236887da76
Test that height is included for incorrect payment details
Ensure that the best know blockchain height is included in the
data of `incorrect_or_unknown_payment_details` message failure.
2020-04-20 08:30:47 +10:00
Franck Royer
fae46a02e3
Include height to incorrect_or_unknown_payment_details failure
`incorrect_or_unknown_payment_details` failure message,
`0x4000 (PERM) | 15`, should include the following data:
- [u64:htlc_msat]
- [u32:height]
This patches ensure that the height is included in all
the occurrences of this failure message.
2020-04-20 08:30:45 +10:00
Matt Corallo
c89514c37c De-Option<> some fields in ChannelMonitor which are set at init
After we moved the ChannelMonitor creation later during Channel
init, we never went back and cleaned up ChannelMonitor to remove
a number of now-useless Option<>s, so we do that now.
2020-04-18 22:02:38 -04:00
Matt Corallo
f5b0663f6a Drop std::error::Error impl for DecodeError
It appears to be effectively-deprecated in Rust now, and didn't
really appear to serve a lot of purpose anyway.
2020-04-18 20:47:16 -04:00
Matt Corallo
7e0b57615f Concretize some types in fuzz, addressing new rustc warnings 2020-04-18 20:47:16 -04:00
Matt Corallo
41b3be7ad0 Fix new rustc warnings for unnecessary parenthesis 2020-04-18 20:47:16 -04:00
Matt Corallo
e286afd0b0 Drop uneccessary indirection in map-updating in 1107ab06c3
1107ab06c3 added a Vec of future
updates to apply during a loop, fixing a borrow checker issue that
didn't exist in the merged version of the patch. This simply reverts
that small part of the change.
2020-04-18 20:47:16 -04:00
Matt Corallo
b9db2ec687
Merge pull request #558 from TheBlueMatt/2020-03-555-nits
Flatten ChannelMonitor substructs that don't add clarity
2020-04-19 00:19:21 +00:00
Matt Corallo
b49e63b1bc Flatten ChannelMonitor substructs that don't add clarity
The new OnchainDetection struct (which is the remnants of the old
KeyStorage enum, which was removed in 1dbda4faed)
doesn't really add any clarity to ChannelMonitor, so best to just
drop it and move its members into ChannelMonitor directly.
2020-04-18 18:10:54 -04:00
Matt Corallo
3c5ba6b619 Drop uneccessary clone() introduced in 16fba9fd66 2020-04-18 18:09:43 -04:00
Matt Corallo
02c1925c16
Merge pull request #559 from ariard/2020-03-move-local-commitment
Split parsing and transaction management for local transactions between Chanmon/Onchain
2020-04-18 00:05:11 +00:00
Antoine Riard
95830edac7 Add test_update_err_monitor_lockdown
This test tries the new lockdown logic in case of a signed-and-broadcast
local commitment transaction while a concurrent ChannelMonitorUpdate for
a next _local_ commitment is submitted from offchain. Update is rejected
as expected with a ChannelMonitorUpdateErr.
2020-04-17 17:50:26 -04:00
Antoine Riard
851ab92ea2 Monitor should panic on receiving buggy update sequences
Channel shouldn't send a ChannelForceClosed update followed by
a LatestLocalCommitmentTxInfo as it would be a programming error
leading to risk of money loss. Force-closing the channel will
broadcast the local commitment transaction, if the revocation
secret for this one is released after its broadcast, it would
allow remote party to claim outputs on this transaction using
the revocation path.
2020-04-17 17:50:26 -04:00
Antoine Riard
ba880e3662 Make acces and signature of local commitment transaction unique
Local commitment transaction broadcast can be triggered by a)
a Channel force-close or b) reaching some block height implying
a onchain HTLC-timeout. If one of this condition is fulfilled,
commitment is signed and from then any state update would be
rejected.

ChannelMonitor init at Channel creation need to be refactored
before to make get_fully_signed_local_tx infaillible to avoid
choking in the test framework.
2020-04-17 17:50:26 -04:00
Antoine Riard
9faf6ca85f Remove temporary anti-duplicata logic 2020-04-17 17:50:26 -04:00
Antoine Riard
1107ab06c3 Move HTLC tx generation in OnchainTxHandler
HTLC Transaction can't be bumped without sighash changes
so their gneeration is one-time for nwo. We move them in
OnchainTxHandler for simplifying ChannelMonitor and to prepare
storage of keys material behind one external signer interface.

Some tests break due to change in transaction broadcaster order.
Number of transactions may vary because of temporary anti-duplicata
tweak can't dissociate between 2- broadcast from different
origins (ChannelMonitor, ChannelManager) and 2-broadcast from same
component.
2020-04-17 17:50:21 -04:00
Antoine Riard
8369541f63 Add OnchainTxHandler::get_fully_signed_htlc
In case of channel force-closure, access to local commitment
transactions and its dependent HTLCs is needed. Instead of using
broadcast_by_local_state which registers outpoint to claim and
outputs to watch which are going to be discarded in this case,
we simply ask OnchainTxHandler to build and sign HTLC transactions
through new API.
2020-04-17 17:43:50 -04:00
Antoine Riard
6b8a516647 Cache csv_local inside OnchainTxHandler
csv_local is csv_delay encumbering local revokable_redeemscript
for to_local an htlc output on local commitment/HTLC transactions.
2020-04-17 17:43:50 -04:00
Antoine Riard
080afeb6ea Cache per-HTLC data in OnchainTxHandler::HTLCTxCache
Splitting further parsing from transaction generation, we cache
transaction elements needed for local HTLC transaction inside
OnchainTxHandler. Duplicated data will be removed from ChannelMonitor
in future commits.
2020-04-17 17:43:50 -04:00
Antoine Riard
010fb3051c Cache HTLC transaction material inside OnchainTxHandler
Splitting further parsing from transaction generation, we cache
transaction elements needed for local HTLC transaction inside
OnchainTxHandler. Duplicated data will be removed from ChannelMonitor
in future commits.
2020-04-17 17:43:50 -04:00
Antoine Riard
c2347d61b4 Remove signing htlc transaction from ChannelMonitor
Extend external signer interface to sign HTLC transactions on its
behalf without seckey passing. This move will allow us to remove
key access access from ChannelMonitor hot memory in further work.

HTLC transactions should stay half-signed by remote until
we need to broadcast them for timing-out/claiming HTLCs onchain.
2020-04-17 17:43:50 -04:00
Antoine Riard
7e395e0265 Remove per_input_material introduce in commit 0011713
Caching of input material for HTLC transaction was introducted
prevently but since then API (InputMaterial) has changed
between ChannelMonitor and OnchainTxHandler
2020-04-17 17:43:50 -04:00
Antoine Riard
3cb61e979c Access signed local commitment through OnchainTxHandler
Implementing dynamic fee bumping implied to cache transaction material
including its witness, to generate a bumped version if needed.

ChannelMonitor is slowly rescoped to its parsing function with ongoing
patchset and data duplicata are removed. If signed local commitment tx
access is needed, it's done through OnchainTxHandler extended API

For test framework purpose, we use the test-only method
ChannelMonitor::unsafe_get_latest_local_commitment_txn to intentionally
generate unsafe local commitment to exerce revocation logic.
2020-04-17 17:43:50 -04:00
Antoine Riard
493ffb81e1 Cache current local commitment number in ChannelMonitor.
By caching current local commitment number instead of deciphering
it from local commitment tx, we may remove local commitment tx
from ChannelMonitor in next commit.
2020-04-17 17:43:50 -04:00
Antoine Riard
2be1f72005 Move local commitment tx generation in OnchainTxHandler
Local Commitment Transaction can't be bumped without anchor outputs
so their generation is one-time for now. We move them in
OnchainTxHandler for simplifying ChannelMonitor and to prepare
storage of keys material behind one external signer interface.

Some tests break due to change in transaction broadcast order but
number of transactions broadcast should stay the same.
2020-04-17 17:43:50 -04:00
Antoine Riard
e46e183084 Prevent any update of local commitment transaction once signed
To prevent any unsafe state discrepancy between offchain and onchain,
once local commitment transaction has been signed due to an event
(either block height for HTLC-timeout or channel force-closure), don't
allow any further update of local commitment transaction view
to avoid delivery of revocation secret to counterparty for the
aformentionned signed transaction.
2020-04-17 17:43:50 -04:00
Antoine Riard
73e0a0112a Cache local_commitment_tx in OnchainTxHandler
As transaction generation and signature is headed to be moved
inside OnchainTxHandler, cache local_commitment_tx signed by remote.

If access to local commitment transaction is needed, we extend Onchain
TxHandler API to do so.
2020-04-17 17:43:50 -04:00
Antoine Riard
04a17b2a15 Cache funding_redeemscript in OnchainTxHandler
As transaction generation and signature is headed to be moved
inside OnchainTxHandler, cache any usefule witness element.
2020-04-17 17:43:50 -04:00
Antoine Riard
f60519daf2 Remove duplicata for local commitment+HTLC txn
Previously, we would regenerate this class of txn twice due to
block-rescan triggered by new watching outputs registered.

This commmit doesn't change behavior, it only tweaks TestBroadcaster
to ensure we modify cleanly tests anticipating next commit
refactor.
2020-04-17 17:43:34 -04:00
Matt Corallo
a44454e1da
Merge pull request #589 from jkczyz/2020-04-feature-fixes
Missing feature checks and tests
2020-04-17 20:03:06 +00:00