Commit Graph

194 Commits

Author SHA1 Message Date
Olaoluwa Osuntokun
0086e6e427
lnwallet: in extractHtlcResolutions use csvDelay gated on commitment ownership
This commit fixes a bug wherein we would use the incorrect csvDelay
when crafting HTLC resolutions after a unilateral channel closure.
Previously, we would always use the csvDelay of the local party, as in
the force close case that’s the correct value. However, a unilateral
channel closure instead requires the _remote_ delay.
2017-09-26 19:06:55 -07:00
Olaoluwa Osuntokun
21782374c9
lnwallet: properly use delayKey for htlc-timeout tx in newHtlcResolution
This commit fixes an existing bug when crafting the HTLC resolution in
the face of a commitment broadcast. Previously, we we’re using the
localKey which is incorrect, as directly below we properly use the
delayKey when crafting the secondLevelHtlcScript to sign.
2017-09-26 18:31:22 -07:00
Olaoluwa Osuntokun
8a682d9ec3
lnwallet: add a MaturityDelay field to UnilateralCloseSummary
This commit adds a new field: MaturityDelay, to the
UnilateralCloseSummary struct. This new field will be required, in an
upcoming update as it’s needed in order to properly sweep the
second-level HTLC outputs after MaturityDelay blocks has passed since
confirmation.
2017-09-26 18:00:24 -07:00
Olaoluwa Osuntokun
34604f6214
lnwallet: properly use the p2wkh script in SignDesc for retributions
This commit fixes a minor bug (that doesn’t affect anything atm) when
crafting the SignDesc for sweeping breached outputs. Previously, we
would take the p2wkh script and then p2wsh-ify that, placing that into
the SignDesc. This is incorrect as the p2wkh script is “injected” into
the sighash when signing, and thus doesn’t need another encoding layer.
2017-09-26 17:57:29 -07:00
Olaoluwa Osuntokun
1d487ea78b Merge pull request #341 from cfromknecht/breach-filter-commit-dust
Breach Arbiter Ignore Dust Commitment Outputs
2017-09-26 17:10:12 -07:00
Conner Fromknecht
223f77d135
lnwallet/channel: filter commitment outputs if dust 2017-09-25 18:57:03 -07:00
Olaoluwa Osuntokun
21d151d2ce
lnwallet: ensure the goroutines of all channels are stopped after test execution 2017-09-24 20:20:15 -07:00
Olaoluwa Osuntokun
9164cc218a
lnwallet: modify ReceiveFailHTLC to return value of HTLC failed 2017-09-24 20:17:53 -07:00
Olaoluwa Osuntokun
f576a74bf6
lnwallet: modify SettleHTLC to return value of HTLC settled
This commit adds an additional return value to SettleHTLC in order to
make way for an upcoming change to modify the way bandwidth status from
the link to the switch is reported.
2017-09-24 20:17:14 -07:00
Olaoluwa Osuntokun
815826caac
lnwallet: remove public LocalAvailableBalance method from channel
This commit removes the current active LocalAvailableBalance method
from the channel state machine itself. We still maintain the internal
availableLocalBalance method locally as this is used to ensure that we
don’t add an HTLC which puts our available balance below zero.
2017-09-24 20:13:04 -07:00
Conner Fromknecht
faf1d40bd0
lnwallet/channel: adds directionality htlc retributions
This commit also adds an incoming flag to
        HtlcRetribution struct to allow the breach arbiter to
        generate the appropriate witness based on the htlc's
        directionality.

        It also ensures that the size of the htlc retribution
        slice is now determined by the size of the number of
        htlcs present in the revoked snapshot, which fixes a
        minor bug that could lead to nil pointer deferences.
2017-09-19 19:18:20 -07:00
Olaoluwa Osuntokun
a52d405998
lnwallet: ensure HTLC values are properly converted to SAT in commit tx
This commit fixes a bug within the HTLC construction and commitment
transaction construction that would result in HTLC _values_ within the
commitment transaction being off by a factor of 1000. This was due to
the fact that we failed to convert the amount of an HTLC, in mSAT, to
SAT before placing it as an output within the commitment transaction.
When attempt to locate the output index of a particular half, we use
the unconverted amount, meaning it was unnoticed.

