Commit Graph
100 Commits
Author SHA1 Message Date
eugene c9a6c80be9 release-notes: update for 0.15.0 2022-05-11 13:50:40 -04:00
eugene 87a486f1f9 htlcswitch: remove synchronous link handoff, special-case keystone err
This allows Switch-initiated payments to be failed back if they don't
make it into a commitment. Prior to this commit, a Switch-initiated
HTLC could get "lost" meaning the circuit wouldn't get deleted except
if conditions were "right" and the network result store would never
be made aware of the HTLC's fate. Switch-initiated HTLC's are now
passed to the link's mailbox to ensure they can be failed back.

This change also special-cases the ErrDuplicateKeystone error from
OpenCircuits(...) so that callers of updateCommitTx() in the link
don't send an Error to the peer if they encounter the keystone error.
With the first async change, the keystone error should now always
be recoverable.
2022-05-11 13:49:37 -04:00
eugene eeedb09e0f release-notes: update for 0.15.0 2022-04-29 16:40:19 -04:00
eugene f7b3da4bb2 htlcswitch+lntest: modify Switch to persist resolution messages
Include unit tests for the Switch, and integration tests that
exercise the persistence logic.
2022-04-29 16:40:19 -04:00
eugene bfed7a088f htlcswitch: introduce resolutionStore to persist cnct messages 2022-04-29 16:40:16 -04:00
eugene caeb650e87 release-notes: update for 0.15.0 2022-04-26 12:52:49 -04:00
eugene 5ec6aafce3 peer: make linter happy 2022-04-26 12:52:49 -04:00
eugene d881679de0 peer+chancloser: allow restarting coop close process
On startup, we'll check whether we have the coop close chan status
and have already broadcasted a coop close txn, and then make a
decision on whether to restart the process based on that.
2022-04-26 12:52:48 -04:00
eugene a94466e936 peer: add createChanCloser function to de-dupe NewChanCloser sites 2022-04-26 12:52:46 -04:00
eugene 0f74c6b775 release-notes: update for 0.15.0 2022-04-19 17:24:21 -04:00
eugene ef83370dcf contractcourt: deadlock fix via temporary unmerged map
The main idea is that NotifyContractUpdate adds the ContractUpdate to
a map called unmerged. It is populated in Start by shallow-copying the
activeHTLCs map values (htlcSet). The htlcSets underlying maps are not
copied, and so unmerged will just contain pointers to them. This should
be fine since unmerged will not modify them. At the call-sites of
activeHTLCs, it is updated to include the unmerged sets. This happens
with a mutex and should not cause any data race, even though it is
copying the underlying map pointers. No persistence should be
necessary since on restart, activeHTLCs and unmerged will just be
populated again.
2022-04-19 17:24:21 -04:00
eugene 4373faa818 channeldb: change to ErrTypeForDecodingErr for amp state
Was instead returning ErrTypeForEncodingErr.
2022-03-23 12:05:11 -04:00
eugene d44d92e4dc release-notes: update release notes for 0.15.0 2022-03-15 14:35:28 -04:00
eugene 932c5f1a7b discovery: move ann sig handling to handleAnnSig 2022-03-15 14:35:27 -04:00
eugene 1e9220dab6 discovery: move channel update handling to handleChanUpdate 2022-03-15 14:35:27 -04:00
eugene 914c96d2cf discovery: move channel ann handling to handleChanAnnouncement 2022-03-15 14:35:27 -04:00
eugene 3bdf0a437d discovery: move node ann code to handleNodeAnnouncement 2022-03-15 14:35:25 -04:00
eugene 0ebfdc488c release-notes: update for 0.15.0 2022-02-25 12:07:17 -05:00
eugene 028dec80cb htlcswitch: only pipeline settle if add is locked-in
The counter-party shouldn't be doing this anyways as they would be
giving away a preimage for free. Them doing this would bork their
own channel due to open circuits not getting trimmed on startup.
Removing this faulty behavior also makes it easier to reason about
the circuit logic.
2022-02-25 12:07:17 -05:00
eugene cac933df62 release-notes: update for 0.15 2022-02-24 13:41:32 -05:00
eugene 9d8ff1fae5 config: clamp channel-commit-interval to reasonable time 2022-02-24 13:41:31 -05:00
eugene ff4d037ff6 release-notes: update 0.15.0 notes 2022-02-24 13:36:13 -05:00
eugene 8607e8c28a multi: reliable hand-off from htlcswitch to contractcourt
This is achieved by changing the 1-way handoff to a 2-way handoff
with a done channel.
2022-02-24 13:35:15 -05:00
eugene 64a51c1524 docs/release-notes: update notes for 0.14.2 2022-01-25 15:42:20 -05:00
eugene ebaffb953a server+contractcourt: hand-off BreachCloseInfo to channel arbitrator
This also changes the chain_watcher and breacharbiter handoff. The
new logic ensures that the channel is only marked as pending closed
when the channel arbitrator has persisted the resolutions and commit
set.
2022-01-25 15:42:20 -05:00
eugene b7407882ac contractcourt: create breachResolver if BreachResolution present
Also transitions to the proper state based on if this is a legacy
breach in the channel arbitrator or a modern breach with a resolver.
2022-01-25 15:42:20 -05:00
eugene af03c8cb46 contractcourt: handle writing BreachResolution in arbitrator log 2022-01-25 15:42:20 -05:00
eugene f99933fa69 server+contractcourt: add breachResolver that subscribes to breacharbiter
Introduces a breachResolver that subscribes to the breacharbiter to
determine if the final justice transaction has confirmed and can
clean itself up.
2022-01-25 15:42:20 -05:00
eugene ead414c689 discovery: use source instead of peer for accurate rejectCache 2022-01-05 04:27:33 +08:00
eugene 2fbc35ca26 docs: update release notes for 0.14.0 2021-10-26 10:32:19 -04:00
eugene ee2162b5d2 htlcswitch: remove 5 second timeout for data race unit tests 2021-10-26 10:32:13 -04:00
eugene 25a0fe2902 docs: update release notes for 0.13.3 2021-09-30 13:44:35 -04:00
eugene 702b3a3258 multi: introduce config-level DustThreshold for defining threshold 2021-09-30 13:44:35 -04:00
eugene 3897baff0a htlcswitch: call evaluateDustThreshold in SendHTLC, handlePacketForward
This commit makes SendHTLC (we are the source) evaluate the dust
threshold of the outgoing channel against the default threshold of
500K satoshis. If the threshold is exceeded by adding this HTLC, we
fail backwards. It also makes handlePacketForward (we are forwarding)
evaluate the dust threshold of the incoming channel and the outgoing
channel and fails backwards if either channel's dust sum exceeds the
default threshold.
2021-09-30 13:44:34 -04:00
eugene 0ce6194e1e htlcswitch: extend ChannelLink iface with dustHandler iface
This allows the Switch to determine the dust exposure of a certain
channel and allows the link to set the feerate of the mailbox given
a fee update.
2021-09-30 13:44:34 -04:00
eugene 0b24603aef htlcswitch: extend Mailbox iface with dust, fee methods
This commit extends the Mailbox interface with the SetDustClosure,
SetFeeRate, and DustPackets methods. This enables the mailbox to
report the dust exposure to the Switch when the Switch decides whether
to forward a dust packet. The dust is counted from the time an Add is
introduced via AddPacket until it is removed via AckPacket. This can
lead to some packets being counted twice before they are signed for,
but this is a trade-off between accuracy and simplicity.
2021-09-30 13:44:34 -04:00
eugene 7d16e58b5c lnwallet: introduce GetDustSum method to calculate worst-case dust sum
It over-estimates the local or remote commitment's dust sum by
counting all updates in both updateLogs that are dust using the
trimmed-to-dust mechanism if applicable. The over-estimation is done
because ensuring an accurate counting is a trade-off between code
simplicity and accuracy.
2021-09-30 13:44:26 -04:00
eugene b0018f2387 docs: update release notes for 0.14.0 2021-09-29 17:09:29 -04:00
eugene 49877545ba htlcswitch: fix flake in TestShutdownIfChannelClean
When Alice receives a CommitSig near the end of the test, the test
assumed that she wouldn't reply with a RevokeAndAck message before
shutdownAssert was called. This led to a test flake. Instead, only
call shutdownAssert after we've received the RevokeAndAck.
2021-09-29 17:04:53 -04:00
eugene b8bfaf076f docs: update release notes for 0.13.3 2021-09-29 13:33:12 -04:00
eugene 950063840a funding+lnwallet: validate ChannelReserve is above DustLimit
This is necessary and is implied by BOLT#02. Both ChannelReserve
parameters should be above both DustLimit parameters. Otherwise,
it is possible for one side to have nothing at stake.
2021-09-29 13:33:12 -04:00
eugene fdcd726f9a multi: replace DefaultDustLimit with script-specific DustLimitForSize
This commit updates call-sites to use the proper dust limits for
various script types. This also updates the default dust limit used
in the funding flow to be 354 satoshis instead of 573 satoshis.
2021-09-29 13:33:10 -04:00
eugene 868958d2bc docs: update release notes for 0.14 2021-09-13 13:29:51 -04:00
eugene aeaa009e92 peer+chancloser: tryLinkShutdown during cooperative close process
Adds a new Brontide struct method tryLinkShutdown that attempts to
fetch the target link and calls ShutdownIfChannelClean on it. This
allows the coop close process to guarantee atomicity of the underlying
channel state. Also removes the UnregisterChannel method from the
chancloser's config as the link is shut down before the chancloser
is created.
2021-09-13 13:29:51 -04:00
eugene 608d11dcbc peer: add mockUpdateHandler for use in mockMessageSwitch 2021-09-13 13:29:50 -04:00
eugene b2e90480ed htlcswitch: extend ChannelLink interface with ShutdownIfChannelClean
This allows a caller to ensure to optimistically shut down the link
if the channel is clean. If the channel is not clean, an error is
returned and the link continues functioning as normal. The caller
should also call RemoveLink to ensure that the link isn't seen as
usable within the switch.
2021-09-13 13:29:50 -04:00
eugene 7621d7f902 lnwallet: add IsChannelClean method and related tests
Adds a method to the LightningChannel struct called IsChannelClean
that returns a boolean telling the caller whether the channel state
is clean or not. Clean in this case means there are no lingering
updates to be signed for, no HTLC's active on either sides commitment
transaction, and no pending commitments on either side. This can be
used for dynamic commitments or during a strict cooperative close
process that ensures atomicity of the channel.
2021-09-13 13:29:43 -04:00
eugene 74693ed491 docs: update release notes for 0.14.0 2021-09-01 16:49:28 -04:00
eugene 2fbee31c6e chainntnfs: populate spendsByHeight during historical dispatch
This commit fixes a buggy scenario where:
- a spend of the desired outpoint occurs
- RegisterSpend is called, not immediately notifying
- caller performs a historical dispatch, calling UpdateSpendDetails
- caller is notified on the Spend channel
- re-org occurs
- caller is not notified of the re-org
We fix this by correctly populating the spendsByHeight map when
dispatchSpendDetails is called. This mirrors the confirmation case.
2021-09-01 16:45:13 -04:00
eugene 9f6f5e963a docs: update release notes for 0.14 2021-08-27 14:12:02 -04:00
eugene de71195bcb chainntnfs/neutrinonotify: update EndHeight after filter update
After the error is received on the filter update errChan, update the
EndHeight if we're performing a historical scan. If a block was mined
after the call to RegisterConf/RegisterSpend but before the filter was
updated, then the block would not have the filter applied. This means
that a block containing the desired conf/spend parameters would be
undetected. Fix this by ensuring the historical scan also includes this
height, as it would previously not be included.
2021-08-27 14:12:02 -04:00
eugene 0d39c0799a chainntnfs/neutrinonotify: call drainChainUpdates when updating filter
Moves filter handling logic for connecting blocks to the
connectFilteredBlock method. The disconnect logic now lives in
disconnectFilteredBlock. After updating the filter, drainChainUpdates
is called which will drain everything from the chainUpdates chan and
apply all updates by calling either connectFilteredBlock or
disconnectFilteredBlock. This will allow callers to update their
EndHeight if performing a historical dispatch, as blocks up to this
height may not have had the filter applied.
2021-08-27 14:12:01 -04:00
eugene b7de0eae93 chainntnfs/neutrinonotify: make chainUpdates a buffered chan
ConcurrentQueue has internal structures so if a filterUpdate exists
in it, the idea of draining the queue may not work reliably. The
update may exist in the ConcurrentQueue but may not be available via
ChanOut() when we're ready to drain the ConcurrentQueue. Fix this by
using a regular buffered chan, which will either have the update or
not have the update. Its size is set to 100 as our tests may generate
quite a bit of updates.
2021-08-27 14:12:01 -04:00
eugene 86f28cdc1d chainntnfs: skip conf dispatch if ntfn already dispatched
This mirrors the logic for the spend case. This prevents a double
dispatch scenario when combined with a later commit. Otherwise, the
confirmation would linger in the buffer which is not ideal.
2021-08-27 14:11:55 -04:00
eugene c3ac95abbd docs: update release notes for 0.14 2021-08-11 16:59:16 -04:00
eugene 9cea8741b1 fuzz/lnwire: minor touch-ups, remove MaxPayloadLength
This commit makes the fuzz/lnwire tests build and run without
crashing.
2021-08-11 16:59:16 -04:00
eugene cbbad3a674 docs: update release notes for 0.14 2021-08-11 15:37:53 -04:00
eugene d0191cb5ed rpcserver: validate FinalCltvDelta and CltvLimit for REST
Missed this check in PR #5293.
2021-08-11 15:37:53 -04:00
eugene db4a488e23 docs: update 0.14 release notes 2021-08-10 17:15:52 -04:00
eugene 23a4fad4ac htlcswitch+peer: CreateAndAddLink in switch, add messageSwitch to peer
This commit allows the peer to be tested without relying on a raw
htlcswitch.Switch pointer. This is accomplished by using a messageSwitch
interface and adding the CreateAndAddLink method to the
htlcswitch.Switch.
2021-08-10 17:15:52 -04:00
eugene e72468646c htlcswitch+peer: embed ChannelUpdateHandler in ChannelLink
GetLink, GetLinksByInterface now use ChannelUpdateHandler.
2021-08-10 17:15:52 -04:00
eugene 051cd8793a htlcswitch: introduce and embed packetHandler interface in ChannelLink
This will allow separating the now-private *htlcPacket methods from
the publicly-used ChannelLink interface methods.
2021-08-10 17:15:51 -04:00
eugene 6c6e353597 htlcswitch+peer: pass BestHeight to ChannelLinkConfig
This allows non-test usages of ChannelLinkConfig to omit the raw
htlcswitch.Switch pointer.
2021-08-10 17:15:49 -04:00
eugene 13d7e97a84 docs: update fuzz.md to explain new build/run process 2021-06-16 12:49:26 -04:00
eugene 6d04f11f94 lnwallet+funding: sanitize upfront_shutdown_script
Otherwise, we would get non-standard txn's and fail to broadcast
them when cooperatively closing a channel. This wouldn't affect
funds security as no HTLCs would be active to steal. This is just
a safety measure as we should only generate standard txn's.
2021-06-11 10:46:21 -04:00
eugene 17646b0c04 go.mod: update btcutil, btcutil/psbt commits for psbt fix
This pulls in the latest btcutil and btcutil/psbt commits which
include a panic fix for malformed PSBT inputs.
2021-05-20 15:56:42 -04:00
eugene a70d0bef34 multi: validate payment params at RPC layer
With this patch, we'll fail out earlier in the cycle in case of
some wonky parameters, and not leave zombie payments in the router
which currently are not cleaned up.
2021-05-13 17:17:52 -04:00
eugene fa5627b779 lnwallet/chanfunding: non-segwit spend Verify test
Also fixes error-handling in the Verify test when expectedErr == ""
2021-04-22 13:04:25 -04:00
eugene b3f14d66f0 lnwallet/chanfunding: assert PSBT Inputs have WitnessUtxo 2021-04-22 13:04:24 -04:00
eugene 9e2cccdbbd docs: add malleability note in psbt.md 2021-04-22 13:04:23 -04:00
eugene 0547364091 lnwallet: add test for state machine regression 2021-04-21 17:42:56 -04:00
eugene 7da2080a3d lnwallet: use tail() instead of tip() in getUnsignedAckedUpdates
The previous behavior would allow updates to be overwritten in some
scenarios. Upon restart, this would lead to a missing settle/fail in
the update logs.
2021-04-21 17:42:56 -04:00
eugene 97007fc4fa lnwallet: fix logUpdate scope in restorePendingLocalUpdates 2021-04-21 17:42:56 -04:00
eugene 9d0d5bdfaf channeldb: AdvanceCommitChainTail clarification comment 2021-04-21 17:42:53 -04:00
eugene 8b463fbc2b lnd: optionally listen on localhost for better security
The --profile flag now accepts both a port and a host:port string.
If profile is set to a port, then pprof debugging information will
be served over localhost. Otherwise, we will attempt to serve pprof
information on the specified host:port (if we are allowed to listen
on it.)