This commit adds a new assertion within the TestSimpleAddSettleWorkflow
test to ensure that the HTLC is found within the commitment transaction
with the proper value in satoshi.
2017-08-30 15:34:18 -07:00
Olaoluwa Osuntokun
6e54aba7ac
lnwallet: convert channel state machine accounting to milli-satoshi 2017-08-22 00:52:50 -07:00
Johan T. Halseth
b9516b7cdd
lnwallet: make CreateCloseProposal take absolute fee instead of fee rate 2017-08-11 12:09:39 +02:00
Olaoluwa Osuntokun
43b736225b
multi: add new method to generate fresh node announcments 2017-08-04 18:32:33 -07:00
Olaoluwa Osuntokun
db793991ac
lnwallet: don't add trimmed HTLC value to initiator commitment fees
This commit fixes a lingering bug in the way the internal channel state
machine handled fee calculation. Previously, we would count the dust
HTLC’s that were trimmed towards the fee that the initiator paid. This
is invalid as otherwise, the initiator would always benefit from dust
HTLC’s. Instead, we now simply “donate” the dust HTLC’s to the miner in
the commitment transaction. This change puts us in compliance with
BOLT-0003.
2017-07-31 20:41:23 -07:00
Olaoluwa Osuntokun
5ece7fec2d
lnwallet: add a String() method to updateType 2017-07-31 20:37:51 -07:00
Olaoluwa Osuntokun
747e0f57d1
multi: fix linter errors 2017-07-30 18:22:45 -07:00
Olaoluwa Osuntokun
899fa1ea3e
lnwallet: properly populate the signDesc within UnilateralCloseSummary
This commit modifies the closeObserver code to populate the signDesc in
the case we have a non-trimmed balance. Additionally, we now also add a
*wire.OutPoint field to the struct in order to allow receivers of the
message to construct a witness that can spend the newly created output
to their wallet.
2017-07-30 17:52:18 -07:00
Olaoluwa Osuntokun
8a23de5303
lnwallet: consult current state instead of revocation log during unilateral closure 2017-07-30 17:52:14 -07:00
Olaoluwa Osuntokun
8121bc77ce
lnwallet: add delivery scripts as a param to CreateCloseProposal+ CompleteCooperativeClose
This commit modifies the methods that transition the state of the
channel into an active closing state. With the new commitment design,
the delivery scripts are no longer pre-committed to the initial funding
messages. Instead, the scripts are sent at the instant that either side
decides to shutdown within the Shutdown message.
2017-07-30 17:51:05 -07:00
Olaoluwa Osuntokun
40e9120c04
lnwallet: populate HTLC resolutions after observing a unilateral channel close 2017-07-30 17:51:02 -07:00
Olaoluwa Osuntokun
01aa4eb2ae
lnwallet: populate HTLC resolutions within the ForceCloseSummary 2017-07-30 17:50:59 -07:00
Olaoluwa Osuntokun
83e0116d7e
lnwallet: extend the UnilateralCloseSummary to include HTLC resolutions
This commit adds a new companion struct: OutgoingHtlcResolution to the
commitment state machine. The purpose of this struct is the provide the
caller with the information necessary to sweep all outgoing HTLC’s in
the case of a broadcast up-to-date commitment transaction.

The HTLC resolutions allow a caller to sweep an outgoing HTLC into
their wallet after the absolute timeout of the HTLc has passed. This is
a two step process, with the first portion consisting of broadcasting
the HTLC timeout transaction itself, and the second portion consisting
of claiming the HTLC itself after a CSV delay.
2017-07-30 17:50:55 -07:00
Olaoluwa Osuntokun
a4c07d061e
lnwallet: the BreachRetribution struct is now aware of HTLC outputs
This commit adds awareness of active HTLC outputs to the
BreachRetribution struct. Previously, in the case of a breach, the
struct was only populated with enough information to sweep the two
commitment outputs. With this commit, the struct now has enough
information to sweep _all_ outputs within the commitment transaction.
2017-07-30 17:50:51 -07:00
Olaoluwa Osuntokun
5a78f80ffe
lnwallet: update restoreStateLogs to be aware of new commitment scheme 2017-07-30 17:50:47 -07:00
Olaoluwa Osuntokun
b9da43a2b8
lnwallet: update fetchCommitmentView due to new commitment design
This commit updates the central fetchCommitmentView method to manage
and derive the necessary easy required to create new commitments due to
the new state machine design within the specification. Each state now
requires us to derive a number of keys for each commitment state:
localDelay, remoteDelay, localKey, remoteKey, the commitment point, and
finally the revocation key itself.
2017-07-30 17:50:43 -07:00
Olaoluwa Osuntokun
3a052d2874
lnwallet: when creating new states, dispatch HTLC signing to sigPool 2017-07-30 17:50:40 -07:00
Olaoluwa Osuntokun
f569b80a80
lnwallet: when verifying new states, dispatch HTLC sig validation to sigPool 2017-07-30 17:50:37 -07:00
Olaoluwa Osuntokun
cd8672f824
lnwallet: update CreateCommitTx due to new key derivation 2017-07-30 17:50:34 -07:00
Olaoluwa Osuntokun
e314b83559
lnwallet: update HTLC script generation to account for new covenant HTLC's
This commit updates the set of functions tasked with generating HTLC’s
scripts for new commitments to now adhere to the new commitment
transaction design. With this change, the process of claiming an HTLC
now requires a second-level HTLC transaction, which solves a prior
issues due to the tight coupling of the timeout and delay clauses when
claiming an HTLC.
2017-07-30 17:50:31 -07:00
Olaoluwa Osuntokun
8b9a58cb15
lnwallet: add a sigPool instances to the state machine struct 2017-07-30 17:50:27 -07:00
Olaoluwa Osuntokun
4c9bd9dc54
lnwallet: when handling possible channel breach, only log if contract breach 2017-07-30 17:50:24 -07:00
Olaoluwa Osuntokun
e56258917e
lnwallet: introduce populateHtlcIndexes for tracking HTLC indexes in commitments
This commit adds a new method to the commitment struct:
populateHtlcIndexes.  populateHtlcIndexes modifies the set of HTLC's
locked-into the target view to have full indexing information
populated. This information is required as we need to keep track of the
indexes of each HTLC in order to properly write the current state to
disk, and also to locate the PaymentDescriptor corresponding to HTLC
outputs in the commitment transaction.

We also modify toChannelDelta to take not of these new changes, and
access the appropriate index directly.
2017-07-30 17:50:21 -07:00
Olaoluwa Osuntokun
549688d793
lnwallet: remove isDustLocal and isDustRemote, replace w/ htlcIsDust
This commit modifies the way we account for dust HTLC’s within the
commitment state machine when creating and validating new states.
Previously, an HTLC was dust if the amount of the HTLC was below the
dustLimit of the commitment chain. Now, with the HTLC covenant
transaction, the value of the HTLC also needs to cover the required fee
of the HTLC covenant transaction at the specified fee rate of the
commitment chain.

As a result, we now determine if an HTLC is dust or not, only at the
commitment site, using the new htlcIsDust function.
2017-07-30 17:50:16 -07:00
Olaoluwa Osuntokun
91165d98bb
lnwallet: eliminate the InitialRevocationWindow within the state machine
This commit modifies the current core channel state machine in order to
may a step towards BOLT-0002 and BOLT-0003 compliance. In this change,
we abandon the prior revocation window, in favor of a fixed revocation
window of size two. The revocation window will be filled at the start
of the lifetime of the channel, and never extended from there until the
channel has been fully closed.

We now maintain two variables, the current un-revoked commitment point,
and the next commitment point to use when creating a new state. The
next commitment point must initially be inserted into the channel state
with the InitNextRevocation method.