We default to the safe option as if the port is connectable, anybody
can connect and see debugging information.

See: https://mmcloughlin.com/posts/your-pprof-is-showing
2021-04-01 12:14:24 -04:00
Eugene 6dca38c561 Merge pull request #5073 from Crypt-iQ/writemessage_03042021
lnwire: remove MaxPayloadLength from lnwire.Message interface
2021-03-09 04:50:40 -08:00
eugene 99a7271289 lntest/itest+lnwallet: add legacy chanrestore test
The test makes use of a nextRevocationProducer that is only used during
integration tests.
2021-03-05 12:49:18 -05:00
eugene bb84f0ebc8 multi: store KeyLocator in OpenChannel, use ECDH
This commit adds a RevocationKeyLocator field to the OpenChannel
struct so that the SCB derivation doesn't have to brute-force the
sha chain root key and match the public key. ECDH derivation is now
used to derive the key instead of regular private key derivation a
la DerivePrivKey. The legacy can still be used to recover old
channels.
2021-03-05 12:49:18 -05:00
eugene 986e69c81b channeldb: add KeyLocator Record 2021-03-05 12:49:16 -05:00
eugene 7ff04d8bad lnwire: remove MaxPayloadLength from Message interface
Removes the MaxPayloadLength function from the Message interface
and checks that each message payload is not greater than MaxMsgBody.
Since all messages are now allowed to be 65535 bytes in size, the
MaxPayloadLength is no longer needed.
2021-03-04 16:48:10 -05:00
eugene bc238ee84c lnd+lnwallet: make capacity check stricter by adding fee
Also patches breacharbiter tests by using the correct commitment
fee and balances.
2021-02-22 12:07:21 -05:00
eugene 80eb5dbece lncfg: add isIPv6Host helper to force v6 addrs through system resolver
With this commit, if --tor.active is specified, then IPv6 addresses
will no longer go through the connmgr.TorLookupIP function from btcd.
This function does not have proper IPv6 support and would fail with
the error "tor general error". Instead, use the system resolver.
2021-02-05 15:37:39 -05:00
eugene 1c407f4026 htlcswitch: reestablish unit tests 2021-02-03 16:47:47 -05:00
eugene 9b09895bde channeldb+lnwallet: lastWasRevokeKey to store last sent rev/sig 2021-02-03 16:43:04 -05:00
eugene f8b98a1d3b lntest/channels: introduce subpackage to deduplicate static structs 2021-01-25 14:04:39 -05:00
Eugene e0439965bb Merge pull request #4757 from Crypt-iQ/fmgr_1109
funding: move Manager to own package
2020-12-17 11:43:12 -05:00
eugene dcdf36f410 lnd+funding: move Manager to funding, change references 2020-12-17 10:45:05 -05:00
eugene e7e872f19a lnd: remove Manager's stop method, linter complaints 2020-12-17 09:50:55 -05:00
eugene 936227798a lnd: remove openChanReq, call InitFundingWorkflow with InitFundingMsg 2020-12-17 09:50:48 -05:00
eugene e85baea1b3 lnd: export InitFundingMsg 2020-12-17 09:36:34 -05:00
eugene 105e961b20 lnd: export Manager's InitFundingWorkflow method 2020-12-17 09:36:34 -05:00
eugene 1b84d07c4d lnd+funding: register funding logger 2020-12-17 09:36:34 -05:00
eugene 6a209bbdaf lnd: export Manager, NewFundingManager 2020-12-17 09:36:34 -05:00
eugene f43fd32daf lnd: remove PendingChannels call from fundingManager 2020-12-17 09:36:34 -05:00
eugene 9c72dd9eba funding+peer: rename Manager interface to Controller 2020-12-17 09:36:34 -05:00
eugene caa0f5da6a multi: move and export funding-related vars to funding package
Also moves the lnd global MaxFundingAmount to server.go
2020-12-17 09:36:34 -05:00
eugene f6524aabcb lnd+funding: use funding.WriteOutpoint instead of lnd version
This commit duplicates the utxonursery's writeOutpoint function
in the funding package so that when the rest of the fundingmanager
code is moved, it can use the WriteOutpoint function for its
channel opening state data.
2020-12-17 09:36:34 -05:00
eugene 61e0f67edf funding: rename from fmgr, change references 2020-12-17 09:36:34 -05:00
eugene f4593f95f4 channeldb/migration20: TestMigrateOutpointIndex 2020-12-10 17:37:59 -08:00
eugene 204b6c51cf channeldb: MigrateOutpointIndex, store indexStatus in outpoint index
Adds an outpoint index that stores a tlv stream. Currently the stream
only contains the outpoint's indexStatus. This should cut down on
big bbolt transactions in several places throughout the codebase.
2020-12-10 17:37:59 -08:00