A major difference between the prior revocation key handling is that
the remote party now instead sends us the _commitment point_ in
isolation, which we then use locally (with our revocation base point)
to create the next full revocation key for _their_ commitment
transaction.
2017-07-30 17:50:13 -07:00
Olaoluwa Osuntokun
c7df82ab68
lnwallet: update the LightningChannel API usage for recent channels changes
This commit updates much of the state interaction within the
LightningChannel structure to account for the recent changes within the
chanenldb involving the OpenChannel struct, namely the introduction of
ChannelConfig and ChannelConstraints.
2017-07-30 17:50:10 -07:00
Olaoluwa Osuntokun
14832d8c09
lnwallet+lnwire: minor grammatical fixes after UpdateFee merge 2017-07-14 17:10:42 -07:00
Johan T. Halseth
ebe05f6568 lnwallet: add update_fee message support.
This commit adds the possibility for the initiator of a
channel to send the update_fee message, as specified
in BOLT#2. After the message is sent and both parties
have committed to the updated fee, all new commitment
messages in the channel will use the specified fee.
2017-07-14 16:39:15 -07:00
bryanvu
5068541044 lnwallet: apply dust HTLC amounts to fees
If an HTLC’s value is below a node’s dust limit, the amount for that
HTLC should be applied to to the fee used for the channel’s commitment
transaction.
2017-07-06 18:05:43 -07:00
Olaoluwa Osuntokun
5dd7b157a0
lnwallet: fix race condition when forwarding by creating new pubkey
This commit fixes a race condition that would at times occur in the
htlcswitch.TestChannelLinkBidirectionalOneHopPayments test case. A race
condition would occur in the goroutine running ReceiveNewCommitment
compared with the grouting that would obtain the snapshot in order to
make a forwarding decision.

We fix this by creating a new public key for each new commitment
transaction such that we complete avoid the read/write race condition.
2017-06-19 17:43:57 +02:00
Olaoluwa Osuntokun
6937a42f2d
lnwallet: add new ShortChanID method to LightningChannel 2017-06-16 23:25:13 +02:00
Olaoluwa Osuntokun
2e05051176
lnwallet: clarify comment within commitment state sanity function 2017-06-08 22:25:06 -07:00
Olaoluwa Osuntokun
9676d476c9
lnwallet: fix race condition in channel state machine, use single mutex
This commit fixes a race condition that was discovered as a result of
the new htlcswitch package. The StateSnapshot method and all of the
other methods which mutate the state of the channel state machine were
using distinct mutexes. The fix is trivial: all methods accessing the
internal channel state variable now use the same mutex.
2017-06-08 22:24:20 -07:00
Olaoluwa Osuntokun
54f849a62e
lnwallet: use the FundingBroadcastHeight as height hint for spend ntfns 2017-06-05 19:17:13 -07:00
Andrey Samokhvalov
f774e3d9bf lnwallet: add missed addition of RHash
add rhash to the payment descriptor when receiving the settle htlc in
order to be able to pass it during settle htlc packet generation and
later find the user pending payment by rhash without additional hashing.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
0e51b1d22d channeldb: add available balance function
In this commit we made state machine to be responsible for returning
proper available balance - amount of satoshi which we able to use at
current moment. This will help us in constrction channel link
abstraction.
2017-05-31 11:06:08 -07:00
Andrey Samokhvalov
fde27716d1 channeldb: add restriction to to use only half of the capacity locally
In this commit severe bug have been fixed which allows the state of the
nodes to be desychnorinesed in the moments of high htlc flow. We limit
the number of the htlc which we can add to commitment transaction
to half of the available capcity. This change fixes the bug when
commimtment transaction on the verge of being full, in this case race
condition might occures and remote htlc will be rejected, but at the
same time they will be added on remote side, the same situiation will
happen with htlc we have added, which cause the commitment transactions
to be different.
2017-05-31 11:06:08 -07:00
bryanvu
408be356fb lnwallet: update channel close to use fee estimation interface
This commit switches the channel close workflow to use the lnwallet fee
estimation interface rather than the hardcoded proposedFee.
2017-05-23 14:31:20 -07:00
bryanvu
514760f529 peer: handling for channel shutdown messages
This commit changes the cooperative channel close workflow to comply
with the latest spec. This adds steps to handle and send shutdown
messages as well as moving responsibility for sending the channel close
message from the initiator to the responder.
2017-05-23 14:31:20 -07:00