Compare commits

..

1291 Commits

Author SHA1 Message Date
rockstardev
db58257e24
Update README.md
Some checks failed
CI / Sqlc check (push) Has been cancelled
CI / RPC and mobile compilation check (push) Has been cancelled
CI / check commits (push) Has been cancelled
CI / lint code (push) Has been cancelled
CI / cross compilation (push) Has been cancelled
CI / sample configuration check (push) Has been cancelled
CI / run ubuntu itests (backend=bitcoind dbbackend=postgres nativesql=true, bitcoind-postgres-nativesql) (push) Has been cancelled
CI / run unit tests (btcd unit-cover) (push) Has been cancelled
CI / run unit tests (btcd unit-race) (push) Has been cancelled
CI / run unit tests (unit tags="kvdb_etcd") (push) Has been cancelled
CI / run unit tests (unit tags="kvdb_postgres") (push) Has been cancelled
CI / run unit tests (unit tags="kvdb_sqlite") (push) Has been cancelled
CI / run unit tests (unit-module) (push) Has been cancelled
CI / run ubuntu itests (backend="bitcoind notxindex", bitcoind-notxindex) (push) Has been cancelled
CI / run ubuntu itests (backend="bitcoind rpcpolling" cover=1, bitcoind-rpcpolling) (push) Has been cancelled
CI / run ubuntu itests (backend=bitcoind cover=1, bitcoind) (push) Has been cancelled
CI / run ubuntu itests (backend=bitcoind dbbackend=etcd, bitcoind-etcd) (push) Has been cancelled
CI / run ubuntu itests (backend=bitcoind dbbackend=postgres, bitcoind-postgres) (push) Has been cancelled
CI / run ubuntu itests (backend=bitcoind dbbackend=sqlite nativesql=true, bitcoind-sqlite-nativesql) (push) Has been cancelled
CI / run ubuntu itests (backend=bitcoind dbbackend=sqlite, bitcoind-sqlite) (push) Has been cancelled
CI / run ubuntu itests (backend=btcd cover=1, btcd) (push) Has been cancelled
CI / run ubuntu itests (backend=neutrino cover=1, neutrino) (push) Has been cancelled
CI / run windows itest (push) Has been cancelled
CI / run macOS itest (push) Has been cancelled
CI / check pinned dependencies (github.com/golang/protobuf v1.5.3) (push) Has been cancelled
CI / check pinned dependencies (google.golang.org/grpc v1.59.0) (push) Has been cancelled
CI / check release notes updated (push) Has been cancelled
CI / finish (push) Has been cancelled
2025-07-22 23:12:37 +02:00
rockstardev
d97fa8b923
Merge pull request #8 from btcpayserver/pr/lnd-v0.18.4-beta
Building BTCPay LND 0.18.4
2025-01-08 16:57:18 -05:00
rockstardev
655d470280 Updating docker files to build 0.18.4 lnd 2025-01-07 18:53:54 -06:00
rockstardev
ce16689d73 Merge remote-tracking branch 'source/0-18-4-branch' 2025-01-07 18:46:41 -06:00
rockstardev
3da675df42
Update README.md
Adding example of local docker build process
2025-01-07 09:57:32 -06:00
rockstardev
e2a063f0e3
Update README.md
Link to Loop and fixing link to commit
2025-01-07 09:47:47 -06:00
Oliver Gugger
ddeb835168
Merge pull request #9367 from lightningnetwork/0-18-4-branch-rc3
release: create branch for v0.18.4-beta
2024-12-17 21:17:09 +01:00
Oliver Gugger
74d15d1fbc
build: bump version to v0.18.4-beta 2024-12-17 21:15:07 +01:00
Oliver Gugger
88cbec291c
Merge branch '0-18-4-branch-rc3-9357' into 0-18-4-branch-rc3 2024-12-16 12:51:50 +01:00
George Tsagkarelis
d30cba1089
contractcourt: include custom records on replayed htlc
When notifying the invoice registry for an exit hop htlc we also want to
include its custom records. The channelLink, the other caller of this
method, already populates this field. So we make sure the contest
resolver does so too.
2024-12-16 12:51:49 +01:00
Oliver Gugger
3c0810963f
Merge pull request #9335 from lightningnetwork/0-18-4-branch-rc2
release: create branch for v0.18.4-beta.rc2
2024-12-11 13:33:04 +01:00
Oliver Gugger
3447484a66
Merge branch '0-18-4-branch-rc2-9316' into 0-18-4-branch-rc2 2024-12-10 22:29:38 +01:00
ziggie
71eb1ae57d
docs: add release-notes for 18.4 2024-12-10 22:29:29 +01:00
ziggie
4c61411802
routing: bugfix for mc reporting of blinded paths
When reporting an error  or a success case of a payment to a
blinded paths, the amounts to forward for intermediate hops
are set to 0 so we need to use the receiver amount instead.
2024-12-10 22:29:29 +01:00
ziggie
a1e5dfc266
routing: add pathfinding test
We add a test where we add duplicate hops in a route and verify
that the pathfinding engine can handle this edge case.
2024-12-10 20:27:25 +01:00
ziggie
c579a6bf2f
routing: improve lasthoppaylaod size calculation
Fixes a bug and makes the function more robust. Before
we would always return the encrypted data size of last hop
of the last path. Now we return the greatest last hop payload
not always the one of the last path.
2024-12-10 20:27:25 +01:00
ziggie
eb93eb7ee9
routing: Use NUMS point for blinded paths
To be able to do MPP payment to multiple blinded routes we need
to add a constant dummy hop as a final hop to every blined path.
This is used when sending or querying a blinded path, to let the
pathfinder be able to send MPP payments over different blinded
routes. For this dummy final hop we use a NUMS key so that we
are sure no other node can use this blinded pubkey either in a
normal or blinded route.
Moreover this helps us handling the mission control data for
blinded paths correctly because we always consider the blinded
pubkey pairs which are registered with mission control when
a payment to a blinded path fails.
2024-12-10 20:27:24 +01:00
ziggie
0b90d3c3c2
input: export NUMS key parser. 2024-12-10 20:24:01 +01:00
Oliver Gugger
f312064bfb
build: bump version to v0.18.4-beta.rc2 2024-12-05 21:49:08 +01:00
Oliver Gugger
b63ac70113
Merge branch '0-18-4-branch-rc2-9333' into 0-18-4-branch-rc2 2024-12-05 21:47:45 +01:00
Oliver Gugger
72b4a1cb34
multi: thread through and use AuxTrafficShaper 2024-12-05 21:46:27 +01:00
Oliver Gugger
662049681d
htlcswitch: thread through packet's inbound wire records
For calculating the available auxiliary bandwidth of a channel, we need
access to the inbound custom wire records of the HTLC packet, which
might contain auxiliary information about the worth of the HTLC packet
apart from the BTC value being transported.
2024-12-05 21:44:58 +01:00
Oliver Gugger
699e2b74f6
multi: move routing.TlvTrafficShaper => htlcswitch.AuxTrafficShaper
With this commit we move the traffic shaper definition from the routing
package to the HTLC switch package as a preparation for being able to
use it there as well.
At the same time we rename it to AuxTrafficShaper to be more in line
with the other auxiliary components.
2024-12-05 21:44:56 +01:00
Oliver Gugger
f5ad1ee438
Merge branch '0-18-4-branch-rc2-9324' into 0-18-4-branch-rc2 2024-12-05 21:41:27 +01:00
ziggie
ae227ce2c6
docs: add release-notes 2024-12-05 21:41:13 +01:00
ziggie
7e228f22a8
contractcourt: refactor start up of arbitrators
We decouple the state machine of the channel arbitrator from
the start-up process so that we can startup the whole daemon
reliably.
2024-12-05 21:40:31 +01:00
Oliver Gugger
c1129bb086
Merge pull request #9183 from lightningnetwork/0-18-4-branch-rc1
release: create branch for v0.18.4-beta.rc1
2024-11-21 20:19:40 +01:00
Oliver Gugger
9246d5c51c
Merge branch '0-18-4-branch-rc1-9288' into 0-18-4-branch-rc1 2024-11-20 15:31:13 +01:00
Oliver Gugger
117a145b97
docs: add release notes 2024-11-20 15:31:12 +01:00
Oliver Gugger
e074a8fab3
chanacceptor: add custom channel commitment type 2024-11-20 15:31:12 +01:00
Oliver Gugger
f9d876e8a3
Merge branch '0-18-4-branch-rc1-9253' into 0-18-4-branch-rc1 2024-11-20 10:44:12 +01:00
ziggie
a4211251bd
docs: add release notes 2024-11-20 10:43:59 +01:00
ziggie
d695383386
rpcserver: add robustness check 2024-11-20 10:42:54 +01:00
ziggie
79d0655a96
multi: introduce an option for resolutions
We don't always need the resolutions in the local force close
summary so we make it an option.
2024-11-20 10:42:54 +01:00
Oliver Gugger
78c8990772
Merge branch '0-18-4-branch-rc1-9272' into 0-18-4-branch-rc1 2024-11-19 12:44:51 +01:00
Olaoluwa Osuntokun
86de1ebdc2
sweep: update storeRecord to include utxo index
In this commit, we complete a recently added feature by ensuring that
even if we go through the RBF loop to create a txn, that we still
populate the `outpointToIndex` map. Unit tests have been updated to
ensure this is always set as expected.
2024-11-19 12:44:51 +01:00
Oliver Gugger
4c9d25cbe7
Merge branch '0-18-4-branch-rc1-9194' into 0-18-4-branch-rc1 2024-11-15 13:09:56 +01:00
Oliver Gugger
04b053e405
docs: move 0.18.4 items, add full list of custom chan PRs 2024-11-15 13:09:35 +01:00
Olaoluwa Osuntokun
e1a25f6c30
sweep: update BudgetInputSet.Budget() to factor in extra budget
In this commit, we update the `Budget()` call to factor in the
`extraBudget` value. Otherwise, when we go to intialize the fee
function, we won't factor in the extra budget, and will determine that
we can't broadcast/bump.
2024-11-15 13:09:10 +01:00
Olaoluwa Osuntokun
6db7d42654
lnwallet: add whoseCommit to FetchLeavesFromCommit
This is useful for additional context to know which commit the
AuxLeafStore is fetching the leaves for.
2024-11-15 13:09:10 +01:00
Olaoluwa Osuntokun
b8035d9db7
sweep: expand NotifyBroadcast to include an outpoint index
In this commit, we expand the `NotifyBroadcast` to include an outpoint
index. This is useful as it indicates the index of a given required tx
out input.
2024-11-15 13:09:09 +01:00
Olaoluwa Osuntokun
83f1c883ba
contractcourt: pass in new aux resolution blob to sweeper in resolvers
With this commit, we update all the resolvers to pass in the new htlc
resolution blobs. Along the way, we remove the old blocking guard on
this resolution logic for HTLCs with blobs.
2024-11-15 13:09:09 +01:00
Olaoluwa Osuntokun
f1a1c033d1
contractcourt: update encode/decode for taproot aux data
When we read/write the aux data, we need to make sure we always set the
new fields for aux HTLCs.
2024-11-15 13:09:09 +01:00
Olaoluwa Osuntokun
6914e6a4a5
contractcourt: add HtlcBlobs to taprootBriefcase
In this commit, we add the set of HtlcBlobs to the taprootBriefcase
struct. This new field will store all the resolution blobs for a given
HTLC. We also add some new property based tests along the way for
adequate test coverage.
2024-11-15 13:09:09 +01:00
Olaoluwa Osuntokun
413fdaf3fb
input: add new Preimage method to input.Input
In this commit, we add a new method to obtain an option of a preimage to
the input.Input struct. This is useful for callers that have an Input,
and want to optionally obtain the preimage.
2024-11-15 13:09:09 +01:00
Olaoluwa Osuntokun
e3eef0adff
lnwallet: populate resolution blob for incoming+outgoing HTLC resolutions
In this commit, we populate the resolution blobs for the incoming and
outgoing HTLCs. We take care to populate the AuxSigDesc with the correct
information, as we need to pass along the second-level aux signature and
also sign desc along with it.
2024-11-15 13:09:09 +01:00
Olaoluwa Osuntokun
84aacc6c39
channel: add ResolutionBlob to Incoming+Outgoing HtlcResolution
Similar to the other blobs we have for the commitment output force close
resolution, these blobs will be used to ensure that we have everything
needed to sweep aux HTLCs.
2024-11-15 13:09:08 +01:00
Olaoluwa Osuntokun
57617dc4f7
channel: always specify ChanType in ResolutionReq 2024-11-15 13:09:08 +01:00
Olaoluwa Osuntokun
a5beb340e4
lnwallet: expand attributes in ResolutionReq
In this commit, we add some additional attributes to the ResolutionReq
struct. These will be used to make sure that we can properly handle all
the HTLC variants, on chain.

The `AuxSigDesc` will be used to communicate if an HTLC needs to go to
the second level or not. It contains the second-level sig information
needed to finalize a broadcast to the second level.
2024-11-15 13:09:07 +01:00
Oliver Gugger
31ace742a5
Merge branch '0-18-4-branch-rc1-9084' into 0-18-4-branch-rc1 2024-11-13 12:52:32 +01:00
Matt Morehouse
2c25f38a5a
discovery: remove check for incorrect number of timestamps
The check is no longer required, as it is now done during decoding.
2024-11-13 12:52:32 +01:00
Matt Morehouse
c8033e1725
lnwire: fail decoding on incorrect number of timestamps
Currently if an incorrect number of timestamps is given, we fail later
on in the GossipSyncer. It makes more sense to fail right away, since we
already do that for incorrect SCID formats (e.g., unsorted or duplicate
SCIDs). There is already a matching check in Encode for incorrect number
of timestamps, so adding this check to Decode makes things symmetric.
2024-11-13 12:52:32 +01:00
Oliver Gugger
9bf48a7e9a
Merge branch '0-18-4-branch-rc1-9082' into 0-18-4-branch-rc1 2024-11-13 12:50:57 +01:00
Matt Morehouse
a4414fbbb9
lnwire: manually compare Timestamps in fuzz test
We can't use require.Equal because it considers nil slices and empty
slices to be not equal.
2024-11-13 12:50:56 +01:00
Oliver Gugger
af08c42d58
Merge branch '0-18-4-branch-rc1-9062' into 0-18-4-branch-rc1 2024-11-08 08:52:31 +01:00
Olaoluwa Osuntokun
b2b5ec052b
contractcourt: use the sweeper for HTLC offered remote timeout resolution
In this commit, we bring the timeout resolver more in line with the
success resolver by using the sweeper to handle the HTLC offered remote
timeout outputs. These are outputs that we can sweep directly from the
remote party's commitment transaction when they broadcast their version
of the commitment transaction.

With this change, we slim down the scope slightly by only doing this for
anchor channels. Non-anchor channels will continue to use the
utxonursery for this output type for now.
2024-11-08 08:52:31 +01:00
Olaoluwa Osuntokun
941590d384
contractcourt: use t.Run in TestHtlcTimeoutResolver
Along the way we refactor the test to eliminate some unnecessary line
length.
2024-11-08 08:52:30 +01:00
Oliver Gugger
906fa0b7b8
Merge branch '0-18-4-branch-rc1-9223' into 0-18-4-branch-rc1 2024-10-30 14:16:37 +01:00
Boris Nagaev
593afee12d
itest: coop_close_with_external_delivery with p2tr
Customize the itest with the type of external delivery address. Test with P2TR
address type in addition to P2WKPH.
2024-10-30 14:16:37 +01:00
Boris Nagaev
552d182594
lnwallet: fix closechannel for P2TR external addr
If the delivery address is P2TR, function InternalKeyForAddr checks its
existance in the wallet to return internal key for it in case it is a custom
taproot channel. It used to return the error returned by wallet.AddressInfo.
The error is now ignored if it is ErrAddressNotFound error. This fixes
"lncli closechannel --delivery_addr <external p2tr address" case.
2024-10-30 14:16:36 +01:00
Oliver Gugger
615f3d633e
Merge branch '0-18-4-branch-rc1-9199' into 0-18-4-branch-rc1 2024-10-25 11:00:09 +02:00
George Tsagkarelis
6f401b4265
invoices: cancel htlc on HtlcModify signal 2024-10-25 11:00:08 +02:00
George Tsagkarelis
2999b37607
lnrpc+invoices: add cancelSet to HtlcModifier interface 2024-10-25 11:00:08 +02:00
Oliver Gugger
b69fc15cc1
Merge branch '0-18-4-branch-rc1-9197' into 0-18-4-branch-rc1 2024-10-22 09:06:30 +02:00
Jonathan Harvey-Buschel
d650829f9b
gitignore: ignore vscode workspace files 2024-10-22 09:06:17 +02:00
Jonathan Harvey-Buschel
455cdffede
lnwallet: test link quit signal handling 2024-10-22 09:06:17 +02:00
Jonathan Harvey-Buschel
8703153c44
multi: link quit can interrupt commitment signing
In this commit, we make sig job handling when singing a next commitment
non-blocking by allowing the shutdown of a channel link to prevent
further waiting on sig jobs by the channel state machine. This addresses
possible cases where the aux signer may be shut down via a separate quit
signal, so the state machine could block indefinitely on receiving an
update on a sig job.
2024-10-22 09:06:17 +02:00
Oliver Gugger
6feb74137d
mod: bump fn to v1.2.3 2024-10-22 09:06:15 +02:00
Jonathan Harvey-Buschel
753301cf38
htlcswitch: pass quit chans as unidirectional
This is a requirement for replacing the quit channel with a Context.
The Done() channel of a Context is always recv-only, so all users of
that channel must not expect a bidirectional channel.
2024-10-22 09:05:42 +02:00
Jonathan Harvey-Buschel
afb7532f17
lnwallet: sort sig jobs before submission 2024-10-22 09:05:42 +02:00
Jonathan Harvey-Buschel
ed5d748a9f
lnwallet: test aux signer shutdown handling 2024-10-22 09:05:42 +02:00
Jonathan Harvey-Buschel
b6363a8da4
lnwallet: refactor test code for HTLC add and recv 2024-10-22 09:05:42 +02:00
Jonathan Harvey-Buschel
afdd53194b
multi: allow mock aux signer to customize sig jobs 2024-10-22 09:05:41 +02:00
Oliver Gugger
6f0d7f9a87
Merge branch '0-18-4-branch-rc1-9195' into 0-18-4-branch-rc1 2024-10-21 13:26:23 +02:00
yyforyongyu
f09b638343
lntest: add method AssertTxnsNotInMempool
So we only need to do one `GetRawMempool` lookup when checking the
exclusion of multiple txns.
2024-10-21 13:26:09 +02:00
yyforyongyu
56e05a3e1e
lntest: remove unused return value 2024-10-21 13:26:09 +02:00
yyforyongyu
1aae94f17d
itest+lntest: stop using pointer to chainhash.Hash
This commit fixes the methods used in `lntest` so they stop using
pointers to chainhash.
2024-10-21 13:26:09 +02:00
Oliver Gugger
3b8b738be9
Merge branch '0-18-4-branch-rc1-9059' into 0-18-4-branch-rc1 2024-10-16 16:00:25 +02:00
Oliver Gugger
55e6460707
docs: add release notes 2024-10-16 15:59:54 +02:00
Oliver Gugger
34ea769501
mod: fix unit tests by updating error matching in btcwallet 2024-10-16 15:59:52 +02:00
Oliver Gugger
57e7b41510
lnwallet: turn off RBF detection in test 2024-10-16 15:58:00 +02:00
Oliver Gugger
6aec5b00ad
lntest: avoid port collision on Tor listen port
bitcoind now seems to listen on the -bind port at all times. So we need
to make sure multiple instances don't collide by using a unique port.
2024-10-16 15:58:00 +02:00
Oliver Gugger
5966150db5
lntest: move debug flag, disable spammy libevent 2024-10-16 15:57:59 +02:00
Oliver Gugger
fe8b89dc2c
github+scripts: bump itests to bitcoind v28, allow testing with RCs 2024-10-16 15:57:59 +02:00
rockstardev
9f0402c685 Updating README 2024-10-15 19:01:28 -05:00
rockstardev
4f332436cc Merge branch 'lnd/v0.18.3-beta'
# Conflicts:
#	docker-initunlocklnd.sh
2024-10-15 18:58:46 -05:00
rockstardev
eb64ae0260 Update README 2024-10-15 18:11:52 -05:00
rockstardev
48120906c9 Merge branch 'lnd/v0.18.3-beta'
# Conflicts:
#	.circleci/config.yml
#	Makefile
#	README.md
#	build/version.go
#	go.mod
#	go.sum
#	linuxamd64.Dockerfile
#	linuxarm32v7.Dockerfile
#	linuxarm64v8.Dockerfile
2024-10-15 18:09:25 -05:00
rockstardev
ae4bb33c6a Adding BtcPayServer related files and resources 2024-10-15 17:56:11 -05:00
rockstardev
8742a9a506
Merge pull request #7 from ziggie1984/fix-lnd-wallet-pw
Fix Password for lnd instance.
2024-10-15 17:36:29 -05:00
Oliver Gugger
9ca21ecf2d
Merge branch '0-18-4-branch-rc1-9187' into 0-18-4-branch-rc1 2024-10-15 17:33:27 +02:00
Oliver Gugger
58bf721f2e
cmd/commands: don't error out on replacement failure 2024-10-15 17:33:26 +02:00
Oliver Gugger
560b7286b5
rpcserver: don't write any custom channel data if empty 2024-10-15 17:33:26 +02:00
ziggie
33508380e7
Fix Password for lnd instance 2024-10-13 15:14:25 +02:00
Oliver Gugger
ca3bde901e
build: bump version to v0.18.4-beta.rc1 2024-10-11 14:46:28 +02:00
Oliver Gugger
89c84f1da6
lnwallet: fix import issue 2024-10-11 14:46:09 +02:00
Oliver Gugger
a3db2145dc
Merge branch '0-18-4-branch-rc1-9154' into 0-18-4-branch-rc1 2024-10-11 14:23:41 +02:00
ziggie
a5eca91602
multi: bump btcd version.
The new SignCompact return values had to be adopted across the
code base.
2024-10-11 14:23:41 +02:00
Oliver Gugger
5c7be35ca5
Merge branch '0-18-4-branch-rc1-8960' into 0-18-4-branch-rc1 2024-10-11 14:23:05 +02:00
Olaoluwa Osuntokun
16edbf3026
sweep: ensure we factor in extra change addrs in MaxFeeRateAllowed 2024-10-11 14:22:50 +02:00
George Tsagkarelis
00ed751ee5
docs: update release notes 2024-10-11 14:22:47 +02:00
Olaoluwa Osuntokun
9f048b0ea3
lnd: signal taproot overlay chans based on config
We also add a sanity check to make sure they can't be signaled without
the aux interfaces.
2024-10-11 14:22:13 +02:00
Olaoluwa Osuntokun
6619646088
lncfg: add new config option for taproot overlay chans 2024-10-11 14:22:13 +02:00
Olaoluwa Osuntokun
3031f21182
rpc+funding: add taproot overlay as RPC chan type 2024-10-11 14:22:12 +02:00
Olaoluwa Osuntokun
4eaba9b3db
lnrpc: add SIMPLE_TAPROOT_OVERLAY feature bit 2024-10-11 14:22:12 +02:00
Olaoluwa Osuntokun
72d437d5c8
funding: add chan type awareness for new taproot chans overlay 2024-10-11 14:22:12 +02:00
Olaoluwa Osuntokun
4efa39ddb1
lnwallet: add awareness of taproot overlay chan type to reservations 2024-10-11 14:22:12 +02:00
Olaoluwa Osuntokun
745f3a6181
feature: add awareness of new taproot chans overlay feature bit
This bit will be false by default in current production deployments.
2024-10-11 14:22:12 +02:00
Olaoluwa Osuntokun
1a3c94a501
lnwire: add new taproot chans overlay feature bit 2024-10-11 14:22:12 +02:00
Olaoluwa Osuntokun
3d7d9d2612
contractcourt: integration aux sweeper to breach arb
Similar to the sweeper, when we're about to make a new breach
transaction, we ask the sweeper for a new change address, if it has one.
Then when we go to publish, we notify broadcast.
2024-10-11 14:22:12 +02:00
Olaoluwa Osuntokun
4c16e55aca
contractcourt: update makeBreachedOutput to accept resolution blob 2024-10-11 14:22:11 +02:00
Olaoluwa Osuntokun
ded6959fd5
contractcourt: update GenSweepScript to return internal key
For the upcoming aux sweeper integration, the internal key is needed for
the call backs.
2024-10-11 14:22:11 +02:00
Olaoluwa Osuntokun
d0501ab840
multi: hook up new aux interfaces 2024-10-11 14:22:11 +02:00
Olaoluwa Osuntokun
678028cee9
contractcourt: pause resolution for HTLCs w/ custom records
This is a hold over until the aux resolution is finalized for HTLC
outputs.
2024-10-11 14:22:11 +02:00
Olaoluwa Osuntokun
a21fb1b69c
sweep: update sweeper to use AuxSweeper to add extra change addr
In this commit, we start to use the AuxSweeper (if present) to obtain a
new extra change addr we should add to the sweeping transaction. With
this, we'll take the set of inputs and our change addr, and then maybe
gain a new change addr to add to the sweep transaction.

The extra change addr will be treated as an extra required tx out,
shared across all the relevant inputs. This'll also be used in
NeedWalletInput to make sure that we add an extra input if needed to be
able to pay for the change addr.
2024-10-11 14:22:11 +02:00
Olaoluwa Osuntokun
23e99ddd4d
sweep: add new AuxSweeper interface
In this commit, we add a new AuxSweeper interface. This'll take a set of
inputs, and a change addr for the sweep transaction, then optionally
return a new sweep output to be added to the sweep transaction.

We also add a new NotifyBroadcast method.  This'll be used to notify
that we're _about_ to broadcast a sweeping transaction. The set of
inputs is passed in, which allows the caller to prepare for the ultimate
broadcast of the sweeping transaction.

We also add ExtraTxOut to BumpRequest pass fees to NotifyBroadcast. This
allows the callee to know the total fee of the sweeping transaction.
2024-10-11 14:22:11 +02:00
Olaoluwa Osuntokun
3726cfa319
server+sweep: convert GenSweepScript to use new addr type
We convert it to use lnwallet.AddrWithKey, as in the future, knowing the
internal key for an address will be useful.
2024-10-11 14:22:11 +02:00
Olaoluwa Osuntokun
fef368bb38
contractcourt: set resolution blob in commitSweepResolver 2024-10-11 14:22:10 +02:00
Olaoluwa Osuntokun
080771db62
input: add ResolutionBlob method to inputKit
We also update breachedOutput w/ the new API.
2024-10-11 14:22:10 +02:00
Olaoluwa Osuntokun
fc02cd7b0c
input: refactor all inputs to use MakeBaseInput, add opts
In this commit, we refactor all the other constructors for the input to
use MakeBaseInput. We also add a new set of functional options as well.
This'll be useful later on to ensure that new options are properly
applied to all the input types.
2024-10-11 14:22:10 +02:00
Olaoluwa Osuntokun
07ee114116
lnwallet+peer: move internalKeyForAddr to lnwallet package
This way we can re-use it. We also make it slightly more generalized.
2024-10-11 14:22:10 +02:00
Olaoluwa Osuntokun
74d27f2c7c
contractcourt: add CommitBlob to taprootBriefcase
This'll be used to store the extra resolution information for the
commitment outputs.
2024-10-11 14:22:10 +02:00
Olaoluwa Osuntokun
f4710ca639
lnwallet: add new aux resolver interface
This will be used by external callers to modify the way we resolve
contracts on chain. For a given contract, we'll store an extra "blob",
that will later be presented during the sweeping phase.
2024-10-11 14:22:10 +02:00
Olaoluwa Osuntokun
900a0a114a
contractcourt: convert taprootBriefcase to use new tlv record type
This commit doesn't yet go all the way to modify all the other records
quite yet.
2024-10-11 14:22:10 +02:00
Olaoluwa Osuntokun
035126b280
lnwire: modify TestLightningWireProtocol to use sub-tests
This way, it's possible to run induvidual tests to target failures.
2024-10-11 14:22:09 +02:00
George Tsagkarelis
9d50e273a3
routing: add htlcAmt to PaymentBandwidth method of TlvTrafficShaper
This commit was added to the 0-19-staging branch recently and therefore
didn't make it into a previous part yet. So it's unrelated to the
changes in this part but is required for the whole custom channel saga.
2024-10-11 14:22:09 +02:00
Oliver Gugger
053b6bcfad
Merge branch '0-18-4-branch-rc1-9134' into 0-18-4-branch-rc1 2024-10-11 14:20:33 +02:00
Elle Mouton
663f4c251e
feature: remove b11 feature bit from default invoice set 2024-10-11 14:20:19 +02:00
Elle Mouton
6df4f27929
server: stop interceptable switch in Stop 2024-10-11 14:20:19 +02:00
Elle Mouton
575d699917
invoices: init quit channel of modifier
Also add atomic start and stop vars to prevent close of a closed
channel.
2024-10-11 14:20:19 +02:00
Elle Mouton
d2c745e610
multi: update PaymentAddr to use fn.Option
Since it is allowed to not be set and so can lead to nil deref panics if
it is a pointer.
2024-10-11 14:20:17 +02:00
Oliver Gugger
7857f38f45
Merge branch '0-18-4-branch-rc1-9095' into 0-18-4-branch-rc1 2024-10-11 14:17:28 +02:00
Oliver Gugger
9ce799578c
multi: add co-op close custom data to close update
With this commit we populate additional information about the close
outputs (including potential custom channel data) in the close update
RPC message.
This will allow custom channels to find out how the additional close
outputs look like on chain and what data they might commit to.

We also hook up the aux custom data formatter, so it can format the
custom channel data to JSON.
2024-10-11 14:17:28 +02:00
Olaoluwa Osuntokun
39e4e8d8a4
peer: decorate delivery addr w/ internal key
In this commit, we move to add the internal key to the delivery addr. This way, we give the aux chan closer the extra information it may need to properly augment the normal co-op close process.
2024-10-11 14:17:28 +02:00
Olaoluwa Osuntokun
fbbcecc635
server+peer: init peer struct w/ AuxChanCloser if present 2024-10-11 14:17:27 +02:00
Olaoluwa Osuntokun
8b97d4f833
lnwallet: modify CoopCloseBalance to not depend on chan commit 2024-10-11 14:17:27 +02:00
Olaoluwa Osuntokun
e536cfad0f
lnwallet/chancloser: add aux chan closer, use in coop flow 2024-10-11 14:17:27 +02:00
Olaoluwa Osuntokun
e2dae56698
lnwallet/chancloser: add new AuxChanCloser interface 2024-10-11 14:17:27 +02:00
Olaoluwa Osuntokun
2d8c4fda2f
lnwallet: add ability to do custom sort for coop close txn 2024-10-11 14:17:27 +02:00
Olaoluwa Osuntokun
0cb211e14c
lnwallet: add ability to add extra co-op close outputs 2024-10-11 14:17:27 +02:00
Olaoluwa Osuntokun
7e4f6f5b4a
lnwallet: add FundingBlob method to LightningChannel 2024-10-11 14:17:27 +02:00
Olaoluwa Osuntokun
6feb189a21
lnwire: add CustomRecords to shutdown message 2024-10-11 14:17:26 +02:00
ffranr
35ce62c021
itest: add basic invoice HTLC modifier integration test
This commit introduces a basic integration test for the invoice
HTLC modifier. The test covers scenarios where an invoice is settled with a
payment that is less than the invoice amount, facilitated by the invoice
HTLC modifier.
2024-10-11 14:17:26 +02:00
Oliver Gugger
0cb599dbf6
lnrpc+rpcserver: encode custom records as custom channel data
With this commit we encode the custom records as a TLV stream into the
custom channel data field of the invoice HTLC.
This allows the custom data parser to parse those records and replace it
with human-readable JSON on the RPC interface.
2024-10-11 14:17:26 +02:00
ffranr
c1aa44c476
multi: pass UpdateAddHtlc message custom records to invoice modifier 2024-10-11 14:17:26 +02:00
Oliver Gugger
109e27cfb2
lnwire: add MergedCopy method to CustomRecords 2024-10-11 14:17:26 +02:00
ffranr
ce7c053de0
lntest: add HtlcModifier support to node RPC harness
This commit enhances the itest LND node harness to include support for
the new `HtlcModifier` RPC endpoint.
At the same time we move another method to the correct file.
2024-10-11 14:17:26 +02:00
ffranr
e417250f6d
invoicesrpc: add HtlcModifier RPC endpoint and modifier RPC server
This commit introduces a singleton invoice HTLC modifier RPC server and
an endpoint to activate it. The server interfaces with the internal
invoice HTLC modifier interpreter, handling the marshalling between RPC
types and internal formats.
2024-10-11 14:17:26 +02:00
ffranr
7285dfa66a
invoicesrpc: add HTLC modifier to invoices RPC server
This commit integrates the HTLC modifier service into the
invoices RPC server.
2024-10-11 14:17:25 +02:00
ffranr
f903e16c47
lnd: initialize invoice settlement interceptor at server startup
This commit initiates the invoice settlement interceptor during the
main server startup, assigning it a handle within the server.
2024-10-11 14:17:25 +02:00
ffranr
4d9422a064
invoices: integrate settlement interceptor with invoice registry
This commit updates the invoice registry to utilize the settlement
interceptor during the invoice settlement routine. It allows the
interceptor to capture the invoice, providing interception clients an
opportunity to determine the settlement outcome.
2024-10-11 14:17:25 +02:00
ffranr
acf0d0ebe8
invoices: add invoice htlc interceptor service
This commit introduces a new invoice htlc interceptor service
that intercepts invoice HTLCs during their settlement phase. It forwards
HTLCs to a subscribed client to determine their settlement outcomes.

This commit also introduces an interface to facilitate integrating the
interceptor with other packages.
2024-10-11 14:17:25 +02:00
Oliver Gugger
153a133ea6
Merge branch '0-18-4-branch-rc1-9072' into 0-18-4-branch-rc1 2024-10-11 14:16:36 +02:00
Oliver Gugger
c3627545be
htlcswitch: override amount check on custom records 2024-10-11 14:16:36 +02:00
Oliver Gugger
b35dae72a5
channeldb: add NextHeight, fix formatting 2024-10-11 14:16:36 +02:00
Oliver Gugger
f9debb148b
lnd: add aux data parser
This commit adds an optional data parser that can inspect and in-place
format custom data of certain RPC messages.
We don't add an implementation of the interface itself, as that will be
provided by external components when packaging up lnd as a bundle with
other software.
2024-10-11 14:16:36 +02:00
Oliver Gugger
23ef68a2f7
lnrpc+rpcserver: add and populate custom channel data 2024-10-11 14:16:36 +02:00
Jonathan Harvey-Buschel
9c80088abd
lnwallet: sort sig jobs before submission
To make sure we attempt to read the results of the sig batches in the
same order they're processed, we sort them _before_ submitting them to
the batch processor.
Otherwise it might happen that we try to read on a result channel that
was never sent on because we aborted due to an error.
We also use slices.SortFunc now which doesn't use reflection and might
be slightly faster.
2024-10-11 14:16:35 +02:00
Olaoluwa Osuntokun
69155bc60b
multi: obtain+verify aux sigs for all second level HTLCs
In this commit, we start to use the new AuxSigner to obtain+verify aux sigs for all second level HTLCs. This is similar to the existing SigPool, but we'll only attempt to do this if the AuxSigner is present (won't be for most channels).
2024-10-11 14:16:35 +02:00
Oliver Gugger
4db0d76ca4
lnwire: add custom records field to type CommitSig 2024-10-11 14:16:35 +02:00
Olaoluwa Osuntokun
b83783cc3d
lnwallet: add WithAuxSigner option to channel 2024-10-11 14:16:35 +02:00
Oliver Gugger
6d3f8af007
lnwallet: clarify usage of cancel and response channels 2024-10-11 14:16:35 +02:00
Oliver Gugger
266aba8a6c
lnwallet: allow read-only access to HtlcView's HTLCs
Due to a recent refactor, the HTLCs are no longer an exported type.
Custom channels need access to those updates, so we provide them in a
read-only manner.
2024-10-11 14:16:35 +02:00
Olaoluwa Osuntokun
6dda51d026
lnwallet: add new AuxSigner interface to mirror SigPool
In this commit, we add a new aux signer interface that's meant to mirror the SigPool. If present, this'll be used to (maybe) obtain signatures for second level HTLCs for certain classes of custom channels.
2024-10-11 14:16:35 +02:00
Oliver Gugger
dbb87b4ef9
funding: inform aux controller about channel ready/finalize 2024-10-11 14:16:34 +02:00
Oliver Gugger
18dca6f4c8
multi: add tapscript root to gossip message 2024-10-11 14:16:34 +02:00
Olaoluwa Osuntokun
1402f087ab
funding+lnwallet: finish hook up new aux funding flow
For the initiator, once we get the signal that the PSBT has been
finalized, we'll call into the aux funder to get the funding desc. For
the responder, once we receive the funding_created message, we'll do the
same.

We now also have local+remote aux leaves for the commitment transaction.

Some old TODO comments that in retrospect aren't required anymore are
removed as well.
2024-10-11 14:16:34 +02:00
Olaoluwa Osuntokun
f2dff16c37
funding+lnwallet: only blind tapscript root early in funding flow
In this commit, we modify the aux funding work flow slightly. We won't
be able to generate the full AuxFundingDesc until both sides has
sent+received funding params. So we'll now only attempt to bind the
tapscript root as soon as we send+recv the open_channel message.

We'll now also make sure that we pass the tapscript root all the way
down into the musig2 session creation.
2024-10-11 14:16:34 +02:00
Olaoluwa Osuntokun
39b1080166
lnwallet: for PsbtIntent return the internal key in the POutput
We also add a new assertion to the itests to ensure the field is being properly set.
2024-10-11 14:16:34 +02:00
Olaoluwa Osuntokun
0a7139c9ca
lnwallet: add TaprootInternalKey method to ShimIntent
If this is a taproot channel, then we'll return the internal key which'll be useful to callers.
2024-10-11 14:16:34 +02:00
Olaoluwa Osuntokun
723621bd2b
config+serer: add AuxFundingController as top level cfg option 2024-10-11 14:16:34 +02:00
Olaoluwa Osuntokun
7f3aff9e10
funding: create new AuxFundingController interface
In this commit, we make a new `AuxFundingController` interface capable of processing messages off the wire. In addition, we can use it to abstract away details w.r.t how we obtain a `AuxFundingDesc` for a given channel.

We'll now use this whenever we get a channel funding request, to make sure we pass along the custom state that a channel may require.
2024-10-11 14:16:33 +02:00
Olaoluwa Osuntokun
5f5bbf9ae2
lnwallet: use AuxFundingDesc to populate all custom chan info
With this commit, we'll now populate all the custom channel information within the OpenChannel and ChannelCommitment structs.
2024-10-11 14:16:33 +02:00
Olaoluwa Osuntokun
f73f5f5582
lnwallet: add new AuxFundingDesc struct
This struct will house all the information we'll need to do a class of custom channels that relies primarily on adding additional items to the tapscript root of the HTLC/commitment/funding outputs.
2024-10-11 14:16:33 +02:00
Oliver Gugger
a7534597dd
Merge branch '0-18-4-branch-rc1-8981' into 0-18-4-branch-rc1 2024-10-11 14:15:30 +02:00
Keagan McClelland
56866448dc
lnwallet: remove unnecessary chanID argument form unsignedLocalUpdates 2024-10-11 14:15:16 +02:00
Keagan McClelland
f8979c0614
htlcswitch+lnwallet: quarantine paymentDescriptor to lnwallet
The objective of this commit is to make paymentDescriptor a private
data structure so we can quarantine it to the lnwallet package.
To accomplish this we had to prevent it from leaking out via the
arguments or return values of the public functions in lnwallet.
This naturally had consequences for the htlcswitch package as we
choose other mechanisms for tracking the data that paymentDescriptor
was responsible for.

Astoundingly, this was highly successful and allowed us to remove
a ton of redundant code. The diff for this commit represents a
substantial reduction in total lines of code as well as extraneous
arguments and return values from key functions.

This also sets the stage for future commits where we actually will
be attempting to rid lnwallet of paymentDescriptor completely.
2024-10-11 14:15:14 +02:00
Keagan McClelland
7e5f6b5802
lnwallet: remove unused function PayDescsFromRemoteLogUpdates
This function is no longer used as of the last commit and it is the
last remaining leak of the PaymentDescriptor type through the public
API.
2024-10-11 14:14:41 +02:00
Keagan McClelland
addf9e8dbe
htlcswitch: remove PaymentDescriptor conversion from reforwardSettleFails
This is part of a systematic removal of PaymentDescriptor from the mechanics
of the htlcswitch package.
2024-10-11 14:14:41 +02:00
Keagan McClelland
870800b81a
htlcswitch+lnwallet: remove PaymentDescriptor from ReceiveRevocation returns
This is part of a systematic removal of PaymentDescriptor from the public
API of the lnwallet package. This marks the last change needed before we
make the PaymentDescriptor structure private.
2024-10-11 14:14:41 +02:00
Keagan McClelland
a3e127d1d6
htlcswitch: remove PaymentDescriptor from processRemoteSettleFails call signature
This is part of a systematic removal of PaymentDescriptor from the mechanics
of the htlcswitch package.
2024-10-11 14:14:41 +02:00
Keagan McClelland
875d2e4664
htlcswitch: remove PaymentDescriptor from processRemoteAdds call signature
This is part of a systematic removal of PaymentDescriptor from the mechanics
of the htlcswitch package.
2024-10-11 14:14:41 +02:00
Keagan McClelland
dd9568b648
htlcswitch: remove PaymentDescriptor from hodlHtlc
This is part of a systematic removal of PaymentDescriptor from the
mechanics of the htlcswitch package.
2024-10-11 14:14:40 +02:00
Keagan McClelland
e7d545fb0a
htlcswitch: remove PaymentDescriptor from the processExitHop's call signature
This is part of a systematic removal of PaymentDescriptor from the mechanics
of the htlcswitch package.
2024-10-11 14:14:40 +02:00
Keagan McClelland
160747cf5e
htlcswitch: remove PaymentDescriptor from settleHTLC's call signature
This is done as part of a systematic removal of PaymentDescriptor from
the mechanics of the htlcswitch package.
2024-10-11 14:14:40 +02:00
Keagan McClelland
22b2568f22
htlcswitch: remove PaymentDescriptor from sendHTLCError's call signature
This is done as part of a systematic removal of PaymentDescriptor from
the mechanics of the htlcswitch package.
2024-10-11 14:14:40 +02:00
Keagan McClelland
7f2fe2e5ff
channeldb: add convenience functions for generating Source/Dest Refs 2024-10-11 14:14:40 +02:00
Keagan McClelland
d364b9b9f8
lnwallet: add function to convert paymentDescriptor to LogUpdate
Here we add a function that is capable of recovering LogUpdates from
paymentDescriptors and we refactor the lnwallet code to use this
rather than doing JIT inline construction of the LogUpdates.
2024-10-11 14:14:40 +02:00
Keagan McClelland
9904af5d96
lnwire+htlcswitch: change NewInvalidBlinding to use array instead of slice 2024-10-11 14:14:40 +02:00
Keagan McClelland
e4497b4f45
htlcswitch: change sendMalformedHTLCError to take array instead of slice 2024-10-11 14:14:39 +02:00
Keagan McClelland
fb841b6436
htlcswitch+lnwallet: fix OnionBlob to 1366 bytes 2024-10-11 14:14:39 +02:00
Keagan McClelland
391370de20
lnwallet: track ChannelID on PaymentDescriptor
In this commit we track the ChannelID on the PaymentDescriptor.
This will be useful in upcoming commits that need to be able to
reconstruct lnwire.Message values from PaymentDescriptors as the
Messages that are exchanged to update channel state all include
the ChannelID.
2024-10-11 14:14:39 +02:00
Keagan McClelland
a40d363936
lnwallet: add ChannelID method to LightningChannel
In this commit we introduce a convenience method to LightningChannel
to allow us to quickly grab the channel id. This will be important
in upcoming commits where we need to remember the ChannelID to
reconstruct update messages.
2024-10-11 14:14:39 +02:00
Oliver Gugger
8cb8f589ee
Merge branch '0-18-4-branch-rc1-9049' into 0-18-4-branch-rc1 2024-10-11 14:13:49 +02:00
George Tsagkarelis
b0be0adcef
itest: add interceptor and first hop data tests 2024-10-11 14:13:49 +02:00
Oliver Gugger
1822b2f79a
lnrpc: add first hop custom data to route 2024-10-11 14:13:48 +02:00
George Tsagkarelis
444ef199a6
routing: use first hop records on path finding 2024-10-11 14:13:48 +02:00
Oliver Gugger
5489b06628
channeldb+routing: persist first hop custom data for route 2024-10-11 14:13:48 +02:00
George Tsagkarelis
6ac750955f
lnd: use impl cfg TlvTrafficShaper 2024-10-11 14:13:48 +02:00
Olaoluwa Osuntokun
ec2b2c6e1e
routing: skip amtInRange for custom HTLCs
We might be trying to send an invoice amount that's greater than the size of the channel, but once you factor in the custom channel logic, an actual HTLC can be sent over the channel to pay that larger payment.

As a result, we'll skip over this check if a have a custom HTLC.
2024-10-11 14:13:48 +02:00
George Tsagkarelis
f927563049
routing: add TlvTrafficShaper to bandwidth hints 2024-10-11 14:13:48 +02:00
George Tsagkarelis
69430ce042
htlcswitch: expose custom channel blob from link 2024-10-11 14:13:48 +02:00
George Tsagkarelis
c70832a823
lnwallet: expose commitment blob from channel 2024-10-11 14:13:47 +02:00
Oliver Gugger
0403b97a87
lnrpc: add first hop custom records to RPC payment info 2024-10-11 14:13:47 +02:00
Oliver Gugger
ff1a45549e
channeldb+routing: persist first hop custom records
With this commit we make sure the first hop custom records aren't lost
on restart/resume of a payment, so we persist it as part of the
PaymentCreationInfo struct.
2024-10-11 14:13:47 +02:00
George Tsagkarelis
857a16d838
lnrpc: add wire records fields to payment+interceptor RPCs 2024-10-11 14:13:47 +02:00
George Tsagkarelis
ef2c9801fb
multi: use wire records on payment and intercept flows 2024-10-11 14:13:47 +02:00
Oliver Gugger
b5efc0ef3e
lnwallet: extract diskCommit, remove unused error return value 2024-10-11 14:13:47 +02:00
ffranr
1b28f47c1d
itest: add itest for field modification HTLC interception response
Implement an integration test where an HTLC is intercepted and the
interception response modifies fields in the resultant p2p message.
2024-10-11 14:13:47 +02:00
ffranr
533b9f2d45
routerrpc: extend HTLC forward interceptor resp with modification fields
This commit extends the forward HTLC intercept response with fields that
can be used in conjunction with a `ResumeModified` action to modify the
intercepted HTLC p2p message.
2024-10-11 14:13:46 +02:00
ffranr
49db662b82
htlcswitch: add resume modified HTLC action to switch
Introduce `ResumeModified` action to resume standard behavior of a p2p
message with optional modifications as specified by the client during
interception.
2024-10-11 14:13:46 +02:00
ffranr
cb15297853
lnwire: add custom records field to type UpdateFulfillHtlc
- Introduce the field `CustomRecords` to the type `UpdateFulfillHtlc`.
- Encode and decode the new field into the `ExtraData` field of the
`update_fulfill_htlc` wire message.
- Empty `ExtraData` field is set to `nil`.
2024-10-11 14:13:46 +02:00
ffranr
2cfa89c719
lnwire: add custom records field to type UpdateAddHtlc
- Introduce the field `CustomRecords` to the type `UpdateAddHtlc`.
- Encode and decode the new field into the `ExtraData` field of
  the `update_add_htlc` wire message.
2024-10-11 14:13:46 +02:00
ffranr
ed69bb8757
lnwire: add ExtraOpaqueData helper functions and methods
Introduces a couple of new helper functions for both the ExtraOpaqueData
and CustomRecords types along with new methods on the ExtraOpaqueData.
2024-10-11 14:13:46 +02:00
ffranr
b07e857aef
lnwire: add unit tests for ExtraOpaqueData.PackRecords 2024-10-11 14:13:46 +02:00
George Tsagkarelis
08ca28773c
itest: add dynamic scid alias routing test 2024-10-11 14:13:46 +02:00
George Tsagkarelis
d6ef2a122f
routerrpc: add XAddLocalChanAliases & XDeleteLocalChanAliases 2024-10-11 14:13:45 +02:00
Oliver Gugger
2b1f347f98
aliasmgr: export alias start and end ranges
Because we restrict custom SCID aliases to be in a specific range, we
export the range start and end values so a user of the RPCs we're going
to add in the next commits can adjust their values to fit within the
range.
2024-10-11 14:13:45 +02:00
Oliver Gugger
148ba49530
aliasmgr: avoid collision when requesting alias
With the new RPC calls that we are going to add in the next commits, it
will be possible for users to add (local only, non-gossipped) SCID
aliases for channels. Since those will be in the same range as the ones
given out by RequestAlias, we need to make sure that when we generate a
new one that it doesn't collide with an already existing one.
2024-10-11 14:13:45 +02:00
Oliver Gugger
4757e891a2
aliasmgr: add map type alias 2024-10-11 14:13:45 +02:00
George Tsagkarelis
4ef68512a9
multi: refresh htlcswitch aliases on aliasmgr update 2024-10-11 14:13:45 +02:00
George Tsagkarelis
0c95dc2118
aliasmgr: add delete local alias method 2024-10-11 14:13:45 +02:00
Oliver Gugger
2da56bd776
Merge branch '0-18-4-branch-rc1-9044' into 0-18-4-branch-rc1 2024-10-11 14:13:12 +02:00
Keagan McClelland
d4a4233e96
lnwallet+htlcswitch: define expanded NumPendingUpdates
This commit squashes the below operations for a net result where
we have an expanded capability of assessing pending updates. This
is made possible by packing the components into Duals in the prior
commits. We squash the operations to simplify review.

htlcswitch+lnwallet: rename PendingLocalUpdateCount

lnwallet: complete pending update queries API for LightningChannel

lnwallet+htlcswitch: consolidate NumPendingUpdates using ChannelParty

This commit makes the observation that we can cleanly define the
NumPendingUpdates function using a single expression by taking
advantage of the relevant fields being properly packed into Duals.
2024-10-11 14:12:54 +02:00
Keagan McClelland
b337213fb2
lnwallet: pack commitment message indices into Dual
This is yet another commit that packs a symmetric structure into
a Dual. This is the last one needed for the time being to consolidate
Num{X}UpdatesPendingOn{Y} functions into a single one.
2024-10-11 14:12:53 +02:00
Keagan McClelland
214dac0c45
lnwallet: pack update logs into Dual
This commit, like the last one packs the update logs into a symmetric
Dual structure. This will allow us to index into them more concisely
in higher order logic.
2024-10-11 14:12:52 +02:00
Keagan McClelland
61383f1014
lnwallet: pack commit chains into Dual
This commit packs the LightningChannel's localCommitmentChain and
remoteCommitmentChain into a Dual structure for better symmetric
access. This will be leveraged by an upcoming commit where we want
to more concisely express how we compute the number of pending
updates.
2024-10-11 14:12:28 +02:00
Keagan McClelland
89a94e9ac8
htlcswitch: extract error handling for syncChanStates 2024-10-11 14:12:27 +02:00
Oliver Gugger
767a6f99a5
Merge branch '0-18-4-branch-rc1-9030' into 0-18-4-branch-rc1 2024-10-11 14:11:58 +02:00
Oliver Gugger
b0728647c9
lnwallet: thread thru input.AuxTapleaf to all relevant areas
In this commit, we start to thread thru the new aux tap leaf structures to all relevant areas. This includes: commitment outputs, resolution creation, breach handling, and also HTLC scripts.
2024-10-11 14:11:58 +02:00
Oliver Gugger
860cacb70a
lnwallet: refactor commit keys to use lntypes.Dual 2024-10-11 14:11:58 +02:00
Oliver Gugger
b1c8a836e3
multi: thread thru the AuxLeafStore everywhere 2024-10-11 14:11:58 +02:00
Olaoluwa Osuntokun
180648072c
channeldb: add HtlcIndex to HTLCEntry
This may be useful for custom channel types that base everything off the index (a global value) rather than the output index (can change with each state).
2024-10-11 14:11:58 +02:00
Olaoluwa Osuntokun
eb600a9447
channeldb: add custom blobs to RevocationLog+HTLCEntry
This'll be useful for custom channel types that want to store extra information that'll be useful to help handle channel revocation cases.
2024-10-11 14:11:58 +02:00
Olaoluwa Osuntokun
1f785e897e
channeldb: convert RevocationLog to use RecordT 2024-10-11 14:11:57 +02:00
Olaoluwa Osuntokun
314a24689c
channeldb: convert HTLCEntry to use tlv.RecordT 2024-10-11 14:11:57 +02:00
Olaoluwa Osuntokun
12ab2c3b51
lnwallet: add TLV blob to PaymentDescriptor + htlc add
In this commit, we add a TLV blob to the PaymentDescriptor struct. We also now thread through this value from the UpdateAddHTLC message to the PaymentDescriptor mapping, and the other way around.
2024-10-11 14:11:57 +02:00
Olaoluwa Osuntokun
ef56d8654e
lnwallet+channeldb: add new AuxLeafStore for dynamic aux leaves
In this commit, we add a new AuxLeafStore which can be used to dynamically fetch the latest aux leaves for a given state. This is useful for custom channel types that will store some extra information in the form of a custom blob, then will use that information to derive the new leaf tapscript leaves that may be attached to reach state.
2024-10-11 14:11:57 +02:00
Olaoluwa Osuntokun
9db810d67a
input: add some utility type definitions for aux leaves
In this commit, we add some useful type definitions for the aux leaf.
2024-10-11 14:11:57 +02:00
Olaoluwa Osuntokun
ae1b121cdd
lnwallet: add custom tlv blob to internal commitment struct
In this commit, we also add the custom TLV blob to the internal commitment struct that we use within the in-memory commitment linked list.

This'll be useful to ensure that we're tracking the current blob for our in memory commitment for when we need to write it to disk.
2024-10-11 14:11:57 +02:00
Olaoluwa Osuntokun
da9ceb131b
lnwallet: export the HtlcView struct
We'll need this later on to ensure we can always interact with the new aux blobs at all stages of commitment transaction construction.
2024-10-11 14:11:57 +02:00
Olaoluwa Osuntokun
cd155d7d17
channeldb: new custom blob nested TLV
In this commit, for each channel, we'll now start to store an optional custom blob. This can be used to store extra information for custom channels in an opauqe manner.
2024-10-11 14:11:56 +02:00
Olaoluwa Osuntokun
41bd293f33
input+lnwallet: update taproot scripts to accept optional aux leaf
In this commit, we update all the taproot scripts to also accept an
optional aux leaf. This aux leaf can be used to add more redemption
paths for advanced channels, or just as an extra commitment space.
2024-10-11 14:11:56 +02:00
Olaoluwa Osuntokun
ca5dcbbf5c
lnwallet: add initial unit tests for musig2+tapscript root chans 2024-10-11 14:11:56 +02:00
Olaoluwa Osuntokun
cae4f21897
lnwallet+peer: add tapscript root awareness to musig2 sessions
With this commit, the channel is now aware of if it's a musig2 channel, that also has a tapscript root. We'll need to always pass in the tapscript root each time we: make the funding output, sign a new state, and also verify a new state.
2024-10-11 14:11:56 +02:00
Olaoluwa Osuntokun
62713c1270
lnwallet: update internal funding flow w/ tapscript root
This isn't hooked up yet to the funding manager, but with this commit, we can now start to write internal unit tests that handle musig2 channels with a tapscript root.
2024-10-11 14:11:56 +02:00
Olaoluwa Osuntokun
b7e153fd82
multi: update GenTaprootFundingScript to pass tapscript root
In most cases, we won't yet be passing a root. The option usage helps us keep the control flow mostly unchanged.
2024-10-11 14:11:56 +02:00
Olaoluwa Osuntokun
9fd8287c7b
lnwallet/chanfunding: add optional tapscript root 2024-10-11 14:11:55 +02:00
Olaoluwa Osuntokun
1e71b1e544
multi: add new tapscript root option to GenTaprootFundingScript
This'll allow us to create a funding output that uses musig2, but uses a tapscript tweak rather than a normal BIP 86 tweak.
2024-10-11 14:11:55 +02:00
Olaoluwa Osuntokun
74cb1f48ad
channeldb: add optional TapscriptRoot field + feature bit 2024-10-11 14:11:55 +02:00
Olaoluwa Osuntokun
e71627f893
channeldb: consolidate root bucket TLVs into new struct
In this commit, we consolidate the root bucket TLVs into a new struct.
This makes it easier to see all the new TLV fields at a glance. We also
convert TLV usage to use the new type param based APis.
2024-10-11 14:11:55 +02:00
Oliver Gugger
264dcd0641
Merge branch '0-18-4-branch-rc1-9025' into 0-18-4-branch-rc1 2024-10-11 14:04:01 +02:00
Oliver Gugger
830dd49fa8
routing+lnrpc: fix log statements 2024-10-11 14:04:00 +02:00
Oliver Gugger
1447493081
server: fix logging of pubkey 2024-10-11 14:04:00 +02:00
Oliver Gugger
2d6ba8c056
cmd/commands: export StripPrefix 2024-10-11 14:04:00 +02:00
Oliver Gugger
4fd1abfe52
lnwallet: add Tree() method, fix formatting 2024-10-11 14:04:00 +02:00
Oliver Gugger
89f75e7d1b
lnwallet: export GenTaprootHtlcScript 2024-10-11 14:04:00 +02:00
Oliver Gugger
29f139225b
lnwallet: export AnchorSize 2024-10-11 14:04:00 +02:00
Oliver Gugger
90470065ba
cmd/lncli: move commands and export
We want to export some of our CLI code to re-use in other projects. But
in Golang you cannot import code from a `main` package.
So we need to move the actual code into its own package and only have
the `func main()` in the `main` package.
2024-10-11 14:04:00 +02:00
Olaoluwa Osuntokun
41ca01a1b7
funding: use atomic.Uint64 for chanIDNonce
This lets us get rid of the mutex usage there. We also shift the algo slightly to increment by 1, then use that as the next value, which plays nicer with the atomics.
2024-10-11 14:03:59 +02:00
Olaoluwa Osuntokun
cd5fa5976a
funding: add new type alias for PendingChanID = [32]byte
This'll be useful for new interface definitions that use the contents of the package.
2024-10-11 14:03:59 +02:00
ffranr
b59ecc9270
htlcswitch: add missing method doc 2024-10-11 14:03:59 +02:00
ffranr
cc2b7b6fda
multi: improve comment grammar 2024-10-11 14:03:59 +02:00
ffranr
58ed8e751d
lnwire: add type CustomRecords
This commit introduces the `CustomRecords` type in the `lnwire` package,
designed to hold arbitrary byte slices. Each entry in this map can
associate with TLV type values that are greater than or equal to 65536.
2024-10-11 14:03:59 +02:00
Oliver Gugger
1893104392
mod: bump tlv to v1.2.6 2024-10-11 14:03:59 +02:00
Olaoluwa Osuntokun
213618adcc
lnwallet/chanfunding: rename assembler.go to interface.go
In this commit, we rename the files as assembler.go houses the primary
interfaces/abstractions of the package. In the rest of the codebase,
this file is near uniformly called interface.go, so we rename the file
to make the repo more digestible at a scan.
2024-10-11 14:03:59 +02:00
Oliver Gugger
7e656257d1
Merge branch '0-18-4-branch-rc1-9007' into 0-18-4-branch-rc1 2024-10-11 14:02:44 +02:00
Oliver Gugger
c849f91590
.golangci: fix config, update new-from-rev 2024-10-11 14:02:31 +02:00
Oliver Gugger
03493d491b
multi: update linter, fix new issues 2024-10-11 14:02:30 +02:00
Oliver Gugger
7502bf3ad9
.golangci: remove or rename old and deprecated linters 2024-10-11 14:01:44 +02:00
Olaoluwa Osuntokun
e735f77d43
build: set min build version to Go 1.22.6
Go 1.23 was released this week, so with this PR we update the build
system to officially support the last two releases.
2024-10-11 14:01:44 +02:00
Oliver Gugger
3b5e1fa764
Merge branch '0-18-4-branch-rc1-8520' into 0-18-4-branch-rc1 2024-10-11 14:01:29 +02:00
Olaoluwa Osuntokun
8eae1eec4a
peer: don't stop global msg router
In this commit, we fix a bug that would cause a global message router to
be stopped anytime a peer disconnected. The global msg router only
allows `Start` to be called once, so afterwards, no messages would
properly be routed.
2024-10-11 14:01:29 +02:00
Olaoluwa Osuntokun
35e48838c3
multi: make MsgRouter available in the ImplementationCfg
With this commit, we allow the `MsgRouter` to be available in the
`ImplementationCfg`. With this, programs outside of lnd itself are able
to now hook into the message processing flow to direct handle custom
messages, and even normal wire messages.
2024-10-11 14:01:29 +02:00
Olaoluwa Osuntokun
e257188017
peer: update readHandler to dispatch to msgRouter if set
Over time with this, we should be able to significantly reduce the size
of the peer.Brontide struct as we only need all those deps as the peer
needs to recognize and handle each incoming wire message itself.
2024-10-11 14:01:29 +02:00
Olaoluwa Osuntokun
a888573fcc
msgmux: add new abstract message router
In this commit, we add a new abstract message router. Over time, the
goal is that this message router replaces the logic we currently have in
the readHandler (the giant switch for each message).

With this new abstraction, can reduce the responsibilities of the
readHandler to *just* reading messages off the wire and handing them off
to the msg router. The readHandler no longer needs to know *where* the
messages should go, or how they should be dispatched.

This will be used in tandem with the new `protofsm` module in an
upcoming PR implementing the new rbf-coop close.
2024-10-11 14:01:29 +02:00
Oliver Gugger
0719c808dd
Merge branch '0-18-4-branch-rc1-8996' into 0-18-4-branch-rc1 2024-10-11 11:42:24 +02:00
Keagan McClelland
8344699a0d
lntypes: Add Dual[A] primitive type
This commit introduces a new type Dual[A] to make it easier to
manage symmetric configurations or state for lightning channels.
2024-10-11 11:42:23 +02:00
rockstardev
d946972ac8 Updating README 2024-07-07 08:18:03 -05:00
rockstardev
c28190c73b Documenting LND update process 2024-07-07 08:11:14 -05:00
rockstardev
a309bbbbf0 Merge branch 'lnd/v0.18.1-beta' and Update README
# Conflicts:
#	linuxamd64.Dockerfile
#	linuxarm32v7.Dockerfile
#	linuxarm64v8.Dockerfile
2024-07-07 08:05:27 -05:00
rockstardev
fc7b2c1d59 Merge branch 'lnd/v0.18.0-beta' and Update README
# Conflicts:
#	.github/workflows/main.yml
#	Makefile
#	README.md
#	build/version.go
#	contractcourt/channel_arbitrator.go
#	docs/release-notes/release-notes-0.17.4.md
#	go.mod
#	go.sum
#	htlcswitch/link.go
#	itest/list_on_test.go
#	itest/lnd_channel_backup_test.go
#	itest/lnd_channel_force_close_test.go
#	itest/lnd_multi-hop_test.go
#	itest/lnd_onchain_test.go
#	itest/lnd_open_channel_test.go
#	itest/lnd_psbt_test.go
#	linuxamd64.Dockerfile
#	linuxarm32v7.Dockerfile
#	linuxarm64v8.Dockerfile
#	lncfg/config.go
#	lncfg/dev.go
#	lncfg/dev_integration.go
#	lnrpc/walletrpc/walletkit.pb.go
#	lntest/harness.go
#	lnwallet/channel.go
#	lnwallet/channel_test.go
#	peer/brontide.go
#	peer/brontide_test.go
#	peer/test_utils.go
#	server.go
#	sweep/sweeper.go
#	sweep/tx_input_set.go
#	sweep/txgenerator.go
2024-07-07 08:04:55 -05:00
rockstardev
6495ab7066 Updating README 2024-07-07 08:03:26 -05:00
rockstardev
9f94d045ae Adding BtcPayServer related files and resources 2024-07-07 06:11:06 -05:00
Olaoluwa Osuntokun
42b856dbb9
Merge pull request #8866 from ellemouton/0-18-1-fix
build: create v0.18.1-beta release branch
2024-06-25 15:34:32 -07:00
Oliver Gugger
f695451da0
build: bump version to v0.18.1-beta 2024-06-25 13:54:50 -07:00
yyforyongyu
362182bd88
docs: update release notes for 0.18.1-beta 2024-06-25 13:46:56 -07:00
yyforyongyu
e34702ab5b
mod: update btcd and btcwallet versions 2024-06-25 13:46:56 -07:00
rockstardev
c841954c51 Bumping golang to 1.22.3 2024-05-31 08:51:13 -05:00
rockstardev
b3aecc7ac5 Bumping loop to 0.28.2 2024-05-31 08:35:44 -05:00
rockstardev
0faa1f4de2 Adding BtcPayServer related files and resources 2024-05-31 08:33:46 -05:00
rockstardev
f6f5e312f3 Merge commit '3da3d28064d2712400f1b579bd4dfa34e04fd227' 2024-05-31 08:25:35 -05:00
rockstardev
8fca329810 Merge basedon-v0.17.3-beta
# Conflicts:
#	docker-initunlocklnd.sh
#	linuxamd64.Dockerfile
#	linuxarm32v7.Dockerfile
#	linuxarm64v8.Dockerfile
2024-05-31 08:25:24 -05:00
rockstardev
9b43b0aa1a Merge commit 'b8c6baa94a949297397faba034a0979fd365609a' 2024-05-31 08:24:06 -05:00
rockstardev
6de26dc8ad Merge basedon-v0.17.1-beta
# Conflicts:
#	build/version.go
#	linuxamd64.Dockerfile
#	linuxarm32v7.Dockerfile
#	linuxarm64v8.Dockerfile
2024-05-31 08:23:52 -05:00
rockstardev
3da3d28064 Adding BtcPayServer related files and resources 2024-02-06 21:29:46 -06:00
Olaoluwa Osuntokun
8bba79222f
build: bump version to v0.17.4-beta 2024-02-05 16:32:42 -08:00
Olaoluwa Osuntokun
ab8f319750
Merge pull request #8455 from Roasbeef/v0-17-4-branch
release: update v0.17.4 release branch to rc2
2024-02-05 11:57:31 -08:00
Olaoluwa Osuntokun
504f0d0024
build: bump version to v0.17.4 rc2 2024-02-02 17:08:07 -08:00
Olaoluwa Osuntokun
18d94a22a3 Merge branch 'v0-17-4-branch-7372' into v0-17-4-branch 2024-02-02 17:06:44 -08:00
Andras Banki-Horvath
b119ac87f9 docs: update release notes for 0.17.4 2024-02-02 17:06:27 -08:00
Andras Banki-Horvath
b1506eca95 itests: add itest for ListSweeps's start_height 2024-02-02 17:05:25 -08:00
Andras Banki-Horvath
1ae89d67ad walletkit: add startheight parameter to ListSweeps
By default ListSweeps will list all sweeps known to the wallet. Over
time this may become expensive to call and callers may not be interested
in the full history. This commit adds a `startheight` parameter to the
`ListSweeps` RPC call. This parameter can be used to fetch sweeps only
from a specified start block height or only unconfirmed ones if it is
set to -1.
2024-02-02 17:04:18 -08:00
Olaoluwa Osuntokun
ed6f03ea3e
Merge pull request #8416 from Roasbeef/v0-17-4-branch
release: create v0.17.4 rc1 release branch
2024-01-30 15:32:34 -08:00
Olaoluwa Osuntokun
b5cfc2fa05 Merge branch 'v0-17-4-branch-8437' into v0-17-4-branch 2024-01-30 11:24:27 -08:00
Elle Mouton
8f1460464e tls_manager: let REST proxy skip tls cert verification 2024-01-30 11:24:12 -08:00
Olaoluwa Osuntokun
6cbe5172d6 Merge branch 'v0-17-4-branch-8428' into v0-17-4-branch 2024-01-29 17:58:17 -08:00
ziggie
b02bbd5e95 docs: update release-notes. 2024-01-29 17:58:08 -08:00
ziggie
f9a2818d95 mod: update btcwallet version.
Update the btcwallet version to fix a case where fetching of
already pruned blocks from our peers was not garbage collected
when the request failed.
2024-01-29 17:57:14 -08:00
Olaoluwa Osuntokun
08cb77c415
build: bump version to v0.17.4-beta.rc1 2024-01-24 16:52:01 -08:00
Olaoluwa Osuntokun
2859a5a16d Merge branch 'v0-17-4-branch-8401' into v0-17-4-branch 2024-01-24 16:51:00 -08:00
yyforyongyu
a6fc5a901a chainreg: satisfy chain.Interface in NoChainSource 2024-01-24 16:50:52 -08:00
yyforyongyu
6d566068df docs: update release notes for mem leak fix 2024-01-24 16:50:51 -08:00
yyforyongyu
033292f2c2 blockcache: fix heap escape in GetBlock
This commit fixes a heap escape found in `GetBlock`. This happens
because the `msgBlock` is a pointer returned from `getBlockImpl`, and
the whole `getBlockImpl` escapes to the heap because it's referenced in
two places,
- in the `Cache`, it's used as a reference type to create the new block.
- this pointer is also returned and now needs to stay on the heap.

The fix is simple, we now make a copy of the block and use the copy
instead, freeing `getBlockImpl` from the heap.
2024-01-24 16:48:32 -08:00
yyforyongyu
68c24831df gomod: update btcd version to fix mem leak 2024-01-24 16:48:30 -08:00
Olaoluwa Osuntokun
599ff50fd4 Merge branch 'v0-17-4-branch-8406' into v0-17-4-branch 2024-01-24 16:46:48 -08:00
ziggie
a258ff74e9 docs: add release-notes. 2024-01-24 16:46:40 -08:00
ziggie
8a825a4687 multi: Add itest for a failed funding flow.
This adds an itest for a failed funding flow by our peer.
2024-01-24 16:46:38 -08:00
ziggie
192c35b2c7 peer: add unit test.
Add a unit test for the removal of a pending channel.
2024-01-24 16:46:02 -08:00
ziggie
39206a96fb funding: initialize remove channel. 2024-01-24 16:46:02 -08:00
Olaoluwa Osuntokun
0d5deef407 Merge branch 'v0-17-4-branch-8413' into v0-17-4-branch 2024-01-24 16:45:41 -08:00
Elle Mouton
c2a597747d docs: add template for 0.17.4 2024-01-24 16:45:41 -08:00
rockstardev
ba80ce46e4 Adding BtcPayServer related files and resources 2023-12-24 23:39:40 -06:00
Olaoluwa Osuntokun
13aa7f9924
build: bump version to v0.17.3-beta 2023-12-05 16:37:53 -08:00
Olaoluwa Osuntokun
d5b05d6930
Merge pull request #8241 from Roasbeef/v0-17-3-branch
release: create v0.17.3-beta.rc1 release branch
2023-12-01 14:17:21 -08:00
Olaoluwa Osuntokun
937fe6fda6
build: bump version to v0.17.3-beta.rc1 2023-11-30 15:08:20 -08:00
Olaoluwa Osuntokun
f550d04c7d Merge branch 'v0-17-3-branch-8232' into v0-17-3-branch 2023-11-30 15:06:14 -08:00
yyforyongyu
01eb7e539a gomod: update btcwallet version 2023-11-30 15:06:14 -08:00
Olaoluwa Osuntokun
b4425f6eea Merge branch 'v0-17-3-branch-8151' into v0-17-3-branch 2023-11-30 15:05:52 -08:00
Eugene Siegel
41e251b0d7 release-notes: update for 0.17.3 2023-11-30 15:05:52 -08:00
Eugene Siegel
dd2ead1022 routing: launch fetchFundingTx in goroutine so router can exit
This commit introduces a wrapper function fetchFundingTxWrapper
which calls fetchFundingTx in a goroutine. This is to avoid an issue
with pruned nodes where the router is attempting to stop, but the
prunedBlockDispatcher is waiting to connect to peers that can serve
the block. This can cause the shutdown process to hang until we
connect to a peer that can send us the block.
2023-11-30 15:05:52 -08:00
Olaoluwa Osuntokun
5565dffbd1 Merge branch 'v0-17-3-branch-8220' into v0-17-3-branch 2023-11-30 15:01:15 -08:00
yyforyongyu
87b4749d60 docs: add release notes for v0.17.3 2023-11-30 15:01:15 -08:00
yyforyongyu
bb27135477 lnwallet: make sure loop var is properly referenced 2023-11-30 15:01:15 -08:00
yyforyongyu
c6d52147e8 lnwallet: add unit test for extractPayDescs 2023-11-30 15:01:15 -08:00
yyforyongyu
8ac3480942 multi: enhance logging around channel reestablishment 2023-11-30 15:01:15 -08:00
Olaoluwa Osuntokun
97975098b9 Merge branch 'v0-17-3-branch-8224' into v0-17-3-branch 2023-11-30 14:58:52 -08:00
yyforyongyu
c6836d777e docs: add release notes for v0.17.3 2023-11-30 14:58:52 -08:00
yyforyongyu
dd8be9fc87 lntest: add verbose logging when node fails to shutdown 2023-11-30 14:58:52 -08:00
yyforyongyu
23e177514f input: use lnutils.SyncMap to store musig2 sessions 2023-11-30 14:58:52 -08:00
rockstardev
b8c6baa94a Adding BtcPayServer related files and resources 2023-11-20 14:43:29 -06:00
Olaoluwa Osuntokun
6744c64e62
build: bump version to v0.17.2-beta 2023-11-20 14:31:32 -06:00
Olaoluwa Osuntokun
ceb8e8a109
Merge pull request #8187 from Roasbeef/v0-17-2-branch
release: create v0.17.2-beta release branch
2023-11-17 16:10:27 -08:00
Olaoluwa Osuntokun
0aaf144b76
build: bump version to v0.17.2-beta.rc2 2023-11-17 18:09:34 -06:00
Olaoluwa Osuntokun
01761ab99b
docs/release-notes: update release notes for v0.17.2 2023-11-17 18:09:17 -06:00
Olaoluwa Osuntokun
04e0c9bc39 Merge branch 'v0-17-2-branch-8198' into v0-17-2-branch 2023-11-17 18:05:43 -06:00
Matt Morehouse
a331308a02 peer: add test for startup race on writeMessage
The test reliably detects
https://github.com/lightningnetwork/lnd/issues/8184.
2023-11-17 18:05:43 -06:00
Matt Morehouse
a283fc62fa peer: enable mockMessageConn to detect data races
We use unsynchronized counters to trigger a report under the race
detector if multiple reads or writes happen concurrently.
2023-11-17 18:05:43 -06:00
Matt Morehouse
0f5e4077ba peer: add missing Close() method to mockMessageConn 2023-11-17 18:05:43 -06:00
Olaoluwa Osuntokun
2988c85479
docs/release-notes: add release notes for v0.17.2 2023-11-16 13:08:15 -08:00
Eugene Siegel
a41833c466 peer: send reestablish, shutdown messages before starting writeHandler
This is to avoid a potential race on WriteMessage and Flush internals.
Because there is no locking on WriteMessage and Flush, if we allow
writeMessage calls in Start after the writeHandler has started,
the writeMessage calls may call WriteMessage/Flush at the same time
that writeMessage calls from the writeHandler does. Since there is
no locking, internals like b.nextHeaderSend can race and cause
panics.
2023-11-16 13:05:16 -08:00
rockstardev
c8bd66e881 Adding BtcPayServer related files and resources 2023-11-14 20:45:27 -06:00
Olaoluwa Osuntokun
744feb04e2
build: bump version to v0.17.1-beta 2023-11-13 11:13:18 -08:00
Olaoluwa Osuntokun
eea15f0952
Merge pull request #8162 from Roasbeef/v0-17-1-branch-rc3
build: create v0.17.1 rc3 release branch
2023-11-08 17:10:55 -08:00
Olaoluwa Osuntokun
18a5dda6a9
build: bump version to v0.17.1-beta.rc3 2023-11-08 15:00:20 -08:00
Olaoluwa Osuntokun
31791aadc8 Merge branch 'v0-17-1-branch-rc3-8158' into v0-17-1-branch-rc3 2023-11-08 14:58:41 -08:00
Eugene Siegel
8e8923c251 release-notes: update for 0.17.1 2023-11-08 14:58:41 -08:00
Eugene Siegel
f7e2db9687 peer: send messages in Start via writeMessage to bypass writeHandler
Without this the following could happen:

* InboundPeerConnected is called while we already have an inbound
connection with the peer. This calls removePeer which calls Disconnect.
* If the peer is starting up in Start, it may be sending messages
synchronously via SendMessage(true, ...). This eventually calls the
writeMessage function which will exit if disconnect is set to 1.
* Since Disconnect was called, disconnect will be 1 and writeMessage
will exit, causing writeHandler to exit.
* If there is more than 1 message being sent, later messages will
queue in queueHandler but be unable to get into sendQueue as the
writeHandler goroutine has exited.
* The synchronous sends will be waiting on the errChan indefinitely
and startReady will never get closed meaning Disconnect will never
proceed.

The end result is that the server's mutex will be held until shutdown.

Avoid this by using writeMessage to bypass the writeHandler goroutine.
2023-11-08 14:58:41 -08:00
Olaoluwa Osuntokun
0116d9bd0b
Merge pull request #8155 from Roasbeef/v0-17-1-branch-rc2
release: create v0.17.1 rc2 release branch
2023-11-07 16:25:20 -08:00
Olaoluwa Osuntokun
8ffd64b554
build: bump version to v0.17.1-beta.rc2 2023-11-06 16:10:55 -08:00
Olaoluwa Osuntokun
7dffad8e13 Merge branch 'v0-17-1-branch-rc2-8116' into v0-17-1-branch-rc2 2023-11-06 16:09:38 -08:00
Oliver Gugger
30fc8e96be GitHub: bump pinned versions in CI check 2023-11-06 16:09:38 -08:00
dependabot[bot]
cbccf61c7f build(deps): bump google.golang.org/grpc from 1.53.0 to 1.56.3
Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.53.0 to 1.56.3.
- [Release notes](https://github.com/grpc/grpc-go/releases)
- [Commits](https://github.com/grpc/grpc-go/compare/v1.53.0...v1.56.3)

---
updated-dependencies:
- dependency-name: google.golang.org/grpc
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-06 16:09:38 -08:00
Olaoluwa Osuntokun
710545b829
Merge pull request #8138 from Roasbeef/v0-17-1-branch-rc1
build: create v0.17.1-rc1 branch
2023-11-01 15:27:51 -07:00
Olaoluwa Osuntokun
155f66b16f Merge branch 'v0-17-1-branch-rc1-8063' into v0-17-1-branch-rc1 2023-11-01 11:17:04 -07:00
Oliver Gugger
464ddb4206 cmd/lncli: fix linter complaint by running make fmt 2023-11-01 11:17:04 -07:00
Olaoluwa Osuntokun
c8409575bb
build: bump version to v0.17.1-beta.rc1 2023-10-31 16:49:13 -07:00
Olaoluwa Osuntokun
2c2ba34537 Merge branch 'v0-17-1-branch-rc1-8132' into v0-17-1-branch-rc1 2023-10-31 16:44:35 -07:00
Olaoluwa Osuntokun
76862ed10b macaroons: reject unknown macaroon versions
We've only ever made macaroons with the v2 versions, so we should
explicitly reject those that aren't actually v2. We add a basic test
along the way, and also add a similar check for the version encoded in
the macaroon ID.
2023-10-31 16:44:35 -07:00
Olaoluwa Osuntokun
948f8732d6 Merge branch 'v0-17-1-branch-rc1-8104' into v0-17-1-branch-rc1 2023-10-31 16:44:17 -07:00
Olaoluwa Osuntokun
6c7bca2a17 docs/release-notes: add entry for nonce init fix 2023-10-31 16:44:17 -07:00
Slyghtning
9fa2057cd4 itest: simple taproot channel status 2023-10-31 16:44:17 -07:00
Slyghtning
b2a5368846 itest: assertions to check channel status 2023-10-31 16:44:17 -07:00
Eugene Siegel
280a97cbaa multi: skip InitRemoteMusigNonces if we've already called it
Prior to this commit, taproot channels had a bug:

- If a disconnect happened before peer.AddNewChannel was called,
  then the subsequent reconnect would call peer.AddNewChannel and
  attempt the ChannelReestablish dance.

- peer.AddNewChannel would call NewLightningChannel with
  populated nonce ChannelOpts. This in turn would call
  InitRemoteMusigNonces which would create a new musig pair session
  and set the channel's pendingVerificationNonce to nil.

- During the reestablish dance, ProcessChanSyncMsg would be called.
  This would also call InitRemoteMusigNonces, except it would fail
  since pendingVerificationNonce was set to nil in the previous
  invocation.

To fix this, we add a new functional option to signal to the init logic
that it doesn't need to call InitRemoteMusigNonces in   in
ProcessChanSyncMsg.
2023-10-31 16:44:17 -07:00
Olaoluwa Osuntokun
db6acec141 Merge branch 'v0-17-1-branch-rc1-8111' into v0-17-1-branch-rc1 2023-10-31 16:43:15 -07:00
Jonathan Harvey-Buschel
452af8ffa1 doc: add release notes for 8111 2023-10-31 16:43:15 -07:00
Jonathan Harvey-Buschel
6ea7d92c2e itest: add GetBlockHeader to ChainKit tests 2023-10-31 16:43:15 -07:00
Jonathan Harvey-Buschel
6a4dabc684 chainrpc+lncli: expose GetBlockHeader + add to CLI 2023-10-31 16:43:15 -07:00
Jonathan Harvey-Buschel
b04927f688 multi: add GetBlockHeader to BlockChainIO 2023-10-31 16:43:15 -07:00
Jonathan Harvey-Buschel
35bfd27467 chainrpc: update proto to expose GetBlockHeader 2023-10-31 16:43:15 -07:00
Olaoluwa Osuntokun
c0b14c7c39 Merge branch 'v0-17-0-branch-rc1-8094' into v0-17-0-branch-rc1 2023-10-31 16:24:16 -07:00
yyforyongyu
52fdf7086c gomod: update btcwallet re rescan race fix 2023-10-31 16:24:16 -07:00
Olaoluwa Osuntokun
6806a13f68 Merge branch 'v0-17-0-branch-rc1-8090' into v0-17-0-branch-rc1 2023-10-31 16:23:00 -07:00
ziggie
42dd0fa912 multi: clarify co-op closure failures. 2023-10-31 16:23:00 -07:00
Olaoluwa Osuntokun
58193ef18c Merge branch 'v0-17-0-branch-rc1-8019' into v0-17-0-branch-rc1 2023-10-31 16:22:29 -07:00
yyforyongyu
a0448eb14a gomod: update btcwallet version 2023-10-31 16:22:29 -07:00
Olaoluwa Osuntokun
5c4f2c129f Merge branch 'v0-17-0-branch-rc1-7965' into v0-17-0-branch-rc1 2023-10-31 16:21:57 -07:00
yyforyongyu
7be54096b6 itest: update related tests to reflect anchor sweeping
This commit updates all related tests to reflect the latest anchor
sweeping behavior. Previously, anchor sweeping is always attempted as
CPFP when a force close is broadcast, while now it only happens when the
deadline is less than 144. For non-CPFP purpose sweeping, it will happen
after one block is mined after the force close transaction is confirmed
as the anchor will be resent to the sweeper with a floor fee rate, hence
making it economical to sweep.
2023-10-31 16:21:57 -07:00
yyforyongyu
b8464ddd7e itest: fix testMultiHopRemoteForceCloseOnChainHtlcTimeout 2023-10-31 16:21:57 -07:00
yyforyongyu
0cb9ccd066 itest: update test testMultiHopHtlcLocalChainClaim to skip CPFP
Since we now only perform CPFP when both the fee rate is higher and the
deadline is less than 144, we need to update the test to reflect that
Bob will not CPFP the force close tx for the channle Alice->Bob.
2023-10-31 16:21:57 -07:00
yyforyongyu
2cb208e97c docs: update release notes 2023-10-31 16:21:57 -07:00
yyforyongyu
91719b0f49 contractcourt+itest: relax anchor sweeping for CPFP purpose
This commit changes from always sweeping anchor for a local force close
to only do so when there is an actual time pressure. After this change,
a forced anchor sweeping will only be attempted when the deadline is
less than 144 blocks.
2023-10-31 16:21:57 -07:00
yyforyongyu
c2148ad757 sweep: prioritize smaller inputs when adding wallet UTXOs
This commit sorts wallet UTXOs by their values when using them for
sweeping inputs. This way we'd avoid locking large UTXOs when sweeping
inputs and also provide an opportunity to aggregate wallet UTXOs.
2023-10-31 16:21:57 -07:00
yyforyongyu
dde605d375 sweeper: add more docs and debug logs 2023-10-31 16:21:57 -07:00
yyforyongyu
7ebc538c10 sweep: use longer variable name for clarity in addToState 2023-10-31 16:21:57 -07:00
Olaoluwa Osuntokun
738e0c64ec Merge branch 'v0-17-0-branch-rc1-7937' into v0-17-0-branch-rc1 2023-10-31 16:21:19 -07:00
eugene
28c260e4ea release-notes: update for 0.17.1 2023-10-31 16:21:19 -07:00
eugene
75406d177b htlcswitch/hop: use InvalidOnionVersion for replayed packets
The link will send an update_fail_malformed_htlc, so we need to set
the BADONION bit. Since there isn't a replay-specific error, we
set the failure code to InvalidOnionVersion which has the BADONION bit.
2023-10-31 16:21:19 -07:00
Olaoluwa Osuntokun
3c605dbff5 Merge branch 'v0-17-0-branch-rc1-8053' into v0-17-0-branch-rc1 2023-10-31 16:20:50 -07:00
Kilian
6521576f42 lncli: fix description of connect/disconnect peer 2023-10-31 16:20:50 -07:00
rockstardev
c54373522e Updating README 2023-10-25 13:59:06 -05:00
rockstardev
11bae66d31 Merge branch 'lnd/v0.17.0-beta' 2023-10-25 13:52:18 -05:00
rockstardev
9115aa385f Updating loop to v0.26.4-beta 2023-10-25 13:49:30 -05:00
rockstardev
e234af10a2 Updating README file 2023-10-25 13:46:50 -05:00
rockstardev
dd83fa5286 Merge branch 'lnd/v0.17.0-beta'
# Conflicts:
#	.github/workflows/main.yml
#	.github/workflows/release.yaml
#	.travis.yml
#	Dockerfile
#	cmd/lncli/cmd_open_channel.go
#	contractcourt/htlc_timeout_resolver.go
#	dev.Dockerfile
#	docs/release-notes/release-notes-0.16.0.md
#	docs/release-notes/release-notes-0.16.1.md
#	docs/release-notes/release-notes-0.16.3.md
#	funding/manager.go
#	funding/manager_test.go
#	go.mod
#	go.sum
#	itest/list_on_test.go
#	itest/lnd_channel_funding_fund_max_test.go
#	itest/lnd_funding_test.go
#	itest/lnd_multi-hop_test.go
#	itest/lnd_open_channel_test.go
#	lnrpc/lightning.pb.go
#	lnrpc/lightning.proto
#	lnrpc/lightning.swagger.json
#	lnrpc/walletrpc/walletkit_server.go
#	lntest/harness.go
#	lntest/harness_assertion.go
#	lnutils/sync_map.go
#	lnwallet/chanfunding/assembler.go
#	lnwallet/chanfunding/coin_select_test.go
#	lnwallet/chanfunding/wallet_assembler.go
#	lnwallet/wallet.go
#	make/builder.Dockerfile
#	peer/brontide.go
#	rpcserver.go
2023-10-25 13:42:10 -05:00
rockstardev
bc951d7c24 Merge branch 'lnd/v0.16.4-beta'
# Conflicts:
#	linuxamd64.Dockerfile
#	linuxarm32v7.Dockerfile
#	linuxarm64v8.Dockerfile
2023-10-25 13:41:40 -05:00
rockstardev
39ecf64086 Merge branch 'lnd/v0.16.3-beta'
# Conflicts:
#	linuxamd64.Dockerfile
#	linuxarm32v7.Dockerfile
#	linuxarm64v8.Dockerfile
2023-10-25 13:41:20 -05:00
rockstardev
5dd6d0a588 Merge branch 'lnd/v0.16.2-beta'
# Conflicts:
#	docker-entrypoint.sh
#	docker-initunlocklnd.sh
#	linuxamd64.Dockerfile
#	linuxarm32v7.Dockerfile
#	linuxarm64v8.Dockerfile
2023-10-25 13:40:51 -05:00
rockstardev
38726b19ad Merge branch 'lnd/v0.16.1-beta'
# Conflicts:
#	Makefile
#	build/version.go
2023-10-25 13:39:14 -05:00
rockstardev
97629cbae2 Merge branch 'lnd/v0.16.0-beta'
# Conflicts:
#	.github/ISSUE_TEMPLATE/bug_report.md
#	aliasmgr/aliasmgr.go
#	aliasmgr/aliasmgr_test.go
#	channeldb/channel.go
#	channeldb/db.go
#	channeldb/meta.go
#	channeldb/meta_test.go
#	channeldb/migration30/iterator.go
#	channeldb/migration30/iterator_test.go
#	channeldb/migration30/lnwallet.go
#	channeldb/migration30/migration.go
#	channeldb/migration30/migration_test.go
#	channeldb/migration30/revocation_log.go
#	channeldb/migration30/test_utils.go
#	channeldb/migtest/migtest.go
#	channeldb/options.go
#	channeldb/payment_control_test.go
#	channeldb/revocation_log_test.go
#	cmd/lncli/cmd_open_channel.go
#	cmd/lncli/walletrpc_active.go
#	config.go
#	config_builder.go
#	discovery/gossiper.go
#	discovery/gossiper_test.go
#	docker-entrypoint.sh
#	docker-initunlocklnd.sh
#	docs/INSTALL.md
#	docs/release-notes/release-notes-0.15.1.md
#	docs/release-notes/release-notes-0.15.3.md
#	funding/manager.go
#	funding/manager_test.go
#	go.mod
#	go.sum
#	htlcswitch/link_test.go
#	htlcswitch/mock.go
#	htlcswitch/switch.go
#	htlcswitch/switch_test.go
#	itest/lnd_nonstd_sweep_test.go
#	itest/lnd_psbt_test.go
#	itest/lnd_remote_signer_test.go
#	itest/lnd_rpc_middleware_interceptor_test.go
#	itest/lnd_signer_test.go
#	itest/lnd_zero_conf_test.go
#	keychain/btcwallet.go
#	linuxamd64.Dockerfile
#	linuxarm32v7.Dockerfile
#	linuxarm64v8.Dockerfile
#	lncfg/db.go
#	lnd.go
#	lnrpc/invoicesrpc/addinvoice.go
#	lnrpc/invoicesrpc/addinvoice_test.go
#	lnrpc/invoicesrpc/invoices.swagger.json
#	lnrpc/lightning.pb.go
#	lnrpc/lightning.pb.gw.go
#	lnrpc/lightning.pb.json.go
#	lnrpc/lightning.proto
#	lnrpc/lightning.swagger.json
#	lnrpc/lightning.yaml
#	lnrpc/lightning_grpc.pb.go
#	lnrpc/neutrinorpc/neutrino_grpc.pb.go
#	lnrpc/routerrpc/router.pb.go
#	lnrpc/signrpc/signer.pb.go
#	lnrpc/signrpc/signer_grpc.pb.go
#	lnrpc/walletrpc/walletkit.pb.go
#	lnrpc/walletrpc/walletkit.pb.gw.go
#	lnrpc/walletrpc/walletkit.pb.json.go
#	lnrpc/walletrpc/walletkit.proto
#	lnrpc/walletrpc/walletkit.yaml
#	lnrpc/walletrpc/walletkit_grpc.pb.go
#	lnrpc/walletrpc/walletkit_server.go
#	lntest/harness_net.go
#	lntest/harness_node.go
#	lntest/itest/lnd_channel_backup_test.go
#	lntest/itest/lnd_multi-hop_htlc_aggregation_test.go
#	lntest/itest/lnd_multi-hop_htlc_local_chain_claim_test.go
#	lntest/itest/lnd_multi-hop_htlc_local_timeout_test.go
#	lntest/itest/lnd_multi-hop_htlc_receiver_chain_claim_test.go
#	lntest/itest/lnd_multi-hop_htlc_remote_chain_claim_test.go
#	lntest/itest/lnd_multi-hop_local_force_close_on_chain_htlc_timeout_test.go
#	lntest/itest/lnd_multi-hop_remote_force_close_on_chain_htlc_timeout_test.go
#	lntest/itest/lnd_multi-hop_test.go
#	lntest/itest/lnd_onchain_test.go
#	lntest/itest/lnd_recovery_test.go
#	lntest/itest/lnd_switch_test.go
#	lntest/itest/lnd_taproot_test.go
#	lntest/itest/lnd_test_list_on_test.go
#	lntest/itest/utils.go
#	lntest/mock/secretkeyring.go
#	lntest/mock/walletcontroller.go
#	lnwallet/btcwallet/btcwallet.go
#	lnwallet/chancloser/chancloser_test.go
#	lnwallet/interface.go
#	peer/brontide.go
#	peer/test_utils.go
#	routing/control_tower_test.go
#	routing/payment_lifecycle.go
#	routing/router.go
#	routing/router_test.go
#	rpcperms/interceptor.go
#	rpcserver.go
#	sample-lnd.conf
#	server.go
2023-10-25 13:37:25 -05:00
rockstardev
9786a1fa2c Adding BtcPayServer related files and resources 2023-10-25 13:22:30 -05:00
rockstardev
f1c2739118 Add watchtowerrpc to install tags
Co-authored-by: d11n <mail@dennisreimann.de>
2023-09-06 15:44:35 -05:00
rockstardev
b8570fcd9d Adding BtcPayServer related files and resources 2023-07-07 10:32:11 -05:00
Olaoluwa Osuntokun
6bd30047c1
build: bump version to v0.16.4
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2023-07-04 12:56:21 -07:00
rockstardev
3c60fc0857 Adding BtcPayServer related files and resources 2023-06-26 11:32:03 -05:00
Olaoluwa Osuntokun
3bf179a888
build: bump version to v0.16.4 rc1
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2023-06-22 11:29:27 -05:00
Olaoluwa Osuntokun
8dcd8529a2 Merge branch 'v0-16-4-branch-7767' into v0-16-4-branch 2023-06-22 11:28:32 -05:00
yyforyongyu
dea815dac2 mod: update btcwallet version 2023-06-22 11:27:53 -05:00
Olaoluwa Osuntokun
47483f1c66
build: bump version to v0.16.3
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2023-06-05 11:51:04 -07:00
Olaoluwa Osuntokun
f76e52e60a
Merge pull request #7724 from Roasbeef/v0-16-3-branch
build: create v0.16.3 release branch
2023-05-29 12:51:56 -07:00
Olaoluwa Osuntokun
29f9fe5c1a
build: bump version to v0.16.3-beta.rc1
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2023-05-29 12:50:34 -07:00
Olaoluwa Osuntokun
96435425e9 Merge branch 'v0-16-3-branch-7726' into v0-16-3-branch 2023-05-29 12:50:05 -07:00
Olaoluwa Osuntokun
96a24e035c docs/release-notes: add release notes for adamant htlc sweeps 2023-05-29 12:50:05 -07:00
Olaoluwa Osuntokun
1ba6467c6b contractcourt: force the sweeper to always resolve outgoing HTLCs
In this commit, we attempt to fix an issue that may lead to force closes due
to small value HTLCs. The sweeper has built in a "negative yield" heuristic
where it won't sweep something that'll result in paying more fees than the
HTLC amount. However for HTLCs, we want to always sweep them, as we don't
cancel back the HTLCs before the outgoing contract is fully resolved.

In the future, we'll start to make more uneconomical decisions about if we
should go to chain at all for small value HTLCs, and also do things like
cancel back early if the HTLC is small and we think we might be contested by
chain fees.
2023-05-29 12:50:05 -07:00
Olaoluwa Osuntokun
9b4fce1468 Merge branch 'v0-16-3-branch-7711' into v0-16-3-branch 2023-05-23 14:23:15 -07:00
Olaoluwa Osuntokun
ddf551f16d htlcswitch: add new LinkFailureDisconnect action
In this commit, we add a new LinkFailureDisconnect action that'll be
used if we detect that the remote party hasn't sent a revoke and ack
when it actually should.

Before this commit, we would log our action, tear down the link, but
then not actually force a connection recycle, as we assumed that if the
TCP connection was actually stale, then the read/write timeout would
expire.

In practice this doesn't always seem to be the case, so we make a strong
action here to actually force a disconnection in hopes that either side
will reconnect and keep the good times rollin' 🕺.
2023-05-23 14:23:05 -07:00
Olaoluwa Osuntokun
5d20d088e9 htlcswitch: add new LinkFailureAction enum
In this commit, we add a new LinkFailureAction enum to take over the old
force close bool. Force closing isn't the only thing we might want to do
when we decide to fail the link, so this is a prep refactoring for an
upcoming change.
2023-05-23 14:22:39 -07:00
Olaoluwa Osuntokun
fcbe6844c0 Merge branch 'v0-16-3-branch-7705' into v0-16-3-branch 2023-05-22 18:13:39 -07:00
Elle Mouton
bd43defefd docs: add release note for 7705 2023-05-22 18:13:26 -07:00
Elle Mouton
9b98352caf macaroons: let ChangePassword re-encrypt all root keys
The ChangePasswords method should re-encrypt all the root keys found
in the store, not just the default root key.
2023-05-22 18:12:19 -07:00
Elle Mouton
143fc4ced4 macaroons: demo ChangePassword bug
This commits uses TestStoreChangePassword to demonstrate that currently
the ChangePassword function only changes the password of the default
root key and not that of other root keys. This will be fixed in an
upcoming commit.
2023-05-22 18:12:19 -07:00
Elle Mouton
51f0082c53 macaroons: Let GenerateNewRootKey be applied to all root keys
With this commit, GenerateNewRootKey will regenerate the Default root
key and will then also check if any other root keys exist and regenerate
those as well.
2023-05-22 18:12:19 -07:00
Elle Mouton
ee01956978 macaroons: demo GenerateNewRootKey bug
This commit adds to the existing TestStoreGenerateNewRootKey to show
that the method only successfully regenerates the root key in the
default root key ID location. This will be fixed in an upcoming commit.
2023-05-22 18:12:19 -07:00
Olaoluwa Osuntokun
b26be81c7a Merge branch 'v0-16-3-branch-7681' into v0-16-3-branch 2023-05-22 18:11:34 -07:00
yyforyongyu
4d0136af8c docs: add release notes 0.16.3 2023-05-22 18:11:26 -07:00
yyforyongyu
caabfb7eb4 itest: cleanup channels for testSwitchOfflineDeliveryOutgoingOffline 2023-05-22 18:11:26 -07:00
yyforyongyu
43b774d1e6 itest: make sure edges are updated in mpp tests 2023-05-22 18:11:26 -07:00
yyforyongyu
1ce7559110 lntest+itest: clean mempool in testHtlcTimeoutResolverExtractPreimageRemote 2023-05-22 18:11:26 -07:00
yyforyongyu
5e1664dc82 mod: update btcwallet's version 2023-05-22 18:11:24 -07:00
rockstardev
15d920456a Accepting signet as LND_ENVIRONMENT variable 2023-05-07 22:41:53 -05:00
rockstardev
cd70936a77 Adding BtcPayServer related files and resources 2023-04-29 08:39:47 -05:00
Olaoluwa Osuntokun
fdbeb1e702 Merge branch 'v0-16-2-branch-7647' into v0-16-2-branch
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2023-04-28 14:03:30 -05:00
yyforyongyu
6cf1b086a9 contractcourt: skip checkpoint timeout resolver upon mempool spend
Previously when a block spend is found for the outpoint, our htlc
timeout resolver will do a checkpoint, which implicitly creates a db
record if there isn't one. Now, if the spend is found in mempool,
the resolver will be deleted once the contract is resolved. Later on
when the spend is found in the block again, the resolver will be created
again, but never gets resolved this time.
2023-04-28 14:03:30 -05:00
yyforyongyu
12f3cd5bb1 contractcourt: add debug logs for unresolved contracts 2023-04-28 14:03:30 -05:00
Olaoluwa Osuntokun
63f01c1ebd
build: bump version to v0.16.2 2023-04-27 16:37:27 -05:00
Olaoluwa Osuntokun
5b00c4fc93 Merge branch 'v0-16-2-branch-7641' into v0-16-2-branch 2023-04-27 16:36:51 -05:00
Olaoluwa Osuntokun
a6345797ae build: update to btcwallet version with async mempool scan
This version of btcwallet demotes some spammy logs (txns replaced in the
mempool), and makes the initial mempool scan async.

Fixes https://github.com/lightningnetwork/lnd/issues/7640
2023-04-27 16:36:51 -05:00
Olaoluwa Osuntokun
f7129c1d62 Merge branch 'v0-16-2-branch-7637' into v0-16-2-branch 2023-04-27 16:35:23 -05:00
yyforyongyu
0d1c5f85fc lnd: skip canceling rebroadcast for neutrino backend 2023-04-27 16:35:23 -05:00
rockstardev
2f4b515afc Adding BtcPayServer related files and resources 2023-04-26 14:34:42 -05:00
Olaoluwa Osuntokun
fb765fdb1d
build: bump version to v0.16.1-beta
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2023-04-24 13:10:16 -05:00
Olaoluwa Osuntokun
a82192efb7
build: bump version to v0.16.1-beta.rc3
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2023-04-21 15:55:42 -07:00
Olaoluwa Osuntokun
508b0a4426 lnd v0.16.0-beta
-----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEE9Pxw8HMQAoQk78IKjkJWWT8XdyAFAmQkNkYACgkQjkJWWT8X
 dyC5fRAAvhiI4TTDqxdJmTcj1nxA6iUYB4nAqL4wegnXSv9ntcaQ5c10vGLiBi9Y
 D/Uqqfnz73OaATRcDjaeZdONTFd4q7mM21ymrAqbfv8OpjeccO5fOrtsAPQKMNK3
 3ipT7Ej+KgF5QatAUlm8joqBJ4SXB9y6AmPqRbdNyBu4yf3AJf69EOjTG2dW+E3x
 XPQfeMw5cBSSM6VKIdTY3cQvzX5jUU3lBtahSL4wChPzh4bYZTnn6hydkSkkmqjp
 SyYD6KYZ4Ul4Mh+evlWzqDwfJHfNL82ZwHxJ1bfrVJQ34ZQanlH014/baRYNR1in
 eALSUf/YRkf65HNETF8g4oeiUFc2ymx4zY3dZMeNZ9Rij0KE6OJVg3ZS/5zUITkJ
 1TWpO92nPe9v6f9SkZA6YotHwUg7GX+II7frs+8d0RGbEipc2JjN2p8DewuszDGi
 QT5iYk+PQcoQVYJM79GmoZAa7DgZASodJGz2Huml6J7cjMXq+3bJ4JCo9L0SMu0B
 mSESi+3Y9Sy4Ujpq3ryqbsehTq/nWQq5nFuA3miLsqEfLy5sunOct0/RhyWtGnFu
 2YEVQPI0cmAFV5v8QsLKtOXj8QSpSsZK7w+G1nbukpa0HhkUZxk3WQxbcbYctIkW
 5D133P3E7yNQm7Nr3JYkwN0foDdWUvAdkQQSVtSBlpZw6kyGnuQ=
 =BNTa
 -----END PGP SIGNATURE-----

Merge tag 'v0.16.0-beta' into v0-16-1-branch-rc3

lnd v0.16.0-beta
2023-04-21 15:52:34 -07:00
Olaoluwa Osuntokun
c2851c2342 Merge branch 'v0-16-1-branch-rc1-7599' into v0-16-1-branch-rc2
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2023-04-21 14:02:01 -07:00
Olaoluwa Osuntokun
fc3b8bff69 sweep: remove conflicted sweep txns from the rebroadcaster
In this commit, we an existing gap in our rebroadcast handling logic. As
is, if we're trying to sweep a transaction and a conflicting transaction
is mined (timeout lands on chain, anchor swept), then we'll continue to
try to rebroadcast the tx in the background.

To resolve this, we give the sweeper a new closure function that it can
use to mark conflicted transactions as no longer requiring rebroadcast.
2023-04-21 14:01:48 -07:00
Olaoluwa Osuntokun
31b27fdd3d
build: bump version to v0.16.1-beta.rc2 2023-04-20 11:35:29 -07:00
Olaoluwa Osuntokun
4c10599ae0 build: bump version to v0.16.1-beta.rc2 2023-04-19 20:59:46 -07:00
Olaoluwa Osuntokun
8c1f9a8e5a Merge branch 'v0-16-1-branch-rc1-7609' into v0-16-1-branch-rc1
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2023-04-19 11:44:32 -07:00
Olaoluwa Osuntokun
c96fe0ec58 chainreg: increase default CLTV value to 80 blocks (~13 hrs)
In this commit, we increase the default CTLV value to 80 blocks.
Initially this was set to 144 blocks in the early days, but then was
lowered to 40 blocks as the lnd implementation matured. By setting this
to a higher value, we increase the safety window (MTTR) when it comes to
node downtime, and also add some buffer room around time locks which may
become more stressed in the future assuming the current mempool load
remains persistent.
2023-04-19 11:43:04 -07:00
Olaoluwa Osuntokun
e808e913ec
Merge pull request #7611 from Roasbeef/v0-16-1-branch-rc1
release: create v0.16.1-beta.rc1 branch
2023-04-19 11:37:05 -07:00
Olaoluwa Osuntokun
a4e815c05c
docs/release-notes: move docs for postgres kvdb 2023-04-19 11:31:28 -07:00
Olaoluwa Osuntokun
334f005ba1 Merge branch 'v0-16-1-branch-rc1-7613' into v0-16-1-branch-rc1 2023-04-19 11:29:49 -07:00
Elle Mouton
11f1735e85 funding: use default fwding policy if persisted values not found
In this commit, a bug is fixed in the funding manager that could result
in the funding process erroring out if the persisted initial forwarding
policy is not found. This could occur if a node restarts after opening a
channel that is not yet fully confirmed and also upgrades their node
from a pre-0.16 version to 0.16 since the values are only expected to be
persisted after 0.16.
2023-04-19 11:29:49 -07:00
yyforyongyu
b90b66ea80 chainreg: update bitcoind polling config 2023-04-18 18:29:27 -07:00
yyforyongyu
e207424da8 docs: update release notes for mempool watch 2023-04-18 18:29:20 -07:00
yyforyongyu
7149b12cd9 itest+lntest: add itest for mempool preimage watch 2023-04-18 18:28:28 -07:00
yyforyongyu
946b4f0184 lntest: add more methods to assert mempool state 2023-04-18 18:28:28 -07:00
yyforyongyu
c15a38407f lnd+contractcourt: add more debug logs
This commit adds more debug logs for witness beacon and channel
arbitrator.
2023-04-18 18:28:28 -07:00
yyforyongyu
f9b1250ecf chainntnfs: remove subscriptions when the relevant tx is confirmed
This commit removes the subscribed inputs from mempool notifier when the
relevant transaction is confirmed.
2023-04-18 18:28:28 -07:00
yyforyongyu
1fa269425e contractcourt+lnd: watch for preimage reveal in mempool
This commit extends the current htlc timeout resolver to also watch for
preimage spend in mempool for a full node backend.

If mempool enabled, the resolver will watch the spend of the htlc output
in mempool and blocks **concurrently**, as if they are independent.

Ideally, a transaction will first appear in mempool then in a block.
However, there's no guarantee it will appear in **our** mempool since
there's no global mempool, thus we need to watch the spend in two places
in case it doesn't go through our mempool.

The current design favors the spend event found in blocks, that is, when
the tx is confirmed, we'd abort the monitoring and conitnue since the
outpoint cannot be double spent and re-appear in mempool again. This is
not true in the rare case of reorg, and we will handle reorg seperately.
2023-04-18 18:28:28 -07:00
yyforyongyu
2fac0af553 contractcourt: refactor spendHtlcOutput for clarity
Also fixes the docs and rename `isSuccessSpend` to `isPreimageSpend`.
2023-04-18 18:28:28 -07:00
yyforyongyu
b765c44539 chainntnfs+chainreg: add interface MempoolWatcher
This commit adds the interface `MempoolWatcher` and uses it in the chain
registry.
2023-04-18 18:28:28 -07:00
yyforyongyu
0e1aaad6d4 chainntnfs+chainreg: add mempool watcher to BtcdNotifier
This commit adds the mempool watcher to btcd notifier to allow the
notifier managing the starting and stopping of the watcher.
2023-04-18 18:28:28 -07:00
yyforyongyu
bf839461b4 chainntnfs+chainreg: add mempool watcher to BitcoindNotifier
This commit adds the mempool watcher to bitcoind notifier to allow the
notifier managing the starting and stopping of the watcher.
2023-04-18 18:28:28 -07:00
yyforyongyu
76ba68091f chainntnfs: patch unit tests for mempool notifier 2023-04-18 18:28:28 -07:00
yyforyongyu
35d1bff321 chainntnfs: add method UnsubscribeEvent to cancel a subscription
This commit adds the method `UnsubscribeEvent` to cancel a single
subscription.
2023-04-18 18:28:27 -07:00
yyforyongyu
318efa4c33 chainntnfs: allow multiple subscriber to the same input
This commit changes the `subscribedInputs` to store a map of subscribers
so multiple subscribers are allowed to receive events from the same
outpoint.
2023-04-18 18:28:27 -07:00
yyforyongyu
208628d7f2 chainntnfs: introduce mempool notifier
This commit adds a mempool notifier which notifies the subscriber the
spending event found in the mempool for a given input.
2023-04-18 18:28:27 -07:00
Olaoluwa Osuntokun
28ab3d5ccb Merge branch 'v0-16-1-branch-rc1-7597' into v0-16-1-branch-rc1 2023-04-18 18:27:36 -07:00
Oliver Gugger
a53b0a483c docs: add release notes 2023-04-18 18:27:36 -07:00
Oliver Gugger
24e1a0ec7d peer: add TODO about initial forwarding policy
The right way to solve the problem of the link not being up to date with
custom user set forwarding policies once the channel is announced would
be to pass in those custom values when the link is created initially.
This requires a bit more of a refactor and is not addressed in this bug
fix.
2023-04-18 18:27:36 -07:00
Oliver Gugger
3c4ba857cc itest: update channel open test to send payment
This commit enhances the custom fee policy channel open test by adding a
second channel and testing forwarding payments through the channel with
the custom forwarding policies.
This was able to reproduce the bug reported in #5796 which was fixed in
a previous commit of this PR.
2023-04-18 18:27:36 -07:00
Oliver Gugger
4cf9d7c982 itest: move lnd_custom_{message => message_test}.go
This recently added file didn't follow the golang naming convention for
tests.
2023-04-18 18:27:36 -07:00
Oliver Gugger
a74793ecbc funding+server: update switch after sending channel update
With this commit we give the funding manager the ability to inform the
switch about custom channel policies, right after we've announced the
channel to the network.
This change is necessary because before #6753 a channel could only be
opened with the default forwarding policies, so the switch automatically
had the "correct" default values. Since #6753 added the ability to
specify forwarding policies at channel open time, we announced those
policies to the network but never updated the switch to inform it about
the changed policies (previously changing the policies was only possible
through the UpdateChannelPolicy RPC which did call the switch).
2023-04-18 18:27:36 -07:00
Oliver Gugger
16f428f580 funding: refactor manager test 2023-04-18 18:27:36 -07:00
Olaoluwa Osuntokun
a49671d076 Merge branch 'v0-16-1-branch-rc1-7604' into v0-16-1-branch-rc1 2023-04-18 18:27:05 -07:00
ziggie
261461deeb docs: update release notes 2023-04-18 18:27:05 -07:00
ziggie
7ab6eb1140 netann: fix logging output 2023-04-18 18:27:05 -07:00
Olaoluwa Osuntokun
70bad093a9 Merge branch 'v0-16-1-branch-rc1-7603' into v0-16-1-branch-rc1 2023-04-18 18:26:44 -07:00
Torakushi
4e402082b3 update release-notes-0.16.1 2023-04-18 18:26:44 -07:00
Torakushi
02be618935 funding: use p2tr by default for batch_open_channel
In LND v0.15.1, batch_open_channel used p2tr by default
for change output. However, in a later version, a breaking
change has been fixed in FundPSBT to make the change type
configurable (default to p2wkh). As batch_open_channel
uses FundPsbt, we need to put back p2tr as default for
change output
2023-04-18 18:26:44 -07:00
Olaoluwa Osuntokun
239fda1894 Merge branch 'v0-16-1-branch-rc1-7473' into v0-16-1-branch-rc1 2023-04-18 18:24:42 -07:00
Emilio Ziniades
32b117b9df lnrpc: test witness type mapping 2023-04-18 18:24:42 -07:00
Emilio Ziniades
43660c2c31 input: note to update witness type protobuf 2023-04-18 18:24:42 -07:00
Emilio Ziniades
aca89c38aa lnrpc: add allWitnessTypes map
Refactor `PendingSweeps` to use `allWitnessTypes` map, and
return an error from `PendingSweeps` if an unknown witness
type is used, instead of logging a warning.
2023-04-18 18:24:42 -07:00
Emilio Ziniades
44dcfec947 lnrpc: update and regenerate witness type proto 2023-04-18 18:24:42 -07:00
Olaoluwa Osuntokun
cf88d105f3 Merge branch 'v0-16-1-branch-rc1-7464' into v0-16-1-branch-rc1 2023-04-18 18:24:01 -07:00
Oliver Gugger
91448274fa docs: add release notes 2023-04-18 18:24:01 -07:00
Oliver Gugger
2509000878 channeldb: use input.GenMultiSigScript 2023-04-18 18:24:01 -07:00
Oliver Gugger
7401de3348 input: set initial script allocation size
The default allocation of 500 bytes for the script that is
used in NewScriptBuilder is way too much for most of our scripts.
With the new functional option we can tune the allocation to exactly
what we need.
2023-04-18 18:24:01 -07:00
Oliver Gugger
020d79f18e input: add script size unit and benchmark tests 2023-04-18 18:24:01 -07:00
Oliver Gugger
3a4ab10806 mod: bump btcd version 2023-04-18 18:24:01 -07:00
Olaoluwa Osuntokun
6c8932a4e1 Merge branch 'v0-16-1-branch-rc1-7593' into v0-16-1-branch-rc1 2023-04-18 18:23:25 -07:00
Oliver Gugger
a7815b29f5 docs: update remote signing docs
With this commit we update the docs according to the latest changes that
were necessary to support loop and pool (which requires all 255
internally used accounts to be imported at wallet creation time).

Fixes #7567.
2023-04-18 18:23:25 -07:00
Olaoluwa Osuntokun
b129e10da3 Merge branch 'v0-16-1-branch-rc1-7588' into v0-16-1-branch-rc1 2023-04-18 18:23:03 -07:00
Olaoluwa Osuntokun
d5be710b95 config: fix bug in walletrpc interaction due to mismatched coin type
In this commit, we fix a bug that would cause the walletrpc on the
simnet chain to not be able to respond to all RPC calls. The issue is
that for the SimNet backend, within chainparams.go:
6e0a67d05b/chainreg/chainparams.go (L45-L51),
we set a new CoinType for Simnet in order to match the RegTest value.

Later on, when we go to verify the on disk accounts against the
in-memory cointype, we fall through to an error case as the in-memory
cointype is 115, while the on disk cointype is 1.

To fix this, when we know we're doing simnet mode, we'll override the
cointype similar to the way we did/do for LTC.

Fixes https://github.com/lightningnetwork/lnd/issues/6807.
2023-04-18 18:23:03 -07:00
Olaoluwa Osuntokun
350f4293c7 Merge branch 'v0-16-1-branch-rc1-7513' into v0-16-1-branch-rc1 2023-04-18 18:22:32 -07:00
Oliver Gugger
c95205a94f docs: add release notes 2023-04-18 18:22:32 -07:00
Olaoluwa Osuntokun
2ded805858 Merge branch 'v0-16-1-branch-rc1-7563' into v0-16-1-branch-rc1 2023-04-18 18:21:49 -07:00
yyforyongyu
0b8ac4870d lnutils: add unit test for SyncMap 2023-04-18 18:21:49 -07:00
yyforyongyu
3d167b2687 lnutils: add methods ForEach, Len and LoadOrStore to SyncMap 2023-04-18 18:21:49 -07:00
Olaoluwa Osuntokun
86fb0d7b51 Merge branch 'v0-16-1-branch-rc1-7442' into v0-16-1-branch-rc1 2023-04-18 18:21:24 -07:00
84adam
2115e338ca docs: add notes on contents of Postgres DB as Key-Value store to Postgres.md 2023-04-18 18:21:24 -07:00
Olaoluwa Osuntokun
eba78e6786 Merge branch 'v0-16-1-branch-rc1-7582' into v0-16-1-branch-rc1 2023-04-18 18:20:58 -07:00
Olaoluwa Osuntokun
39cc227d0d build: update build system to Go 1.20.3 2023-04-18 18:20:58 -07:00
Olaoluwa Osuntokun
36b7dc6c17 Merge branch 'v0-16-1-branch-rc1-6903' into v0-16-1-branch-rc1 2023-04-18 18:19:16 -07:00
Slyghtning
326c4f2c55 docs: update release notes 2023-04-18 18:19:16 -07:00
Slyghtning
a1cd4eafbd funding unit: fundmax sanity check for new channel commitment types. 2023-04-18 18:19:16 -07:00
Slyghtning
c5f48e6079 itest: respect the reserved wallet balance when using fundmax 2023-04-18 18:19:16 -07:00
Bjarne Magnussen
ac7a391732 chanfunding: allow to set a reserved amount not used for funding 2023-04-18 18:19:16 -07:00
Bjarne Magnussen
5c3b1724ab lntest/itest: adds tests for fundmax flag of cli:openchannel 2023-04-18 18:19:15 -07:00
Slyghtning
c1a9d15a82 lncli: fundmax flag for openchannel 2023-04-18 18:19:15 -07:00
Slyghtning
238ef0d2eb lnd+lnwallet: fundmax flag for openchannel 2023-04-18 18:19:15 -07:00
Bjarne Magnussen
26b23e2af0 lnd: handles the FundMax field inside parseOpenChannelReq
Adds handling of the `FundMax` field when parsing an
`OpenChannelRequest` with `rpcServer.parseOpenChannelReq`.
2023-04-18 18:19:15 -07:00
Bjarne Magnussen
444bbfa9f7 lnrpc: adds a field FundMax to OpenChannelRequest 2023-04-18 18:19:15 -07:00
Bjarne Magnussen
d65789950c chanfunding: adds ability to fund up to some maximum amount
Allows to define a maximum amount to provision a channel
opening with using a new field `FundUpToMaxAmt` on the
`Request` struct. Also adds a new coin select function
`CoinSelectUpToAmount` to select coins up to a maximum
amount respecting a minimum amount.
2023-04-18 18:19:15 -07:00
rockstardev
c855d83a4b Updating to bullseye for arm 2023-04-13 00:14:07 -05:00
rockstardev
90231dd41c New golang only available with buster docker images 2023-04-12 23:24:40 -05:00
rockstardev
1b4bbca8ad Updating loop to 0.22 2023-04-12 23:13:20 -05:00
rockstardev
21703127a4 Updating builder docker images for new golang version 2023-04-12 23:13:08 -05:00
rockstardev
4c434438e3 Adding BtcPayServer related files and resources 2023-04-12 22:56:21 -05:00
d11n
3f80670831
Merge pull request #6 from sgiammy/feature/signet-support-entrypoint
accept 'signet' as LND_ENVIRONMENT variable
2022-11-07 14:49:39 +01:00
rockstardev
1c4bd230e1
Cleaning up README, adding new version 2022-11-04 10:48:01 -05:00
rockstardev
f52aff64f7
Merge branch 'version/0.15.4-beta-loop-0.20.2' 2022-11-04 10:36:33 -05:00
rockstardev
3f25db755c
Merge branch 'version/0.15.4-beta' 2022-11-04 10:09:39 -05:00
rockstardev
8d7079d997
Adding BtcPayServer related files and resources 2022-11-04 10:53:46 +01:00
rockstardev
9c2807eba4
Adding BtcPayServer related files and resources 2022-11-01 21:54:18 +09:00
Oliver Gugger
96fe51e2e5
Merge pull request #7098 from lightningnetwork/btcd-bump-23-3
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
mod+build: bump btcd version to v0.23.3 and bump lnd version to v0.15.4-beta
2022-11-01 13:44:01 +01:00
Oliver Gugger
c8a3fbe265
funding: fix linter error 2022-11-01 13:34:01 +01:00
Oliver Gugger
64f20b6b5b
build: bump version to v0.15.4-beta 2022-11-01 13:20:04 +01:00
Oliver Gugger
77cd2bf5e4
docs: add release notes for 0.15.4-beta 2022-11-01 13:19:40 +01:00
Oliver Gugger
d65833fca4
mod: bump btcd to v0.23.3 2022-11-01 13:18:15 +01:00
Olaoluwa Osuntokun
b4e7131bdb
build: bump version to v0.15.3-beta
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2022-10-17 10:52:17 -07:00
Olaoluwa Osuntokun
f674960e4e
Merge pull request #7017 from Roasbeef/v0-15-3-branch
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
release: create release branch for v0.15.3
2022-10-14 15:29:50 -04:00
Olaoluwa Osuntokun
34cd2f5d7c
build: bump version to v0.15.3-beta.rc1 2022-10-14 15:28:48 -04:00
Oliver Gugger
4c6f9eca5a docs: update remote signing update hint to v0.15.3-beta [skip ci]
This commit bumps the recommended version to upgrade to for remote
signing setups.
2022-10-13 12:57:35 -04:00
eugene
69b7d9666d funding: ignore maxWaitNumBlocksFundingConf for zero conf channels
This is so that if the funding transaction hasn't been confirmed
in 2016 blocks, the channel isn't marked as closed by the responder.
2022-10-13 12:57:35 -04:00
rockstardev
77dbf5d22e
Cleaning up README, adding 0.15.2-beta version 2022-10-12 15:47:39 -05:00
rockstardev
0a6f48ae0b
Merge branch 'version/0.15.2-beta' 2022-10-12 15:30:10 -05:00
rockstardev
cd045c0c65
Cleaning up README, adding new version 2022-10-12 15:14:32 -05:00
rockstardev
700c66ea86
Merge branch 'version/0.15.0-beta'
# Conflicts:
#	.circleci/config.yml
#	Makefile
#	build/version.go
#	chainreg/no_chain_backend.go
#	channeldb/graph_test.go
#	config_builder.go
#	contractcourt/briefcase.go
#	discovery/gossiper.go
#	docs/INSTALL.md
#	docs/release-notes/release-notes-0.14.2.md
#	go.mod
#	go.sum
#	htlcswitch/decayedlog_test.go
#	lnrpc/lightning.pb.go
#	lnrpc/lightning.proto
#	lnrpc/lightning.swagger.json
#	lnrpc/routerrpc/router.pb.go
#	lnrpc/rpc_utils.go
#	lnrpc/signrpc/signer_server.go
#	lnrpc/walletrpc/walletkit.pb.go
#	lnrpc/walletrpc/walletkit_server.go
#	lntest/harness_net.go
#	lntest/harness_node.go
#	lntest/itest/lnd_channel_force_close_test.go
#	lntest/itest/lnd_channel_policy_test.go
#	lntest/itest/lnd_open_channel_test.go
#	lntest/itest/lnd_psbt_test.go
#	lntest/itest/lnd_remote_signer_test.go
#	lnwallet/btcwallet/btcwallet.go
#	lnwallet/btcwallet/psbt.go
#	lnwallet/btcwallet/psbt_test.go
#	lnwallet/btcwallet/signer.go
#	lnwallet/btcwallet/signer_test.go
#	lnwallet/chainfee/estimator_test.go
#	lnwallet/interface.go
#	lnwallet/rpcwallet/healthcheck.go
#	lnwallet/rpcwallet/rpcwallet.go
#	log.go
#	macaroons/constraints.go
#	routing/missioncontrol_state_test.go
#	rpcserver.go
#	tools.go
2022-10-12 15:13:06 -05:00
Olaoluwa Osuntokun
004e2a1066 docs/release-notes: fix release notes for zero conf safety fix 2022-10-10 19:13:22 -07:00
Olaoluwa Osuntokun
110d29438a Merge branch 'v0-15-3-branch-6957' into v0-15-3-branch 2022-10-10 19:12:45 -07:00
Olaoluwa Osuntokun
8c6bc4d9b2 lnwallet/chancloser: fix loop variable shadowing in TestMaxFeeBailOut 2022-10-10 19:12:34 -07:00
Olaoluwa Osuntokun
1b95bfe171 lnwallet/chancloser: properly compute initial fee of cop close txn
In this commit, we modify the way we compute the starting ideal fee for
the co-op close transaction. Before thsi commit, channel.CalcFee was
used, which'll compute the fee based on the commitment transaction
itself, rathern than the co-op close transaction. As the co-op close
transaction is potentailly bigger (two P2TR outputs) than the commitment
transaction, this can cause us to under estimate the fee, which can
result in the fee rate being too low to propagate.

To remedy this, we now compute a fee estimate from scratch, based on the
delivery fees of the two parties.

We also add a bug fix in the chancloser unit tests that wasn't caught
due to loop variable shadowing.

The wallet import itest has been updated as well, since we'll now pay
600 extra saothis to close the channel, since we're accounting for the
added weight of the P2TR outputs.

Fixes #6953
2022-10-10 19:12:32 -07:00
Olaoluwa Osuntokun
2fe1da8109 Merge branch 'v0-15-3-branch-6966' into v0-15-3-branch 2022-10-10 19:10:01 -07:00
Oliver Gugger
a18a559a4b docs: add release notes [skip ci] 2022-10-10 19:09:50 -07:00
Oliver Gugger
27b60143cb docs: describe remote signing upgrade process
This commit adds a short guide that explains how a remote signing node
setup should be migrated from lnd v0.14.x-beta to lnd v0.15.x-beta and
adds a note to all 0.15.x release notes.
2022-10-10 19:08:49 -07:00
Oliver Gugger
cfe30ed674 cmd/lncli: add p2tr address type to account import 2022-10-10 19:07:52 -07:00
Olaoluwa Osuntokun
2ec4e5bdbd Merge branch 'v0-15-3-branch-6914' into v0-15-3-branch 2022-10-10 19:07:15 -07:00
positiveblue
714210492e docs: add release notes for hop hint selection refactor 2022-10-10 19:06:24 -07:00
positiveblue
4d0cff73ea aliasmgr: cache peer alias in memory 2022-10-10 19:05:40 -07:00
positiveblue
102d4f8d48 invoicesrpc: unit tests for invoice hop hints 2022-10-10 19:05:40 -07:00
positiveblue
9b40f5dbfd invoicesrpc: refactor addinvocie hop hint selection
In order to reduce the number of calls to the db we try to process as
few channels as we can + try to not do extra work for each of them.

- First fetch all the channels. Then, filter all the public ones and
  sort the potential candidates by remote balance.

- Filter out each potential candidate as soon as possible.

- Only check the alias if the channel supports scid aliases.

- Because we sort the channels by remote balance, we will hit the
  target amount, if possible, as soon as we can.

We do not want to leak information about our remote balances, so we
shuffle the hop hints (the forced ones go always first) so the invoice
receiver does not know which channels have more balance than others.
2022-10-10 19:05:39 -07:00
positiveblue
55b7bc6a42 style: format invoicesrpc/addinvoice.go 2022-10-10 19:04:37 -07:00
Olaoluwa Osuntokun
dce4f282ac Merge branch 'v0-15-3-branch-6941' into v0-15-3-branch 2022-10-10 19:03:26 -07:00
Olaoluwa Osuntokun
48c167b860 build: update to latest version of btcwallet w/ taproot estimation fix
Fixes https://github.com/lightningnetwork/lnd/issues/6873
2022-10-10 19:02:02 -07:00
Olaoluwa Osuntokun
f10eff4495 Merge branch 'v0-15-3-branch-6892' into v0-15-3-branch 2022-10-10 18:59:00 -07:00
eugene
33ecc9d177 release-notes: update for 0.15.2 2022-10-10 18:58:45 -07:00
eugene
3897f595a5 server.go: add peerChan to peerConnectedListeners in NotifyWhenOnline
This fixes a bug where a caller would:
- call NotifyWhenOnline and pass in a channel
- the server's mutex is held and the pubStr is checked in peersByPub
- the peer object is in the peersByPub map
- the peer object has its quit channel closed
- QuitSignal is called in the select statement, and the function
  returns
- the caller is still waiting for the channel to be sent on forever
  since it was never sent on or added to the peerConnectedListeners
  slice.

This patch fixes the above bug by adding the channel to the
peerConnectedListeners slice if the QuitSignal select case is called.
2022-10-10 18:57:55 -07:00
Olaoluwa Osuntokun
80a7ff8963 Merge branch 'v0-15-3-branch-6926' into v0-15-3-branch 2022-10-10 18:56:19 -07:00
Oliver Gugger
7a859109d2 docs: add release notes 2022-10-10 18:56:07 -07:00
Oliver Gugger
b344d9fd69 lnrpc: add additional REST binding for QueryRoutes
Lists with non-primitive members aren't supported in the query string of
a GET request with the current version of the grpc-gateway library. To
allow route_hints to be set through REST, we also offer a POST endpoint
for that call where the encoding of the request parameter can be
specified as JSON.
2022-10-10 18:54:48 -07:00
Olaoluwa Osuntokun
dd7566dab5 Merge branch 'v0-15-3-branch-6899' into v0-15-3-branch 2022-10-10 18:53:49 -07:00
Evan Kaloudis
d71639220c lnrpc/gen_protos.sh: remove js build tag 2022-10-10 18:53:48 -07:00
rockstardev
a5d3f08cca
Removing experimental features, no longer needed 2022-10-10 16:36:09 +09:00
rockstardev
276ce611e6
Updating circleci image for multiarch task
Previous one got depricated
https://circleci.com/blog/ubuntu-14-16-image-deprecation/
2022-10-10 16:36:09 +09:00
rockstardev
09386f1433
Adding BtcPayServer related files and resources 2022-10-10 16:36:09 +09:00
Olaoluwa Osuntokun
08a957ff45
Merge pull request #7005 from Roasbeef/v0-15-2-branch
release: create v0.15.2 hot fix branch to fix wire parsing issue
2022-10-09 19:34:33 -07:00
Olaoluwa Osuntokun
aff2ed3a6a
build: bump version to v0.15.2
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2022-10-09 18:45:32 -07:00
Olaoluwa Osuntokun
d65d3dd0cd
docs/release-notes: shift prior 0.15.2 release to 0.15.3
We also add an entry for the _new_ 0.15.2 hot fix release.
2022-10-09 18:44:58 -07:00
Olaoluwa Osuntokun
a502c386cd
build: update to version of btcd with wire parsing bug fix
Fixes https://github.com/lightningnetwork/lnd/issues/7002
2022-10-09 18:43:48 -07:00
Olaoluwa Osuntokun
fd1a95bf32
build: bump version to v0.15.1-beta
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2022-08-30 13:17:47 -07:00
Olaoluwa Osuntokun
e5e20a71be Merge branch 'v0.15.1-beta-6847' into v0.15.1-branch-rc2
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2022-08-22 18:05:29 -05:00
Olaoluwa Osuntokun
29ac0e171c build: bump version to v0.15.1-beta.rc2 2022-08-22 18:05:11 -05:00
Elle Mouton
7324256f42 rpcserver+docs: add default case to addr type switch
This commit adds a default case to the address type switch statement in
the NewAddress rpc server function. This catches any invalid address
types and returns an error.
2022-08-22 18:03:42 -05:00
Olaoluwa Osuntokun
cabeef2128
Merge pull request #6827 from Roasbeef/v0.15.1-branch-rc1
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
multi: create v0.15.1 rc1 release branch
2022-08-15 14:19:58 -07:00
Olaoluwa Osuntokun
b9ae910d39 Merge branch 'v0.15.1-beta-6588' into v0.15.1-branch-rc1 2022-08-15 11:59:45 -07:00
Carsten Otto
b4177b5b9d peer: add pubkey to log messages 2022-08-15 11:59:27 -07:00
Olaoluwa Osuntokun
5e3c70600b Merge branch 'v0.15.1-beta-6510' into v0.15.1-branch-rc1 2022-08-15 11:58:24 -07:00
ErikEk
63012b84da doc: release notes 2022-08-15 11:57:38 -07:00
ErikEk
92c3769c2d neutrinorpc: add getblockhash command 2022-08-15 11:56:45 -07:00
ErikEk
1a72fa7be6 neutrinorpc: add getblockhash functionality 2022-08-15 11:56:45 -07:00
Olaoluwa Osuntokun
e682abcf8f
build: bump version to v0.15.1-beta.rc1 2022-08-12 17:12:56 -07:00
Olaoluwa Osuntokun
9ac8bd4097 Merge branch 'v0.15.1-beta-6826' into v0.15.1-branch-rc1 2022-08-12 17:12:20 -07:00
Olaoluwa Osuntokun
037636a702 chainreg: update tapoort node awareness to account for bitcoind 19+
Bitcoind 23 will use the new `getdeploymentinfo` while versions after 19
(but below 23) will use the `UnifiedSoftForks` field instead of the
`SoftForks UnifiedSoftForks` field.

With this PR the taproot gating logic has been tested on bitcoind
versions: 21, 22, and 23. 21 is when the taproot logic was first added.
2022-08-12 17:12:20 -07:00
Olaoluwa Osuntokun
92a657e7f0 Merge branch 'v0.15.1-beta-6664' into v0.15.1-branch-rc1 2022-08-12 17:12:03 -07:00
eugene
43b08b75e7 release-notes: update for 0.15.1 2022-08-12 17:12:03 -07:00
eugene
414edeb5bd funding: defer sending channel_update until received funding_locked
This is required by BOLT#07 as otherwise the counter-party will
discard the channel_update as they may not consider the channel
"ready" or reorg-safe. Most other implementations besides eclair
have work-arounds for this, but it is nice to be spec-compliant.
2022-08-12 17:12:03 -07:00
Olaoluwa Osuntokun
0d8bae8004 Merge branch 'v0.15.1-beta-6820' into v0.15.1-branch-rc1 2022-08-12 17:11:43 -07:00
Olaoluwa Osuntokun
259f104a48 build: update to latest versions of btec, btcutil, and btcutil/psbt
Fixes #6668
2022-08-12 17:11:43 -07:00
Olaoluwa Osuntokun
1294c3d03f Merge branch 'v0.15.1-beta-6716' into v0.15.1-branch-rc1 2022-08-12 17:11:19 -07:00
eugene
197e3b7c26 release-notes: update for 0.15.1 2022-08-12 17:11:19 -07:00
eugene
bf7c417216 lntest: update zero-conf tests to account for zeroconfacceptor 2022-08-12 17:11:19 -07:00
eugene
5003af9c59 chanacceptor+lnrpc: update the commitmentTypes, send zero-conf to client
This updates the RPCAcceptor to send the correct commitment type
even if the zero-conf or scid-alias channel types are set. This also
adds two bools to the ChannelAcceptRequest struct that denotes whether
the funder set the zero-conf and scid-alias channel types.
2022-08-12 17:11:19 -07:00
eugene
10d4953b31 multi: add zeroconfacceptor that default rejects if no rpc acceptors
This is a safety mechanism so that zero-conf channels are not accepted
by default if no rpc acceptor exists.
2022-08-12 17:11:19 -07:00
Olaoluwa Osuntokun
51fd540c36 Merge branch 'v0.15.1-beta-6810' into v0.15.1-branch-rc1 2022-08-12 17:10:53 -07:00
Olaoluwa Osuntokun
973265483d docs/release-notes: add release notes entry 2022-08-12 17:10:53 -07:00
Olaoluwa Osuntokun
2e2357449f lnwallet/chanfunding: assumes all change outputs are P2TR 2022-08-12 17:10:53 -07:00
Olaoluwa Osuntokun
7bf83b13a8 lnwallet: use P2TR addresses for change outputs for funding coin select 2022-08-12 17:10:53 -07:00
Olaoluwa Osuntokun
62a52cf56c rpc: use P2TR addresses when sending funds back to wallet (anchor reserve) 2022-08-12 17:10:53 -07:00
Olaoluwa Osuntokun
090f30966e sweep: change outputs are now P2TR 2022-08-12 17:10:53 -07:00
Olaoluwa Osuntokun
13f82ba388 watchtower: uses P2TR for sweep, delivery, and reward addresses
In this commit, we modify the watch tower to use P2TR addrs for just
about anything sweep related.

One eye sore in this diff are the changes to
`backup_task_internal_test.go`. All the values are hard coded, and now
either differ by a value of 48, or needed to be modified to account for
the new assumptions propagated to rewards values and fees.
2022-08-12 17:10:53 -07:00
Olaoluwa Osuntokun
98c69a3988 contractcourt: the breach arb now uses P2TR outputs for sweep addrs 2022-08-12 17:10:53 -07:00
Olaoluwa Osuntokun
bc18282e1f server: default sweep addrs to P2TR
This change covers sweep addresses for: the breach arbitrator, and watch
tower clients.
2022-08-12 17:10:53 -07:00
Olaoluwa Osuntokun
f44464e592 Merge branch 'v0.15.1-beta-6633' into v0.15.1-branch-rc1 2022-08-12 17:10:21 -07:00
Olaoluwa Osuntokun
21668be1f6 docs/release-notes: add release notes entry 2022-08-12 17:10:21 -07:00
Olaoluwa Osuntokun
637dd0f902 lntest/itest: add new itest to cover taproot co-op close 2022-08-12 17:10:21 -07:00
Olaoluwa Osuntokun
a210475d11 feature+lncfg: add config option to turn of anysegwit 2022-08-12 17:10:21 -07:00
Olaoluwa Osuntokun
a3951d4774 peer: send taproot addrs during co-op close based on new feature bit
If the ShutdownAnySegwitOptional option is active, then we can safely
send these newer addresses.
2022-08-12 17:10:21 -07:00
Olaoluwa Osuntokun
41db3ea19b funding: send taproot addrs as upfront shutdown if ShutdownAnySegwitOptional is active 2022-08-12 17:10:21 -07:00
Olaoluwa Osuntokun
436bf51411 lnwallet/chanclose: update ProcessCloseMsg to check co-op close addrs
We only want to allow p2wkh, p2tr, and p2wsh addresses, so we'll utilize
the newly public wallet function to restrict this.
2022-08-12 17:10:21 -07:00
Olaoluwa Osuntokun
dc87d6016f lnwallet: export ValidateUpfrontShutdown and restrict allowed addrs
In this commit, we catch up our logic with the latest version of the
spec that removed support for normal p2kh and p2sh addresses for co-op
closes, in order to make dust calculations more uniform.
2022-08-12 17:10:21 -07:00
Olaoluwa Osuntokun
6a00952dcc lnwire+feature: add awareness of option_shutdown_anysegwit
In this commit, we add awareness of the option_shutdown_anysegwit that
permits both sides to send newer segwit based addresses. This'll
eventually enable us to send taproot addresses for co-op close.
2022-08-12 17:10:21 -07:00
Olaoluwa Osuntokun
31b7baa4f3 Merge branch 'v0.15.1-beta-6734' into v0.15.1-branch-rc1 2022-08-12 17:09:53 -07:00
eugene
05f05e6e79 release-notes: update for 0.15.1 2022-08-12 17:09:53 -07:00
eugene
44ad0165e5 rpc+cli: add general ListAliases function to dump all aliases 2022-08-12 17:09:53 -07:00
eugene
1bee0bd1fc rpc: add zero-conf, alias information to {list,closed}channels 2022-08-12 17:09:53 -07:00
Olaoluwa Osuntokun
9c4209bb4b Merge branch 'v0.15.1-beta-6816' into v0.15.1-branch-rc1 2022-08-12 17:09:38 -07:00
eugene
3ada219762 docs: add documentation for zero-conf channels
This short doc goes into how to open zero-conf channels as either
the funder or fundee.
2022-08-12 17:09:38 -07:00
eugene
a91770553f funding: remove TODO 2022-08-12 17:09:38 -07:00
Olaoluwa Osuntokun
72754ba6b1 Merge branch 'v0.15.1-beta-6740' into v0.15.1-branch-rc1 2022-08-12 17:09:25 -07:00
eugene
f54dfe30aa release-notes: update for 0.15.1 2022-08-12 17:09:25 -07:00
eugene
ed1fdd264c sweep: account for all script types in craftSweepTx
With this change, transactions created via craftSweepTx will be
standard. Previously, p2wsh/p2pkh scripts passed in via SendCoins would
be weighted as p2wpkh scripts. With a feerate of 1 sat/vbyte,
transactions returned would be non-standard. Luckily, the critical
sweeper subsystem only used p2wpkh scripts so this only affected
callers from the rpcserver.

Also added is an integration test that fails if SendCoins manages
to generate a non-standard transaction. All script types are now
accounted for in getWeightEstimate, which now errors if an unknown
script type is passed in.
2022-08-12 17:09:25 -07:00
Olaoluwa Osuntokun
7357df9202 Merge branch 'v0.15.1-beta-6770' into v0.15.1-branch-rc1 2022-08-12 17:08:47 -07:00
Olaoluwa Osuntokun
f9ef5c6ffe docs/release-notes: add entry for 0.15.1 2022-08-12 17:08:47 -07:00
Olaoluwa Osuntokun
6201b2d7f0 multi: thread through the new max fee field for co-op close
In this commit, we parse the new max fee field, and pass it through the
switch, all the way to the peer where it's ultimately passed into the
chan closer state machine.
2022-08-12 17:08:47 -07:00
Olaoluwa Osuntokun
ab14e29757 lnrpc: add a new max_fee field to the CloseChannel RPC call
In this commit, we add a new max_fee field that we'll use to decide when
to bail out of a co-op close dance as the initiator.
2022-08-12 17:08:47 -07:00
Olaoluwa Osuntokun
b6ea634ba9 lnwallet/chancloser: add tests for the new max fee behavior 2022-08-12 17:08:47 -07:00
Olaoluwa Osuntokun
2fb304b6f4 lnwallet/chancloser: remove raw state machine pointer, add channel interface
In this commit, we remove the raw channel state machine pointer from the
chan closer and instead replace that with an interface that captures
*just* the methods we need in order to do the co-op close dance.

This is a preparatory refactoring for some upcoming unit tests.
2022-08-12 17:08:47 -07:00
Olaoluwa Osuntokun
e0d8f461a1 lnwallet: add new AbsoluteThawHeight method
This lets callers get the thaw height without needing to first obtain a
snapshot of the channel state.
2022-08-12 17:08:47 -07:00
Olaoluwa Osuntokun
9ae013ca46 lnwallet/chancloser: remove the commit fee clamp, introduce max fee
In this commit, we stop clamping the ideal fee rate to the commitment
fee of the channel. This catches us up to this PR of the spec:
https://github.com/lightning/bolts/pull/847.

We also do away with the old 3x ideal fee "max fee", and replace that
with an explicit max fee. This new max fee will either be the default
multiplier of the ideal fee, or a new user specified max fee value.
2022-08-12 17:08:47 -07:00
Olaoluwa Osuntokun
170c9fd8c3 Merge branch 'v0.15.1-beta-6798' into v0.15.1-branch-rc1 2022-08-12 17:07:51 -07:00
Olaoluwa Osuntokun
deeaa0c9c7 chainreg: shutdown if backend node doesn't support taproot
In this commit, we add a check during normal node construction to see if
the backend node supports Taproot. If it doesn't, then we want to
shutdown and force the user to take note.

To check if the node supports Taproot, we'll first try the normal
getblockchaininfo call. If this works, cool, then we can rely on the
value. If it doesn't, then we'll fall back to the getdeploymentinfo call
which was added in a recent version of bitcoind [1]. Newer versions of
bitcoind might also have this call, and the getblockchaininfo call, but
not actually populate the softforks field [2]. In this case, we'll fall
back, and we also account for the case when the getblockchaininfo RPC is
removed all together.

[1]: https://github.com/bitcoin/bitcoin/pull/23508
[2]: https://github.com/bitcoin/bitcoin/pull/25114

Fixes #6773
2022-08-12 17:07:51 -07:00
Olaoluwa Osuntokun
345e66153b Merge branch 'v0.15.1-beta-6809' into v0.15.1-branch-rc1 2022-08-12 17:07:39 -07:00
positiveblue
8ad95972af docs: Add release notes for feature bit fix (#6809) 2022-08-12 17:07:39 -07:00
positiveblue
f96866915b feature: remove ScidAliasOptional dependency on ExplicitChannelTypeOptional
The [spec](https://github.com/lightning/bolts/blob/master/09-features.md)
does not specify a dependency between `ScidAliasOptional` (47) and
`ExplicitChannelTypeOptional` (45).

This bug lead to some connectivity issues with peers not setting the
45 feature bit while setting the 47.

The issue [6802](https://github.com/lightningnetwork/lnd/issues/6802) is
an example of this.
2022-08-12 17:07:39 -07:00
Olaoluwa Osuntokun
d9d0e470ad Merge branch 'v0.15.1-beta-6736' into v0.15.1-branch-rc1 2022-08-12 17:07:20 -07:00
bitromortac
5c93c2c677 config: allow independent rpccookie config
The bitcoind .cookie contains an autogenerated user (__cookie__) and
password (random string), which can be used instead of the rpc user name
and password. This commit allows for running against bitcoind without
having to access bitcoin.conf like in the case for pure
user/password/zmq configuration.
2022-08-12 17:07:08 -07:00
Olaoluwa Osuntokun
91329e7970 Merge branch 'v0.15.1-beta-6469' into v0.15.1-branch-rc1 2022-08-12 17:06:11 -07:00
yyforyongyu
f2c767e79a docs: add release note for optional migration 2022-08-12 17:05:59 -07:00
yyforyongyu
c09f1875aa channeldb: skip dry run mode for optional migrations 2022-08-12 17:05:24 -07:00
yyforyongyu
2a6ac8a117 migration30: validate migration results before deleting old buckets
This commit adds a new method `validateMigration` to be used prior to
the deletion of the old buckets to be extraly cautious.
2022-08-12 17:05:24 -07:00
yyforyongyu
a5755d4568 migration30: cover the case where v0.15.0 is active
This commit changes how we locate the next migration height by including
the scenario where `lnd@v0.15.0` is active. In the new version, we will
see a mixed of new and old logs under the same open channel bucket.
Hence, we need to alter how we locate the next un-migrated height.
2022-08-12 17:05:24 -07:00
yyforyongyu
626a8b3504 multi: add the flag prune-revocation to perform the optional migration 2022-08-12 17:05:24 -07:00
yyforyongyu
65a2f3ac81 channeldb: add optional meta and migration30
This commit enables the db to run optional migrations that are specified
by config flags. To achieve this, an optional meta is introduced to
manage the optional migrations. We distinguish the two types of
migrations here so it's easier to manage them for the concern a future
migration can cause trouble for us to determine the db version if we
don't.
2022-08-12 17:05:24 -07:00
yyforyongyu
e84fa208ff migration30: add benchmark test 2022-08-12 17:05:24 -07:00
yyforyongyu
45903c2f5e migration30+migtest: add unit tests for migration 2022-08-12 17:05:24 -07:00
yyforyongyu
02879f08c0 migration30: add migration to convert old revocation logs
This commit adds the migration that's used to convert the old revocation
logs into the new format. The migration is fault-tolerant, meaning the
process can be interrupted and the migration will pick up what's left
when running again. We also cap how many records to be processed in each
db transaction to prevent OOM.
2022-08-12 17:05:24 -07:00
yyforyongyu
120dc4ae77 migration30: add unit tests for iterator 2022-08-12 17:05:24 -07:00
yyforyongyu
955ef2e10e migration30: add supporting functions to help with unit tests
This commit adds supporting functions that will be used in the unit
test. The testing data are also added as hard-coded. We choose to copy
the most of the testing data from our itest results such that a) they
are "real" data that can be used to calculate scripts and b) we preserve
the result generated by the current code so a future change won't affect
our test.
2022-08-12 17:05:24 -07:00
yyforyongyu
7b46d1dc1d migration30: add iterator to assist migration
This commit adds several utility functions to assist the migration. In
particular, an updateLocator is added to gives us the next un-migration
position in our buckets. This locator helps us to continue the job
in case of an interrupted migration. It also serves as an indicator on
whether the migration is finished or not.
2022-08-12 17:05:24 -07:00
yyforyongyu
658515c9ce migration30: add related revocation log and lnwallet code
This commit adds relevant code from the revocation_log.go and the
package lnwallet. The code is needed to migrate the data, and we choose
to copy the code instead of importing to preserve the version such that
a future change won't affect current migration. An alternative would be
tagging each of the packages imported.
2022-08-12 17:05:24 -07:00
Olaoluwa Osuntokun
c8935e61bc Merge branch 'v0.15.1-beta-6748' into v0.15.1-branch-rc1 2022-08-12 17:04:56 -07:00
Martin Habovštiak
c4dde72aa3 doc: Deprecation reason of settled on Invoice
This documents how to deal with `settled` being deprecated. It took me quite a bit of digging without such documentation.

[skip ci]
2022-08-12 17:04:56 -07:00
Olaoluwa Osuntokun
d6fd8d1ba1 Merge branch 'v0.15.1-beta-6754' into v0.15.1-branch-rc1 2022-08-12 17:04:09 -07:00
Elle Mouton
8a17009afa multi: registration complete MW interceptor msg
In this commit, we change the flow of the rpc middleware registration
a bit. In order to allow a client to add rpc middleware interceptors in
a deterministic order, we now make the server send a "registration
complete" message to the client after compeleting the registration
process so that the client knows when it can go ahead and register the
next client.
2022-08-12 17:04:09 -07:00
Olaoluwa Osuntokun
95a6425189 Merge branch 'v0.15.1-beta-6763' into v0.15.1-branch-rc1 2022-08-12 17:03:57 -07:00
Thebora Kompanioni
c327a35e4e fix: go version in ARMv6 section of INSTALL.md 2022-08-12 17:03:57 -07:00
Olaoluwa Osuntokun
510ca08e64 Merge branch 'v0.15.1-beta-6741' into v0.15.1-branch-rc1 2022-08-12 17:03:44 -07:00
Matt Morehouse
7881f0a510 doc: update release notes 2022-08-12 17:03:43 -07:00
Matt Morehouse
2c4cf9379f itest: fix sign_psbt failure
Ensure the wallet has synced the blockchain before attempting to spend
funds.

Prior to this fix, I get the following error:
  rpc error: code = Unknown desc = wallet couldn't fund PSBT: error
      creating funding TX: insufficient funds available to construct
      transaction
2022-08-12 17:03:43 -07:00
Olaoluwa Osuntokun
2275d75f07 Merge branch 'v0.15.1-beta-6742' into v0.15.1-branch-rc1 2022-08-12 17:03:01 -07:00
Symphonic3
ac7d8e5d13 Fix typo in abandonchannel description
i_know_what_im_doing --> i_know_what_i_am_doing
2022-08-12 17:03:01 -07:00
Olaoluwa Osuntokun
6e59bd811a Merge branch 'v0.15.1-beta-6739' into v0.15.1-branch-rc1 2022-08-12 17:02:47 -07:00
Elle Mouton
74a8cb09e5 rpcperms: re-init mw lookup map after removal of one
After removing a registered middlware from the slice, we need to update
the index lookup map with the updated index for each middleware.
2022-08-12 17:02:47 -07:00
Olaoluwa Osuntokun
62dcb3ca34 Merge branch 'v0.15.1-beta-6545' into v0.15.1-branch-rc1 2022-08-12 17:02:31 -07:00
yyforyongyu
c9461d3925 docs: add release note for skip_temp_err 2022-08-12 17:02:31 -07:00
yyforyongyu
31ba12d553 routerrpc+cmd: use skip_temp_err when sending to route 2022-08-12 17:02:31 -07:00
yyforyongyu
ec8506e923 routerrpc: add new field skip_temp_err in SendToRouteRequest 2022-08-12 17:02:31 -07:00
yyforyongyu
b4df816530 routing: fix unit test for SendToRoute
This commit removes the old multi shards test for `SendToRoute` as the
method doesn't support sending MPP. The original test passed due to a
flawed mocking method, where the mockers bypassed the public interfaces
to maintain their internal state, which caused a non-exsiting situation
that a temp error wouldn't fail the payment. A new unit test is added to
demonstrate the actual case.
2022-08-12 17:02:31 -07:00
yyforyongyu
350ddfb1c7 routing: add unit test for SendToRouteSkipTempErr 2022-08-12 17:02:31 -07:00
yyforyongyu
1ad08d1b44 routing: add SendToRouteSkipTempErr to skip temp error failure
This commit adds a new method `SendToRouteSkipTempErr` that skips
failing the payment unless a terminal error occurred. This is
accomplished by demoting the original `SendToRoute` to a private method
and creating two new methods on top of it to minimize code change.
2022-08-12 17:02:31 -07:00
Carsten Otto
eb95fc9579 router: fix typos 2022-08-12 17:02:31 -07:00
Olaoluwa Osuntokun
07a0a22531 Merge branch 'v0.15.1-beta-6722' into v0.15.1-branch-rc1 2022-08-12 17:00:50 -07:00
ErikEk
23f7923d2b doc: release notes 2022-08-12 17:00:50 -07:00
ErikEk
cacf83e0ec itest: cover sign and verify msg 2022-08-12 17:00:50 -07:00
ErikEk
d32427eb06 signrpc: add schnorr sig to sign and validate msg 2022-08-12 17:00:50 -07:00
Olaoluwa Osuntokun
bb5199936c Merge branch 'v0.15.1-beta-6718' into v0.15.1-branch-rc1 2022-08-12 17:00:38 -07:00
Slyghtning
a70fe7e41e lncli: chan_point option for abandonchannel [skip ci] 2022-08-12 17:00:38 -07:00
Olaoluwa Osuntokun
01be76c631 Merge branch 'v0.15.1-beta-6630' into v0.15.1-branch-rc1 2022-08-12 17:00:13 -07:00
Oliver Gugger
b9d15055a6 docs: update release notes 2022-08-12 17:00:13 -07:00
Oliver Gugger
94204f529a itest: add integration test for error interception 2022-08-12 17:00:13 -07:00
Oliver Gugger
0412784cb4 itest: add integration test for request replacement 2022-08-12 17:00:13 -07:00
Oliver Gugger
f0b762cbf8 rpcperms: intercept errors too 2022-08-12 17:00:13 -07:00
Oliver Gugger
bbb1781e1d lnrpc: add is_error to intercept message 2022-08-12 17:00:13 -07:00
Oliver Gugger
179d1b8db5 lnrpc: describe request replacement in API docs
This commit updates the comments in the proto file to mention the new
behavior of also being able to replace request messages.
2022-08-12 17:00:13 -07:00
Oliver Gugger
45c499a022 rpcperms: allow requests to be replaced as well
With this commit we allow a replacement message to be sent by the
middleware for a request type as well as the response type. This allows
an incoming RPC request to be modified before it is forwarded to lnd.
2022-08-12 17:00:13 -07:00
Oliver Gugger
83defb449a rpcperms: add replaceProtoMsg
Because of the way the gRPC Receive() method is designed, we need a way
to replace a proto message with the content of another one without
replacing the original instance itself (e.g. overwrite all values in the
existing struct instance).
2022-08-12 17:00:13 -07:00
Oliver Gugger
b08d1b2a4f lnrpc: enable RPC middleware in REST WebSockets
If we don't flag the /v1/middleware call as request streaming, it can't
be used properly with REST WebSockets because the proxy would close the
connection after the first request message.
2022-08-12 17:00:13 -07:00
Olaoluwa Osuntokun
cc8ccabec4 Merge branch 'v0.15.1-beta-6714' into v0.15.1-branch-rc1 2022-08-12 16:59:53 -07:00
Oliver Gugger
5e8a073203 docs: add release notes 2022-08-12 16:59:53 -07:00
Oliver Gugger
5a038a9de1 itest: fix timeout in sign_psbt test 2022-08-12 16:59:53 -07:00
Oliver Gugger
d7dcbbf9d8 lnwallet: don't create BIP044 key scope by default
With a change in #6379 we made sure that all default scopes are added to
the the wallet. Unfortunately this included the BIP044 key scope that
our wallet doesn't really use. This breaks the remote signing setup
because we don't export the account of the BIP044 scope and therefore
run into an issue on the watch-only side when attempting to create the
wallet.
2022-08-12 16:59:53 -07:00
Olaoluwa Osuntokun
db32955f54 Merge branch 'v0.15.1-beta-6724' into v0.15.1-branch-rc1 2022-08-12 16:59:15 -07:00
Elle Mouton
7778d987f4 lncli: add ignore_pair flag to queryroutes 2022-08-12 16:59:15 -07:00
Olaoluwa Osuntokun
a936eeee9a Merge branch 'v0.15.1-beta-6712' into v0.15.1-branch-rc1 2022-08-12 16:58:53 -07:00
Olaoluwa Osuntokun
bedebc5caa lntest: keep all failed payments by default for HarnessNode
In this commit, we fix a detected flake: we go to make a payment, and
then want to assert that 2 attempts we required. The existing logic
assumes that the success and the payment will still be on disk. With a
recent PR, we now delete failed payments by default, but after the fact,
in a non-atomic fashion.

We fix this issue simply by having all the nodes keep around failed
payments for the sake of all the old itests that assumed this
information would always be on disk.

Introduced in: https://github.com/lightningnetwork/lnd/pull/6438.

Fixes https://github.com/lightningnetwork/lnd/issues/6711.
2022-08-12 16:58:53 -07:00
Olaoluwa Osuntokun
907e1084fc Merge branch 'v0.15.1-beta-6709' into v0.15.1-branch-rc1 2022-08-12 16:58:27 -07:00
Elle Mouton
3968f2a50f rpcperms: enforce order of interceptors
In this commit, we let the registered middleware interceptors be stored
in a slice rather than a map so that the order in which the interceptors
are executed is guarenteed to be the same as the order in which they
were registered.
2022-08-12 16:58:27 -07:00
Olaoluwa Osuntokun
45751da711 Merge branch 'v0.15.1-beta-5955' into v0.15.1-branch-rc1 2022-08-12 16:58:16 -07:00
eugene
c8395475c8 funding: revert earlier change for LDK compatibility
This removes the requirement that the zero-conf channel acceptor
flow use anchors. Also adds a fail-early check for minimum depth
zero in the non zero conf case. It would fail later, but it makes
more sense to fail immediately when receiving AcceptChannel.
2022-08-12 16:58:16 -07:00
eugene
78d7545e4d release-notes: update for 0.15.0 2022-08-12 16:58:16 -07:00
eugene
a226894cda sample-lnd: showing how to enable scid-alias, zero-conf feature bits 2022-08-12 16:58:16 -07:00
eugene
3b66147164 itest: zero-conf, scid-alias channel-type integration tests 2022-08-12 16:58:16 -07:00
eugene
ffb7f1d017 multi: add zero-conf, scid-alias channel-types to rpc
This allows the open channel rpcs to use the zero-conf or scid-alias
channel types.
2022-08-12 16:58:16 -07:00
eugene
e0221e593f server+netann+peer: put peer's alias in Update, proper config for link
This commit modifies the netann subsystem to use the peer's alias
for ChannelUpdates where appropriate (i.e. in case we are sending
the alias to the peer). It also modifies the loadActiveChannels
function in the peer package to handle upgrading a channel when the
scid-alias feature bit is turned on.
2022-08-12 16:58:16 -07:00
eugene
fff6f6b07c chanbackup: handle Single creation for zero-conf channels
The SCB function NewSingle is now zero-conf aware. Since the confirmed
short channel id may be unknown, it may use the broadcast height.
2022-08-12 16:58:16 -07:00
eugene
ea4be6069b contractcourt: set proper height hint for zero-conf channels
The contractcourt's chain watcher is now zero-conf aware and will use
an appropriate heightHint when scanning the chain.
2022-08-12 16:58:16 -07:00
eugene
adea487638 rpcserver+invoicesrpc: alias-aware AddInvoice,AddHoldInvoice rpc
AddInvoice,AddHoldInvoice now issue invoices that include our
peer's aliases. Some extra sanity checks are included to ensure we
don't leak our confirmed SCID for a private channel.
2022-08-12 16:58:16 -07:00
eugene
7ec5d09ef1 server+funding: allow scid-alias, zero-conf chantypes, scid-alias
feature-bit channels

This allows opening zero-conf chan-type, scid-alias chan-type, and
scid-alias feature-bit channels. scid-alias chan-type channels are
required to be private. Two paths are available for opening a zero-conf
channel:

* explicit chan-type negotiation
* LDK carve-out where chan-types are not used, LND is on the
  receiving end, and a ChannelAcceptor is used to enable zero-conf

When a zero-conf channel is negotiated, the funding manager:
* sends a FundingLocked with an alias
* waits for a FundingLocked from the remote peer
* calls addToRouterGraph to persist the channel using our alias in
  the graph. The peer's alias is used to send them a ChannelUpdate.
* wait for six confirmations. If public, the alias edge in the
  graph is deleted and replaced (not atomically) with the confirmed
  edge. Our policy is also read-and-replaced, but the counterparty's
  policy won't exist until they send it to us.

When a scid-alias-feature channel is negotiated, the funding manager:
* sends a FundingLocked with an alias:
* calls addToRouterGraph, sends ChannelUpdate with the confirmed SCID
  since it exists.
* when six confirmations occurs, the edge is deleted and re-inserted
  since the peer may have sent us an alias ChannelUpdate that we are
  storing in the graph.

Since it is possible for a user to toggle the scid-alias-feature-bit
to on while channels exist in the funding manager, care has been taken
to ensure that an alias is ALWAYS sent in the funding_locked message
if this happens.
2022-08-12 16:58:16 -07:00
eugene
37c68c1f19 server+htlcswitch: prevent privacy leaks, allow alias routing
This intent of this change is to prevent privacy leaks when routing
with aliases and also to allow routing when using an alias. The
aliases are our aliases.

Introduces are two maps:

* aliasToReal:
  This is an N->1 mapping for a channel. The keys are the set of
  aliases and the value is the confirmed, on-chain SCID.

* baseIndex:
  This is also an N->1 mapping for a channel. The keys are the set
  of aliases and the value is the "base" SCID (whatever is in the
  OpenChannel.ShortChannelID field). There is also a base->base
  mapping, so not all keys are aliases.

The above maps are populated when a link is added to the switch and
when the channel has confirmed on-chain. The maps are not removed
from if the link is removed, but this is fine since forwarding won't
occur.

* getLinkByMapping
  This function is introduced to adhere to the spec requirements that
  using the confirmed SCID of a private, scid-alias-feature-bit
  channel does not work. Lnd implements a stricter version of the spec
  and disallows this behavior if the feature-bit was negotiated, rather
  than just the channel type. The old, privacy-leak behavior is
  preserved.

The spec also requires that if we must fail back an HTLC, the
ChannelUpdate must use the SCID of whatever was in the onion, to avoid
a privacy leak. This is also done by passing in the relevant SCID to
the mailbox and link. Lnd will also cancel back on the "incoming" side
if the InterceptableSwitch was used or if the link failed to decrypt
the onion. In this case, we are cautious and replace the SCID if an
alias exists.
2022-08-12 16:58:16 -07:00
eugene
d242b86232 server+routing: pass isAlias to router
This allows the router to determine what is and isn't an alias from
lnd's definition of an alias. Any ChannelAnnouncement that has an
alias ShortChannelID field is not verified on-chain. To prevent a
DoS vector from existing, the gossiper ensures that only the local
lnd node can send its ChannelAnnouncements to the router with an
alias ShortChannelID.
2022-08-12 16:58:16 -07:00
eugene
550f8f0d5a server+discovery: alias-handling in gossiper
An OptionalMsgField has been added that allows outside subsystems
to provide a short channel id we should insert into a ChannelUpdate
that we then sign and send to our peer.

When the gossiper receives a ChannelUpdate, it will query the
alias manager by the passed-in FindBaseByAlias function to determine
if the short channel id in the ChannelUpdate points to a known
channel. If this lookup returns an error, we'll fallback to using
the original id in the ChannelUpdate when querying the router.
The lookup and potential fallback must occur in order to properly
lock the multimutex, query the correct router channels, and rate
limit the correct short channel id. An unfortunate side effect of
receiving ChannelUpdates from our peer that reference on of our
aliases rather than the real SCID is that we must store this policy.
Yet it is not broadcast-able. Care has been taken to ensure the
gossiper does not broadcast *any* ChannelUpdate with an alias SCID.

The cachedNetworkMsg uses the new processedNetworkMsg struct. This
is necessary so that delete-and-reinsert in the funding manager
doesn't process a ChannelUpdate twice and end up in a deadlock since
the err chan is no longer being used.
2022-08-12 16:58:16 -07:00
eugene
d7d84a1f7e aliasmgr: new data store containing our, peer's aliases
This introduces the a store for managing all things alias-related.

There are two maps:

* baseToSet:
  This stores the "base" short channel id as the key. The value is
  the set of all aliases issued for this channel. The "base" SCID is
  whatever is stored in the OpenChannel's ShortChannelID member. For
  everything other than zero-conf channels, this is the confirmed SCID.
  For zero-conf channels, this is the very first alias assigned. This is
  used mostly by the Switch to retrieve a set of aliases and determine
  if it is safe to forward.

* aliasToBase:
  This stores the reverse mapping of baseToSet. Each key is an alias
  SCID and the value is the "base" SCID. This is exclusively used by
  the gossiper to determine if an alias in a ChannelUpdate our peer
  sends actually references a channel we know of.

The functions make use of the above two maps:

* AddLocalAlias:
  This persists the {alias, base} pair in the database. The baseToSet
  map is populated. The aliasToBase is optionally populated depending on
  where this function is called from. Upgrade cases, where the
  scid-alias feature bit is toggled and channels already exist, will
  not persist to the gossip map. This is mainly to simplify the tangle
  of logic that would otherwise occur.

* GetAliases:
  This fetches the set of aliases by using the passed-in base SCID. This
  is used in the Switch and other places where the alias set is needed.

* FindBaseSCID:
  This fetches the base given an alias. This is used in the gossiper to
  determine validity of a peer's ChannelUpdate that contains an alias.

* DeleteSixConfs:
  This removes the aliasToBase map entry for the given "base". This is
  used when the gossiper mappings are no longer needed, i.e. when the
  channel has six confirmations and is public.

* PutPeerAlias:
  Stores the peer's alias.

* GetPeerAlias:
  Fetches the peer's alias.

* RequestAlias:
  Generates an alias for us in the range 16000000:0:0 and
  16250000:16777215:65535
2022-08-12 16:58:16 -07:00
eugene
888fbc6be3 lnwallet: extend Reservation with alias chan-type, feature-bit flags
This extends the Reservation arguments to include whether a pending
channel open has negotiated the zero-conf channel type, the scid-alias
channel type, and/or the scid-alias feature bit. The result of those
negotiates are stored in the OpenChannel's ChanType. The arguments to
NewChannelReservation have also been simplified.
2022-08-12 16:58:16 -07:00
eugene
5d2b686f0b channeldb: BigSize migration, store zero-conf, scid-alias bits
This introduces a BigSize migration that is used to expand the width
of the ChannelStatus and ChannelType fields. Three channel "types"
are added - ZeroConfBit, ScidAliasChanBit, and ScidAliasFeatureBit.
ScidAliasChanBit denotes that the scid-alias channel type was
negotiated for the channel. ScidAliasFeatureBit denotes that the
scid-alias feature bit was negotiated during the *lifetime* of the
channel. Several helper functions on the OpenChannel struct are
exposed to aid callers from different packages.

The RefreshShortChanID has been renamed to Refresh.

A new function BroadcastHeight is used to guard access to the
mutable FundingBroadcastHeight member. This prevents data races.
2022-08-12 16:58:16 -07:00
eugene
23b6460201 lnwire: add alias to FundingLocked in TLV
This adds an optional short channel id field to the FundingLocked
message that is sent/received as a TLV segment inside the
ExtraOpaqueData field.
2022-08-12 16:58:16 -07:00
eugene
c815fb8de7 server+lncfg: protocol flag to enable scid-alias, zero-conf feature bits
This allows the zero-conf and scid-alias feature bits to be toggled
using the config. The feature bits are off by default to protect users
from accidentally incurring the risk of a zero-conf channel.
2022-08-12 16:58:16 -07:00
eugene
113de58d77 lnwire+feature: new zero-conf, scid-alias feature bit + chantypes
This defines the zero-conf feature bit, the scid-alias feature bit,
the zero-conf channel type, and the scid-alias channel type. It also
defines the dependency "tree" that exists for the feature bits.

The scid-alias feature bit signals that the node requires an alias
short channel id to be sent in funding_locked. The scid-alias channel
type requires that the channel is private, in addition to some other
forwarding-related privacy measures.
2022-08-12 16:58:16 -07:00
Olaoluwa Osuntokun
e5870319be Merge branch 'v0.15.1-beta-6705' into v0.15.1-branch-rc1 2022-08-12 16:57:56 -07:00
Slyghtning
270971c475 lncli: chan_point option for updatechanstatus 2022-08-12 16:57:56 -07:00
Olaoluwa Osuntokun
5c8e8ae7be Merge branch 'v0.15.1-beta-6698' into v0.15.1-branch-rc1 2022-08-12 16:57:44 -07:00
Slyghtning
c25641b624 lncli: Fix batchopenchannel help text [skip ci] 2022-08-12 16:57:44 -07:00
Olaoluwa Osuntokun
d4cf0f1bdc Merge branch 'v0.15.1-beta-6636' into v0.15.1-branch-rc1 2022-08-12 16:57:31 -07:00
Tommy Volk
43e6a20d37 gitrelease-notes: update release notes for 0.15.1 2022-08-12 16:57:31 -07:00
Tommy Volk
60017f87f4 multi: migrate assert.NoError to require.NoError 2022-08-12 16:57:31 -07:00
Olaoluwa Osuntokun
f14a02c356 Merge branch 'v0.15.1-beta-6438' into v0.15.1-branch-rc1 2022-08-12 16:57:03 -07:00
Tommy Volk
fc2c90275c gitrelease-notes: update release notes for 0.15.1 2022-08-12 16:57:03 -07:00
Tommy Volk
064e0c6273 channeldb+routing: htlcs are pruned on settle 2022-08-12 16:57:03 -07:00
Tommy Volk
0a1289d606 multi: add keep-failed-payment-attempts flag 2022-08-12 16:57:03 -07:00
Olaoluwa Osuntokun
0d98121f12 Merge branch 'v0.15.1-beta-6685' into v0.15.1-branch-rc1 2022-08-12 16:56:20 -07:00
Oliver Gugger
b8e5b9b5e5 docs: fix formatting and phrasing [skip ci] 2022-08-12 16:56:10 -07:00
Oliver Gugger
4d2c9928dd docs: remove duplicate headings 2022-08-12 16:56:09 -07:00
Oliver Gugger
d1b33e0fbf docs: move 0.15.1 release notes item 2022-08-12 16:54:57 -07:00
Olaoluwa Osuntokun
d4cdc01073 Merge branch 'v0.15.1-beta-6642' into v0.15.1-branch-rc1 2022-08-12 16:53:46 -07:00
eugene
d707b239f7 release-notes: update for 0.15.1 2022-08-12 16:53:32 -07:00
eugene
3171d17edf htlcswitch: add linkStopIndex to cleanly shutdown ChannelLink
With this, extra calls to RemoveLink will wait for the link to
fully stop. This is accomplished by a map that stores a single stop
channel that callers to RemoveLink will listen on. This map is not
consulted when the Switch is shutting down and calls Stop on each
individual link. Though that could be added in the future, it is
not necessary.
2022-08-12 16:51:55 -07:00
Olaoluwa Osuntokun
e28de57075 Merge branch 'v0.15.1-beta-6687' into v0.15.1-branch-rc1 2022-08-12 16:51:33 -07:00
Oliver Gugger
7279732c92 docs: add release notes 2022-08-12 16:51:22 -07:00
Oliver Gugger
f273d11a3b itest: add test for FundPsbt->SignPsbt|FinalizePsbt flow 2022-08-12 16:50:34 -07:00
Oliver Gugger
d88e58c34f lnwallet: fix bug in SignPsbt with np2wkh addresses
Fixes #6626.
If either of the two fields FinalScriptSig or FinalScriptWitness is set
on an input of a PSBT then that results in most of the fields of that
input not to be serialized in the packet anymore, since the input is
considered to be complete.
But because a signer isn't supposed to set any of the Final* fields,
this was wrong from the beginning. Only the finalizer will set those
fields.
2022-08-12 16:50:34 -07:00
Olaoluwa Osuntokun
492ed23d70 Merge branch 'v0.15.1-beta-6592' into v0.15.1-branch-rc1 2022-08-12 16:50:21 -07:00
priyanshiiit
4a0ae8cd61 docs: adds wallet reserve rpc & field in wallet balance 2022-08-12 16:49:19 -07:00
priyanshiiit
51a2fb5c33 lntest: adds check for reserve 2022-08-12 16:48:38 -07:00
priyanshiiit
de09d56369 lnrpc+lncli: adds required reserve rpc & cli 2022-08-12 16:48:38 -07:00
priyanshiiit
8f4dd85773 lnrpc+lnd: adds required reserve in walletbalance rpc 2022-08-12 16:48:38 -07:00
priyanshiiit
212832e8de lnwallet: adds RequiredReserve method 2022-08-12 16:48:38 -07:00
priyanshiiit
e07c6c2681 lnwallet: exports fields related to AnchorChans 2022-08-12 16:48:38 -07:00
Olaoluwa Osuntokun
3e889a5069 Merge branch 'v0.15.1-beta-6680' into v0.15.1-branch-rc1 2022-08-12 16:44:38 -07:00
Oliver Gugger
e1fb7dd4ca docs: add release notes 2022-08-12 16:44:38 -07:00
Oliver Gugger
2c5ac5554e itest: add itest for p2tr via ComputeInputScript 2022-08-12 16:44:38 -07:00
Oliver Gugger
e45a2b9f12 itest: fix incorrect naming 2022-08-12 16:44:38 -07:00
Oliver Gugger
d1ea22dde3 itest: rename too specific variables 2022-08-12 16:44:38 -07:00
Oliver Gugger
90a0df6d90 signer: fix comment about p2tr in ComputeInputScript 2022-08-12 16:44:38 -07:00
Oliver Gugger
e59c410282 signrpc: fix p2tr support in ComputeInputScript 2022-08-12 16:44:38 -07:00
Olaoluwa Osuntokun
ebe0fb155d Merge branch 'v0.15.1-beta-6655' into v0.15.1-branch-rc1 2022-08-12 16:44:10 -07:00
eugene
aaf2a0238e release-notes: update for 0.15.1 2022-08-12 16:44:10 -07:00
eugene
acf35c4e6c itest: update switch delivery tests with more robust reconnect logic 2022-08-12 16:44:10 -07:00
eugene
6f07a7e9e9 server.go: replace call to removePeer with Disconnect in DisconnectPeer
Without this, calls to DisconnectPeer would bypass the
peerTerminationWatcher and allow subsequent connect requests to
go through before the peer's links were fully shut down. This could
lead to force closes.
2022-08-12 16:44:10 -07:00
Olaoluwa Osuntokun
80cd2b1b7e Merge branch 'v0.15.1-beta-6577' into v0.15.1-branch-rc1 2022-08-12 16:43:42 -07:00
ziggie
d588c04997 docs: update release note 2022-08-12 16:43:12 -07:00
ziggie
1502ce73ea cmd/lncli: make hop hint inclusion opt-in for addholdinvoice 2022-08-12 16:42:23 -07:00
Olaoluwa Osuntokun
71d754890e Merge branch 'v0.15.1-beta-6676' into v0.15.1-branch-rc1 2022-08-12 16:41:47 -07:00
Oliver Gugger
231c4b86a1 doc: add release notes 2022-08-12 16:41:47 -07:00
Oliver Gugger
4383f20477 .gitignore: add release build directory to ignore list
Fixes #6672.
A new metadata tag called build.vcs.modified was added in Go 1.18.x that
indicates whether there were any untracked files present during the
build or not.
Because the `make release` command creates a directory in which the
output packages are created, and because that directory was not added
to git and also not ignored by it, the build.vcs.modified flag was
different to the docker build which resulted in a different digest of
the resulting binary.
2022-08-12 16:41:47 -07:00
Olaoluwa Osuntokun
49465b8e32 Merge branch 'v0.15.1-beta-6682' into v0.15.1-branch-rc1 2022-08-12 16:41:27 -07:00
ErikEk
b393e37e19 dep: urfave/cli update 2022-08-12 16:41:27 -07:00
Olaoluwa Osuntokun
8cbb3ab598 Merge branch 'v0.15.1-beta-6673' into v0.15.1-branch-rc1 2022-08-12 16:41:00 -07:00
yyforyongyu
f53522001b channeldb: fix data race in TestSerializeHTLCEntries 2022-08-12 16:41:00 -07:00
Olaoluwa Osuntokun
d532c60d99 Merge branch 'v0.15.1-beta-6321' into v0.15.1-branch-rc1 2022-08-12 16:40:40 -07:00
priyanshiiit
c7387534ea docs: add previous outpoints to listchaintxns 2022-08-12 16:40:40 -07:00
priyanshiiit
3b05e5607f lntest: adds test for previous outpoints 2022-08-12 16:40:40 -07:00
priyanshiiit
ddc54387ba lnrpc: add previous_outpoints to listchaintxns 2022-08-12 16:40:40 -07:00
priyanshiiit
bd32b648f4 lnwallet: add previous_outpoints to ListTransactionDetails 2022-08-12 16:40:40 -07:00
Olaoluwa Osuntokun
12afc2f447 Merge branch 'v0.15.1-beta-6559' into v0.15.1-branch-rc1 2022-08-12 16:39:00 -07:00
ErikEk
47ba871d82 doc: release note 2022-08-12 16:36:33 -07:00
ErikEk
3f3bc404c2 doc: subscribe/cancel/lookup invoices rest 2022-08-12 16:35:40 -07:00
Olaoluwa Osuntokun
ffd9226c82 Merge branch 'v0.15.1-beta-6576' into v0.15.1-branch-rc1 2022-08-12 16:35:02 -07:00
Elle Mouton
bdad44761e docs/release-notes: add note for 6576 2022-08-12 16:35:02 -07:00
Elle Mouton
8dd4571442 cmd/lncli: add payment_addr flag to buildroute 2022-08-12 16:35:02 -07:00
rockstardev
ca4d531435
Removing experimental features, no longer needed 2022-07-25 18:58:05 -05:00
rockstardev
acd72a7fe5
Updating circleci image for multiarch task
Previous one got depricated
https://circleci.com/blog/ubuntu-14-16-image-deprecation/
2022-07-25 18:49:44 -05:00
rockstardev
b0473a9034
Adding BtcPayServer related files and resources 2022-07-25 17:59:45 -05:00
sgiammy
713b79680f accept 'signet' as LND_ENVIRONMENT variable 2022-03-18 13:36:32 +00:00
rockstardev
48e3fa8eed
Cleaning up README, adding new versions 2022-02-07 01:11:40 -06:00
rockstardev
6a5c491ee6
Merge branch 'version/0.14.2-beta'
# Conflicts:
#	Makefile
2022-02-07 01:10:24 -06:00
rockstardev
722219aaf8
Adding BtcPayServer related files and resources 2022-02-07 00:36:59 -06:00
Olaoluwa Osuntokun
1e511be523
build: bump version to v0.14.2-beta
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2022-02-03 12:20:47 -08:00
Olaoluwa Osuntokun
8c0d61c7e2
build: bump version to v0.14.2-beta.rc2
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2022-02-03 12:19:40 -08:00
Olaoluwa Osuntokun
5446478ec0 lnwallet: increase legacy fee limit threshold to 1k sats
In this commit, we increase the legacy fee limit threshold (the amount
below which we'll allow 100% of funds to go to fees for the non-v2 RPC
calls) from 50 sats to 1k sats.
2022-02-03 12:19:01 -08:00
Olaoluwa Osuntokun
d4b621b0be Merge branch 'v0.14.2-beta-6226' into v0-14-2-branch-rc1 2022-02-02 12:55:37 -08:00
Oliver Gugger
11c57040aa lncli: use amount based default routing fee 2022-02-02 12:55:16 -08:00
Oliver Gugger
4754e87ce6 lnrpc: use amount based default routing fee 2022-02-02 12:54:15 -08:00
Oliver Gugger
2295ae34ee lnwallet: introduce default routing fee calculation 2022-02-02 12:54:15 -08:00
Olaoluwa Osuntokun
25081770b6
build: bump version to v0.14.2-beta.rc1
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2022-01-26 11:20:10 -08:00
Olaoluwa Osuntokun
824c2a70fc
Merge pull request #6201 from Roasbeef/v0.14.2-branch-rc1
multi: create v0.14.2-beta-rc1 branch
2022-01-26 11:13:46 -08:00
Olaoluwa Osuntokun
9448ca93ea
channeldb: fix unit test API usage after graph cache speedups 2022-01-25 18:18:37 -08:00
Olaoluwa Osuntokun
09b1ae99e6
Merge branch 'v0.14.2-beta-6200' into v0.14.2-branch-rc1 2022-01-25 17:56:22 -08:00
Olaoluwa Osuntokun
8f12fe3daa docs/release-notes: add entry for fee rate bug fix and rpc change 2022-01-25 17:52:24 -08:00
Andras Banki-Horvath
4be12bcd2c itest: add test for the channel policy fee rate round down bug 2022-01-25 17:52:24 -08:00
ErikEk
ed3defc412 lnrpc: fix the existing routing fee inaccuracy
When updating the channel routing policy, we encounter an inaccurate
precision error when calculating the routing fee. The issue stems from
the way the IEEE 754 standard works.

The solution here is to add a uint64 parameter (as mentioned in the
issue) and keep the float64 fee_rate parameter but rounding the product
of the base and fee rate.
2022-01-25 17:52:22 -08:00
Olaoluwa Osuntokun
4b9a23b251 Merge branch 'v0.14.2-beta-6158' into v0.14.2-branch-rc1 2022-01-25 17:49:22 -08:00
eugene
5dbff49d96 docs/release-notes: update notes for 0.14.2 2022-01-25 17:49:08 -08:00
eugene
de4332a6a9 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 17:48:41 -08:00
eugene
324c578f77 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 17:48:02 -08:00
eugene
9b4ab45c5a contractcourt: handle writing BreachResolution in arbitrator log 2022-01-25 17:48:02 -08:00
eugene
3e301785a4 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 17:48:02 -08:00
Olaoluwa Osuntokun
4f85ff8b69 Merge branch 'v0.14.2-beta-6185' into v0.14.2-branch-rc1 2022-01-25 17:46:56 -08:00
Daniel McNally
99b1347789 rpcperms: set CustomCaveatCondition on middleware req
This sets the `CustomCaveatCondition` value on rpc middleware requests
if one exists. Previously, this value was always blank even if the
macaroon had a value set for its custom caveat condition.
2022-01-25 17:46:56 -08:00
Daniel McNally
a619a9bb04 macaroons: add GetCustomCaveatCondition func
This adds a `GetCustomCaveatCondition` function that returns the custom
caveat condition for a given macaroon and caveat name. Previously there
was no function for getting the custom caveat condition from a macaroon,
only for setting one.
2022-01-25 17:46:56 -08:00
Olaoluwa Osuntokun
a7676e83f4 Merge branch 'v0.14.2-beta-6111' into v0.14.2-branch-rc1 2022-01-25 17:45:13 -08:00
Joost Jager
c6439b907b channeldb: speed up graph cache loading
Use the optimized ForEachChannel method to reduce the graph cache
loading time.
2022-01-25 17:44:43 -08:00
Joost Jager
07a9130734 channeldb: reallocate node in ForEachNodeCacheable
Allows cacheableNode to be used outside of the callback. This is a
preparation for optimization of the graph cache population.
2022-01-25 17:44:09 -08:00
Joost Jager
543eff9d24 channeldb: optimize ForEachChannel
In this commit, we modify the implementation of ForEachChannel to
utilize the new kvdb method ForAll. This greatly reduces the number of
round-trips to the database needed to iterate over all channels
in the graph.
2022-01-25 17:44:09 -08:00
Joost Jager
8a7afd17fb channeldb: extract deserializeChanEdgePolicyRaw
Allows for pure deserialization without depending on a database connection.
2022-01-25 17:44:09 -08:00
Joost Jager
a95acb393b channeldb: extract AddNodeFeatures
Preparation for efficient graph cache loading where we don't iterate
over the channels of each node in the network individually.
2022-01-25 17:44:09 -08:00
Joost Jager
ab79c7bcaa kvdb: add ForAll
A new method to allow efficient range queries for backends that support
it.
2022-01-25 17:44:09 -08:00
Joost Jager
d6c1b7129d routing: remove unused ForEachChannel 2022-01-25 17:44:09 -08:00
Joost Jager
2d2bb75d85 kvdb/postgres: use readonly db transaction if possible 2022-01-25 17:44:09 -08:00
Olaoluwa Osuntokun
592c5363c4 Merge branch 'v0.14.2-beta-6180' into v0.14.2-branch-rc1 2022-01-25 17:43:18 -08:00
Andras Banki-Horvath
695baa1b45 docs: update release notes 0.14.2 2022-01-25 17:43:18 -08:00
Andras Banki-Horvath
5dca6dce00 lncli: add force flag to 2022-01-25 17:43:18 -08:00
Andras Banki-Horvath
5915f546a3 routing: add option to force import MC pair history
This commit adds the `force` flag to the `XImportMissionControl` RPC
which allows skipping rules around the pair import except for what is
mandatory to make values meaningful. This can be useful for when clients
would like to forcibly override MC state in order to manipulate routing
results.
2022-01-25 17:43:18 -08:00
Olaoluwa Osuntokun
7d5841e95e Merge branch 'v0.14.2-beta-6159' into v0.14.2-branch-rc1 2022-01-25 17:42:51 -08:00
Olaoluwa Osuntokun
6476f1601c docs/release-notes: add entry for historical chan bucket check 2022-01-25 17:42:51 -08:00
Olaoluwa Osuntokun
1d16c44db9 contractcourt: catch error when no historical bucket exists
For older nodes, this bucket was never created, so we'll get an error if
we try and query it. In this commit, we catch this error like we do when
a given channel doesn't have the information (but the bucket actually
exists).

Fixes #6155
2022-01-25 17:42:51 -08:00
Olaoluwa Osuntokun
0a9153593c Merge branch 'v0.14.2-beta-6144' into v0.14.2-branch-rc1 2022-01-25 17:42:33 -08:00
Olaoluwa Osuntokun
8c284fd150 docs/release-notes: add entry for peer defer fix 2022-01-25 17:42:33 -08:00
Olaoluwa Osuntokun
785b4118f8 lnwire+peer: clamp pong bytes, make ping handler more effcieint
This was not properly enforced and would be a spec violation on the
peer's end. Also re-use a pong buffer to save on heap allocations if
there are a lot of peers. The pong buffer is only read from, so this
is concurrent safe.
2022-01-25 17:42:33 -08:00
Olaoluwa Osuntokun
f206992cfc peer: always defer clean up of the block epoch client used for ping headers
In this commit, we fix an inadvertent memory leak by ensuring we always
use `defer` to clean up the allocated objects/memory we use to be
notified of new blocks to update what we send within the set of ping
headers.

A further optimization here would be using a single global block epoch
housed within the server, that all peer `pingHandler` goroutines use
directly.

Fixes #6143.
2022-01-25 17:42:33 -08:00
Olaoluwa Osuntokun
b59470e351 Merge branch 'v0.14.2-beta-6146' into v0.14.2-branch-rc1 2022-01-25 17:42:18 -08:00
yyforyongyu
50bddcab38 docs: add release note for closing txid 2022-01-25 17:42:18 -08:00
yyforyongyu
981464846a rpcserver: add closing txid in WaitingCloseChannel 2022-01-25 17:42:18 -08:00
yyforyongyu
ea595cbee1 rpcserver: split PendingChannels into three sections
This commit refactors the method PendingChannels for maintenance
purpose.
2022-01-25 17:42:18 -08:00
Olaoluwa Osuntokun
ade8514afe Merge branch 'v0.14.2-beta-6140' into v0.14.2-branch-rc1 2022-01-25 17:41:56 -08:00
Joost Jager
384962c272 htlcswitch: fix duplicate close
The decayed log database opening and closing is managed at a higher
level in config_builder.go.
2022-01-25 17:41:56 -08:00
Olaoluwa Osuntokun
6b36326259 Merge branch 'v0.14.2-beta-6006' into v0.14.2-branch-rc1 2022-01-25 17:41:14 -08:00
Oliver Gugger
1052aabfeb docs: update remote signing doc and release notes 2022-01-25 17:41:02 -08:00
Oliver Gugger
b597690741 multi: add migrate-wallet-to-watch-only flag
To enable converting an existing wallet with private key material into a
watch-only wallet on first startup with remote signing enabled, we add a
new flag. Since the conversion is a destructive process, this shouldn't
happen automatically just because remote signing is enabled.
2022-01-25 17:40:15 -08:00
Oliver Gugger
52f313593e lnwallet: initialize first 255 accounts
This fixes lightninglabs/loop#437 by adding all accounts that are used
in liquidity products such as Loop or Pool. Since both of these products
use key families below 255, we can get by with that number.
The alternative to creating way too many accounts (which increases the
default wallet size by ~250kB) would be to hard code the exact accounts
used by Loop (99) and Pool (210). But that sounds like a bad idea given
that there could always be more accounts being added to those (or other)
products. By making sure the first 255 accounts exist, we have a lot
more flexibility in those products for choosing key families.
2022-01-25 17:40:15 -08:00
Oliver Gugger
cc7d5e57eb multi: add nochainbackend option 2022-01-25 17:40:15 -08:00
Oliver Gugger
c538d3d307 multi: add health check for remote signer 2022-01-25 17:40:15 -08:00
Oliver Gugger
cd2012719b multi: make remote signer RPC timeout configurable 2022-01-25 17:40:15 -08:00
Oliver Gugger
a34ac85c50 rpcwallet: add critical log to remote signer errors 2022-01-25 17:40:15 -08:00
Oliver Gugger
0a2e56245f config_builder+rpcwallet: simplify RPC signing
With the remote signing instance now not needing to know anything about
addresses or current derivation indices, we don't need to forward any
such calls to that instance and can simplify the RPCKeyRing
considerably.
2022-01-25 17:40:15 -08:00
Oliver Gugger
248c6fc723 walletrpc+itest: add SignPsbt RPC 2022-01-25 17:40:15 -08:00
Oliver Gugger
d868ca3e34 btcwallet: add SignPsbt 2022-01-25 17:40:15 -08:00
Oliver Gugger
286e3742f6 lnd+lnwallet: add logger for btcwallet+rpcwallet 2022-01-25 17:40:15 -08:00
Oliver Gugger
6602efde63 lnwallet: add derivation and prev TX to UTXO 2022-01-25 17:40:15 -08:00
Oliver Gugger
9a54f273c2 btcwallet: add method for deriving key from BIP32 path 2022-01-25 17:40:15 -08:00
Oliver Gugger
5b331cfe27 btcwallet: move PSBT related methods to own file
This is a pure code move commit to extract the FundPsbt and FinalizePsbt
methods into their own file.
2022-01-25 17:40:15 -08:00
Oliver Gugger
5176a2c8d0 lnwallet+lntest+mod: bump btcwallet to export ScriptForOutput 2022-01-25 17:40:15 -08:00
Oliver Gugger
e3e21745d3 signrpc: remove incomplete sentence and TODO
We use SignOutputRaw which expects a witness script being set, even for
P2WKH. There is a special case in SignOutputRaw for the case where the
script is a p2wkh script, then the input script is reconstructed
correctly for the sighash.
2022-01-25 17:40:15 -08:00
Oliver Gugger
a6e931ed5b multi: fix formatting 2022-01-25 17:40:15 -08:00
Olaoluwa Osuntokun
d3714376d2 Merge branch 'v0.14.2-beta-6139' into v0.14.2-branch-rc1 2022-01-25 17:39:05 -08:00
Oliver Gugger
c505c5f946 docs: add release notes 2022-01-25 17:39:05 -08:00
Oliver Gugger
e5f62a0349 lntest: export base node config for re-use 2022-01-25 17:39:05 -08:00
Oliver Gugger
5f5f8573e1 lntest: export ListenerFormat constant 2022-01-25 17:39:05 -08:00
Oliver Gugger
3e99fea7bc lntest: fix colliding variable name
The variable name "bytes" collides with an imported package name, so we
rename it to avoid shadowing.
2022-01-25 17:39:05 -08:00
Olaoluwa Osuntokun
777d2f2f22 Merge branch 'v0.14.2-beta-6052' into v0.14.2-branch-rc1 2022-01-25 17:38:35 -08:00
Oliver Gugger
170684a170 itest: fix RPC middleware itest 2022-01-25 17:38:35 -08:00
yyforyongyu
beb1f06d9f itest: start using harness miner in harness net
This commit replaces the old miner with the new HarnessMiner and cleans
harness_node.go by moving methods into the test_common.go.
2022-01-25 17:38:35 -08:00
yyforyongyu
bc1d70a184 itest: introduce harness miner
This commit adds a new component, harness miner, to the itest. This
newly added component is responsible for checking the mempool and blocks
for the itest.
2022-01-25 17:38:35 -08:00
yyforyongyu
5a17ec3b65 itest: refactor initClientWhenReady to clean up init node 2022-01-25 17:38:35 -08:00
yyforyongyu
880d977346 itest: add method waitTillServerState in harness node 2022-01-25 17:38:35 -08:00
yyforyongyu
5b69e2c626 itest: use node.rpc namespace inside harness net
This commit adds a new struct RPCClients to better handle rpc clients.
A private field, rpc, is added to HarnessNode to prevent direct access
to its clients. Inside RPCClients, all clients are exported in case a
test case need access to a specific client.
2022-01-25 17:38:35 -08:00
yyforyongyu
e6df1522a7 itest: shorten functions inside harness node
This commit refactors the long function start() into smaller pieces and
moves commonly used functions into test_common.go.
2022-01-25 17:38:35 -08:00
Olaoluwa Osuntokun
0ae6c5dcf6 Merge branch 'v0.14.2-beta-5756' into v0.14.2-branch-rc1 2022-01-25 17:33:59 -08:00
yyforyongyu
0db1b7ec11 docs: update release note for itest ctxt fix 2022-01-25 17:33:45 -08:00
yyforyongyu
ea1fec84be makefile: add itest-clean to kill uncleaned processes 2022-01-25 17:32:36 -08:00
yyforyongyu
837569875e itest: replace fakeLogger with v2 logger with Discard 2022-01-25 17:32:36 -08:00
yyforyongyu
1fe306e21c itest: use run context when making rpc requests 2022-01-25 17:32:36 -08:00
yyforyongyu
360638879b itest: rename harness net file and add run context
This commit renames harness.go to harness_net.go. It also adds a run
context which is served as the parent context when creating new
contexts.
2022-01-25 17:32:36 -08:00
yyforyongyu
3000a691e5 itest: manage context within HarnessNode
This commit removes the context as a param needed when calling methods
of HarnessNode. This change moves the context management inside
HarnessNode, aside from saving us a few lines, it makes the context
creation/timeout less error-prone.
2022-01-25 17:32:36 -08:00
yyforyongyu
16526e40a8 itest: use ProcessState and runCtx to control process quit 2022-01-25 17:32:36 -08:00
yyforyongyu
4275e74cd3 itest: add run context to harness node
This commit adds a running context to HarnessNode which replaces all the
background context used and also serves as a way to signal quit when the
test is shutting down.
2022-01-25 17:32:36 -08:00
yyforyongyu
fd92c738e9 itest: add test_common to hold commonly used methods
A new file, test_common.go, is added to hold commonly used functions
across lntest.
2022-01-25 17:32:36 -08:00
Olaoluwa Osuntokun
c2fa9ff229 Merge branch 'v0.14.2-beta-6054' into v0.14.2-branch-rc1 2022-01-25 17:30:17 -08:00
yyforyongyu
8c92e029eb docs: add release note for premature msg fix 2022-01-25 17:28:10 -08:00
eugene
137fe297a6 discovery: use source instead of peer for accurate rejectCache 2022-01-25 17:26:45 -08:00
yyforyongyu
e07ab7aea6 discovery: resend premature messages when new blocks arrive
This commit adds a method to resend premature when new blocks arrive.
Previously when a message has specified a block+delta in the future, we
would ignore the message and never process it again, causing an open
channel never being broadcast under fast blocks generation. This commit
fixes it by saving the future messages and resending them once the
required block height is reached.
2022-01-25 17:26:45 -08:00
yyforyongyu
4f1905cea1 discovery: sync blocks in a dedicated goroutine
This commit moves syncing blocks into a dedicated goroutine to avoid the
race condition where several go channels are ready and the block height
update is pushed after a network message is processed.
2022-01-25 17:26:45 -08:00
yyforyongyu
bbc16ae30f routing+discovery: uniform error codes in routing 2022-01-25 17:26:45 -08:00
yyforyongyu
c808d27fef discovery: transit all inactive syncers when needed 2022-01-25 17:26:45 -08:00
yyforyongyu
c48db1ebeb discovery: shorten mutex locking closure 2022-01-25 17:26:45 -08:00
yyforyongyu
9b51237607 funding: add explicit log to avoid confusion 2022-01-25 17:26:45 -08:00
yyforyongyu
bad0db11b8 funding: add String method for channelOpeningState
The newly added String method can be helpful in reading logs.
2022-01-25 17:26:45 -08:00
yyforyongyu
3d0bd75947 chainntnfs: add more verbose logs for txnotifier 2022-01-25 17:26:45 -08:00
yyforyongyu
92cda1a358 discovery: add verbose network messages related logs 2022-01-25 17:26:45 -08:00
Olaoluwa Osuntokun
eb5f6d5d92 Merge branch 'v0.14.2-beta-6116' into v0.14.2-branch-rc1 2022-01-25 17:25:27 -08:00
Joost Jager
7845fe0bba itest: increase pg database connection limit 2022-01-25 17:25:14 -08:00
yyforyongyu
e39fbcef11 docs: add release note for peer conn fix 2022-01-25 17:23:18 -08:00
yyforyongyu
fc7b5f8b5f server: fix peers not ignored during bootstrapping
This commit fixes the issue where duplicate peers are used both in
making persistent connections and bootstrap connections. When we init
bootstrapping, we need to ignore peers that have connections already
made so far plus peers which we are attempting to make connections with,
hence the persistent peers.
2022-01-25 17:21:40 -08:00
yyforyongyu
a4e87fd2de multi: enhance logging for debugging peer connection 2022-01-25 17:21:40 -08:00
Olaoluwa Osuntokun
c8ba5e2ca3 Merge branch 'v0.14.2-beta-6108' into 0-14-2-branch-rc1 2022-01-25 17:17:48 -08:00
Joost Jager
dc0b0e9b38 kvdb/postgres: fix context cancellation 2022-01-25 17:17:48 -08:00
Joost Jager
94def4508e kvdb/postgres: fix tests 2022-01-25 17:17:48 -08:00
Olaoluwa Osuntokun
9f53786bdb docs/release-notes: add entry for chan type fix 2022-01-25 17:16:12 -08:00
Olaoluwa Osuntokun
ba46b98c3c funding: always send a channel type in explicit mode
In this commit, we switch to always sending a channel type when we're in
explicit mode. This is compatible with prior versions of lnd as they
won't send a channel type, and we'll just arrive at the same type via
the existing implicit funding.

Fixes https://github.com/lightningnetwork/lnd/issues/6067
2022-01-25 17:16:12 -08:00
Matthew Bajorek
9d399d412a docs: update release note for #6073 [skip ci] 2022-01-25 17:14:13 -08:00
Matthew Bajorek
3e3de70a7a netann: clarify invalid config timeout constraints [skip ci] 2022-01-25 17:13:52 -08:00
Elle Mouton
e8002dd536 lnwallet+docs: minrelayfee always above fee floor
The minimum relay fee is always ensured to be above our fee floor except
in the very first min relay fee query to bitcoind. This commit ensures
that the fee floor is respected in this first query.
2022-01-25 17:11:56 -08:00
Bjarne Magnussen
c8173b60b3 add to release notes 0.14.2 2022-01-25 17:08:34 -08:00
Bjarne Magnussen
f06aecc5da lnrpc: refactor populating lnrpc.Transaction inside SubscribeTransaction 2022-01-25 17:07:48 -08:00
Martin Habovstiak
a5471576ea docs: added release notes regarding #5539 2022-01-25 17:06:32 -08:00
Martin Habovstiak
6678f25ca0 test: don't enforce reserved value in PSBT midstep
This adds an integration test that makes sure channel can be funded from
empty wallet using PSBT if the funding transaction contains an output
belonging to the wallet, satisfying the reserve.
2022-01-25 17:06:32 -08:00
Martin Habovstiak
1b9a126809 lnwallet: don't enforce new reserved value in PSBT midstep
This change avoids enforcing new reserved value when PSBT funding is not
finished yet as new inputs and outputs may still be added that could
change the outcome of the check.

This originally failed in the scenario when funding a channel from
external wallet *and depositing to on-chain wallet* was done
simultaneously in a single transaction. If such transaction confirms
then reserved UTXO is guaranteed to be available but the check didn't
take it into account.

The enforcement still occurs in the final step of PSBT funding flow, so
it is safe. It also occurs in case of non-PSBT funding.
2022-01-25 17:06:32 -08:00
Matthew Bajorek
ad8fc3ceb7 lncli: Add json flag to trackpayment [skip ci] 2022-01-25 17:03:39 -08:00
Olaoluwa Osuntokun
2bdb8e3b62 Merge branch 'v0.14.2-beta-5971' into 0-14-2-branch-rc1 2022-01-25 17:02:16 -08:00
yyforyongyu
acbc11fd40 docs: add release note for ChanStatusFlags 2022-01-25 17:02:16 -08:00
yyforyongyu
b227d72067 rpcserver: expose ChanStatusFlags in pending close
This commit exposes the ChanStatusFlags inside waitingCloseResp such
that the channel close type is exposed.
2022-01-25 17:02:16 -08:00
Andras Banki-Horvath
9c0d2cf208 docs: update release notes 2022-01-25 17:01:13 -08:00
Andras Banki-Horvath
36d98a9b3d routing: fix memory corruption in MC store
Since bbolt returns references to internally stored data when storing
locally it's best to copy the byte slices returned or alternatively
convert them to string (which also makes a copy) to avoid crashes casued
by memory corruption.
2022-01-25 16:59:22 -08:00
Olaoluwa Osuntokun
24a033900a Merge branch 'v0.14.2-beta-6062' into 0-14-2-branch-rc1 2022-01-25 16:59:00 -08:00
yyforyongyu
9c81108de2 docs: update release note for fee rate fix 2022-01-25 16:59:00 -08:00
yyforyongyu
361b8a9691 chainfee: update test TestWebAPIFeeEstimator 2022-01-25 16:59:00 -08:00
yyforyongyu
a9bb51a788 chainfee: handle conf target not found in cache 2022-01-25 16:59:00 -08:00
Olaoluwa Osuntokun
3fb9cbc032 Merge branch 'v0.14.2-beta-6071' into 0-14-2-branch-rc1 2022-01-25 16:57:57 -08:00
kon
e179d3f0e4 routerrpc: fix wrong error messages
when payment_hash or final_cltv_delta and payment_request was set, the error message showed that the parameters shouldn't be set with dest instead of payment_request

[skip ci]
2022-01-25 16:57:57 -08:00
Olaoluwa Osuntokun
f02f230ba9 Merge branch 'v0.14.2-beta-6049' into 0-14-2-branch-rc1 2022-01-25 16:57:18 -08:00
Andras Banki-Horvath
508a3714aa docs: update release notes 2022-01-25 16:57:18 -08:00
Andras Banki-Horvath
2a4b3fe354 etcd: make max message size configurable 2022-01-25 16:57:18 -08:00
Olaoluwa Osuntokun
4062003c91 Merge branch 'v0.14.2-beta-6035' into 0-14-2-branch-rc1 2022-01-25 16:56:54 -08:00
naveen
f99cf4f7cb multi: Remove GO111MODULE env variable in Makefile
The `GO111MODULE` variable is not required from go 1.16
https://go.dev/blog/go116-module-changes
2022-01-25 16:56:54 -08:00
Oliver Gugger
f12f40dfcb mod+tools+Makefile: use go install to fetch dependencies
Instead of hard coding a commit to use for a binary tool that we use
during the build process, we now only use "go install" to install the
binaries and the golang builtin versioning system to pin the exact
version/commit we want to use in go.mod.
2022-01-25 16:56:54 -08:00
Oliver Gugger
e9e580ee1a GitHub+Makefile: remove travis goals 2022-01-25 16:56:54 -08:00
Oliver Gugger
43507e969c docs+Makefile: remove goveralls
We use a GitHub Action for sending the coverage to coveralls.io and
don't need the goveralls binary anymore.
2022-01-25 16:56:54 -08:00
rockstardev
b767e1c7ae
Reverting changes picked up from feature branches
These changes haven't made it into master on lightning/lnd
2021-12-22 20:58:31 -06:00
rockstardev
e2ddfde44e
Cleaning up README, adding new versions 2021-12-22 19:51:11 -06:00
rockstardev
a08ce6fdb7
Merge branch 'version/0.14.1-beta' 2021-12-22 19:40:35 -06:00
rockstardev
177d04ecaa
Merge branch 'version/0.14.0-beta'
# Conflicts:
#	.github/pull_request_template.md
#	README.md
#	build/version.go
#	chainreg/chainregistry.go
#	cmd/lncli/cmd_payments.go
#	docs/release-notes/release-notes-0.13.3.md
#	docs/release-notes/release-notes-0.14.0.md
#	go.mod
#	go.sum
#	htlcswitch/interfaces.go
#	htlcswitch/switch.go
#	htlcswitch/switch_test.go
#	lntest/itest/lnd_test.go
#	lnwallet/test_utils.go
2021-12-22 19:40:23 -06:00
rockstardev
bfda9ea312
Merge branch 'version/0.13.3-beta'
# Conflicts:
#	linuxamd64.Dockerfile
#	linuxarm32v7.Dockerfile
#	linuxarm64v8.Dockerfile
2021-12-22 19:38:40 -06:00
rockstardev
94693c31b7
Adding BtcPayServer related files and resources
(cherry picked from commit 14517a97ea)
(cherry picked from commit a185998bcf)
2021-11-25 14:10:40 +09:00
rockstardev
b9f43ac43e
Adding BtcPayServer related files and resources
(cherry picked from commit 14517a97ea)
(cherry picked from commit a185998bcf)
2021-11-20 21:39:49 +09:00
rockstardev
67907c415e
Bumping loop to v0.15.0-beta 2021-10-09 12:34:34 -05:00
rockstardev
820c830ae1
Updating docker images to compile for new version of GoLang 2021-10-09 12:33:26 -05:00
rockstardev
83b7c64b76
Merge branch 'version/0.13.1-beta'
# Conflicts:
#	.github/workflows/main.yml
#	.github/workflows/release.yaml
#	.travis.yml
#	Makefile
#	channeldb/channel.go
#	channeldb/channel_test.go
#	cmd/lncli/cmd_pay.go
#	config.go
#	contractcourt/briefcase_test.go
#	discovery/gossiper.go
#	discovery/gossiper_test.go
#	docker-initunlocklnd.sh
#	docs/release.md
#	invoices/invoice_expiry_watcher_test.go
#	linuxamd64.Dockerfile
#	linuxarm32v7.Dockerfile
#	linuxarm64v8.Dockerfile
#	lncfg/gossip.go
#	lnrpc/Dockerfile
#	lnrpc/gen_protos.sh
#	lnrpc/gen_protos_docker.sh
#	lnrpc/invoicesrpc/invoices_server.go
#	lnrpc/routerrpc/router.pb.go
#	lnrpc/routerrpc/router.proto
#	lnrpc/routerrpc/router.swagger.json
#	lnrpc/routerrpc/router_backend.go
#	lnrpc/rpc.pb.go
#	lntest/itest/lnd_test.go
#	lntest/itest/log_error_whitelist.txt
#	routing/integrated_routing_context_test.go
#	routing/payment_session.go
#	routing/router.go
#	routing/router_test.go
#	rpcserver.go
#	sample-lnd.conf
#	scripts/verify-install.sh
#	server.go
2021-10-09 12:22:29 -05:00
rockstardev
25c56c4974
Commenting script to preserve information about tricky unlocking mechanism 2021-10-09 11:33:26 -05:00
rockstardev
22937c97f1
Improving unlock script to wait for proper state when it comes to wallet unlocking 2021-10-09 11:33:20 -05:00
rockstardev
9f60321b89
Installing xxd on arm32 and arm64 2021-10-09 11:33:13 -05:00
rockstardev
787ab54072
Updating init http error code condition with lnd-0.13.1-beta 2021-10-09 11:32:48 -05:00
rockstardev
9a8f64c512
Adding loop binary in lnd container 2021-10-09 11:32:41 -05:00
rockstardev
2fa461271b
Adding environment variable to influence LND's rest host
(cherry picked from commit 39d25171ce)
(cherry picked from commit 7b6c31d223)
2021-10-09 11:31:03 -05:00
rockstardev
e32d15659b
Adding BtcPayServer related files and resources
(cherry picked from commit 14517a97ea)
(cherry picked from commit a185998bcf)
2021-10-09 11:30:47 -05:00
Oliver Gugger
4f567577db
build: bump version to v0.13.3-beta
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2021-10-04 16:07:22 +02:00
Olaoluwa Osuntokun
186b6cce2b
build: bump version to v0.13.3-beta.rc2
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2021-10-03 12:22:04 -07:00
Olaoluwa Osuntokun
ab8d342cad multi: fix cherry-pick compilation issues 2021-10-03 12:21:16 -07:00
Oliver Gugger
6e519ca910 scripts: verify version in manifest
To make a downgrade attack harder, we also check that the version string
is contained in the manifest, on the same line as the hash.
2021-10-03 12:18:27 -07:00
Oliver Gugger
4569ed424d scripts: allow packaged release archive to be verified
Instead of only allowing to verify installed/unpacked binaries, we also
allow a single binary or packaged release archive to be verified.
2021-10-03 12:16:40 -07:00
Oliver Gugger
c97040b77e docker: add keys to docker image
Because the PGP keys are no longer downloaded from Keybase but are used
from the repo directly, we also have to copy them to the Docker image so
we can run the script without needing to supply them through a volume.
2021-10-03 12:16:40 -07:00
Oliver Gugger
53899b3fd4 scripts: pin signatures to keys
With this commit we add a new restriction that checks that the
username in the signature file (manifest-<username>-<version>.sig) actually
does have a signing key and that the signature was created with that key.
The signature is only counted towards the minimum of 5 signatures if
that check is successful.
The changes in this commit were inspired by @kixunil in #5048.
2021-10-03 12:16:40 -07:00
Oliver Gugger
50b7748f2c scripts: make sure signature files have unique names
To fix a simple attack where the same file would be uploaded multiple
times under the same name, we make sure we only count unique file names.
2021-10-03 12:16:40 -07:00
positiveblue
6d1fa7d84a scripts: add positiveblue key to verify script 2021-10-03 12:16:40 -07:00
Oliver Gugger
fca4058f2e scripts: add signing keys to repo
Instead of importing the keys from Keybase, we add all the signing keys
to the repository. In addition to having the key file present each key's
ID must also be added to the verification script. This acts as a double
check that the correct key is added and makes a key change more
explicit.
2021-10-03 12:16:40 -07:00
Conner Fromknecht
13bc2eee66 docs: update release verification scripts for v0.12.1-beta 2021-10-03 12:16:40 -07:00
Conner Fromknecht
cda414c84d docs: remove unnecessary docker pull from release verification
Docker will automatically pull the image if it isn't found locally.
2021-10-03 12:16:40 -07:00
Conner Fromknecht
a8bb570a19 scripts/verify-install.sh: pass expected version as argument
This removes a vulnerability brought up by @Kixunil where both the lnd
and lncli binaries are executed to obtain their version before they have
been verified against the release. A malicious binary could have already
compromised the user's system before any of the checks had been
performed.

This commit it split out from the doc changes so that it can easily be
cherry-picked to master/0.13.0.
2021-10-03 12:16:40 -07:00
Oliver Gugger
fb8a841d3e scripts: extract functions
As a preparation to make the script easier to understand, we extract
some of the sub tasks into functions.
2021-10-03 12:16:40 -07:00
Harsha Goli
29a6b101fd scripts: add arshbot key to verify script 2021-10-03 12:16:40 -07:00
Olaoluwa Osuntokun
0342c8b33c
build: bump version to v0.13.3-beta.rc1 2021-10-03 11:52:39 -07:00
eugene
2f68e95013 docs: update release notes for 0.13.3 2021-10-03 11:30:53 -07:00
eugene
0e3d06a562 multi: introduce config-level DustThreshold for defining threshold 2021-10-03 11:30:53 -07:00
eugene
072bde093c 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-10-03 11:30:52 -07:00
eugene
16d59544ea 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-10-03 11:29:44 -07:00
eugene
4558381ffa 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-10-03 11:28:39 -07:00
eugene
1fc413e2f6 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-10-03 11:28:38 -07:00
eugene
c6fe623061 docs: update release notes for 0.13.3 2021-10-03 11:25:05 -07:00
eugene
655778d80d 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-10-03 11:25:05 -07:00
eugene
ddbd0b672a 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-10-03 11:25:02 -07:00
Olaoluwa Osuntokun
86d3dec7b9
build: bump version to v0.13.2-beta
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2021-08-18 17:42:48 -07:00
Olaoluwa Osuntokun
ef70a92e49 Merge branch 'v0.13.2-beta-5554' into 0-13-2-branch 2021-08-18 17:37:07 -07:00
Olaoluwa Osuntokun
fed9c1cd8d docs/release-notes: add item for easy AMP CLI re-use 2021-08-18 17:37:07 -07:00
Olaoluwa Osuntokun
eac3f8ea1f docs/release-notes: add item for sendpayment pay_addr bug fix 2021-08-18 17:37:07 -07:00
Olaoluwa Osuntokun
6057200c72 cmd/lncli: add new option for easy AMP invoice re-use
In this commit, we add a new option (`--amp-reuse`) that allows for easy
AMP invoice re-use when using either the `sendpayment` command.
2021-08-18 17:37:07 -07:00
Olaoluwa Osuntokun
683f6f3b2e cmd/lncli: always parse the pay_addr field for sendpayment
In this commit, we fix a bug that would cause attempts to re-use an AMP
invoice to fail. Without this commit, we would only attempt to parse the
payment addr if no invoice was specified, so a user manually specifying the
pubkey of the detonation. The fix is straight forward: always parse the
`pay_addr` field as the user may be attempting to re-use an AMP invoice w/o
open coding each of the sections.
2021-08-18 17:37:07 -07:00
rockstardev
dec49aa15b
Commenting script to preserve information about tricky unlocking mechanism 2021-08-12 22:28:28 -05:00
rockstardev
824a998274
Improving unlock script to wait for proper state when it comes to wallet unlocking 2021-08-12 21:38:32 -05:00
rockstardev
570bc0824f
Installing xxd on arm32 and arm64 2021-08-12 20:54:51 -05:00
rockstardev
6baa0ee593
Updating init http error code condition with lnd-0.13.1-beta 2021-08-01 01:27:12 +02:00
rockstardev
025f953f6f
Adding loop binary in lnd container 2021-08-01 01:26:42 +02:00
rockstardev
f0714bf36e
Adding environment variable to influence LND's rest host
(cherry picked from commit 39d25171ce)
(cherry picked from commit 7b6c31d223)
2021-08-01 00:36:40 +02:00
rockstardev
ae1b824e4b
Adding BtcPayServer related files and resources
(cherry picked from commit 14517a97ea)
(cherry picked from commit a185998bcf)
2021-08-01 00:36:27 +02:00
rockstardev
c49af2288c
Merge branch 'version/0.12.1-beta'
# Conflicts:
#	.github/workflows/docker.yml
#	.github/workflows/main.yml
#	.github/workflows/release.yaml
#	docker-entrypoint.sh
#	docker-initunlocklnd.sh
#	linuxamd64.Dockerfile
#	linuxarm32v7.Dockerfile
#	linuxarm64v8.Dockerfile
#	lncfg/address.go
2021-07-31 23:29:04 +02:00
Olaoluwa Osuntokun
596fd90ef3
build: bump version to v0.13.1-beta
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2021-07-19 11:02:54 -07:00
Olaoluwa Osuntokun
db577b23b4 Merge branch 'v0.13.1-beta-5472' into 0-13-1-branch 2021-07-19 11:01:07 -07:00
Joost Jager
2b49c4d344 build: bump btcwallet 2021-07-19 11:01:07 -07:00
Olaoluwa Osuntokun
17b0461583
build: bump version to v0.13.1-beta.rc2
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
2021-07-07 16:12:41 -07:00
rockstardev
7d676848cb
Extracting running Loop to separate script 2021-05-23 12:45:54 -05:00
rockstardev
a1c04622d3
Letting old condition continue in order for Loop to be started 2021-05-19 08:44:39 -05:00
rockstardev
8187303ada
Updating loop to 0.12.2-beta 2021-05-12 23:04:12 -05:00
rockstardev
78d5af59ee
Loop listener has problems if immidatelly starter, increasing wait time 2021-04-22 23:26:56 -05:00
rockstardev
3b3c52f1e7 Lnd doesn't listen on localhost, so we need to pass in host 2021-03-21 19:17:47 -05:00
rockstardev
b4ac312d2e Updating path to MACAROON_FILE 2021-03-21 13:23:08 -05:00
rockstardev
7e82d9a451 Adding loop to arm32v7 and arm64v8 images 2021-03-21 11:54:22 -05:00
rockstardev
e0089475f7 Consolidating string in logger to match sh name 2021-03-21 11:40:52 -05:00
rockstardev
ae99043041 Adding loop binary in lnd container 2021-03-21 11:36:45 -05:00
rockstardev
c7f4e0c306 Adding environment variable to influence LND's rest host
(cherry picked from commit 39d25171ce)
(cherry picked from commit 7b6c31d223)
2021-03-14 10:31:08 -05:00
rockstardev
5b63dc1f67 Adding BtcPayServer related files and resources
(cherry picked from commit 14517a97ea)
(cherry picked from commit a185998bcf)
2021-03-14 10:30:59 -05:00
Conner Fromknecht
d233f61383
Merge pull request #5052 from cfromknecht/v0.12.1-beta.rc7-branch-commits
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
v0.12.1-beta.rc7
2021-02-22 16:55:05 -08:00
Conner Fromknecht
51aaf2bb13
build/version: bump to v0.12.1-beta.rc7 2021-02-22 12:23:16 -08:00
Conner Fromknecht
923134e52c
docs: update release verification scripts for v0.12.1-beta 2021-02-22 12:22:03 -08:00
Conner Fromknecht
a38c82d8c7
docs: remove unnecessary docker pull from release verification
Docker will automatically pull the image if it isn't found locally.
2021-02-22 12:19:43 -08:00
Conner Fromknecht
3ae60cd63f
scripts/verify-install.sh: pass expected version as argument
This removes a vulnerability brought up by @Kixunil where both the lnd
and lncli binaries are executed to obtain their version before they have
been verified against the release. A malicious binary could have already
compromised the user's system before any of the checks had been
performed.

This commit it split out from the doc changes so that it can easily be
cherry-picked to master/0.13.0.
2021-02-22 12:18:43 -08:00
Conner Fromknecht
953e3cc50d
Merge pull request #5045 from cfromknecht/v0.12.1-beta.rc6-branch-commits
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
v0.12.1-beta.rc6
2021-02-18 17:03:01 -08:00
Conner Fromknecht
7bfec3f8c2
build/version: bump to v0.12.1-beta.rc6 2021-02-18 11:47:56 -08:00
Conner Fromknecht
5fd74659bc
routing: avoid modifying AssumeChannelValid in unit tests
This produces a race condition when reading AssumeChannelValid from a
different goroutine. Instead we isolate the test cases and initial
AssumeChannelValid properly.
2021-02-18 08:52:35 -08:00
Conner Fromknecht
f1786f9454
routing: dial back max concurrent block fetches
This commit reduces the number of concurrent validation operations the
router will perform when fully validating the channel graph. Reports
from several users indicate that GetInfo would hang for several minutes,
which is believed to be caused by attempting to validate massive amounts
of channels in parallel. This commit returns the limit back to its
original state before adding the batched gossip improvements.

We keep the 1000 concurrent validation request limit for
AssumeChannelValid, since we don't fetch blocks in that case. This
allows us to still keep the performance benefits on mobile/low-resource
devices.
2021-02-18 08:52:34 -08:00
Conner Fromknecht
5cddeb7449
Merge pull request #5039 from cfromknecht/v0.12.1-beta.rc5-branch-commits
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
v0.12.1-beta.rc5
2021-02-17 12:58:23 -08:00
Conner Fromknecht
1f012c461e
build/version: bump to v0.12.1-beta.rc5 2021-02-17 12:15:59 -08:00
Conner Fromknecht
64660a2574
Revert "lnrpc/routerrpc: use new default value of 16 for maxparts"
This reverts commit 25b90832e3d74e62176a9c71b0b724d6fb49a39d, as
well as reverting some changes in other commits in the PR that weren't
fully attomic with the primary commit.
2021-02-17 12:15:58 -08:00
Conner Fromknecht
5643fe8dbe
github: check-each-commit from v0.12.0-beta 2021-02-17 12:15:58 -08:00
Oliver Gugger
1ed3c340e8
scripts: detect whether sha256sum or shasum is available
The shasum command isn't available in Alpine linux while the sha256sum
command isn't available on MacOS. We add a simple switch that tries to
detect which one is available.
2021-02-17 12:01:21 -08:00
Oliver Gugger
877fd96e8c
make: use make for docker-release
To fix an issue where the golang version would be picked up from the
host system if the docker-release command was used, we switch over to
using make inside of the container as well instead of feeding the
parameters into the release script manually.
We only pass in the flags that we might actually want to overwrite.
2021-02-17 12:01:18 -08:00
Conner Fromknecht
d6c697d509
Merge pull request #5027 from cfromknecht/v0.12.1-beta.rc4-branch-commits
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
v0.12.1-beta.rc4
2021-02-16 16:34:09 -08:00
Conner Fromknecht
d51f61af25
build/version: bump to v0.12.1-beta.rc4 2021-02-16 13:58:33 -08:00
Olaoluwa Osuntokun
2f4de5dc5f
cmd/lncli: add max shard size parsing for payment commands 2021-02-16 10:12:27 -08:00
Olaoluwa Osuntokun
be54ac78a6
routing: if MaxShardAmt is set, then use that as a ceiling for our splits
In this commit, we thread through the necessary state to allow users to
set a max shard amount. If this value is set, then this'll effectively
serve as a ceiling for all our split attempts. If we need to split,
we'll first try to use `paymentAmt/2`, if that's bigger than
`MaxShardAmt, then we'll use the latter instead.

Ideally in the future we have a dynamic way to automatically set both
the `MaxShardAmt` as well as `MaxParts` for users. Until then exposing
these two new fields will allow us to experiment with setting them
automatically using the RPC interface, and also give users a bit more
control over how we attempt to route payments, akin to coin control for
on-chain payments.

Fixes #4730
2021-02-16 10:12:26 -08:00
Olaoluwa Osuntokun
3a4b44a480
lnrpc/routerrpc+routing: add new MaxShardAmt field to LightningPayment 2021-02-16 10:12:26 -08:00
Olaoluwa Osuntokun
59764d7b04
lnrpc/routerrpc: add new max_shard_size_msat field to SendPaymentRequest 2021-02-16 10:12:25 -08:00
Olaoluwa Osuntokun
d29528bb69
lnrpc/routerrpc: use new default value of 16 for maxparts
In this commit, we raise the default value for the `MaxParts` field from
1 to 16. This change was motivated by the fact that many users either
forget, or don't even know this field is there in the first place. A
value of 16 was chosen rather arbitraliy (other than power of 2). In
the future, we should tune this value based on the expected number of
payment attempts for a given payment amount.
2021-02-16 10:12:01 -08:00
Conner Fromknecht
87a3aad001
htlcswitch: init mockFeeEstimator in other LinkChannelConfigs
If the tests don't execute quick enough, the link will try to sample the
network fee and cause a panic. This happens semi-regularly on travis.
2021-02-15 13:17:34 -08:00
Conner Fromknecht
6236c5b620
lntest: add Block height out of range to whitelist 2021-02-15 13:17:04 -08:00
Conner Fromknecht
5fe7d19e6a
lntest: add unable to extract ChannelUpdate to whitelist 2021-02-15 13:17:04 -08:00
Conner Fromknecht
48caa962cb
scripts/verify-install.sh: combine final SUCCESS logs 2021-02-15 13:16:51 -08:00
Conner Fromknecht
87dfb04f1e
scripts/verify-install: bump min required signatures to 5 2021-02-15 13:16:51 -08:00
Oliver Gugger
7027e940ef
scripts: add more verbose error messages to verification
We want to be more precise in what exactly went wrong and what the cause
could be.
2021-02-15 13:16:51 -08:00
Oliver Gugger
34c2d77ec5
docs+scripts: switch to detached signatures
Due to a misunderstanding of how the gpg command line options work, we
didn't actually create detached signatures because the --clear-sign
flag would overwrite that. We update our verification script to now only
download the detached signatures and verify them against the main
manifest file.
We also update the signing instructions.
2021-02-15 13:16:51 -08:00
Oliver Gugger
cdea598a30
scripts: verify hash length
To make sure we've actually calculated the hash correctly, we make sure
it's 64 characters long.
2021-02-15 13:16:51 -08:00
Oliver Gugger
00dc248baa
scripts: use shasum instead of sha256sum
Because the sha256sum binary isn't available on MacOS we instead use the
shasum -a 256 command that was used before.
2021-02-15 13:16:51 -08:00
Oliver Gugger
547181d36f
config: clean and expand backup file path
Because the CleanAndExpandPath function wasn't applied to the backup
file path, any path that contained a tilde for the home directory didn't
work.
2021-02-15 13:16:10 -08:00
Oliver Gugger
7627c619a1
scripts: allow verification of custom binary
Instead of only allowing the installed versions of lnd and lncli to be
verified, we now also support specifying explicit paths to binaries that
we want to verify.
2021-02-15 13:15:56 -08:00
Conner Fromknecht
de8dbe2c74
Merge pull request #5014 from cfromknecht/v0.12.1-beta.rc3-branch-commits
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
v0.12.1-beta.rc3
2021-02-11 18:01:09 -08:00
Conner Fromknecht
4ca83c3bc1
build/version: bump to v0.12.1-beta.rc3 2021-02-11 16:35:18 -08:00
Conner Fromknecht
cb6e677400
github/workflows: pin exact docker release 2021-02-11 16:32:50 -08:00
Conner Fromknecht
ea2b0150c6
Merge pull request #5009 from cfromknecht/v0.12.1-beta.rc2-branch-commits
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
v0.12.1-beta.rc2
2021-02-11 12:57:02 -08:00
Conner Fromknecht
1e2190e86d
build/version: bump to v0.12.1-beta.rc2 2021-02-11 00:46:32 -08:00
Olaoluwa Osuntokun
b57ea5c1cd
lncfg: detect tor resolution error case and fallback to system resolver
In this commit, we fix a bug that would cause resolution of items in
/etc/hosts (or the like) to fail as Tor wouldn't recognize them as
proper host names. With this commit, we'll catch this error and fall
back to the system's resolver.
2021-02-11 00:36:58 -08:00
Olaoluwa Osuntokun
6bca1fbc30
lncfg: use net.ParseIP to detect IPv6 addresses 2021-02-11 00:36:58 -08:00
eugene
71ab07763d
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-11 00:36:57 -08:00
Wilmer Paulino
b38d8d84d9
discovery: use token bucket based rate limiting to throttle gossip
The recently added gossip throttling was shown to be too aggressive,
especially with our auto channel enable/disable signaling. We switch to
a token bucket based system instead as it's based on time, rather than a
block height which isn't constantly updated at a given rate.
2021-02-11 00:36:19 -08:00
Wilmer Paulino
4d0a8ed435
Revert "lncfg: add new legacy protocol option to turn off gossip throttling"
This reverts commit b1fbbcf562.
2021-02-11 00:36:18 -08:00
Wilmer Paulino
083a62a3b2
Revert "discovery: add new option to toggle gossip rate limiting"
This reverts commit 13a2598ded.
2021-02-11 00:36:18 -08:00
Wilmer Paulino
423082a4a4
Revert "lntest: always turn off gossip throttling for nodes created in itests"
This reverts commit 447c9f2c0b.
2021-02-11 00:36:18 -08:00
Johan T. Halseth
673cbc6d91
discovery/gossiper: add local updates to graph immediately
Since the batch interval can potentially be long, adding local updates
to the graph could be slow. This would slow down operations like adding
our own channel update and announcements during the funding process, and
updating edge policies for local channels.

Now we instead check whether the update is remote or not, and only for
remote updates use the SchedulerOption to lazily add them to the graph.
2021-02-11 00:35:52 -08:00
Johan T. Halseth
e35c97c214
routing: let graph methods take scheduler option 2021-02-11 00:35:52 -08:00
Johan T. Halseth
6dde42eee6
channeldb: add SchedulerOp arg to graph update methods 2021-02-11 00:35:52 -08:00
Johan T. Halseth
3a1e34b100
batch: add option for executing requests immediately
We make the default non-lazy, and will make the incoming gossip requests
lazy.
2021-02-11 00:35:52 -08:00
Conner Fromknecht
7b98483ebe
discovery: don't historical sync when NumActiveSyncers == 0
Currently when numgraphsyncpeers=0, lnd will still attempt to perform
an initial historical sync. We change this behavior here to forgoe
historical sync entirely when numgraphsyncpeers is zero, since the
routing table isn't being updated anyway while the node is active.

This permits a no-graph lnd mode where no syncing occurs at all.
2021-02-11 00:35:32 -08:00
carla
d75756b1d1
itest: add coverage for hold invoices with hop hints
This PR updates the hold invoice itest to create a private
channel, and sets the private option on the invoices created
to add coverage for the addition of hop hints.
2021-02-11 00:35:19 -08:00
Wilmer Paulino
1378b83f7a
discovery: use source of ann upon confirmed channel ann batch
We do this instead of using the source of the AnnounceSignatures
message, as we filter out the source when broadcasting any
announcements, leading to the remote node not receiving our channel
update. Note that this is done more for the sake of correctness and to
address a flake within the integration tests, as channel updates are
sent directly and reliably to channel counterparts.
2021-02-11 00:35:02 -08:00
Olaoluwa Osuntokun
1c5ff35260
Revert "Merge pull request #4895 from wpaulino/disallow-premature-chan-updates"
This reverts commit 6e6384114c, reversing
changes made to 98ea433271.
2021-02-11 00:35:02 -08:00
rockstardev
3de4af2348
fix: correct no-rest-tls parameter in error message 2021-02-11 00:33:48 -08:00
Oliver Gugger
b67c840b4c
make: clean mobile stubs before building release
To fix an issue where the vendor.tar.gz in a release build had a
different hash if the mobile RPC stubs were in the mobile/ folder, we
clean those out first.

The culprit was the `google.golang.org/grpc/test/bufconn` package which
is currently only used in the mobile RPC stubs and nowhere else.
Therefore the vendor/module.txt was different when vendoring with the
generated mobile RPC stubs being around.
2021-02-11 00:33:48 -08:00
Johan T. Halseth
d61ec5c2f7
docs: correct sign command 2021-02-11 00:26:53 -08:00
rockstardev
a3b83494ee Update README to add link to our repository with C# Lightning clients 2021-02-07 13:37:55 -06:00
rockstardev
ed9e64e810 Update README to fix link to LND 0.12.0 image on Docker Hub 2021-02-07 13:36:12 -06:00
rockstardev
d73673492f Disabling TLS check so that we can listen on all interfaces for btcpayserver-docker deployments 2021-02-06 19:27:21 -06:00
rockstardev
bb5edcd3c6 Removing .github folder from origin repo 2021-02-06 17:21:13 -06:00
rockstardev
de4509adc1 Update README for 0.12.0-beta 2021-02-06 17:15:02 -06:00
Conner Fromknecht
79c8ecc9d7
Merge pull request #4980 from cfromknecht/v0.12.1-beta.rc1-branch-commits
Some checks failed
Docker image build / main (push) Has been cancelled
Release build / Release build (push) Has been cancelled
v0.12.1-beta.rc1
2021-02-03 22:06:50 -08:00
Conner Fromknecht
964f2e7781
bulid: bump version to v0.12.1-beta.rc1 2021-02-03 20:33:59 -08:00
eugene
ad052ad7f0
htlcswitch: reestablish unit tests 2021-02-03 20:32:45 -08:00
eugene
1d3985d3af
channeldb+lnwallet: lastWasRevokeKey to store last sent rev/sig 2021-02-03 20:32:15 -08:00
Olaoluwa Osuntokun
e06f817b47
routing: add new TestPaymentAddrOnlyNoSplit test case
This test case ensures that we won't try to split payment if the dest
has the payment addr bit, but NOT the mpp optional/require bit.
2021-02-03 20:32:03 -08:00
Olaoluwa Osuntokun
732eabc8df
routing: allow custom dest feature bits in integratedRoutingContext.testPayment
This is a preparatory commit for a new test to ensure that if a node
only has the TLV and payment addr feature bits, we don't try to split a
payment.
2021-02-03 20:31:49 -08:00
Conner Fromknecht
bb1f738d1d
gen_protos_docker: make image build non-quiet
This allows users to see progress whenever the docker image is
[re]built, and (esp on non-linux hosts) track the size of the build
context being uploaded. Currently no output is displayed, so it's hard
to attribute the source of latency, e.g. network latency, building
layers, a large work directory, etc.
2021-02-03 20:31:37 -08:00
Olaoluwa Osuntokun
2cc8b16339
build: update CI builds to use go 1.15.7 2021-02-03 20:31:26 -08:00
Juan Pablo Civile
d6d6f5b1a3
routing: limit max parts if the invoice doesn't declare MPP support 2021-02-03 20:31:12 -08:00
Juan Pablo Civile
905e1cb009
routerrpc: limit max parts if the invoice doesn't declare MPP support 2021-02-03 20:30:59 -08:00
Conner Fromknecht
aeaf5c0ed2
lntest: fix linter errors 2021-02-03 20:30:49 -08:00
Conner Fromknecht
775b6e5f68
discovery/sync_manager: remove unneeded markGraphSyncing
AFAICT it's not possible to flip back from bein synced_to_chain, so we
remove the underlying call that could reflect this. The method is moved
into the test file since it's still used to test correctness of other
portions of the flow.
2021-02-03 20:30:36 -08:00
Conner Fromknecht
bbe090a538
lntest: call markGraphSynced from gossipSyncer
Rather than performing this call in the SyncManager, we give each
gossipSyncer the ability to mark the first sync completed. This permits
pinned syncers to contribute towards the rpc-level synced_to_graph
value, allowing the value to be true after the first pinned syncer or
regular syncer complets. Unlinke regular syncers, pinned syncers can
proceed in parallel possibly decreasing the waiting time if consumers
rely on this field before proceeding to load their application.
2021-02-03 20:30:25 -08:00
Conner Fromknecht
e6af248ed8
lntest/graph_top: test pinned syncers 2021-02-03 20:30:17 -08:00
Conner Fromknecht
f04074835d
lntest/graph_top: remove dependence on net.Alice/Bob 2021-02-03 20:30:09 -08:00
Conner Fromknecht
275055d4a0
config: expose gossip.pinned-syncers for conf
The pinned syncer set is exposed as a comma-separated list of pubkeys.
2021-02-03 20:29:56 -08:00
Conner Fromknecht
c8ce80a3f4
lnrpc: expose PINNED_SYNC for listpeers 2021-02-03 20:29:40 -08:00
Conner Fromknecht
505133310d
discovery: perform initial historical sync for pinned peers 2021-02-03 20:29:24 -08:00
Conner Fromknecht
4db594425b
discovery: add support for PinnedSyncers
A pinned syncer is an ActiveSyncer that is configured to always remain
active for the lifetime of the connection. Pinned syncers do not count
towards the total NumActiveSyncer count, which are rotated periodically.

This features allows nodes to more tightly synchronize their routing
tables by ensuring they are always receiving gossip from distinguished
subset of peers.
2021-02-03 20:29:11 -08:00
Conner Fromknecht
631e6b99f9
discovery/sync_manager: Pause/Resume HistoricalSyncTicker
This gives each initial historical syncer an equal amount of time before
being rotated, even if some fail.
2021-02-03 20:29:00 -08:00
Conner Fromknecht
816c3dd2a8
discovery/sync_manager: make setHistoricalSyncer closure 2021-02-03 20:28:46 -08:00
Conner Fromknecht
8259dac5fb
discovery/sync_manager: break out IsGraphSynced check 2021-02-03 20:28:35 -08:00
Conner Fromknecht
d67d02bde5
discovery: handle err for linter 2021-02-03 20:28:28 -08:00
Andras Banki-Horvath
14653865b2
invoices+rpc: add missing channel graph to the AddInvoiceConfig
The Graph which is referenced later in the AddInvoice call graph is
unset when adding a hodl invoice. This resulted in a crash.
2021-02-03 20:28:19 -08:00
eugene
ab6ad25a92
lntest/channels: introduce subpackage to deduplicate static structs 2021-02-03 20:28:01 -08:00
Umar Bolatov
f92ec41e74
Fix typo in restorechanbackup command description 2021-02-03 20:27:54 -08:00
Oliver Gugger
a4168b2e07
ci: check mobile compilation in same step as RPC
Because we now build a docker image for the RPC compilation, we can save
some execution minutes if we run the mobile RPC and code compilation check in the
same step of the CI workflow.
2021-02-03 20:27:48 -08:00
Oliver Gugger
f15f0f8126
make+lnrpc: compile mobile RPC with docker too
Now that we have a base docker image that has all our RPC compilation
dependencies installed, we can also run the mobile RPC compilation
there. This removes the need to install falafel and goimports on the
local machine.
2021-02-03 20:27:42 -08:00
Oliver Gugger
3ad5a90800
mobile: remove grpc-gateway import
Because we compile the REST code from the rest-annotations.yaml and no
longer import the annotations in the proto files, we don't need to
specify the custom import path anymore.
2021-02-03 20:27:35 -08:00
Oliver Gugger
0fb4e7c60c
multi: remove proto install script 2021-02-03 20:27:28 -08:00
Oliver Gugger
9048a92016
make+lnrpc: use docker to compile protos
This commit aims to make it easier for developers to compile our
protobuf definitions. They now only need to have docker installed
instead of a whole set of binaries and libraries all pinned to very
specific versions.
2021-02-03 20:27:21 -08:00
Johan T. Halseth
b23dce1bc8
monitoring: run go fmt 2021-02-03 20:27:15 -08:00
Johan T. Halseth
1108c63218
make: run goimports during make fmt 2021-02-03 20:27:09 -08:00
Johan T. Halseth
cfb2343121
make: exclude autogenerated files from go fmt 2021-02-03 20:27:03 -08:00
Joost Jager
dbddc0e841
lnrpc: add htlc attempt id 2021-02-03 20:26:45 -08:00
Oliver Gugger
22f35f40be
scripts: don't fail on missing public key
When verifying the release signatures, we don't want to fail if a
signer's signature is not available in the gpg key ring. Instead we just
don't want to count the signature for now and still succeed if there's
at least one other good sig with a known key.
2021-02-03 20:26:38 -08:00
Oliver Gugger
6c1abd4de9
GitHub: use vendored actions for steps with sensitive info
To avoid leaking any sensitive information like Docker Hub credentials
because of compromised actions repositories, we use our own, vendored
actions for all steps that potentially touch sensitive information.
2021-02-03 20:26:33 -08:00
Jake Sylvestre
be692522d7
docs: add mac clang-format instructions 2021-02-03 20:26:27 -08:00
Vlad Stan
6c661b65b6
docker: add an extra listener for localhost
Make sure the lncli command can be used inside of the container without
needing to specify the --rpcserver flag all the time. Issue: #4937
2021-02-03 20:26:20 -08:00
Johan T. Halseth
49ac6a15be
scripts: add halseth key to verify script 2021-02-03 20:26:13 -08:00
Johan T. Halseth
236c839ee7
netann: ignore unknown channel updat on startup
Since the funding manager might be in process of adding the edge to the
graph, we ignore the error.
2021-02-03 20:05:24 -08:00
rockstardev
dfc8b00332 Merge branch 'version/0.12.0-beta' 2021-01-31 23:58:00 -06:00
rockstardev
f40c6ec9dd Update readme for 0.12.0-beta.rc5 2021-01-31 16:38:56 -06:00
rockstardev
29b40b7c2e Merge branch 'version/0.12.0-beta.rc5'
# Conflicts:
#	README.md
#	config.go
#	docker-entrypoint.sh
#	docker-initunlocklnd.sh
#	go.mod
#	rpcserver.go
2021-01-31 16:36:59 -06:00
rockstardev
38376fce72 Adding environment variable to influence LND's rest host
(cherry picked from commit 39d25171ce)
(cherry picked from commit 7b6c31d223)
2021-01-31 16:32:19 -06:00
rockstardev
6ab9e9a778 Adding BtcPayServer related files and resources
(cherry picked from commit 14517a97ea)
(cherry picked from commit a185998bcf)
2021-01-31 16:32:14 -06:00
rockstardev
7b6c31d223 Adding environment variable to influence LND's rest host
(cherry picked from commit 39d25171ce)
2021-01-10 13:16:16 -06:00
rockstardev
a185998bcf Adding BtcPayServer related files and resources
(cherry picked from commit 14517a97ea)
2021-01-10 13:16:06 -06:00
rockstardev
0795375787 Updating readme for 0.11.0 2020-09-28 16:13:16 -05:00
rockstardev
72f916e5d7 Merge branch 'version/0.11.0-beta'
# Conflicts:
#	Makefile
#	channeldb/invoice_test.go
#	channeldb/meta_test.go
#	channeldb/payments.go
#	config.go
#	docker-entrypoint.sh
#	go.mod
#	go.sum
#	invoices/invoiceregistry_test.go
#	lnd.go
#	lnrpc/chainrpc/chainnotifier_server.go
#	lnrpc/routerrpc/router.pb.go
#	lnrpc/wtclientrpc/wtclient.go
#	lntest/itest/lnd_multi-hop-error-propagation.go
#	lntest/itest/lnd_multi-hop-payments.go
#	lntest/itest/lnd_test.go
#	lnwallet/btcwallet/btcwallet.go
#	log.go
#	rpcserver.go
#	watchtower/wtclient/client.go
2020-09-28 16:12:05 -05:00
Nicolas Dorier
59b57ebdc0
Update docker-entrypoint.sh 2020-09-14 12:56:54 +09:00
rockstardev
4a4374005b Adding BtcPayServer related files and resources 2020-08-30 01:54:38 -05:00
rockstardev
160aaf40d0 Adding net import that got removed 2020-08-30 01:20:06 -05:00
nicolas.dorier
df5e4eed8d Allow unsafe authentication on regtest 2020-08-30 01:20:05 -05:00
nicolas.dorier
67fabc30bb Do not assume setting options partially are unintentional 2020-08-30 01:20:04 -05:00
nicolas.dorier
477983cf64 Add --notls to disable TLS for REST endpoint 2020-08-30 01:19:46 -05:00
rockstardev
903a5ae4c5 Updating Readme to clarify purpose of repository 2020-06-09 00:01:20 -05:00
rockstardev
6574ea15ef Merge branch 'version/0.10.1-beta' 2020-06-08 23:48:34 -05:00
rockstardev
4a7514fba7 Merge branch 'version/0.9.2-beta' 2020-06-08 23:47:19 -05:00
rockstardev
9c0e948662 Merge branch 'version/0.8.2-beta' 2020-06-08 23:46:50 -05:00
rockstardev
ee7b9cefc1 Merge branch 'version/0.8.1-beta' 2020-06-08 23:46:35 -05:00
rockstardev
30efca1a0e Adding default LND tags to our docker container release 2020-06-08 23:16:33 -05:00
rockstardev
43f266655a Updating docker builder images 2020-06-08 23:16:19 -05:00
rockstardev
0a7bedc21e Adding net import that got removed 2020-06-08 23:16:14 -05:00
rockstardev
adc4b8e425 Fix typos in docker-entrypoint.sh
Thanks: https://github.com/btcpayserver/lnd/pull/2
2020-06-08 23:16:07 -05:00
rockstardev
da572ca2af Setting execute permission on .sh files 2020-06-08 23:16:01 -05:00
rockstardev
109da44f48 Adjusting Makefile for fresh version string 2020-06-08 23:15:53 -05:00
rockstardev
8ebc7f4c06 Adding BtcPayServer related files and resources 2020-06-08 23:15:15 -05:00
nicolas.dorier
0cf1a3f6b6 Allow unsafe authentication on regtest 2020-06-08 23:15:10 -05:00
nicolas.dorier
dcd6e32a05 Do not assume setting options partially are unintentional 2020-06-08 23:13:44 -05:00
nicolas.dorier
98ec34c523 Add --notls to disable TLS for REST endpoint 2020-06-08 23:13:37 -05:00
Olaoluwa Osuntokun
52bb3f3370
build: bump version to 0.10.1-beta 2020-06-03 11:18:49 -07:00
Olaoluwa Osuntokun
4f2221d56c
build: bump version to v0.10.1-beta.rc3 2020-05-28 15:56:19 -07:00
Olaoluwa Osuntokun
df2c832aa8 Merge branch 'v0.10.1-beta-4327' into v0.10.1-beta-rc3-branch 2020-05-28 15:50:46 -07:00
Joost Jager
bca3bb4d33 routing: don't treat bad features as an unexpected error
Previous behavior led to the payment loop being abandoned immediately,
resulting in a payment stuck in state in_flight.
2020-05-28 15:50:46 -07:00
Olaoluwa Osuntokun
018b55881e Merge branch 'v0.10.1-beta-4332' into v0.10.1-beta-rc3-branch 2020-05-28 15:50:26 -07:00
Conner Fromknecht
564217213c lnd: use Infof to format errors on channeldb open 2020-05-28 15:50:26 -07:00
Conner Fromknecht
745bf0a6c9 channeldb/db: lower-case ErrDryRunMigrationOk message 2020-05-28 15:50:26 -07:00
Olaoluwa Osuntokun
cb36cd9357 Merge branch 'v0.10.1-beta-4335' into v0.10.1-beta-rc3-branch 2020-05-28 15:50:01 -07:00
Joost Jager
6cd4cc47c1 rpcserver+routerrpc: remove payment limit 2020-05-28 15:48:09 -07:00
Olaoluwa Osuntokun
ac7bb1dec2 Merge branch 'v0.10.1-beta-4298' into v0.10.1-beta-rc3-branch 2020-05-27 16:04:16 -07:00
Conner Fromknecht
5cb7ca6bf4 invoices/invoiceregistry: properly synchronize backlog
This commit moves the db calls for retrieving add and settle backlogs
outide of the main event loop. All other db operations are performed
outside of the event loop and synchronized via the invoice registry's
mutex, which also synchronizes the order in which events submitted to be
processed.

This resolves various concurrency issues where notifications can be
missed of inconsistent reads against the databse. This is especially
important in this case because we are actually making two separate
database calls.
2020-05-27 16:04:16 -07:00
Conner Fromknecht
544e606e2c invoices: return error from SubscribeNotifications on shutdown 2020-05-27 16:04:16 -07:00
Conner Fromknecht
2edda573a5 channeldb/invoices: ignore error when no settles exist
This fixes a bug that would cause no backlog to be delivered at all.
2020-05-27 16:04:16 -07:00
Olaoluwa Osuntokun
ae6e84ddfd
build: bump version to v0.10.1-beta.rc2 2020-05-21 17:26:15 -07:00
Olaoluwa Osuntokun
d764cc8fbf Merge branch 'v0.10.1-beta-4302' into v0.10.1-beta-rc2-branch 2020-05-21 17:24:08 -07:00
Wilmer Paulino
c45b2387c2 btcwallet: add transaction outputs bounds check to FetchInputInfo
This prevents a panic when providing an incompatible output index for
the transaction.
2020-05-21 17:23:23 -07:00
Olaoluwa Osuntokun
e883304279
build: bump version to v0.10.1-beta.rc1 2020-05-18 19:28:34 -07:00
Olaoluwa Osuntokun
2c789d92d3 Merge branch 'v0.10.1-beta-4291' into v0.10.1-beta-rc1-branch 2020-05-18 19:26:35 -07:00
Wilmer Paulino
adbbde6f31 build: update to latest btcd and btcwallet versions
This update introduces backwards compatibility for btcd nodes running
versions prior to v0.20.1-beta.
2020-05-18 19:26:08 -07:00
Olaoluwa Osuntokun
580d478cd3 Merge branch 'v0.10.1-beta-4226' into v0.10.1-beta-rc1-branch 2020-05-18 19:25:27 -07:00
Roei Erez
e52982fd0b Ensure chain notifier is started before accessed.
The use case comes from the RPC layer that is ready before the
chain notifier which is used in the sub server.
2020-05-18 19:25:27 -07:00
Roei Erez
470537ec3a chainntnfs: use sync.Once to start notifiers. 2020-05-18 19:25:27 -07:00
Olaoluwa Osuntokun
d63198a792 Merge branch 'v0.10.1-beta-4277' into v0.10.1-beta-rc1-branch 2020-05-18 19:25:15 -07:00
Joost Jager
d914f55e2c lnwallet: return signer error 2020-05-18 19:25:15 -07:00
Olaoluwa Osuntokun
35c23a9d85 Merge branch 'v0.10.1-beta-4274' into v0.10.1-beta-rc1-branch 2020-05-18 19:24:53 -07:00
Wilmer Paulino
0c13b29a0e wtmock: prevent race conditions by not using ClientSession pointers
These race conditions originate from the mock database storing and
returning pointers, rather than returning a copy.

Observed on Travis:

WARNING: DATA RACE
Read at 0x00c0003222b8 by goroutine 149:
  github.com/lightningnetwork/lnd/watchtower/wtclient.(*sessionQueue).drainBackups()
      /home/runner/work/lnd/lnd/watchtower/wtclient/session_queue.go:288 +0xed
  github.com/lightningnetwork/lnd/watchtower/wtclient.(*sessionQueue).sessionManager()
      /home/runner/work/lnd/lnd/watchtower/wtclient/session_queue.go:281 +0x450

Previous write at 0x00c0003222b8 by goroutine 93:
  github.com/lightningnetwork/lnd/watchtower/wtclient.getClientSessions()
      /home/runner/work/lnd/lnd/watchtower/wtclient/client.go:365 +0x24f
  github.com/lightningnetwork/lnd/watchtower/wtclient.(*TowerClient).handleNewTower()
      /home/runner/work/lnd/lnd/watchtower/wtclient/client.go:1063 +0x23e
  github.com/lightningnetwork/lnd/watchtower/wtclient.(*TowerClient).backupDispatcher()
      /home/runner/work/lnd/lnd/watchtower/wtclient/client.go:784 +0x10b9
2020-05-18 19:24:52 -07:00
Wilmer Paulino
3afa4178ba wtclient: test case re-add removed tower 2020-05-18 19:24:52 -07:00
Wilmer Paulino
badbc5a491 rpc: use existing rpc logger for wtclientrpc
The logger string used to identify the wtclient and wtclientrpc loggers
was the same, leading to being unable to modify the log level of the
wtclient logger as it would be overwritten with the wtclientrpc's one.
To simplify things, we decide to use the existing RPC logger for
wtclientrpc.
2020-05-18 19:24:52 -07:00
Wilmer Paulino
1cbb574333 wtclient: filter out inactive sessions upon adding existing/new tower 2020-05-18 19:24:52 -07:00
Wilmer Paulino
2de2f28d23 wtclient: load missing info into client sessions upon new tower
This addresses a potential panic in where we relied on this missing info
being populated.
2020-05-18 19:24:52 -07:00
Wilmer Paulino
4a91472469 wtclient: refactor existing candidate session filtering into method 2020-05-18 19:24:52 -07:00
Olaoluwa Osuntokun
7daead6d85 Merge branch 'v0.10.1-beta-4257' into v0.10.1-beta-rc1-branch 2020-05-18 19:24:17 -07:00
Joost Jager
5e83ed9d89 routing+routerrpc: add multiple outgoing channel restriction 2020-05-18 19:23:12 -07:00
Joost Jager
389b715f15 routing/test: add channel id constants 2020-05-18 19:20:15 -07:00
Olaoluwa Osuntokun
eb445d5789 Merge branch 'v0.10.1-beta-2668' into v0.10.1-beta-rc1-branch 2020-05-18 19:19:34 -07:00
Conner Fromknecht
412d7f5c38 config: adds cli configurable --migration-dry-run 2020-05-18 19:18:25 -07:00
Conner Fromknecht
4b7e8669ac channeldb/db: adds optional dry-run abort for migrations 2020-05-18 19:17:08 -07:00
Olaoluwa Osuntokun
935c2f2c10 Merge branch 'v0.10.1-beta-4253' into v0.10.1-beta-rc1-branch 2020-05-18 19:16:41 -07:00
Olaoluwa Osuntokun
3c0b438f16 cmd/lncli: remove usage of Millisecond() for Go 1.12
The new table format for the pay command started to use the
`Millisecond()` method on `time.Duration`. However, this method was only
added in Go 1.13, so this breaks the build for Go 1.12. We replace this
by manual division. `time.Duration` "natively" is in nanoseconds, so we
covert to milli seconds by dividing my `time.Millisecond`, which is
1,000,000.
2020-05-18 19:16:41 -07:00
Olaoluwa Osuntokun
b38c529ba8 Merge branch 'v0.10.1-beta-4234' into v0.10.1-beta-rc1-branch 2020-05-18 19:16:13 -07:00
carla
3289b31b09 lntest/test: add htlc events test to multi-hop error propagation 2020-05-18 19:16:13 -07:00
carla
a80c69982d lntest/test: move multi-hop error propagation into its own file 2020-05-18 19:16:13 -07:00
carla
926892c906 lntest/test: test htlcnotifier stream for successful multi-hop payments 2020-05-18 19:16:13 -07:00
carla
d70f77efaf lntest/test: move multi-hop payments test into own file 2020-05-18 19:16:13 -07:00
carla
08da737316 lnrpc: add failure detail none to link event rpc 2020-05-18 19:16:13 -07:00
Olaoluwa Osuntokun
913c787082 Merge branch 'v0.10.1-beta-4241' into v0.10.1-beta-rc1-branch 2020-05-18 19:15:32 -07:00
Olaoluwa Osuntokun
f8b85eaf12 channeldb: eliminate extra copy in QueryPayments
In this commit, we eliminate an extraneous copy in the `QueryPayments`
method. Before this commit, we would copy each payment from the initial
FetchPayments call into a new slice. However, pointers to payments are
return from `FetchPayments`, so we can just maintain that same reference
rather than copying again when we want to limit our response.
2020-05-18 19:15:32 -07:00
Olaoluwa Osuntokun
4384978728 Merge branch 'v0.10.1-beta-4176' into v0.10.1-beta-rc1-branch 2020-05-18 19:14:56 -07:00
Wilmer Paulino
97e5763601 rpcserver: omit uptime in ListChannels response if server not started
If the server hasn't fully started yet, it's possible that the channel
event store hasn't either, so it won't be able to consume any requests
until then. To prevent blocking, we'll just omit the uptime related
fields for now.
2020-05-18 19:14:56 -07:00
Wilmer Paulino
08f25bb5bf rpcserver: include upfront shutdown script in ListChannels response
This field could be omitted from the response if we were unable to
calculate the channel's uptime.
2020-05-18 19:14:56 -07:00
rockstardev
5cfd1603da Adding default LND tags to our docker container release 2020-05-13 17:45:38 -05:00
rockstardev
b4c54919e9 Updating docker builder images 2020-04-24 17:46:16 -05:00
rockstardev
62e49ec081 Adding net import that got removed 2020-04-24 17:45:46 -05:00
rockstardev
840abbbdd2 Fix typos in docker-entrypoint.sh
Thanks: https://github.com/btcpayserver/lnd/pull/2
2020-04-24 17:08:08 -05:00
rockstardev
967b0662ce Setting execute permission on .sh files 2020-04-24 17:08:02 -05:00
rockstardev
afb350e553 Adjusting Makefile for fresh version string 2020-04-24 17:07:55 -05:00
rockstardev
83994bef9c Adding BtcPayServer related files and resources 2020-04-24 17:07:49 -05:00
nicolas.dorier
7324f343b9 Allow unsafe authentication on regtest 2020-04-24 17:07:42 -05:00
nicolas.dorier
7c275b2b25 Do not assume setting options partially are unintentional 2020-04-24 17:07:36 -05:00
nicolas.dorier
f05de358c7 Add --notls to disable TLS for REST endpoint 2020-04-24 17:07:29 -05:00
Olaoluwa Osuntokun
ab87dc5fe2
build: bump version to v0.9.2-beta 2020-03-12 17:02:03 -07:00
Olaoluwa Osuntokun
9f47bbc552
build: update to x/crypto version w/o broken poly1305 arm assembly
In this commit, we update to a new version of `x/crypto` that drops
broken ARM assembly that can cause a segfault in systems like raspis.
The broken assembly was removed in this commit to the runtime:
8b774103d3.

Fixes #4052.
2020-03-12 17:01:57 -07:00
Olaoluwa Osuntokun
8aead58288
build: update to version v0.9.1-beta 2020-02-28 18:06:29 -03:00
Olaoluwa Osuntokun
a7cf1b4ff5 build: bump version to v0.9.1-beta.rc1
We also add '.' to the semantic versioning alphabet to ensure it isn't
stripped out.
2020-02-20 19:24:25 -08:00
Olaoluwa Osuntokun
e78d2a061b Merge branch 'v0.9.1-beta-3932' into v0.9.1-beta-rc1-branch 2020-02-20 18:59:05 -08:00
Johan T. Halseth
1fa21e6bcd lnd: reload cert data after renewal
After renewing the certificate, the new certificate wasn't actually
loaded and used, causing the old one to be used until lnd was restarted.
This fixes that by reloading it after it has been written.
2020-02-20 18:59:04 -08:00
Johan T. Halseth
d7f6a39704 lnd+cert: recreate TLS files if IPs or DNS changed
This commit makes lnd recreate its TLS certificate if the config's
tlsextradomains or tlsextraips changed. This is useful, since earlier
user would have to manually delete the files to trigger lnd to recreate
them.

To ensure users don't accidentally have their TLS certificate recreated,
we gate it behind a flag --tlsautorefresh that defaults to false.
2020-02-20 18:59:04 -08:00
Johan T. Halseth
2c8a18fe6f cert+test: IsOutdated check for TLS files if IPs or DNS changed
This commit creates a new utility method IsOutdated that can be used to
check whether a TLS certificate mathces the extra IPs and domains given
in the lnd config.
2020-02-20 18:59:04 -08:00
Johan T. Halseth
51aba35512 cert: extract IP and DNS parsing into methods 2020-02-20 18:59:04 -08:00
Olaoluwa Osuntokun
362d53e5bb Merge branch 'v0.9.1-beta-3691' into v0.9.1-beta-rc1-branch 2020-02-20 18:58:45 -08:00
Johan T. Halseth
15099045fc lnwallet/channel: add TODO 2020-02-20 18:58:45 -08:00
Johan T. Halseth
8db2465638 lnwallet/channel: take remote commitment view into availableBalance calculation
Since our HTLC must also be added to the remote commitment, we do the
balance caluclation also from the remote chain perspective and report
our minimum balance from the two commit views as our available balance.
2020-02-20 18:58:45 -08:00
Johan T. Halseth
c30831dd0d lnwallet: take remote initiator's balance into account
When we send non-dust HTLCs as the non-initiator, the remote party will
have to pay the extra commitment fee. To account for this we figure out
if they can afford paying this fee, if not we report that we only have
balance available for dust HTLCs, since these HTLCs won't increase the
commitment fee.
2020-02-20 18:58:45 -08:00
Johan T. Halseth
e3da653f33 lnwallet/channel: account for HTLC fee when reporting available balance 2020-02-20 18:58:45 -08:00
Johan T. Halseth
7628eb2b76 link+lnwallet: move bandwidth channel reserve validation into channel
Since we want to handle the edge case where paying the HTLC fee would
take the initiator below the reserve, we move the subtraction of the
reserve into availableBalance where this calculation will be performed.
2020-02-20 18:58:45 -08:00
Johan T. Halseth
2f0c01c992 lnwallet/channel: break up availableBalance 2020-02-20 18:58:45 -08:00
Johan T. Halseth
60d843f32d lnwallet: check local commitment sanity when adding HTLC
This commit adds an extra validation step when adding HTLCs. Previously
we would only validate the remote commitment resulting from adding an
HTLC, which in most cases is enough. However, there are situations where
the dustlimits are different, which could lead to the resulting remote
commitment from adding the HTLC being valid, but not the local
commitment.

Now we also validate the local commitment. A test to trigger the case is
added.
2020-02-20 18:58:45 -08:00
Johan T. Halseth
9373f92940 lnwallet tests: add test for dipping remote below chan reserve
This commit adds a test that was previously not performed, namely that
adding a HTLC would dip the remote initiator below its channel reserve.
2020-02-20 18:58:44 -08:00
Johan T. Halseth
e5c39a6569 lnwallet/channel: make validateCommitmentSanity take our/their predict
add

To ba able to validate the commitment sanity both for remote and local
commitments, and at the same time predict both our and their add, we let
validateCommitmentSanity take an extra payment descriptor to make this
possible.
2020-02-20 18:58:44 -08:00
Olaoluwa Osuntokun
74eeff5370 Merge branch 'v0.9.1-beta-3910' into v0.9.1-beta-rc1-branch 2020-02-20 18:58:15 -08:00
nsa
28aece1220 lnwallet: adding TestMaxAsynchronousHtlcs unit test
Adds a new test which asserts that the new ReceiveHTLC logic can
handle proper commitment overflow calculation in the face of
asynchronous updates.
2020-02-20 18:58:15 -08:00
nsa
46c5293ff4 lnwallet: fixing unit tests to properly handle new receive validation
This commit fixes the TestMaxAcceptedHTLCs, TestMaxPendingAmount,
TestMinHTLC, & TestChanReserve unit tests to pass with the new
ReceiveHTLC logic. Instead of asserting specific failures upon
receiving a new commitment signature, the various assertions were
moved to assert on the error returned from ReceiveHTLC.
2020-02-20 18:58:15 -08:00
nsa
22b8402322 lnwallet: call valdiateCommitmentSanity in ReceiveHTLC
This commit checks the commitment sanity when receiving an HTLC so
that if a commitment transaction will overflow from an ADD, it is
caught earlier rather than in ReceiveNewCommitment.
2020-02-20 18:58:15 -08:00
Olaoluwa Osuntokun
ab2324c652 Merge branch 'v0.9.1-beta-3998' into v0.9.1-beta-rc1-branch 2020-02-20 18:57:38 -08:00
Johan T. Halseth
2908984b16 lnwallet: state transition from correct node during test, remove panic
The unit test TestNewBreachRetributionSkipsDustHtlcs triggered a state
transition from Bob, even though it was Alice that had added the HTLCs.
This is wrong since it will lead to Bob still owing Alice a commitment,
which is not accounted for in the unit tests.

We add a sanity check that the add heights has been set for all entries
found in the logs, and return an error otherwise. This won't happen
during normal operation, but it does reveal the mistake in the unit
test, which is fixed by making Alice trigger the transition.

In addition we resolve a long standing TODO by removing a (purposeful)
panic in the channel state machine. Old version of lnd had a bug that
could lead to the parent entries being lost during channel restore. A
panic was added to get to the bottom of if.

This is now fixed, so new nodes shouldn't encounter it. However, to be
on the safe side, instead of panicking we return an error back to
gracefully exit the channel state machine.
2020-02-20 18:57:37 -08:00
Johan T. Halseth
857d26eb71 lnwallet: unify remote and local update log fetch 2020-02-20 18:57:37 -08:00
Olaoluwa Osuntokun
e3e93ab0e6 Merge branch 'v0.9.1-beta-3876' into v0.9.1-beta-rc1-branch 2020-02-20 18:56:01 -08:00
Roei Erez
6152625c53 contractcourt+switch: keep channels with timed-out initiated htlcs.
This commit enables the user to specify he is not interested in
automatically close channels with pending payments that their
corresponding htlcs have timed-out.
By requiring a configurable grace period uptime of our node
before closing such channels, we give a chance to the other node to
properly cancel the htlc and avoid unnecessary on-chain transaction.
In mobile it is very important for the user experience as otherwise
channels will be force closed more frequently.
2020-02-20 18:56:01 -08:00
Roei Erez
f24db730e4 contractcourt: change shouldGoOnChain signature.
This commit changes the shouldGoOnChain signature to get the htlc
as parameter. I will allow the function to take decisions based on
whether the htlc is Incoming or Outgoing.
2020-02-20 18:56:01 -08:00
Olaoluwa Osuntokun
66210aa722 Merge branch 'v0.9.1-beta-3965' into v0.9.1-beta-rc1-branch 2020-02-20 18:54:43 -08:00
Oliver Gugger
8fb33dc5bf rpcserver: instruct REST marshaler to emit default values
This change instructs the REST proxy server to overwrite its default
JSON marshaler settings. That allows us to set EmitDefaults to true
which will result in all JSON fields returned in REST responses to
be fully populated, even if their values are falsey.
2020-02-20 18:54:43 -08:00
Olaoluwa Osuntokun
fbcf388a56 Merge branch 'v0.9.1-beta-3980' into v0.9.1-beta-rc1-branch 2020-02-20 18:54:04 -08:00
Joost Jager
b0c6c1c39c invoices: fix htlc timer deadlock 2020-02-20 18:54:04 -08:00
Joost Jager
44495fdefb invoices: move log into update context 2020-02-20 18:54:04 -08:00
Joost Jager
eea67b00cb invoices: add hash to update context 2020-02-20 18:54:04 -08:00
Olaoluwa Osuntokun
b269185cf0 Merge branch 'v0.9.1-beta-3950' into v0.9.1-beta-rc1-branch 2020-02-20 18:53:34 -08:00
Andras Banki-Horvath
8437f127f0 invoices: fix slow startup with many expired invoices
This commit intends to fix slow first startup time when there are many
invoices that need to be canceled. The slowdown is caused by a combination
of adding invoices to the expiry watcher one-by-one and slow
cancellation. Due to slow cancellation and the unbuffered channel which
we use to pass invoices to the expiry watcher blocks the registry.
With this fix we'll instead batch add invoices to the expiry watcher and
thereby won't block the registry startup.
2020-02-20 18:53:33 -08:00
Olaoluwa Osuntokun
f102a00a04 Merge branch 'v0.9.1-beta-3925' into v0.9.1-beta-rc1-branch 2020-02-20 18:52:54 -08:00
Wilmer Paulino
1d8da3123e discovery: check ChainHash in QueryChannelRange messages
If the provided ChainHash in a QueryChannelRange message does not match
that of our current chain, then we should send a blank response, rather
than reply with channels for the wrong chain.
2020-02-20 18:52:54 -08:00
Olaoluwa Osuntokun
4ac37c9f34 Merge branch 'v0.9.1-beta-3992' into v0.9.1-beta-rc1-branch 2020-02-20 18:52:36 -08:00
Joost Jager
156f683e87 lnwallet: fix invalid value use in restoreUpdate
Updates were always restored with the same log index. This could cause a
crash when the logs were compacted and possibly other problems
elsewhere.

Extended unit test to cover the crash scenario.
2020-02-20 18:52:36 -08:00
Olaoluwa Osuntokun
ba822bb7cc Merge branch 'v0.9.1-beta-3872' into v0.9.1-beta-rc1-branch 2020-02-20 18:51:53 -08:00
Joost Jager
666da0d10c lnwallet: restore unsigned acked remote updates
This commit updates the channel state machine to
persistently store remote updates that we have received a
signature for, but that we haven't yet included in a commit
signature of our own.

Previously those updates were only stored in memory and
dropped across restarts. This lead to the production of
an invalid signature and channel force closure. The remote
party expects us to include those updates.
2020-02-20 18:51:52 -08:00
Joost Jager
38445efce7 lnwallet: extract pending local updates restore method
Extract method in preparation for restoring dangling remote updates. We
need to get rid of the early return.
2020-02-20 18:51:52 -08:00
Joost Jager
9da8ad6aa7 channeldb: extract log update serialization
Extract functionality to methods as a preparation for serializing remote
log updates.
2020-02-20 18:51:52 -08:00
Joost Jager
a1b6edef87 channeldb: update UpdateCommitment description
This method is only used to update the local commitment transaction.
Updated comment accordingly.
2020-02-20 18:51:52 -08:00
Joost Jager
716c87fc4e lnwallet/test: test remote update after restart
This test asserts that remote updates that are locked-in on the local
commitment, but haven't been signed for on the remote commitment, are
properly restored after a restart.
2020-02-20 18:51:52 -08:00
Joost Jager
f8b1c8162c lnwallet/test: describe existing bug after restart with dangling remote updates 2020-02-20 18:51:52 -08:00
Joost Jager
1f477f443b lnwallet: restore missing field in local log update
When restoring an htlc fulfill update from disk, the payment hash wasn't
restored previously.
2020-02-20 18:51:52 -08:00
Olaoluwa Osuntokun
25b3d78cb5 Merge branch 'v0.9.1-beta-4017' into v0.9.1-beta-rc1-branch 2020-02-20 18:49:12 -08:00
Olaoluwa Osuntokun
d0d542c477 build: update to latest btcwallet version with rescan addr fix
In this commit, we update to the latest `btcwallet` version that
includes a fix for how we perform rescans. Before this commit, the
wallet would load ALL the created keys into the wallet to perform a
rescan. This is unnecessary, as many of the keys we create are actually
used in contracts, so the wallet can't spend them directly anyway.

For neutrino nodes, this would've caused them to attempt o match more
items in the filter than necessary, possibly resulting in an increased
number of false positive block fetches.
2020-02-20 18:48:36 -08:00
rockstardev
84c25f83bd Setting execute permission on .sh files 2020-01-14 15:25:38 -06:00
rockstardev
2fbbcd2e1d Adjusting Makefile for fresh version string 2020-01-14 15:25:32 -06:00
rockstardev
2e98e45a6e Adding BtcPayServer related files and resources 2020-01-14 15:25:26 -06:00
nicolas.dorier
84200f9299 Allow unsafe authentication on regtest 2020-01-14 15:25:21 -06:00
nicolas.dorier
dc2ef53b82 Do not assume setting options partially are unintentional 2020-01-14 15:25:14 -06:00
nicolas.dorier
4ba6cd647d Add --notls to disable TLS for REST endpoint 2020-01-14 15:25:07 -06:00
Olaoluwa Osuntokun
9cd40c5950
build: bump version to v0.8.2 2019-12-11 16:55:34 -08:00
Olaoluwa Osuntokun
0bc44ec5aa Merge branch 'v0.8.2-beta-3804' into v0.8.2-beta-rc2-branch 2019-12-06 16:10:35 -08:00
Olaoluwa Osuntokun
7ab4667114 Revert "funding: ensure the chan policy max htlc size is below max pay size"
This reverts commit 9b3385e87d.
2019-12-06 16:10:35 -08:00
Olaoluwa Osuntokun
dbb1f3b873 Revert "peer: clamp a link's max HTLC forwarding policy to current max HTLC pay size"
This reverts commit c943d85019.
2019-12-06 16:10:35 -08:00
Olaoluwa Osuntokun
87851c2cdf Merge branch 'v0.8.2-beta-3752' into v0.8.2-beta-rc1-branch 2019-12-04 19:40:58 -08:00
Johan T. Halseth
da737764d0 chainntnfs/txnotifier: promote historical spend log to info
And add some more details.
2019-12-04 19:40:57 -08:00
Johan T. Halseth
8d54778c16 chainntnfs/txnotifier: add more debug logs aroung spend dispatch
To track down missing spends.
2019-12-04 19:40:57 -08:00
Johan T. Halseth
ab9ac096ea chainntnfs/bitcoind: log finished hitsorical spend dispatch 2019-12-04 19:40:57 -08:00
Johan T. Halseth
0bcc2bb52f chainntnfs/interface: add String method for SpendDetaill 2019-12-04 19:40:57 -08:00
Johan T. Halseth
afeb6eea65 chainntnfs/txnotifier: include script in SpendRequest string representation 2019-12-04 19:40:57 -08:00
Olaoluwa Osuntokun
594c832180 Merge branch 'v0.8.2-beta-3790' into v0.8.2-beta-rc1-branch 2019-12-04 19:40:10 -08:00
Olaoluwa Osuntokun
d7fd142d1f funding: ensure the chan policy max htlc size is below max pay size 2019-12-04 19:40:09 -08:00
Olaoluwa Osuntokun
0df8cf866d peer: clamp a link's max HTLC forwarding policy to current max HTLC pay size
In this commit, we start to clamp the max HTLC forwarding policy to the
current register max HTLC payment size. By doing this, we ensure that
any links that have a advertised max HTLC transit size above the max
payment size will reject any incoming or outgoing attempts for such
large payments.
2019-12-04 19:40:09 -08:00
Olaoluwa Osuntokun
1fab42a7e2 lnrpc/routerrpc: make SendToRoute consistent with other payment RPCs
In this commitment, we make the `SendToRoute` RPC call consistent with
all the other payment RPCs which will properly adhere to the current max
payment sat limit. This is a prep commit for the future wumbo soft cap
that will eventually land in lnd.
2019-12-04 19:40:09 -08:00
Olaoluwa Osuntokun
6a6ba4efd7 htlcswitch: fix inconsistency between attribute name and godoc comment 2019-12-04 19:40:09 -08:00
Olaoluwa Osuntokun
bb6e3d92e9 cmd/lncli: exit if user opts to not recover SCB files 2019-12-04 19:39:31 -08:00
Olaoluwa Osuntokun
6893931fbf Merge branch 'v0.8.2-beta-3719' into v0.8.2-beta-rc1-branch 2019-12-04 19:38:45 -08:00
Oliver Gugger
6530b499fc lntest: add unconfirmed channel SCB test 2019-12-04 19:38:45 -08:00
Oliver Gugger
9b65a90f3f chanbackup: set funding broadcast height on restore 2019-12-04 19:38:45 -08:00
Oliver Gugger
b3599b0354 chanbackup: encode broadcast height in chan ID for unconfirmed channels 2019-12-04 19:38:45 -08:00
Olaoluwa Osuntokun
f345297009 Merge branch 'v0.8.2-beta-3737' into v0.8.2-beta-rc1-branch 2019-12-04 19:36:37 -08:00
Oliver Gugger
8ebf765924 lntest: add SCB repeated restore test 2019-12-04 19:36:37 -08:00
Oliver Gugger
b8bda0d934 chanbackup: continue recovery if channel already exists 2019-12-04 19:36:37 -08:00
Olaoluwa Osuntokun
f5aae3c06c Merge branch 'v0.8.2-beta-3698' into v0.8.2-beta-rc1-branch 2019-12-04 19:34:18 -08:00
Andreas M. Antonopoulos
dae5f614fc Warn user before doing SCB restore
SCB restore closes all open channels. We need to warn users that this is what will happen if they try to do an SCB restore.
2019-12-04 19:34:18 -08:00
rockstardev
052358f9c8 Setting execute permission on .sh files 2019-11-21 23:48:53 -06:00
rockstardev
08ad05bca0 Adjusting Makefile for fresh version string 2019-11-21 23:28:39 -06:00
rockstardev
a6b5798acd Adding BtcPayServer related files and resources 2019-11-21 23:28:29 -06:00
nicolas.dorier
8aedb15382 Allow unsafe authentication on regtest 2019-11-21 23:27:43 -06:00
nicolas.dorier
127dabcc02 Do not assume setting options partially are unintentional 2019-11-21 23:24:15 -06:00
nicolas.dorier
f0d13cbb8e Add --notls to disable TLS for REST endpoint 2019-11-21 23:23:52 -06:00
Wilmer Paulino
0bff2ed554 lnwallet: fix test inconsistencies to support bitcoind 0.19.0
bitcoind's sendrawtransaction API in v0.19.0 now enforces a maximum fee
rate of 0.1 BTC/kb and valid output scripts.
2019-11-14 16:32:14 -08:00
Wilmer Paulino
2b1effdf99 build: bump btcsuite and neutrino dependencies to latest tagged versions
The btcwallet update includes some edge-case wallet bug fixes and an
optimization on ZMQ connections for bitcoind backends.

The btcd update allows for compatibility with bitcoind v0.19.0 backends.
2019-11-14 16:31:56 -08:00
332 changed files with 32575 additions and 9980 deletions

View File

@ -21,7 +21,7 @@ defaults:
shell: bash
env:
BITCOIN_VERSION: "27"
BITCOIN_VERSION: "28"
TRANCHES: 8
@ -31,7 +31,7 @@ env:
# /dev.Dockerfile
# /make/builder.Dockerfile
# /.github/workflows/release.yml
GO_VERSION: 1.22.5
GO_VERSION: 1.22.6
jobs:
########################

View File

@ -11,12 +11,11 @@ defaults:
env:
# If you change this value, please change it in the following files as well:
# /.travis.yml
# /Dockerfile
# /dev.Dockerfile
# /make/builder.Dockerfile
# /.github/workflows/main.yml
GO_VERSION: 1.22.5
GO_VERSION: 1.22.6
jobs:
main:

1
.gitignore vendored
View File

@ -66,6 +66,7 @@ profile.tmp
.DS_Store
.vscode
*.code-workspace
# Coverage test
coverage.txt

View File

@ -1,18 +1,8 @@
run:
# timeout for analysis
deadline: 10m
go: "1.22.6"
# Skip autogenerated files for mobile and gRPC as well as copied code for
# internal use.
skip-files:
- "mobile\\/.*generated\\.go"
- "\\.pb\\.go$"
- "\\.pb\\.gw\\.go$"
- "internal\\/musig2v040"
skip-dirs:
- channeldb/migration_01_to_11
- channeldb/migration/lnwire21
# Abort after 10 minutes.
timeout: 10m
build-tags:
- autopilotrpc
@ -57,7 +47,6 @@ linters-settings:
- G306 # Poor file permissions used when writing to a new file.
staticcheck:
go: "1.22.5"
checks: ["-SA1019"]
lll:
@ -133,25 +122,15 @@ linters:
- gochecknoinits
# Deprecated linters. See https://golangci-lint.run/usage/linters/.
- interfacer
- golint
- maligned
- scopelint
- exhaustivestruct
- bodyclose
- contextcheck
- nilerr
- noctx
- rowserrcheck
- sqlclosecheck
- structcheck
- tparallel
- unparam
- wastedassign
- ifshort
- varcheck
- deadcode
- nosnakecase
# Disable gofumpt as it has weird behavior regarding formatting multiple
@ -191,7 +170,7 @@ linters:
- wrapcheck
# Allow dynamic errors.
- goerr113
- err113
# We use ErrXXX instead.
- errname
@ -207,15 +186,41 @@ linters:
# The linter is too aggressive and doesn't add much value since reviewers
# will also catch magic numbers that make sense to extract.
- gomnd
- mnd
# Some of the tests cannot be parallelized. On the other hand, we don't
# gain much performance with this check so we disable it for now until
# unit tests become our CI bottleneck.
# Some of the tests cannot be parallelized. On the other hand, we don't
# gain much performance with this check so we disable it for now until
# unit tests become our CI bottleneck.
- paralleltest
# New linters that we haven't had time to address yet.
- testifylint
- perfsprint
- inamedparam
- copyloopvar
- tagalign
- protogetter
- revive
- depguard
- gosmopolitan
- intrange
issues:
# Only show newly introduced problems.
new-from-rev: 8c66353e4c02329abdacb5a8df29998035ec2e24
new-from-rev: 77c7f776d5cbf9e147edc81d65ae5ba177a684e5
# Skip autogenerated files for mobile and gRPC as well as copied code for
# internal use.
skip-files:
- "mobile\\/.*generated\\.go"
- "\\.pb\\.go$"
- "\\.pb\\.gw\\.go$"
- "internal\\/musig2v040"
skip-dirs:
- channeldb/migration_01_to_11
- channeldb/migration/lnwire21
exclude-rules:
# Exclude gosec from running for tests so that tests with weak randomness
@ -256,8 +261,8 @@ issues:
- forbidigo
- godot
# Allow fmt.Printf() in lncli.
- path: cmd/lncli/*
# Allow fmt.Printf() in commands.
- path: cmd/commands/*
linters:
- forbidigo

View File

@ -3,7 +3,7 @@
# /make/builder.Dockerfile
# /.github/workflows/main.yml
# /.github/workflows/release.yml
FROM golang:1.22.5-alpine as builder
FROM golang:1.22.6-alpine as builder
# Force Go to use the cgo based DNS resolver. This is required to ensure DNS
# queries required to connect to linked containers succeed.

View File

@ -43,7 +43,7 @@ endif
# GO_VERSION is the Go version used for the release build, docker files, and
# GitHub Actions. This is the reference version for the project. All other Go
# versions are checked against this version.
GO_VERSION = 1.22.5
GO_VERSION = 1.22.6
GOBUILD := $(LOOPVARFIX) go build -v
GOINSTALL := $(LOOPVARFIX) go install -v

153
README.md
View File

@ -1,98 +1,89 @@
## Lightning Network Daemon
# BTCPayServer LND
[![Release build](https://github.com/lightningnetwork/lnd/actions/workflows/release.yaml/badge.svg)](https://github.com/lightningnetwork/lnd/actions/workflows/release.yaml)
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/lightningnetwork/lnd/blob/master/LICENSE)
[![Irc](https://img.shields.io/badge/chat-on%20libera-brightgreen.svg)](https://web.libera.chat/#lnd)
[![Godoc](https://godoc.org/github.com/lightningnetwork/lnd?status.svg)](https://godoc.org/github.com/lightningnetwork/lnd)
[![Go Report Card](https://goreportcard.com/badge/github.com/lightningnetwork/lnd)](https://goreportcard.com/report/github.com/lightningnetwork/lnd)
This repository is used to build LND Docker container images that are distributed with BTCPayServer by default.
<img src="logo.png">
Docker images are published to https://hub.docker.com/r/btcpayserver/lnd/
The Lightning Network Daemon (`lnd`) - is a complete implementation of a
[Lightning Network](https://lightning.network) node. `lnd` has several pluggable back-end
chain services including [`btcd`](https://github.com/btcsuite/btcd) (a
full-node), [`bitcoind`](https://github.com/bitcoin/bitcoin), and
[`neutrino`](https://github.com/lightninglabs/neutrino) (a new experimental light client). The project's codebase uses the
[btcsuite](https://github.com/btcsuite/) set of Bitcoin libraries, and also
exports a large set of isolated re-usable Lightning Network related libraries
within it. In the current state `lnd` is capable of:
* Creating channels.
* Closing channels.
* Completely managing all channel states (including the exceptional ones!).
* Maintaining a fully authenticated+validated channel graph.
* Performing path finding within the network, passively forwarding incoming payments.
* Sending outgoing [onion-encrypted payments](https://github.com/lightningnetwork/lightning-onion)
through the network.
* Updating advertised fee schedules.
* Automatic channel management ([`autopilot`](https://github.com/lightningnetwork/lnd/tree/master/autopilot)).
Versions:
- [0.18.3-beta](https://hub.docker.com/layers/btcpayserver/lnd/v0.18.3-beta/images/sha256-513ddd55a5af44a14e27110ee14cb28f1c7a69205bcaa2fba4e66275c1f725e5?context=repo)
- Includes 0.28.7-beta Loop
- [Fix for lnd unlock password \n problem](https://github.com/btcpayserver/lnd/pull/7)
- [0.18.1-beta](https://hub.docker.com/layers/btcpayserver/lnd/v0.18.1-beta/images/sha256-5fbfa76a218ab59bf9206485f4c0c071a525f9f0906255a5672054741d043b79?context=repo)
- Includes 0.28.5-beta Loop
- [0.18.0-beta](https://hub.docker.com/layers/btcpayserver/lnd/v0.18.0-beta/images/sha256-e6043dddf0bdbd5c740e882447c441b37f87f2c736ebb08747a4aff5e100d9bf?context=repo)
- Includes 0.28.2-beta Loop
- [0.17.4-beta](https://hub.docker.com/layers/btcpayserver/lnd/v0.17.4-beta/images/sha256-b62ecff5ca71d37f9b4846f35b4d86ddc4faa3fc1dd0618ae9221d99f47708bd?context=explore)
- Includes 0.26.6-beta Loop
- [0.17.3-beta](https://hub.docker.com/layers/btcpayserver/lnd/v0.17.3-beta/images/sha256-141611de6c062835e9513dd1ec4155c779d7a7b55258eb1fe06e228b0835fa56?context=repo)
- Includes 0.26.6-beta Loop
- [0.17.2-beta](https://hub.docker.com/layers/btcpayserver/lnd/v0.17.2-beta/images/sha256-936767369b703a67daf6db6a008a3b53c15f407d29a7ad2327a0de28f5951b30?context=explore)
- Includes 0.26.5-beta Loop
- [0.17.1-beta](https://hub.docker.com/layers/btcpayserver/lnd/v0.17.1-beta/images/sha256-b5c106136bd33a422463c736a1db8bd3541f95ac6f277dae86ab2a01b0c3445a?context=explore)
- Includes 0.26.5-beta Loop
- [0.17.0-beta](https://hub.docker.com/layers/btcpayserver/lnd/v0.17.0-beta/images/sha256-58b98f983cd786bcb4d48ea8586144cafd44d58dc3018e26bfbfcf875f495368?context=explore)
- Includes 0.26.4-beta Loop
- [0.17.0-beta](https://hub.docker.com/layers/btcpayserver/lnd/v0.17.0-beta/images/sha256-58b98f983cd786bcb4d48ea8586144cafd44d58dc3018e26bfbfcf875f495368?context=explore)
- Includes 0.26.4-beta Loop
- [0.16.4-beta-1](https://hub.docker.com/layers/btcpayserver/lnd/v0.16.4-beta-1/images/sha256-9dd204b62d6c892485b3dd8a76e8f48545ceda5702c9d47329ba4bcbc535a8b4?context=explore)
- [0.16.3-beta](https://hub.docker.com/layers/btcpayserver/lnd/v0.16.3-beta/images/sha256-9ff34769378cfca18664c7d1da3747e7ad7fb7f38a9a7b82a3d4f85e5bfef7bf?context=explore)
- [0.16.2-beta-1](https://hub.docker.com/layers/btcpayserver/lnd/v0.16.2-beta-1/images/sha256-bfff9de84a0a4af9d643ff555125358861b70374976b970cc00d1e7fc44ed520?context=explore)
- [0.16.1-beta](https://hub.docker.com/layers/btcpayserver/lnd/v0.16.0-beta/images/sha256-f0eb70c20691aaa2ffc34fd5bd6c284299c84e96152cda5e46882a3aa4a3c6a2?context=explore)
- [0.16.0-beta](https://hub.docker.com/layers/btcpayserver/lnd/v0.16.0-beta/images/sha256-f0eb70c20691aaa2ffc34fd5bd6c284299c84e96152cda5e46882a3aa4a3c6a2?context=explore)
- [0.15.4-beta](https://hub.docker.com/layers/btcpayserver/lnd/v0.15.4-beta-1/images/sha256-cadbbff93cf36146e24fa4f32170b4b9d278a2e1acfdc50470790a94506ee9c3?context=explore)
- [Other versions are tagged](https://github.com/btcpayserver/lnd/tags), but obsoleted and not supported.
- All LND versions prior to 0.15.4 contain a consensus bug that prevents them from properly parsing transactions with more than 500,000 witness items per input (https://github.com/btcsuite/btcd/issues/1906)
- All LND versions prior to 0.15.2 contain a bug that prevents them from properly parsing Taproot transactions with script size over 11000 bytes (https://github.com/lightningnetwork/lnd/issues/7002)
- LND version 0.14.0-beta shipped with check that made it incompatable with c-lightning and eclair (https://github.com/lightningnetwork/lnd/issues/5890)
- All LND versions prior to 0.13.3 contain specification-level vulnerability (https://lists.linuxfoundation.org/pipermail/lightning-dev/2021-October/003257.html)
- All LND versions prior to 0.7 contain critical vulnerability (https://lists.linuxfoundation.org/pipermail/lightning-dev/2019-September/002174.html)
## Lightning Network Specification Compliance
`lnd` _fully_ conforms to the [Lightning Network specification
(BOLTs)](https://github.com/lightningnetwork/lightning-rfc). BOLT stands for:
Basis of Lightning Technology. The specifications are currently being drafted
by several groups of implementers based around the world including the
developers of `lnd`. The set of specification documents as well as our
implementation of the specification are still a work-in-progress. With that
said, the current status of `lnd`'s BOLT compliance is:
Each version is marked with appropriate `basedon-vX.X.X-beta` tags. We are using `basedon` prefix in order not to conflict with LND tags from source repository.
- [X] BOLT 1: Base Protocol
- [X] BOLT 2: Peer Protocol for Channel Management
- [X] BOLT 3: Bitcoin Transaction and Script Formats
- [X] BOLT 4: Onion Routing Protocol
- [X] BOLT 5: Recommendations for On-chain Transaction Handling
- [X] BOLT 7: P2P Node and Channel Discovery
- [X] BOLT 8: Encrypted and Authenticated Transport
- [X] BOLT 9: Assigned Feature Flags
- [X] BOLT 10: DNS Bootstrap and Assisted Node Location
- [X] BOLT 11: Invoice Protocol for Lightning Payments
## Updating LND version in BTCPay Server
## Developer Resources
1. **Update https://github.com/btcpayserver/lnd**
The daemon has been designed to be as developer friendly as possible in order
to facilitate application development on top of `lnd`. Two primary RPC
interfaces are exported: an HTTP REST API, and a [gRPC](https://grpc.io/)
service. The exported APIs are not yet stable, so be warned: they may change
drastically in the near future.
a) Go to https://github.com/lightningnetwork/lnd/releases and find the commit on which we should add our resources.
b) Checkout a new branch for that commit, usually in the format of `lnd/v0.18.3-beta`.
c) Cherry-pick the `Adding BtcPayServer related files and resources` commit. [Example commit](https://github.com/btcpayserver/lnd/commit/ae4bb33c6a3db8b7cc01d18fdf46e600ead9bed4).
d) Tag it with the `basedon-v*` prefix name and push it. For v0.18.1, the tag name was `basedon-v0.18.3-beta`.
i. Before you push the tag to CircleCI to build and publish image to Docker Hub, you can test if building the image works locally.
ii. You can do this for linuxamd64 for example by using command `docker build --pull -t local-lnd:test_version -f linuxamd64.Dockerfile .`
e) The build process will start (it [matches on tag format](.circleci/config.yml#L11)). Here is [an example CircleCI build](https://app.circleci.com/pipelines/github/btcpayserver/lnd/202/workflows/b90b5888-c0b8-4207-860e-a63ce21077af).
f) The resulting image will be published to Docker Hub. Example [Docker Hub image for v0.18.3](https://hub.docker.com/layers/btcpayserver/lnd/v0.18.3-beta/images/sha256-513ddd55a5af44a14e27110ee14cb28f1c7a69205bcaa2fba4e66275c1f725e5?context=repo).
An automatically generated set of documentation for the RPC APIs can be found
at [api.lightning.community](https://api.lightning.community). A set of developer
resources including guides, articles, example applications and community resources can be found at:
[docs.lightning.engineering](https://docs.lightning.engineering).
Occasionally, there are problems with:
- Versioning of base Docker images used for building Go binaries. You may need to bump that base image - [example commit](https://github.com/btcpayserver/lnd/commit/c841954c515a9d067c24987291316b093b91c2f2).
- [Updating Loop](https://github.com/lightninglabs/loop) as part of the package, which needs to happen occasionally. [Example bump of Loop version](https://github.com/btcpayserver/lnd/commit/b3aecc7ac58280ef662e39ba99461573a30fe79a
Finally, we also have an active
[Slack](https://lightning.engineering/slack.html) where protocol developers, application developers, testers and users gather to
discuss various aspects of `lnd` and also Lightning in general.
3. **Update https://github.com/btcpayserver/BTCPayServer.Lightning**
## Installation
In order to build from source, please see [the installation
instructions](docs/INSTALL.md).
Now we need to update the dependency in our Lightning library project. This library has tests, so we will know if something is broken.
## Docker
To run lnd from Docker, please see the main [Docker instructions](docs/DOCKER.md)
a) Modify the `docker-compose.yml` file to reference the new LND version. [Example](https://github.com/btcpayserver/BTCPayServer.Lightning/pull/162/commits/413784ef9b2a8e7aa0496eb91f792ff0086c0ef7).
b) Checkout a new branch for that commit, usually in the format of `feat/lnd-0.18.1`.
c) Title the commit `Bumping LND to 0.18.1-beta`.
d) Open a pull request and reference Docker Hub and Tag. [Example PR](https://github.com/btcpayserver/BTCPayServer.Lightning/pull/162).
e) Once tests pass, you can merge it.
## IRC
* irc.libera.chat
* channel #lnd
* [webchat](https://web.libera.chat/#lnd)
4. **Update https://github.com/btcpayserver/btcpayserver**
## Safety
This will give access to LND to the whole dev team and allow for further testing on their dev machines if everything works as expected.
When operating a mainnet `lnd` node, please refer to our [operational safety
guidelines](docs/safety.md). It is important to note that `lnd` is still
**beta** software and that ignoring these operational guidelines can lead to
loss of funds.
a) Modify 4 `docker-compose.yml` files in `BTCPayServer.Tests`. [Example pull request to emulate](https://github.com/btcpayserver/btcpayserver/pull/6795).
b) When you open the PR, include the version and link to the BTCPayServer.Lightning PR.
c) Once tests pass, you can merge it.
## Security
5. **Update https://github.com/btcpayserver/btcpayserver-docker**
The developers of `lnd` take security _very_ seriously. The disclosure of
security vulnerabilities helps us secure the health of `lnd`, privacy of our
users, and also the health of the Lightning Network as a whole. If you find
any issues regarding security or privacy, please disclose the information
responsibly by sending an email to security at lightning dot engineering,
preferably encrypted using our designated PGP key
(`91FE464CD75101DA6B6BAB60555C6465E5BCB3AF`) which can be found
[here](https://gist.githubusercontent.com/Roasbeef/6fb5b52886183239e4aa558f83d085d3/raw/5fa96010af201628bcfa61e9309d9b13d23d220f/security@lightning.engineering).
a) Now that everything is prepared, open a PR in the btcpayserver-docker repository to allow these changes to propagate to everyone. [Example pull request](https://github.com/btcpayserver/btcpayserver-docker/pull/911).
b) Open the PR in DRAFT mode and tag @NicolasDorier and @Pavlenex as reviewers. They typically handle releases, and once they test that the LND version update works on their server, they can ACK the update and merge it as part of the release process.
## Further reading
* [Step-by-step send payment guide with docker](https://github.com/lightningnetwork/lnd/tree/master/docker)
* [Contribution guide](https://github.com/lightningnetwork/lnd/blob/master/docs/code_contribution_guidelines.md)
## Source repository
https://github.com/lightningnetwork/lnd
## Links
* [BTCPayServer main repo](https://github.com/btcpayserver/btcpayserver)
* [BTCPayServer-Docker repo](https://github.com/btcpayserver/btcpayserver-docker)
* [BTCPayServer.Lightning](https://github.com/btcpayserver/BTCPayServer.Lightning)

View File

@ -5,11 +5,22 @@ import (
"fmt"
"sync"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/htlcswitch/hop"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnwire"
"golang.org/x/exp/maps"
)
// UpdateLinkAliases is a function type for a function that locates the active
// link that matches the given shortID and triggers an update based on the
// latest values of the alias manager.
type UpdateLinkAliases func(shortID lnwire.ShortChannelID) error
// ScidAliasMap is a map from a base short channel ID to a set of alias short
// channel IDs.
type ScidAliasMap map[lnwire.ShortChannelID][]lnwire.ShortChannelID
var (
// aliasBucket stores aliases as keys and their base SCIDs as values.
// This is used to populate the maps that the Manager uses. The keys
@ -47,17 +58,18 @@ var (
// operations.
byteOrder = binary.BigEndian
// startBlockHeight is the starting block height of the alias range.
startingBlockHeight = 16_000_000
// AliasStartBlockHeight is the starting block height of the alias
// range.
AliasStartBlockHeight uint32 = 16_000_000
// endBlockHeight is the ending block height of the alias range.
endBlockHeight = 16_250_000
// AliasEndBlockHeight is the ending block height of the alias range.
AliasEndBlockHeight uint32 = 16_250_000
// StartingAlias is the first alias ShortChannelID that will get
// assigned by RequestAlias. The starting BlockHeight is chosen so that
// legitimate SCIDs in integration tests aren't mistaken for an alias.
StartingAlias = lnwire.ShortChannelID{
BlockHeight: uint32(startingBlockHeight),
BlockHeight: AliasStartBlockHeight,
TxIndex: 0,
TxPosition: 0,
}
@ -68,6 +80,10 @@ var (
// errNoPeerAlias is returned when the peer's alias for a given
// channel is not found.
errNoPeerAlias = fmt.Errorf("no peer alias found")
// ErrAliasNotFound is returned when the alias is not found and can't
// be mapped to a base SCID.
ErrAliasNotFound = fmt.Errorf("alias not found")
)
// Manager is a struct that handles aliases for LND. It has an underlying
@ -77,10 +93,14 @@ var (
type Manager struct {
backend kvdb.Backend
// linkAliasUpdater is a function used by the alias manager to
// facilitate live update of aliases in other subsystems.
linkAliasUpdater UpdateLinkAliases
// baseToSet is a mapping from the "base" SCID to the set of aliases
// for this channel. This mapping includes all channels that
// negotiated the option-scid-alias feature bit.
baseToSet map[lnwire.ShortChannelID][]lnwire.ShortChannelID
baseToSet ScidAliasMap
// aliasToBase is a mapping that maps all aliases for a given channel
// to its base SCID. This is only used for channels that have
@ -98,9 +118,15 @@ type Manager struct {
}
// NewManager initializes an alias Manager from the passed database backend.
func NewManager(db kvdb.Backend) (*Manager, error) {
m := &Manager{backend: db}
m.baseToSet = make(map[lnwire.ShortChannelID][]lnwire.ShortChannelID)
func NewManager(db kvdb.Backend, linkAliasUpdater UpdateLinkAliases) (*Manager,
error) {
m := &Manager{
backend: db,
baseToSet: make(ScidAliasMap),
linkAliasUpdater: linkAliasUpdater,
}
m.aliasToBase = make(map[lnwire.ShortChannelID]lnwire.ShortChannelID)
m.peerAlias = make(map[lnwire.ChannelID]lnwire.ShortChannelID)
@ -215,12 +241,22 @@ func (m *Manager) populateMaps() error {
// AddLocalAlias adds a database mapping from the passed alias to the passed
// base SCID. The gossip boolean marks whether or not to create a mapping
// that the gossiper will use. It is set to false for the upgrade path where
// the feature-bit is toggled on and there are existing channels.
// the feature-bit is toggled on and there are existing channels. The linkUpdate
// flag is used to signal whether this function should also trigger an update
// on the htlcswitch scid alias maps.
func (m *Manager) AddLocalAlias(alias, baseScid lnwire.ShortChannelID,
gossip bool) error {
gossip, linkUpdate bool) error {
// We need to lock the manager for the whole duration of this method,
// except for the very last part where we call the link updater. In
// order for us to safely use a defer _and_ still be able to manually
// unlock, we use a sync.Once.
m.Lock()
defer m.Unlock()
unlockOnce := sync.Once{}
unlock := func() {
unlockOnce.Do(m.Unlock)
}
defer unlock()
err := kvdb.Update(m.backend, func(tx kvdb.RwTx) error {
// If the caller does not want to allow the alias to be used
@ -270,6 +306,18 @@ func (m *Manager) AddLocalAlias(alias, baseScid lnwire.ShortChannelID,
m.aliasToBase[alias] = baseScid
}
// We definitely need to unlock the Manager before calling the link
// updater. If we don't, we'll deadlock. We use a sync.Once to ensure
// that we only unlock once.
unlock()
// Finally, we trigger a htlcswitch update if the flag is set, in order
// for any future htlc that references the added alias to be properly
// routed.
if linkUpdate {
return m.linkAliasUpdater(baseScid)
}
return nil
}
@ -340,6 +388,74 @@ func (m *Manager) DeleteSixConfs(baseScid lnwire.ShortChannelID) error {
return nil
}
// DeleteLocalAlias removes a mapping from the database and the Manager's maps.
func (m *Manager) DeleteLocalAlias(alias,
baseScid lnwire.ShortChannelID) error {
// We need to lock the manager for the whole duration of this method,
// except for the very last part where we call the link updater. In
// order for us to safely use a defer _and_ still be able to manually
// unlock, we use a sync.Once.
m.Lock()
unlockOnce := sync.Once{}
unlock := func() {
unlockOnce.Do(m.Unlock)
}
defer unlock()
err := kvdb.Update(m.backend, func(tx kvdb.RwTx) error {
aliasToBaseBucket, err := tx.CreateTopLevelBucket(aliasBucket)
if err != nil {
return err
}
var aliasBytes [8]byte
byteOrder.PutUint64(aliasBytes[:], alias.ToUint64())
// If the user attempts to delete an alias that doesn't exist,
// we'll want to inform them about it and not just do nothing.
if aliasToBaseBucket.Get(aliasBytes[:]) == nil {
return ErrAliasNotFound
}
return aliasToBaseBucket.Delete(aliasBytes[:])
}, func() {})
if err != nil {
return err
}
// Now that the database state has been updated, we'll delete the
// mapping from the Manager's maps.
aliasSet, ok := m.baseToSet[baseScid]
if !ok {
return ErrAliasNotFound
}
// We'll filter the alias set and remove the alias from it.
aliasSet = fn.Filter(func(a lnwire.ShortChannelID) bool {
return a.ToUint64() != alias.ToUint64()
}, aliasSet)
// If the alias set is empty, we'll delete the base SCID from the
// baseToSet map.
if len(aliasSet) == 0 {
delete(m.baseToSet, baseScid)
} else {
m.baseToSet[baseScid] = aliasSet
}
// Finally, we'll delete the aliasToBase mapping from the Manager's
// cache (but this is only set if we gossip the alias).
delete(m.aliasToBase, alias)
// We definitely need to unlock the Manager before calling the link
// updater. If we don't, we'll deadlock. We use a sync.Once to ensure
// that we only unlock once.
unlock()
return m.linkAliasUpdater(baseScid)
}
// PutPeerAlias stores the peer's alias SCID once we learn of it in the
// channel_ready message.
func (m *Manager) PutPeerAlias(chanID lnwire.ChannelID,
@ -392,6 +508,19 @@ func (m *Manager) GetPeerAlias(chanID lnwire.ChannelID) (lnwire.ShortChannelID,
func (m *Manager) RequestAlias() (lnwire.ShortChannelID, error) {
var nextAlias lnwire.ShortChannelID
m.RLock()
defer m.RUnlock()
// haveAlias returns true if the passed alias is already assigned to a
// channel in the baseToSet map.
haveAlias := func(maybeNextAlias lnwire.ShortChannelID) bool {
return fn.Any(func(aliasList []lnwire.ShortChannelID) bool {
return fn.Any(func(alias lnwire.ShortChannelID) bool {
return alias == maybeNextAlias
}, aliasList)
}, maps.Values(m.baseToSet))
}
err := kvdb.Update(m.backend, func(tx kvdb.RwTx) error {
bucket, err := tx.CreateTopLevelBucket(aliasAllocBucket)
if err != nil {
@ -404,6 +533,29 @@ func (m *Manager) RequestAlias() (lnwire.ShortChannelID, error) {
// StartingAlias to it.
nextAlias = StartingAlias
// If the very first alias is already assigned, we'll
// keep incrementing until we find an unassigned alias.
// This is to avoid collision with custom added SCID
// aliases that fall into the same range as the ones we
// generate here monotonically. Those custom SCIDs are
// stored in a different bucket, but we can just check
// the in-memory map for simplicity.
for {
if !haveAlias(nextAlias) {
break
}
nextAlias = getNextScid(nextAlias)
// Abort if we've reached the end of the range.
if nextAlias.BlockHeight >=
AliasEndBlockHeight {
return fmt.Errorf("range for custom " +
"aliases exhausted")
}
}
var scratch [8]byte
byteOrder.PutUint64(scratch[:], nextAlias.ToUint64())
return bucket.Put(lastAliasKey, scratch[:])
@ -418,6 +570,26 @@ func (m *Manager) RequestAlias() (lnwire.ShortChannelID, error) {
)
nextAlias = getNextScid(lastScid)
// If the next alias is already assigned, we'll keep
// incrementing until we find an unassigned alias. This is to
// avoid collision with custom added SCID aliases that fall into
// the same range as the ones we generate here monotonically.
// Those custom SCIDs are stored in a different bucket, but we
// can just check the in-memory map for simplicity.
for {
if !haveAlias(nextAlias) {
break
}
nextAlias = getNextScid(nextAlias)
// Abort if we've reached the end of the range.
if nextAlias.BlockHeight >= AliasEndBlockHeight {
return fmt.Errorf("range for custom " +
"aliases exhausted")
}
}
var scratch [8]byte
byteOrder.PutUint64(scratch[:], nextAlias.ToUint64())
return bucket.Put(lastAliasKey, scratch[:])
@ -433,11 +605,11 @@ func (m *Manager) RequestAlias() (lnwire.ShortChannelID, error) {
// ListAliases returns a carbon copy of baseToSet. This is used by the rpc
// layer.
func (m *Manager) ListAliases() map[lnwire.ShortChannelID][]lnwire.ShortChannelID {
func (m *Manager) ListAliases() ScidAliasMap {
m.RLock()
defer m.RUnlock()
baseCopy := make(map[lnwire.ShortChannelID][]lnwire.ShortChannelID)
baseCopy := make(ScidAliasMap)
for k, v := range m.baseToSet {
setCopy := make([]lnwire.ShortChannelID, len(v))
@ -496,10 +668,10 @@ func getNextScid(last lnwire.ShortChannelID) lnwire.ShortChannelID {
// IsAlias returns true if the passed SCID is an alias. The function determines
// this by looking at the BlockHeight. If the BlockHeight is greater than
// startingBlockHeight and less than endBlockHeight, then it is an alias
// AliasStartBlockHeight and less than AliasEndBlockHeight, then it is an alias
// assigned by RequestAlias. These bounds only apply to aliases we generate.
// Our peers are free to use any range they choose.
func IsAlias(scid lnwire.ShortChannelID) bool {
return scid.BlockHeight >= uint32(startingBlockHeight) &&
scid.BlockHeight < uint32(endBlockHeight)
return scid.BlockHeight >= AliasStartBlockHeight &&
scid.BlockHeight < AliasEndBlockHeight
}

View File

@ -23,7 +23,11 @@ func TestAliasStorePeerAlias(t *testing.T) {
require.NoError(t, err)
defer db.Close()
aliasStore, err := NewManager(db)
linkUpdater := func(shortID lnwire.ShortChannelID) error {
return nil
}
aliasStore, err := NewManager(db, linkUpdater)
require.NoError(t, err)
var chanID1 [32]byte
@ -52,7 +56,11 @@ func TestAliasStoreRequest(t *testing.T) {
require.NoError(t, err)
defer db.Close()
aliasStore, err := NewManager(db)
linkUpdater := func(shortID lnwire.ShortChannelID) error {
return nil
}
aliasStore, err := NewManager(db, linkUpdater)
require.NoError(t, err)
// We'll assert that the very first alias we receive is StartingAlias.
@ -68,6 +76,118 @@ func TestAliasStoreRequest(t *testing.T) {
require.Equal(t, nextAlias, alias2)
}
// TestAliasLifecycle tests that the aliases can be created and deleted.
func TestAliasLifecycle(t *testing.T) {
t.Parallel()
// Create the backend database and use this to create the aliasStore.
dbPath := filepath.Join(t.TempDir(), "testdb")
db, err := kvdb.Create(
kvdb.BoltBackendName, dbPath, true, kvdb.DefaultDBTimeout,
)
require.NoError(t, err)
defer db.Close()
updateChan := make(chan struct{}, 1)
linkUpdater := func(shortID lnwire.ShortChannelID) error {
updateChan <- struct{}{}
return nil
}
aliasStore, err := NewManager(db, linkUpdater)
require.NoError(t, err)
const (
base = uint64(123123123)
alias = uint64(456456456)
)
// Parse the aliases and base to short channel ID format.
baseScid := lnwire.NewShortChanIDFromInt(base)
aliasScid := lnwire.NewShortChanIDFromInt(alias)
aliasScid2 := lnwire.NewShortChanIDFromInt(alias + 1)
// Add the first alias.
err = aliasStore.AddLocalAlias(aliasScid, baseScid, false, true)
require.NoError(t, err)
// The link updater should be called.
<-updateChan
// Query the aliases and verify the results.
aliasList := aliasStore.GetAliases(baseScid)
require.Len(t, aliasList, 1)
require.Contains(t, aliasList, aliasScid)
// Add the second alias.
err = aliasStore.AddLocalAlias(aliasScid2, baseScid, false, true)
require.NoError(t, err)
// The link updater should be called.
<-updateChan
// Query the aliases and verify the results.
aliasList = aliasStore.GetAliases(baseScid)
require.Len(t, aliasList, 2)
require.Contains(t, aliasList, aliasScid)
require.Contains(t, aliasList, aliasScid2)
// Delete the first alias.
err = aliasStore.DeleteLocalAlias(aliasScid, baseScid)
require.NoError(t, err)
// The link updater should be called.
<-updateChan
// We expect to get an error if we attempt to delete the same alias
// again.
err = aliasStore.DeleteLocalAlias(aliasScid, baseScid)
require.ErrorIs(t, err, ErrAliasNotFound)
// The link updater should _not_ be called.
select {
case <-updateChan:
t.Fatal("link alias updater should not have been called")
default:
}
// Query the aliases and verify that first one doesn't exist anymore.
aliasList = aliasStore.GetAliases(baseScid)
require.Len(t, aliasList, 1)
require.Contains(t, aliasList, aliasScid2)
require.NotContains(t, aliasList, aliasScid)
// Delete the second alias.
err = aliasStore.DeleteLocalAlias(aliasScid2, baseScid)
require.NoError(t, err)
// The link updater should be called.
<-updateChan
// Query the aliases and verify that none exists.
aliasList = aliasStore.GetAliases(baseScid)
require.Len(t, aliasList, 0)
// We now request an alias generated by the aliasStore. This should give
// the first from the pre-defined list of allocated aliases.
firstRequested, err := aliasStore.RequestAlias()
require.NoError(t, err)
require.Equal(t, StartingAlias, firstRequested)
// We now manually add the next alias from the range as a custom alias.
secondAlias := getNextScid(firstRequested)
err = aliasStore.AddLocalAlias(secondAlias, baseScid, false, true)
require.NoError(t, err)
// When we now request another alias from the allocation list, we expect
// the third one (tx position 2) to be returned.
thirdRequested, err := aliasStore.RequestAlias()
require.NoError(t, err)
require.Equal(t, getNextScid(secondAlias), thirdRequested)
require.EqualValues(t, 2, thirdRequested.TxPosition)
}
// TestGetNextScid tests that given a current lnwire.ShortChannelID,
// getNextScid returns the expected alias to use next.
func TestGetNextScid(t *testing.T) {
@ -80,7 +200,7 @@ func TestGetNextScid(t *testing.T) {
name: "starting alias",
current: StartingAlias,
expected: lnwire.ShortChannelID{
BlockHeight: uint32(startingBlockHeight),
BlockHeight: AliasStartBlockHeight,
TxIndex: 0,
TxPosition: 1,
},

View File

@ -43,7 +43,7 @@ const (
AppMinor uint = 18
// AppPatch defines the application patch for this binary.
AppPatch uint = 3
AppPatch uint = 4
// AppPreRelease MUST only contain characters from semanticAlphabet per
// the semantic versioning spec.

View File

@ -24,6 +24,7 @@ import (
"github.com/lightningnetwork/lnd/chainntnfs/neutrinonotify"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/channeldb/models"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/kvdb"
@ -63,6 +64,14 @@ type Config struct {
// state.
ChanStateDB *channeldb.ChannelStateDB
// AuxLeafStore is an optional store that can be used to store auxiliary
// leaves for certain custom channel types.
AuxLeafStore fn.Option[lnwallet.AuxLeafStore]
// AuxSigner is an optional signer that can be used to sign auxiliary
// leaves for certain custom channel types.
AuxSigner fn.Option[lnwallet.AuxSigner]
// BlockCache is the main cache for storing block information.
BlockCache *blockcache.BlockCache

View File

@ -356,6 +356,30 @@ func (r *RPCAcceptor) sendAcceptRequests(errChan chan error,
):
commitmentType = lnrpc.CommitmentType_SIMPLE_TAPROOT
case channelFeatures.OnlyContains(
lnwire.SimpleTaprootOverlayChansRequired,
lnwire.ZeroConfRequired,
lnwire.ScidAliasRequired,
):
commitmentType = lnrpc.CommitmentType_SIMPLE_TAPROOT_OVERLAY
case channelFeatures.OnlyContains(
lnwire.SimpleTaprootOverlayChansRequired,
lnwire.ZeroConfRequired,
):
commitmentType = lnrpc.CommitmentType_SIMPLE_TAPROOT_OVERLAY
case channelFeatures.OnlyContains(
lnwire.SimpleTaprootOverlayChansRequired,
lnwire.ScidAliasRequired,
):
commitmentType = lnrpc.CommitmentType_SIMPLE_TAPROOT_OVERLAY
case channelFeatures.OnlyContains(
lnwire.SimpleTaprootOverlayChansRequired,
):
commitmentType = lnrpc.CommitmentType_SIMPLE_TAPROOT_OVERLAY
case channelFeatures.OnlyContains(
lnwire.StaticRemoteKeyRequired,
):

View File

@ -226,28 +226,109 @@ const (
// A tlv type definition used to serialize an outpoint's indexStatus
// for use in the outpoint index.
indexStatusType tlv.Type = 0
// A tlv type definition used to serialize and deserialize a KeyLocator
// from the database.
keyLocType tlv.Type = 1
// A tlv type used to serialize and deserialize the
// `InitialLocalBalance` field.
initialLocalBalanceType tlv.Type = 2
// A tlv type used to serialize and deserialize the
// `InitialRemoteBalance` field.
initialRemoteBalanceType tlv.Type = 3
// A tlv type definition used to serialize and deserialize the
// confirmed ShortChannelID for a zero-conf channel.
realScidType tlv.Type = 4
// A tlv type definition used to serialize and deserialize the
// Memo for the channel channel.
channelMemoType tlv.Type = 5
)
// openChannelTlvData houses the new data fields that are stored for each
// channel in a TLV stream within the root bucket. This is stored as a TLV
// stream appended to the existing hard-coded fields in the channel's root
// bucket. New fields being added to the channel state should be added here.
//
// NOTE: This struct is used for serialization purposes only and its fields
// should be accessed via the OpenChannel struct while in memory.
type openChannelTlvData struct {
// revokeKeyLoc is the key locator for the revocation key.
revokeKeyLoc tlv.RecordT[tlv.TlvType1, keyLocRecord]
// initialLocalBalance is the initial local balance of the channel.
initialLocalBalance tlv.RecordT[tlv.TlvType2, uint64]
// initialRemoteBalance is the initial remote balance of the channel.
initialRemoteBalance tlv.RecordT[tlv.TlvType3, uint64]
// realScid is the real short channel ID of the channel corresponding to
// the on-chain outpoint.
realScid tlv.RecordT[tlv.TlvType4, lnwire.ShortChannelID]
// memo is an optional text field that gives context to the user about
// the channel.
memo tlv.OptionalRecordT[tlv.TlvType5, []byte]
// tapscriptRoot is the optional Tapscript root the channel funding
// output commits to.
tapscriptRoot tlv.OptionalRecordT[tlv.TlvType6, [32]byte]
// customBlob is an optional TLV encoded blob of data representing
// custom channel funding information.
customBlob tlv.OptionalRecordT[tlv.TlvType7, tlv.Blob]
}
// encode serializes the openChannelTlvData to the given io.Writer.
func (c *openChannelTlvData) encode(w io.Writer) error {
tlvRecords := []tlv.Record{
c.revokeKeyLoc.Record(),
c.initialLocalBalance.Record(),
c.initialRemoteBalance.Record(),
c.realScid.Record(),
}
c.memo.WhenSome(func(memo tlv.RecordT[tlv.TlvType5, []byte]) {
tlvRecords = append(tlvRecords, memo.Record())
})
c.tapscriptRoot.WhenSome(
func(root tlv.RecordT[tlv.TlvType6, [32]byte]) {
tlvRecords = append(tlvRecords, root.Record())
},
)
c.customBlob.WhenSome(func(blob tlv.RecordT[tlv.TlvType7, tlv.Blob]) {
tlvRecords = append(tlvRecords, blob.Record())
})
// Create the tlv stream.
tlvStream, err := tlv.NewStream(tlvRecords...)
if err != nil {
return err
}
return tlvStream.Encode(w)
}
// decode deserializes the openChannelTlvData from the given io.Reader.
func (c *openChannelTlvData) decode(r io.Reader) error {
memo := c.memo.Zero()
tapscriptRoot := c.tapscriptRoot.Zero()
blob := c.customBlob.Zero()
// Create the tlv stream.
tlvStream, err := tlv.NewStream(
c.revokeKeyLoc.Record(),
c.initialLocalBalance.Record(),
c.initialRemoteBalance.Record(),
c.realScid.Record(),
memo.Record(),
tapscriptRoot.Record(),
blob.Record(),
)
if err != nil {
return err
}
tlvs, err := tlvStream.DecodeWithParsedTypes(r)
if err != nil {
return err
}
if _, ok := tlvs[memo.TlvType()]; ok {
c.memo = tlv.SomeRecordT(memo)
}
if _, ok := tlvs[tapscriptRoot.TlvType()]; ok {
c.tapscriptRoot = tlv.SomeRecordT(tapscriptRoot)
}
if _, ok := tlvs[c.customBlob.TlvType()]; ok {
c.customBlob = tlv.SomeRecordT(blob)
}
return nil
}
// indexStatus is an enum-like type that describes what state the
// outpoint is in. Currently only two possible values.
type indexStatus uint8
@ -325,6 +406,11 @@ const (
// SimpleTaprootFeatureBit indicates that the simple-taproot-chans
// feature bit was negotiated during the lifetime of the channel.
SimpleTaprootFeatureBit ChannelType = 1 << 10
// TapscriptRootBit indicates that this is a MuSig2 channel with a top
// level tapscript commitment. This MUST be set along with the
// SimpleTaprootFeatureBit.
TapscriptRootBit ChannelType = 1 << 11
)
// IsSingleFunder returns true if the channel type if one of the known single
@ -395,6 +481,12 @@ func (c ChannelType) IsTaproot() bool {
return c&SimpleTaprootFeatureBit == SimpleTaprootFeatureBit
}
// HasTapscriptRoot returns true if the channel is using a top level tapscript
// root commitment.
func (c ChannelType) HasTapscriptRoot() bool {
return c&TapscriptRootBit == TapscriptRootBit
}
// ChannelStateBounds are the parameters from OpenChannel and AcceptChannel
// that are responsible for providing bounds on the state space of the abstract
// channel state. These values must be remembered for normal channel operation
@ -496,6 +588,53 @@ type ChannelConfig struct {
HtlcBasePoint keychain.KeyDescriptor
}
// commitTlvData stores all the optional data that may be stored as a TLV stream
// at the _end_ of the normal serialized commit on disk.
type commitTlvData struct {
// customBlob is a custom blob that may store extra data for custom
// channels.
customBlob tlv.OptionalRecordT[tlv.TlvType1, tlv.Blob]
}
// encode encodes the aux data into the passed io.Writer.
func (c *commitTlvData) encode(w io.Writer) error {
var tlvRecords []tlv.Record
c.customBlob.WhenSome(func(blob tlv.RecordT[tlv.TlvType1, tlv.Blob]) {
tlvRecords = append(tlvRecords, blob.Record())
})
// Create the tlv stream.
tlvStream, err := tlv.NewStream(tlvRecords...)
if err != nil {
return err
}
return tlvStream.Encode(w)
}
// decode attempts to decode the aux data from the passed io.Reader.
func (c *commitTlvData) decode(r io.Reader) error {
blob := c.customBlob.Zero()
tlvStream, err := tlv.NewStream(
blob.Record(),
)
if err != nil {
return err
}
tlvs, err := tlvStream.DecodeWithParsedTypes(r)
if err != nil {
return err
}
if _, ok := tlvs[c.customBlob.TlvType()]; ok {
c.customBlob = tlv.SomeRecordT(blob)
}
return nil
}
// ChannelCommitment is a snapshot of the commitment state at a particular
// point in the commitment chain. With each state transition, a snapshot of the
// current state along with all non-settled HTLCs are recorded. These snapshots
@ -562,6 +701,11 @@ type ChannelCommitment struct {
// able by us.
CommitTx *wire.MsgTx
// CustomBlob is an optional blob that can be used to store information
// specific to a custom channel type. This may track some custom
// specific state for this given commitment.
CustomBlob fn.Option[tlv.Blob]
// CommitSig is one half of the signature required to fully complete
// the script for the commitment transaction above. This is the
// signature signed by the remote party for our version of the
@ -571,9 +715,26 @@ type ChannelCommitment struct {
// Htlcs is the set of HTLC's that are pending at this particular
// commitment height.
Htlcs []HTLC
}
// TODO(roasbeef): pending commit pointer?
// * lets just walk through
// amendTlvData updates the channel with the given auxiliary TLV data.
func (c *ChannelCommitment) amendTlvData(auxData commitTlvData) {
auxData.customBlob.WhenSomeV(func(blob tlv.Blob) {
c.CustomBlob = fn.Some(blob)
})
}
// extractTlvData creates a new commitTlvData from the given commitment.
func (c *ChannelCommitment) extractTlvData() commitTlvData {
var auxData commitTlvData
c.CustomBlob.WhenSome(func(blob tlv.Blob) {
auxData.customBlob = tlv.SomeRecordT(
tlv.NewPrimitiveRecord[tlv.TlvType1](blob),
)
})
return auxData
}
// ChannelStatus is a bit vector used to indicate whether an OpenChannel is in
@ -867,6 +1028,16 @@ type OpenChannel struct {
// channel that will be useful to our future selves.
Memo []byte
// TapscriptRoot is an optional tapscript root used to derive the MuSig2
// funding output.
TapscriptRoot fn.Option[chainhash.Hash]
// CustomBlob is an optional blob that can be used to store information
// specific to a custom channel type. This information is only created
// at channel funding time, and after wards is to be considered
// immutable.
CustomBlob fn.Option[tlv.Blob]
// TODO(roasbeef): eww
Db *ChannelStateDB
@ -1025,6 +1196,64 @@ func (c *OpenChannel) SetBroadcastHeight(height uint32) {
c.FundingBroadcastHeight = height
}
// amendTlvData updates the channel with the given auxiliary TLV data.
func (c *OpenChannel) amendTlvData(auxData openChannelTlvData) {
c.RevocationKeyLocator = auxData.revokeKeyLoc.Val.KeyLocator
c.InitialLocalBalance = lnwire.MilliSatoshi(
auxData.initialLocalBalance.Val,
)
c.InitialRemoteBalance = lnwire.MilliSatoshi(
auxData.initialRemoteBalance.Val,
)
c.confirmedScid = auxData.realScid.Val
auxData.memo.WhenSomeV(func(memo []byte) {
c.Memo = memo
})
auxData.tapscriptRoot.WhenSomeV(func(h [32]byte) {
c.TapscriptRoot = fn.Some[chainhash.Hash](h)
})
auxData.customBlob.WhenSomeV(func(blob tlv.Blob) {
c.CustomBlob = fn.Some(blob)
})
}
// extractTlvData creates a new openChannelTlvData from the given channel.
func (c *OpenChannel) extractTlvData() openChannelTlvData {
auxData := openChannelTlvData{
revokeKeyLoc: tlv.NewRecordT[tlv.TlvType1](
keyLocRecord{c.RevocationKeyLocator},
),
initialLocalBalance: tlv.NewPrimitiveRecord[tlv.TlvType2](
uint64(c.InitialLocalBalance),
),
initialRemoteBalance: tlv.NewPrimitiveRecord[tlv.TlvType3](
uint64(c.InitialRemoteBalance),
),
realScid: tlv.NewRecordT[tlv.TlvType4](
c.confirmedScid,
),
}
if len(c.Memo) != 0 {
auxData.memo = tlv.SomeRecordT(
tlv.NewPrimitiveRecord[tlv.TlvType5](c.Memo),
)
}
c.TapscriptRoot.WhenSome(func(h chainhash.Hash) {
auxData.tapscriptRoot = tlv.SomeRecordT(
tlv.NewPrimitiveRecord[tlv.TlvType6, [32]byte](h),
)
})
c.CustomBlob.WhenSome(func(blob tlv.Blob) {
auxData.customBlob = tlv.SomeRecordT(
tlv.NewPrimitiveRecord[tlv.TlvType7](blob),
)
})
return auxData
}
// Refresh updates the in-memory channel state using the latest state observed
// on disk.
func (c *OpenChannel) Refresh() error {
@ -2351,6 +2580,12 @@ type HTLC struct {
// HTLC. It is stored in the ExtraData field, which is used to store
// a TLV stream of additional information associated with the HTLC.
BlindingPoint lnwire.BlindingPointRecord
// CustomRecords is a set of custom TLV records that are associated with
// this HTLC. These records are used to store additional information
// about the HTLC that is not part of the standard HTLC fields. This
// field is encoded within the ExtraData field.
CustomRecords lnwire.CustomRecords
}
// serializeExtraData encodes a TLV stream of extra data to be stored with a
@ -2369,6 +2604,11 @@ func (h *HTLC) serializeExtraData() error {
records = append(records, &b)
})
records, err := h.CustomRecords.ExtendRecordProducers(records)
if err != nil {
return err
}
return h.ExtraData.PackRecords(records...)
}
@ -2390,8 +2630,19 @@ func (h *HTLC) deserializeExtraData() error {
if val, ok := tlvMap[h.BlindingPoint.TlvType()]; ok && val == nil {
h.BlindingPoint = tlv.SomeRecordT(blindingPoint)
// Remove the entry from the TLV map. Anything left in the map
// will be included in the custom records field.
delete(tlvMap, h.BlindingPoint.TlvType())
}
// Set the custom records field to the remaining TLV records.
customRecords, err := lnwire.NewCustomRecords(tlvMap)
if err != nil {
return err
}
h.CustomRecords = customRecords
return nil
}
@ -2529,6 +2780,8 @@ func (h *HTLC) Copy() HTLC {
copy(clone.Signature[:], h.Signature)
copy(clone.RHash[:], h.RHash[:])
copy(clone.ExtraData, h.ExtraData)
clone.BlindingPoint = h.BlindingPoint
clone.CustomRecords = h.CustomRecords.Copy()
return clone
}
@ -2690,6 +2943,14 @@ func serializeCommitDiff(w io.Writer, diff *CommitDiff) error { // nolint: dupl
}
}
// We'll also encode the commit aux data stream here. We do this here
// rather than above (at the call to serializeChanCommit), to ensure
// backwards compat for reads to existing non-custom channels.
auxData := diff.Commitment.extractTlvData()
if err := auxData.encode(w); err != nil {
return fmt.Errorf("unable to write aux data: %w", err)
}
return nil
}
@ -2750,6 +3011,17 @@ func deserializeCommitDiff(r io.Reader) (*CommitDiff, error) {
}
}
// As a final step, we'll read out any aux commit data that we have at
// the end of this byte stream. We do this here to ensure backward
// compatibility, as otherwise we risk erroneously reading into the
// wrong field.
var auxData commitTlvData
if err := auxData.decode(r); err != nil {
return nil, fmt.Errorf("unable to decode aux data: %w", err)
}
d.Commitment.amendTlvData(auxData)
return &d, nil
}
@ -3728,6 +4000,13 @@ func (c *OpenChannel) Snapshot() *ChannelSnapshot {
},
}
localCommit.CustomBlob.WhenSome(func(blob tlv.Blob) {
blobCopy := make([]byte, len(blob))
copy(blobCopy, blob)
snapshot.ChannelCommitment.CustomBlob = fn.Some(blobCopy)
})
// Copy over the current set of HTLCs to ensure the caller can't mutate
// our internal state.
snapshot.Htlcs = make([]HTLC, len(localCommit.Htlcs))
@ -4030,32 +4309,9 @@ func putChanInfo(chanBucket kvdb.RwBucket, channel *OpenChannel) error {
return err
}
// Convert balance fields into uint64.
localBalance := uint64(channel.InitialLocalBalance)
remoteBalance := uint64(channel.InitialRemoteBalance)
// Create the tlv stream.
tlvStream, err := tlv.NewStream(
// Write the RevocationKeyLocator as the first entry in a tlv
// stream.
MakeKeyLocRecord(
keyLocType, &channel.RevocationKeyLocator,
),
tlv.MakePrimitiveRecord(
initialLocalBalanceType, &localBalance,
),
tlv.MakePrimitiveRecord(
initialRemoteBalanceType, &remoteBalance,
),
MakeScidRecord(realScidType, &channel.confirmedScid),
tlv.MakePrimitiveRecord(channelMemoType, &channel.Memo),
)
if err != nil {
return err
}
if err := tlvStream.Encode(&w); err != nil {
return err
auxData := channel.extractTlvData()
if err := auxData.encode(&w); err != nil {
return fmt.Errorf("unable to encode aux data: %w", err)
}
if err := chanBucket.Put(chanInfoKey, w.Bytes()); err != nil {
@ -4142,6 +4398,12 @@ func putChanCommitment(chanBucket kvdb.RwBucket, c *ChannelCommitment,
return err
}
// Before we write to disk, we'll also write our aux data as well.
auxData := c.extractTlvData()
if err := auxData.encode(&b); err != nil {
return fmt.Errorf("unable to write aux data: %w", err)
}
return chanBucket.Put(commitKey, b.Bytes())
}
@ -4244,45 +4506,14 @@ func fetchChanInfo(chanBucket kvdb.RBucket, channel *OpenChannel) error {
}
}
// Create balance fields in uint64, and Memo field as byte slice.
var (
localBalance uint64
remoteBalance uint64
memo []byte
)
// Create the tlv stream.
tlvStream, err := tlv.NewStream(
// Write the RevocationKeyLocator as the first entry in a tlv
// stream.
MakeKeyLocRecord(
keyLocType, &channel.RevocationKeyLocator,
),
tlv.MakePrimitiveRecord(
initialLocalBalanceType, &localBalance,
),
tlv.MakePrimitiveRecord(
initialRemoteBalanceType, &remoteBalance,
),
MakeScidRecord(realScidType, &channel.confirmedScid),
tlv.MakePrimitiveRecord(channelMemoType, &memo),
)
if err != nil {
return err
var auxData openChannelTlvData
if err := auxData.decode(r); err != nil {
return fmt.Errorf("unable to decode aux data: %w", err)
}
if err := tlvStream.Decode(r); err != nil {
return err
}
// Attach the balance fields.
channel.InitialLocalBalance = lnwire.MilliSatoshi(localBalance)
channel.InitialRemoteBalance = lnwire.MilliSatoshi(remoteBalance)
// Attach the memo field if non-empty.
if len(memo) > 0 {
channel.Memo = memo
}
// Assign all the relevant fields from the aux data into the actual
// open channel.
channel.amendTlvData(auxData)
channel.Packager = NewChannelPackager(channel.ShortChannelID)
@ -4318,7 +4549,9 @@ func deserializeChanCommit(r io.Reader) (ChannelCommitment, error) {
return c, nil
}
func fetchChanCommitment(chanBucket kvdb.RBucket, local bool) (ChannelCommitment, error) {
func fetchChanCommitment(chanBucket kvdb.RBucket,
local bool) (ChannelCommitment, error) {
var commitKey []byte
if local {
commitKey = append(chanCommitmentKey, byte(0x00))
@ -4332,7 +4565,23 @@ func fetchChanCommitment(chanBucket kvdb.RBucket, local bool) (ChannelCommitment
}
r := bytes.NewReader(commitBytes)
return deserializeChanCommit(r)
chanCommit, err := deserializeChanCommit(r)
if err != nil {
return ChannelCommitment{}, fmt.Errorf("unable to decode "+
"chan commit: %w", err)
}
// We'll also check to see if we have any aux data stored as the end of
// the stream.
var auxData commitTlvData
if err := auxData.decode(r); err != nil {
return ChannelCommitment{}, fmt.Errorf("unable to decode "+
"chan aux data: %w", err)
}
chanCommit.amendTlvData(auxData)
return chanCommit, nil
}
func fetchChanCommitments(chanBucket kvdb.RBucket, channel *OpenChannel) error {
@ -4440,6 +4689,25 @@ func deleteThawHeight(chanBucket kvdb.RwBucket) error {
return chanBucket.Delete(frozenChanKey)
}
// keyLocRecord is a wrapper struct around keychain.KeyLocator to implement the
// tlv.RecordProducer interface.
type keyLocRecord struct {
keychain.KeyLocator
}
// Record creates a Record out of a KeyLocator using the passed Type and the
// EKeyLocator and DKeyLocator functions. The size will always be 8 as
// KeyFamily is uint32 and the Index is uint32.
//
// NOTE: This is part of the tlv.RecordProducer interface.
func (k *keyLocRecord) Record() tlv.Record {
// Note that we set the type here as zero, as when used with a
// tlv.RecordT, the type param will be used as the type.
return tlv.MakeStaticRecord(
0, &k.KeyLocator, 8, EKeyLocator, DKeyLocator,
)
}
// EKeyLocator is an encoder for keychain.KeyLocator.
func EKeyLocator(w io.Writer, val interface{}, buf *[8]byte) error {
if v, ok := val.(*keychain.KeyLocator); ok {
@ -4468,22 +4736,6 @@ func DKeyLocator(r io.Reader, val interface{}, buf *[8]byte, l uint64) error {
return tlv.NewTypeForDecodingErr(val, "keychain.KeyLocator", l, 8)
}
// MakeKeyLocRecord creates a Record out of a KeyLocator using the passed
// Type and the EKeyLocator and DKeyLocator functions. The size will always be
// 8 as KeyFamily is uint32 and the Index is uint32.
func MakeKeyLocRecord(typ tlv.Type, keyLoc *keychain.KeyLocator) tlv.Record {
return tlv.MakeStaticRecord(typ, keyLoc, 8, EKeyLocator, DKeyLocator)
}
// MakeScidRecord creates a Record out of a ShortChannelID using the passed
// Type and the EShortChannelID and DShortChannelID functions. The size will
// always be 8 for the ShortChannelID.
func MakeScidRecord(typ tlv.Type, scid *lnwire.ShortChannelID) tlv.Record {
return tlv.MakeStaticRecord(
typ, scid, 8, lnwire.EShortChannelID, lnwire.DShortChannelID,
)
}
// ShutdownInfo contains various info about the shutdown initiation of a
// channel.
type ShutdownInfo struct {

View File

@ -17,6 +17,7 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/channeldb/models"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnmock"
@ -173,7 +174,7 @@ func fundingPointOption(chanPoint wire.OutPoint) testChannelOption {
}
// channelIDOption is an option which sets the short channel ID of the channel.
var channelIDOption = func(chanID lnwire.ShortChannelID) testChannelOption {
func channelIDOption(chanID lnwire.ShortChannelID) testChannelOption {
return func(params *testChannelParams) {
params.channel.ShortChannelID = chanID
}
@ -326,6 +327,9 @@ func createTestChannelState(t *testing.T, cdb *ChannelStateDB) *OpenChannel {
uniqueOutputIndex.Add(1)
op := wire.OutPoint{Hash: key, Index: uniqueOutputIndex.Load()}
var tapscriptRoot chainhash.Hash
copy(tapscriptRoot[:], bytes.Repeat([]byte{1}, 32))
return &OpenChannel{
ChanType: SingleFunderBit | FrozenBit,
ChainHash: key,
@ -347,6 +351,7 @@ func createTestChannelState(t *testing.T, cdb *ChannelStateDB) *OpenChannel {
FeePerKw: btcutil.Amount(5000),
CommitTx: channels.TestFundingTx,
CommitSig: bytes.Repeat([]byte{1}, 71),
CustomBlob: fn.Some([]byte{1, 2, 3}),
},
RemoteCommitment: ChannelCommitment{
CommitHeight: 0,
@ -356,6 +361,7 @@ func createTestChannelState(t *testing.T, cdb *ChannelStateDB) *OpenChannel {
FeePerKw: btcutil.Amount(5000),
CommitTx: channels.TestFundingTx,
CommitSig: bytes.Repeat([]byte{1}, 71),
CustomBlob: fn.Some([]byte{4, 5, 6}),
},
NumConfsRequired: 4,
RemoteCurrentRevocation: privKey.PubKey(),
@ -368,6 +374,9 @@ func createTestChannelState(t *testing.T, cdb *ChannelStateDB) *OpenChannel {
ThawHeight: uint32(defaultPendingHeight),
InitialLocalBalance: lnwire.MilliSatoshi(9000),
InitialRemoteBalance: lnwire.MilliSatoshi(3000),
Memo: []byte("test"),
TapscriptRoot: fn.Some(tapscriptRoot),
CustomBlob: fn.Some([]byte{1, 2, 3}),
}
}
@ -575,24 +584,32 @@ func assertCommitmentEqual(t *testing.T, a, b *ChannelCommitment) {
func assertRevocationLogEntryEqual(t *testing.T, c *ChannelCommitment,
r *RevocationLog) {
t.Helper()
// Check the common fields.
require.EqualValues(
t, r.CommitTxHash, c.CommitTx.TxHash(), "CommitTx mismatch",
t, r.CommitTxHash.Val, c.CommitTx.TxHash(), "CommitTx mismatch",
)
// Now check the common fields from the HTLCs.
require.Equal(t, len(r.HTLCEntries), len(c.Htlcs), "HTLCs len mismatch")
for i, rHtlc := range r.HTLCEntries {
cHtlc := c.Htlcs[i]
require.Equal(t, rHtlc.RHash, cHtlc.RHash, "RHash mismatch")
require.Equal(t, rHtlc.Amt, cHtlc.Amt.ToSatoshis(),
"Amt mismatch")
require.Equal(t, rHtlc.RefundTimeout, cHtlc.RefundTimeout,
"RefundTimeout mismatch")
require.EqualValues(t, rHtlc.OutputIndex, cHtlc.OutputIndex,
"OutputIndex mismatch")
require.Equal(t, rHtlc.Incoming, cHtlc.Incoming,
"Incoming mismatch")
require.Equal(t, rHtlc.RHash.Val[:], cHtlc.RHash[:], "RHash")
require.Equal(
t, rHtlc.Amt.Val.Int(), cHtlc.Amt.ToSatoshis(), "Amt",
)
require.Equal(
t, rHtlc.RefundTimeout.Val, cHtlc.RefundTimeout,
"RefundTimeout",
)
require.EqualValues(
t, rHtlc.OutputIndex.Val, cHtlc.OutputIndex,
"OutputIndex",
)
require.Equal(
t, rHtlc.Incoming.Val, cHtlc.Incoming, "Incoming",
)
}
}
@ -657,6 +674,7 @@ func TestChannelStateTransition(t *testing.T) {
CommitTx: newTx,
CommitSig: newSig,
Htlcs: htlcs,
CustomBlob: fn.Some([]byte{4, 5, 6}),
}
// First update the local node's broadcastable state and also add a
@ -694,9 +712,14 @@ func TestChannelStateTransition(t *testing.T) {
// have been updated.
updatedChannel, err := cdb.FetchOpenChannels(channel.IdentityPub)
require.NoError(t, err, "unable to fetch updated channel")
assertCommitmentEqual(t, &commitment, &updatedChannel[0].LocalCommitment)
assertCommitmentEqual(
t, &commitment, &updatedChannel[0].LocalCommitment,
)
numDiskUpdates, err := updatedChannel[0].CommitmentHeight()
require.NoError(t, err, "unable to read commitment height from disk")
if numDiskUpdates != uint64(commitment.CommitHeight) {
t.Fatalf("num disk updates doesn't match: %v vs %v",
numDiskUpdates, commitment.CommitHeight)
@ -799,10 +822,10 @@ func TestChannelStateTransition(t *testing.T) {
// Check the output indexes are saved as expected.
require.EqualValues(
t, dummyLocalOutputIndex, diskPrevCommit.OurOutputIndex,
t, dummyLocalOutputIndex, diskPrevCommit.OurOutputIndex.Val,
)
require.EqualValues(
t, dummyRemoteOutIndex, diskPrevCommit.TheirOutputIndex,
t, dummyRemoteOutIndex, diskPrevCommit.TheirOutputIndex.Val,
)
// The two deltas (the original vs the on-disk version) should
@ -844,10 +867,10 @@ func TestChannelStateTransition(t *testing.T) {
// Check the output indexes are saved as expected.
require.EqualValues(
t, dummyLocalOutputIndex, diskPrevCommit.OurOutputIndex,
t, dummyLocalOutputIndex, diskPrevCommit.OurOutputIndex.Val,
)
require.EqualValues(
t, dummyRemoteOutIndex, diskPrevCommit.TheirOutputIndex,
t, dummyRemoteOutIndex, diskPrevCommit.TheirOutputIndex.Val,
)
assertRevocationLogEntryEqual(t, &oldRemoteCommit, prevCommit)
@ -1642,6 +1665,24 @@ func TestHTLCsExtraData(t *testing.T) {
),
}
// Custom channel data htlc with a blinding point.
customDataHTLC := HTLC{
Signature: testSig.Serialize(),
Incoming: false,
Amt: 10,
RHash: key,
RefundTimeout: 1,
OnionBlob: lnmock.MockOnion(),
BlindingPoint: tlv.SomeRecordT(
tlv.NewPrimitiveRecord[lnwire.BlindingPointTlvType](
pubKey,
),
),
CustomRecords: map[uint64][]byte{
uint64(lnwire.MinCustomRecordsTlvType + 3): {1, 2, 3},
},
}
testCases := []struct {
name string
htlcs []HTLC
@ -1663,6 +1704,7 @@ func TestHTLCsExtraData(t *testing.T) {
mockHtlc,
blindingPointHTLC,
mockHtlc,
customDataHTLC,
},
},
}

View File

@ -286,6 +286,27 @@ func NewFwdPkg(source lnwire.ShortChannelID, height uint64,
}
}
// SourceRef is a convenience method that returns an AddRef to this forwarding
// package for the index in the argument. It is the caller's responsibility
// to ensure that the index is in bounds.
func (f *FwdPkg) SourceRef(i uint16) AddRef {
return AddRef{
Height: f.Height,
Index: i,
}
}
// DestRef is a convenience method that returns a SettleFailRef to this
// forwarding package for the index in the argument. It is the caller's
// responsibility to ensure that the index is in bounds.
func (f *FwdPkg) DestRef(i uint16) SettleFailRef {
return SettleFailRef{
Source: f.Source,
Height: f.Height,
Index: i,
}
}
// ID returns an unique identifier for this package, used to ensure that sphinx
// replay processing of this batch is idempotent.
func (f *FwdPkg) ID() []byte {

View File

@ -2382,7 +2382,7 @@ func TestStressTestChannelGraphAPI(t *testing.T) {
methodsMu.Unlock()
err := fn()
require.NoErrorf(t, err, fmt.Sprintf(name))
require.NoErrorf(t, err, name)
}
})
}

View File

@ -2,7 +2,6 @@ package migration_01_to_11
import (
"bytes"
"fmt"
"testing"
"time"
@ -154,12 +153,7 @@ func signDigestCompact(hash []byte) ([]byte, error) {
privKey, _ := btcec.PrivKeyFromBytes(testPrivKeyBytes)
// ecdsa.SignCompact returns a pubkey-recoverable signature
sig, err := ecdsa.SignCompact(privKey, hash, isCompressedKey)
if err != nil {
return nil, fmt.Errorf("can't sign the hash: %w", err)
}
return sig, nil
return ecdsa.SignCompact(privKey, hash, isCompressedKey), nil
}
// getPayReq creates a payment request for the given net.

View File

@ -8,6 +8,7 @@ import (
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/fn"
)
// ChannelEdgeInfo represents a fully authenticated channel along with all its
@ -62,6 +63,11 @@ type ChannelEdgeInfo struct {
// the value output in the outpoint that created this channel.
Capacity btcutil.Amount
// TapscriptRoot is the optional Merkle root of the tapscript tree if
// this channel is a taproot channel that also commits to a tapscript
// tree (custom channel).
TapscriptRoot fn.Option[chainhash.Hash]
// ExtraOpaqueData is the set of data that was appended to this
// message, some of which we may not actually know how to iterate or
// parse. By holding onto this data, we ensure that we're able to

View File

@ -195,6 +195,11 @@ type PaymentCreationInfo struct {
// PaymentRequest is the full payment request, if any.
PaymentRequest []byte
// FirstHopCustomRecords are the TLV records that are to be sent to the
// first hop of this payment. These records will be transmitted via the
// wire message only and therefore do not affect the onion payload size.
FirstHopCustomRecords lnwire.CustomRecords
}
// htlcBucketKey creates a composite key from prefix and id where the result is
@ -1010,10 +1015,21 @@ func serializePaymentCreationInfo(w io.Writer, c *PaymentCreationInfo) error {
return err
}
// Any remaining bytes are TLV encoded records. Currently, these are
// only the custom records provided by the user to be sent to the first
// hop. But this can easily be extended with further records by merging
// the records into a single TLV stream.
err := c.FirstHopCustomRecords.SerializeTo(w)
if err != nil {
return err
}
return nil
}
func deserializePaymentCreationInfo(r io.Reader) (*PaymentCreationInfo, error) {
func deserializePaymentCreationInfo(r io.Reader) (*PaymentCreationInfo,
error) {
var scratch [8]byte
c := &PaymentCreationInfo{}
@ -1046,6 +1062,15 @@ func deserializePaymentCreationInfo(r io.Reader) (*PaymentCreationInfo, error) {
}
c.PaymentRequest = payReq
// Any remaining bytes are TLV encoded records. Currently, these are
// only the custom records provided by the user to be sent to the first
// hop. But this can easily be extended with further records by merging
// the records into a single TLV stream.
c.FirstHopCustomRecords, err = lnwire.ParseCustomRecordsFrom(r)
if err != nil {
return nil, err
}
return c, nil
}
@ -1071,6 +1096,25 @@ func serializeHTLCAttemptInfo(w io.Writer, a *HTLCAttemptInfo) error {
return err
}
// Merge the fixed/known records together with the custom records to
// serialize them as a single blob. We can't do this in SerializeRoute
// because we're in the middle of the byte stream there. We can only do
// TLV serialization at the end of the stream, since EOF is allowed for
// a stream if no more data is expected.
producers := []tlv.RecordProducer{
&a.Route.FirstHopAmount,
}
tlvData, err := lnwire.MergeAndEncode(
producers, nil, a.Route.FirstHopWireCustomRecords,
)
if err != nil {
return err
}
if _, err := w.Write(tlvData); err != nil {
return err
}
return nil
}
@ -1108,6 +1152,22 @@ func deserializeHTLCAttemptInfo(r io.Reader) (*HTLCAttemptInfo, error) {
a.Hash = &hash
// Read any remaining data (if any) and parse it into the known records
// and custom records.
extraData, err := io.ReadAll(r)
if err != nil {
return nil, err
}
customRecords, _, _, err := lnwire.ParseAndExtractCustomRecords(
extraData, &a.Route.FirstHopAmount,
)
if err != nil {
return nil, err
}
a.Route.FirstHopWireCustomRecords = customRecords
return a, nil
}
@ -1373,6 +1433,8 @@ func SerializeRoute(w io.Writer, r route.Route) error {
}
}
// Any new/extra TLV data is encoded in serializeHTLCAttemptInfo!
return nil
}
@ -1406,5 +1468,7 @@ func DeserializeRoute(r io.Reader) (route.Route, error) {
}
rt.Hops = hops
// Any new/extra TLV data is decoded in deserializeHTLCAttemptInfo!
return rt, nil
}

View File

@ -13,8 +13,10 @@ import (
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/record"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/lightningnetwork/lnd/tlv"
"github.com/stretchr/testify/require"
)
@ -108,7 +110,7 @@ func makeFakeInfo() (*PaymentCreationInfo, *HTLCAttemptInfo) {
// Use single second precision to avoid false positive test
// failures due to the monotonic time component.
CreationTime: time.Unix(time.Now().Unix(), 0),
PaymentRequest: []byte(""),
PaymentRequest: []byte("test"),
}
a := NewHtlcAttempt(
@ -124,51 +126,64 @@ func TestSentPaymentSerialization(t *testing.T) {
c, s := makeFakeInfo()
var b bytes.Buffer
if err := serializePaymentCreationInfo(&b, c); err != nil {
t.Fatalf("unable to serialize creation info: %v", err)
}
require.NoError(t, serializePaymentCreationInfo(&b, c), "serialize")
// Assert the length of the serialized creation info is as expected,
// without any custom records.
baseLength := 32 + 8 + 8 + 4 + len(c.PaymentRequest)
require.Len(t, b.Bytes(), baseLength)
newCreationInfo, err := deserializePaymentCreationInfo(&b)
require.NoError(t, err, "unable to deserialize creation info")
if !reflect.DeepEqual(c, newCreationInfo) {
t.Fatalf("Payments do not match after "+
"serialization/deserialization %v vs %v",
spew.Sdump(c), spew.Sdump(newCreationInfo),
)
}
require.NoError(t, err, "deserialize")
require.Equal(t, c, newCreationInfo)
b.Reset()
if err := serializeHTLCAttemptInfo(&b, s); err != nil {
t.Fatalf("unable to serialize info: %v", err)
// Now we add some custom records to the creation info and serialize it
// again.
c.FirstHopCustomRecords = lnwire.CustomRecords{
lnwire.MinCustomRecordsTlvType: []byte{1, 2, 3},
}
require.NoError(t, serializePaymentCreationInfo(&b, c), "serialize")
newCreationInfo, err = deserializePaymentCreationInfo(&b)
require.NoError(t, err, "deserialize")
require.Equal(t, c, newCreationInfo)
b.Reset()
require.NoError(t, serializeHTLCAttemptInfo(&b, s), "serialize")
newWireInfo, err := deserializeHTLCAttemptInfo(&b)
require.NoError(t, err, "unable to deserialize info")
newWireInfo.AttemptID = s.AttemptID
require.NoError(t, err, "deserialize")
// First we verify all the records match up porperly, as they aren't
// able to be properly compared using reflect.DeepEqual.
err = assertRouteEqual(&s.Route, &newWireInfo.Route)
if err != nil {
t.Fatalf("Routes do not match after "+
"serialization/deserialization: %v", err)
// First we verify all the records match up properly.
require.Equal(t, s.Route, newWireInfo.Route)
// We now add the new fields and custom records to the route and
// serialize it again.
b.Reset()
s.Route.FirstHopAmount = tlv.NewRecordT[tlv.TlvType0](
tlv.NewBigSizeT(lnwire.MilliSatoshi(1234)),
)
s.Route.FirstHopWireCustomRecords = lnwire.CustomRecords{
lnwire.MinCustomRecordsTlvType + 3: []byte{4, 5, 6},
}
require.NoError(t, serializeHTLCAttemptInfo(&b, s), "serialize")
newWireInfo, err = deserializeHTLCAttemptInfo(&b)
require.NoError(t, err, "deserialize")
require.Equal(t, s.Route, newWireInfo.Route)
// Clear routes to allow DeepEqual to compare the remaining fields.
newWireInfo.Route = route.Route{}
s.Route = route.Route{}
newWireInfo.AttemptID = s.AttemptID
// Call session key method to set our cached session key so we can use
// DeepEqual, and assert that our key equals the original key.
require.Equal(t, s.cachedSessionKey, newWireInfo.SessionKey())
if !reflect.DeepEqual(s, newWireInfo) {
t.Fatalf("Payments do not match after "+
"serialization/deserialization %v vs %v",
spew.Sdump(s), spew.Sdump(newWireInfo),
)
}
require.Equal(t, s, newWireInfo)
}
// assertRouteEquals compares to routes for equality and returns an error if

View File

@ -7,6 +7,7 @@ import (
"math"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
@ -16,16 +17,15 @@ import (
const (
// OutputIndexEmpty is used when the output index doesn't exist.
OutputIndexEmpty = math.MaxUint16
)
// A set of tlv type definitions used to serialize the body of
// revocation logs to the database.
//
// NOTE: A migration should be added whenever this list changes.
revLogOurOutputIndexType tlv.Type = 0
revLogTheirOutputIndexType tlv.Type = 1
revLogCommitTxHashType tlv.Type = 2
revLogOurBalanceType tlv.Type = 3
revLogTheirBalanceType tlv.Type = 4
type (
// BigSizeAmount is a type alias for a TLV record of a btcutil.Amount.
BigSizeAmount = tlv.BigSizeT[btcutil.Amount]
// BigSizeMilliSatoshi is a type alias for a TLV record of a
// lnwire.MilliSatoshi.
BigSizeMilliSatoshi = tlv.BigSizeT[lnwire.MilliSatoshi]
)
var (
@ -54,6 +54,74 @@ var (
ErrOutputIndexTooBig = errors.New("output index is over uint16")
)
// SparsePayHash is a type alias for a 32 byte array, which when serialized is
// able to save some space by not including an empty payment hash on disk.
type SparsePayHash [32]byte
// NewSparsePayHash creates a new SparsePayHash from a 32 byte array.
func NewSparsePayHash(rHash [32]byte) SparsePayHash {
return SparsePayHash(rHash)
}
// Record returns a tlv record for the SparsePayHash.
func (s *SparsePayHash) Record() tlv.Record {
// We use a zero for the type here, as this'll be used along with the
// RecordT type.
return tlv.MakeDynamicRecord(
0, s, s.hashLen,
sparseHashEncoder, sparseHashDecoder,
)
}
// hashLen is used by MakeDynamicRecord to return the size of the RHash.
//
// NOTE: for zero hash, we return a length 0.
func (s *SparsePayHash) hashLen() uint64 {
if bytes.Equal(s[:], lntypes.ZeroHash[:]) {
return 0
}
return 32
}
// sparseHashEncoder is the customized encoder which skips encoding the empty
// hash.
func sparseHashEncoder(w io.Writer, val interface{}, buf *[8]byte) error {
v, ok := val.(*SparsePayHash)
if !ok {
return tlv.NewTypeForEncodingErr(val, "SparsePayHash")
}
// If the value is an empty hash, we will skip encoding it.
if bytes.Equal(v[:], lntypes.ZeroHash[:]) {
return nil
}
vArray := (*[32]byte)(v)
return tlv.EBytes32(w, vArray, buf)
}
// sparseHashDecoder is the customized decoder which skips decoding the empty
// hash.
func sparseHashDecoder(r io.Reader, val interface{}, buf *[8]byte,
l uint64) error {
v, ok := val.(*SparsePayHash)
if !ok {
return tlv.NewTypeForEncodingErr(val, "SparsePayHash")
}
// If the length is zero, we will skip encoding the empty hash.
if l == 0 {
return nil
}
vArray := (*[32]byte)(v)
return tlv.DBytes32(r, vArray, buf, 32)
}
// HTLCEntry specifies the minimal info needed to be stored on disk for ALL the
// historical HTLCs, which is useful for constructing RevocationLog when a
// breach is detected.
@ -72,116 +140,90 @@ var (
// made into tlv records without further conversion.
type HTLCEntry struct {
// RHash is the payment hash of the HTLC.
RHash [32]byte
RHash tlv.RecordT[tlv.TlvType0, SparsePayHash]
// RefundTimeout is the absolute timeout on the HTLC that the sender
// must wait before reclaiming the funds in limbo.
RefundTimeout uint32
RefundTimeout tlv.RecordT[tlv.TlvType1, uint32]
// OutputIndex is the output index for this particular HTLC output
// within the commitment transaction.
//
// NOTE: we use uint16 instead of int32 here to save us 2 bytes, which
// gives us a max number of HTLCs of 65K.
OutputIndex uint16
OutputIndex tlv.RecordT[tlv.TlvType2, uint16]
// Incoming denotes whether we're the receiver or the sender of this
// HTLC.
//
// NOTE: this field is the memory representation of the field
// incomingUint.
Incoming bool
Incoming tlv.RecordT[tlv.TlvType3, bool]
// Amt is the amount of satoshis this HTLC escrows.
//
// NOTE: this field is the memory representation of the field amtUint.
Amt btcutil.Amount
Amt tlv.RecordT[tlv.TlvType4, tlv.BigSizeT[btcutil.Amount]]
// amtTlv is the uint64 format of Amt. This field is created so we can
// easily make it into a tlv record and save it to disk.
//
// NOTE: we keep this field for accounting purpose only. If the disk
// space becomes an issue, we could delete this field to save us extra
// 8 bytes.
amtTlv uint64
// CustomBlob is an optional blob that can be used to store information
// specific to revocation handling for a custom channel type.
CustomBlob tlv.OptionalRecordT[tlv.TlvType5, tlv.Blob]
// incomingTlv is the uint8 format of Incoming. This field is created
// so we can easily make it into a tlv record and save it to disk.
incomingTlv uint8
}
// RHashLen is used by MakeDynamicRecord to return the size of the RHash.
//
// NOTE: for zero hash, we return a length 0.
func (h *HTLCEntry) RHashLen() uint64 {
if h.RHash == lntypes.ZeroHash {
return 0
}
return 32
}
// RHashEncoder is the customized encoder which skips encoding the empty hash.
func RHashEncoder(w io.Writer, val interface{}, buf *[8]byte) error {
v, ok := val.(*[32]byte)
if !ok {
return tlv.NewTypeForEncodingErr(val, "RHash")
}
// If the value is an empty hash, we will skip encoding it.
if *v == lntypes.ZeroHash {
return nil
}
return tlv.EBytes32(w, v, buf)
}
// RHashDecoder is the customized decoder which skips decoding the empty hash.
func RHashDecoder(r io.Reader, val interface{}, buf *[8]byte, l uint64) error {
v, ok := val.(*[32]byte)
if !ok {
return tlv.NewTypeForEncodingErr(val, "RHash")
}
// If the length is zero, we will skip encoding the empty hash.
if l == 0 {
return nil
}
return tlv.DBytes32(r, v, buf, 32)
// HtlcIndex is the index of the HTLC in the channel.
HtlcIndex tlv.OptionalRecordT[tlv.TlvType6, uint16]
}
// toTlvStream converts an HTLCEntry record into a tlv representation.
func (h *HTLCEntry) toTlvStream() (*tlv.Stream, error) {
const (
// A set of tlv type definitions used to serialize htlc entries
// to the database. We define it here instead of the head of
// the file to avoid naming conflicts.
//
// NOTE: A migration should be added whenever this list
// changes.
rHashType tlv.Type = 0
refundTimeoutType tlv.Type = 1
outputIndexType tlv.Type = 2
incomingType tlv.Type = 3
amtType tlv.Type = 4
)
records := []tlv.Record{
h.RHash.Record(),
h.RefundTimeout.Record(),
h.OutputIndex.Record(),
h.Incoming.Record(),
h.Amt.Record(),
}
return tlv.NewStream(
tlv.MakeDynamicRecord(
rHashType, &h.RHash, h.RHashLen,
RHashEncoder, RHashDecoder,
h.CustomBlob.WhenSome(func(r tlv.RecordT[tlv.TlvType5, tlv.Blob]) {
records = append(records, r.Record())
})
h.HtlcIndex.WhenSome(func(r tlv.RecordT[tlv.TlvType6, uint16]) {
records = append(records, r.Record())
})
tlv.SortRecords(records)
return tlv.NewStream(records...)
}
// NewHTLCEntryFromHTLC creates a new HTLCEntry from an HTLC.
func NewHTLCEntryFromHTLC(htlc HTLC) (*HTLCEntry, error) {
h := &HTLCEntry{
RHash: tlv.NewRecordT[tlv.TlvType0](
NewSparsePayHash(htlc.RHash),
),
tlv.MakePrimitiveRecord(
refundTimeoutType, &h.RefundTimeout,
RefundTimeout: tlv.NewPrimitiveRecord[tlv.TlvType1](
htlc.RefundTimeout,
),
tlv.MakePrimitiveRecord(
outputIndexType, &h.OutputIndex,
OutputIndex: tlv.NewPrimitiveRecord[tlv.TlvType2](
uint16(htlc.OutputIndex),
),
tlv.MakePrimitiveRecord(incomingType, &h.incomingTlv),
// We will save 3 bytes if the amount is less or equal to
// 4,294,967,295 msat, or roughly 0.043 bitcoin.
tlv.MakeBigSizeRecord(amtType, &h.amtTlv),
)
Incoming: tlv.NewPrimitiveRecord[tlv.TlvType3](htlc.Incoming),
Amt: tlv.NewRecordT[tlv.TlvType4](
tlv.NewBigSizeT(htlc.Amt.ToSatoshis()),
),
HtlcIndex: tlv.SomeRecordT(tlv.NewPrimitiveRecord[tlv.TlvType6](
uint16(htlc.HtlcIndex),
)),
}
if len(htlc.CustomRecords) != 0 {
blob, err := htlc.CustomRecords.Serialize()
if err != nil {
return nil, err
}
h.CustomBlob = tlv.SomeRecordT(
tlv.NewPrimitiveRecord[tlv.TlvType5, tlv.Blob](blob),
)
}
return h, nil
}
// RevocationLog stores the info needed to construct a breach retribution. Its
@ -191,15 +233,15 @@ func (h *HTLCEntry) toTlvStream() (*tlv.Stream, error) {
type RevocationLog struct {
// OurOutputIndex specifies our output index in this commitment. In a
// remote commitment transaction, this is the to remote output index.
OurOutputIndex uint16
OurOutputIndex tlv.RecordT[tlv.TlvType0, uint16]
// TheirOutputIndex specifies their output index in this commitment. In
// a remote commitment transaction, this is the to local output index.
TheirOutputIndex uint16
TheirOutputIndex tlv.RecordT[tlv.TlvType1, uint16]
// CommitTxHash is the hash of the latest version of the commitment
// state, broadcast able by us.
CommitTxHash [32]byte
CommitTxHash tlv.RecordT[tlv.TlvType2, [32]byte]
// HTLCEntries is the set of HTLCEntry's that are pending at this
// particular commitment height.
@ -209,21 +251,65 @@ type RevocationLog struct {
// directly spendable by us. In other words, it is the value of the
// to_remote output on the remote parties' commitment transaction.
//
// NOTE: this is a pointer so that it is clear if the value is zero or
// NOTE: this is an option so that it is clear if the value is zero or
// nil. Since migration 30 of the channeldb initially did not include
// this field, it could be the case that the field is not present for
// all revocation logs.
OurBalance *lnwire.MilliSatoshi
OurBalance tlv.OptionalRecordT[tlv.TlvType3, BigSizeMilliSatoshi]
// TheirBalance is the current available balance within the channel
// directly spendable by the remote node. In other words, it is the
// value of the to_local output on the remote parties' commitment.
//
// NOTE: this is a pointer so that it is clear if the value is zero or
// NOTE: this is an option so that it is clear if the value is zero or
// nil. Since migration 30 of the channeldb initially did not include
// this field, it could be the case that the field is not present for
// all revocation logs.
TheirBalance *lnwire.MilliSatoshi
TheirBalance tlv.OptionalRecordT[tlv.TlvType4, BigSizeMilliSatoshi]
// CustomBlob is an optional blob that can be used to store information
// specific to a custom channel type. This information is only created
// at channel funding time, and after wards is to be considered
// immutable.
CustomBlob tlv.OptionalRecordT[tlv.TlvType5, tlv.Blob]
}
// NewRevocationLog creates a new RevocationLog from the given parameters.
func NewRevocationLog(ourOutputIndex uint16, theirOutputIndex uint16,
commitHash [32]byte, ourBalance,
theirBalance fn.Option[lnwire.MilliSatoshi], htlcs []*HTLCEntry,
customBlob fn.Option[tlv.Blob]) RevocationLog {
rl := RevocationLog{
OurOutputIndex: tlv.NewPrimitiveRecord[tlv.TlvType0](
ourOutputIndex,
),
TheirOutputIndex: tlv.NewPrimitiveRecord[tlv.TlvType1](
theirOutputIndex,
),
CommitTxHash: tlv.NewPrimitiveRecord[tlv.TlvType2](commitHash),
HTLCEntries: htlcs,
}
ourBalance.WhenSome(func(balance lnwire.MilliSatoshi) {
rl.OurBalance = tlv.SomeRecordT(tlv.NewRecordT[tlv.TlvType3](
tlv.NewBigSizeT(balance),
))
})
theirBalance.WhenSome(func(balance lnwire.MilliSatoshi) {
rl.TheirBalance = tlv.SomeRecordT(tlv.NewRecordT[tlv.TlvType4](
tlv.NewBigSizeT(balance),
))
})
customBlob.WhenSome(func(blob tlv.Blob) {
rl.CustomBlob = tlv.SomeRecordT(
tlv.NewPrimitiveRecord[tlv.TlvType5, tlv.Blob](blob),
)
})
return rl
}
// putRevocationLog uses the fields `CommitTx` and `Htlcs` from a
@ -242,15 +328,32 @@ func putRevocationLog(bucket kvdb.RwBucket, commit *ChannelCommitment,
}
rl := &RevocationLog{
OurOutputIndex: uint16(ourOutputIndex),
TheirOutputIndex: uint16(theirOutputIndex),
CommitTxHash: commit.CommitTx.TxHash(),
HTLCEntries: make([]*HTLCEntry, 0, len(commit.Htlcs)),
OurOutputIndex: tlv.NewPrimitiveRecord[tlv.TlvType0](
uint16(ourOutputIndex),
),
TheirOutputIndex: tlv.NewPrimitiveRecord[tlv.TlvType1](
uint16(theirOutputIndex),
),
CommitTxHash: tlv.NewPrimitiveRecord[tlv.TlvType2, [32]byte](
commit.CommitTx.TxHash(),
),
HTLCEntries: make([]*HTLCEntry, 0, len(commit.Htlcs)),
}
commit.CustomBlob.WhenSome(func(blob tlv.Blob) {
rl.CustomBlob = tlv.SomeRecordT(
tlv.NewPrimitiveRecord[tlv.TlvType5, tlv.Blob](blob),
)
})
if !noAmtData {
rl.OurBalance = &commit.LocalBalance
rl.TheirBalance = &commit.RemoteBalance
rl.OurBalance = tlv.SomeRecordT(tlv.NewRecordT[tlv.TlvType3](
tlv.NewBigSizeT(commit.LocalBalance),
))
rl.TheirBalance = tlv.SomeRecordT(tlv.NewRecordT[tlv.TlvType4](
tlv.NewBigSizeT(commit.RemoteBalance),
))
}
for _, htlc := range commit.Htlcs {
@ -265,12 +368,9 @@ func putRevocationLog(bucket kvdb.RwBucket, commit *ChannelCommitment,
return ErrOutputIndexTooBig
}
entry := &HTLCEntry{
RHash: htlc.RHash,
RefundTimeout: htlc.RefundTimeout,
Incoming: htlc.Incoming,
OutputIndex: uint16(htlc.OutputIndex),
Amt: htlc.Amt.ToSatoshis(),
entry, err := NewHTLCEntryFromHTLC(htlc)
if err != nil {
return err
}
rl.HTLCEntries = append(rl.HTLCEntries, entry)
}
@ -306,31 +406,27 @@ func fetchRevocationLog(log kvdb.RBucket,
func serializeRevocationLog(w io.Writer, rl *RevocationLog) error {
// Add the tlv records for all non-optional fields.
records := []tlv.Record{
tlv.MakePrimitiveRecord(
revLogOurOutputIndexType, &rl.OurOutputIndex,
),
tlv.MakePrimitiveRecord(
revLogTheirOutputIndexType, &rl.TheirOutputIndex,
),
tlv.MakePrimitiveRecord(
revLogCommitTxHashType, &rl.CommitTxHash,
),
rl.OurOutputIndex.Record(),
rl.TheirOutputIndex.Record(),
rl.CommitTxHash.Record(),
}
// Now we add any optional fields that are non-nil.
if rl.OurBalance != nil {
lb := uint64(*rl.OurBalance)
records = append(records, tlv.MakeBigSizeRecord(
revLogOurBalanceType, &lb,
))
}
rl.OurBalance.WhenSome(
func(r tlv.RecordT[tlv.TlvType3, BigSizeMilliSatoshi]) {
records = append(records, r.Record())
},
)
if rl.TheirBalance != nil {
rb := uint64(*rl.TheirBalance)
records = append(records, tlv.MakeBigSizeRecord(
revLogTheirBalanceType, &rb,
))
}
rl.TheirBalance.WhenSome(
func(r tlv.RecordT[tlv.TlvType4, BigSizeMilliSatoshi]) {
records = append(records, r.Record())
},
)
rl.CustomBlob.WhenSome(func(r tlv.RecordT[tlv.TlvType5, tlv.Blob]) {
records = append(records, r.Record())
})
// Create the tlv stream.
tlvStream, err := tlv.NewStream(records...)
@ -351,14 +447,6 @@ func serializeRevocationLog(w io.Writer, rl *RevocationLog) error {
// format.
func serializeHTLCEntries(w io.Writer, htlcs []*HTLCEntry) error {
for _, htlc := range htlcs {
// Patch the incomingTlv field.
if htlc.Incoming {
htlc.incomingTlv = 1
}
// Patch the amtTlv field.
htlc.amtTlv = uint64(htlc.Amt)
// Create the tlv stream.
tlvStream, err := htlc.toTlvStream()
if err != nil {
@ -376,27 +464,20 @@ func serializeHTLCEntries(w io.Writer, htlcs []*HTLCEntry) error {
// deserializeRevocationLog deserializes a RevocationLog based on tlv format.
func deserializeRevocationLog(r io.Reader) (RevocationLog, error) {
var (
rl RevocationLog
ourBalance uint64
theirBalance uint64
)
var rl RevocationLog
ourBalance := rl.OurBalance.Zero()
theirBalance := rl.TheirBalance.Zero()
customBlob := rl.CustomBlob.Zero()
// Create the tlv stream.
tlvStream, err := tlv.NewStream(
tlv.MakePrimitiveRecord(
revLogOurOutputIndexType, &rl.OurOutputIndex,
),
tlv.MakePrimitiveRecord(
revLogTheirOutputIndexType, &rl.TheirOutputIndex,
),
tlv.MakePrimitiveRecord(
revLogCommitTxHashType, &rl.CommitTxHash,
),
tlv.MakeBigSizeRecord(revLogOurBalanceType, &ourBalance),
tlv.MakeBigSizeRecord(
revLogTheirBalanceType, &theirBalance,
),
rl.OurOutputIndex.Record(),
rl.TheirOutputIndex.Record(),
rl.CommitTxHash.Record(),
ourBalance.Record(),
theirBalance.Record(),
customBlob.Record(),
)
if err != nil {
return rl, err
@ -408,14 +489,16 @@ func deserializeRevocationLog(r io.Reader) (RevocationLog, error) {
return rl, err
}
if t, ok := parsedTypes[revLogOurBalanceType]; ok && t == nil {
lb := lnwire.MilliSatoshi(ourBalance)
rl.OurBalance = &lb
if t, ok := parsedTypes[ourBalance.TlvType()]; ok && t == nil {
rl.OurBalance = tlv.SomeRecordT(ourBalance)
}
if t, ok := parsedTypes[revLogTheirBalanceType]; ok && t == nil {
rb := lnwire.MilliSatoshi(theirBalance)
rl.TheirBalance = &rb
if t, ok := parsedTypes[theirBalance.TlvType()]; ok && t == nil {
rl.TheirBalance = tlv.SomeRecordT(theirBalance)
}
if t, ok := parsedTypes[customBlob.TlvType()]; ok && t == nil {
rl.CustomBlob = tlv.SomeRecordT(customBlob)
}
// Read the HTLC entries.
@ -432,14 +515,28 @@ func deserializeHTLCEntries(r io.Reader) ([]*HTLCEntry, error) {
for {
var htlc HTLCEntry
customBlob := htlc.CustomBlob.Zero()
htlcIndex := htlc.HtlcIndex.Zero()
// Create the tlv stream.
tlvStream, err := htlc.toTlvStream()
records := []tlv.Record{
htlc.RHash.Record(),
htlc.RefundTimeout.Record(),
htlc.OutputIndex.Record(),
htlc.Incoming.Record(),
htlc.Amt.Record(),
customBlob.Record(),
htlcIndex.Record(),
}
tlvStream, err := tlv.NewStream(records...)
if err != nil {
return nil, err
}
// Read the HTLC entry.
if _, err := readTlvStream(r, tlvStream); err != nil {
parsedTypes, err := readTlvStream(r, tlvStream)
if err != nil {
// We've reached the end when hitting an EOF.
if err == io.ErrUnexpectedEOF {
break
@ -447,13 +544,13 @@ func deserializeHTLCEntries(r io.Reader) ([]*HTLCEntry, error) {
return nil, err
}
// Patch the Incoming field.
if htlc.incomingTlv == 1 {
htlc.Incoming = true
if t, ok := parsedTypes[customBlob.TlvType()]; ok && t == nil {
htlc.CustomBlob = tlv.SomeRecordT(customBlob)
}
// Patch the Amt field.
htlc.Amt = btcutil.Amount(htlc.amtTlv)
if t, ok := parsedTypes[htlcIndex.TlvType()]; ok && t == nil {
htlc.HtlcIndex = tlv.SomeRecordT(htlcIndex)
}
// Append the entry.
htlcs = append(htlcs, &htlc)
@ -469,6 +566,7 @@ func writeTlvStream(w io.Writer, s *tlv.Stream) error {
if err := s.Encode(&b); err != nil {
return err
}
// Write the stream's length as a varint.
err := tlv.WriteVarInt(w, uint64(b.Len()), &[8]byte{})
if err != nil {

View File

@ -8,6 +8,7 @@ import (
"testing"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lntest/channels"
"github.com/lightningnetwork/lnd/lnwire"
@ -33,17 +34,38 @@ var (
0xff, // value = 255
}
customRecords = lnwire.CustomRecords{
lnwire.MinCustomRecordsTlvType + 1: []byte("custom data"),
}
blobBytes = []byte{
// Corresponds to the encoded version of the above custom
// records.
0xfe, 0x00, 0x01, 0x00, 0x01, 0x0b, 0x63, 0x75, 0x73, 0x74,
0x6f, 0x6d, 0x20, 0x64, 0x61, 0x74, 0x61,
}
testHTLCEntry = HTLCEntry{
RefundTimeout: 740_000,
OutputIndex: 10,
Incoming: true,
Amt: 1000_000,
amtTlv: 1000_000,
incomingTlv: 1,
RefundTimeout: tlv.NewPrimitiveRecord[tlv.TlvType1, uint32](
740_000,
),
OutputIndex: tlv.NewPrimitiveRecord[tlv.TlvType2, uint16](
10,
),
Incoming: tlv.NewPrimitiveRecord[tlv.TlvType3](true),
Amt: tlv.NewRecordT[tlv.TlvType4](
tlv.NewBigSizeT(btcutil.Amount(1_000_000)),
),
CustomBlob: tlv.SomeRecordT(
tlv.NewPrimitiveRecord[tlv.TlvType5](blobBytes),
),
HtlcIndex: tlv.SomeRecordT(
tlv.NewPrimitiveRecord[tlv.TlvType6, uint16](0x33),
),
}
testHTLCEntryBytes = []byte{
// Body length 23.
0x16,
// Body length 45.
0x2d,
// Rhash tlv.
0x0, 0x0,
// RefundTimeout tlv.
@ -54,6 +76,45 @@ var (
0x3, 0x1, 0x1,
// Amt tlv.
0x4, 0x5, 0xfe, 0x0, 0xf, 0x42, 0x40,
// Custom blob tlv.
0x5, 0x11, 0xfe, 0x00, 0x01, 0x00, 0x01, 0x0b, 0x63, 0x75, 0x73,
0x74, 0x6f, 0x6d, 0x20, 0x64, 0x61, 0x74, 0x61,
// HLTC index tlv.
0x6, 0x2, 0x0, 0x33,
}
testHTLCEntryHash = HTLCEntry{
RHash: tlv.NewPrimitiveRecord[tlv.TlvType0](NewSparsePayHash(
[32]byte{0x33, 0x44, 0x55},
)),
RefundTimeout: tlv.NewPrimitiveRecord[tlv.TlvType1, uint32](
740_000,
),
OutputIndex: tlv.NewPrimitiveRecord[tlv.TlvType2, uint16](
10,
),
Incoming: tlv.NewPrimitiveRecord[tlv.TlvType3](true),
Amt: tlv.NewRecordT[tlv.TlvType4](
tlv.NewBigSizeT(btcutil.Amount(1_000_000)),
),
}
testHTLCEntryHashBytes = []byte{
// Body length 54.
0x36,
// Rhash tlv.
0x0, 0x20,
0x33, 0x44, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// RefundTimeout tlv.
0x1, 0x4, 0x0, 0xb, 0x4a, 0xa0,
// OutputIndex tlv.
0x2, 0x2, 0x0, 0xa,
// Incoming tlv.
0x3, 0x1, 0x1,
// Amt tlv.
0x4, 0x5, 0xfe, 0x0, 0xf, 0x42, 0x40,
}
localBalance = lnwire.MilliSatoshi(9000)
@ -68,24 +129,29 @@ var (
CommitTx: channels.TestFundingTx,
CommitSig: bytes.Repeat([]byte{1}, 71),
Htlcs: []HTLC{{
RefundTimeout: testHTLCEntry.RefundTimeout,
OutputIndex: int32(testHTLCEntry.OutputIndex),
Incoming: testHTLCEntry.Incoming,
Amt: lnwire.NewMSatFromSatoshis(
testHTLCEntry.Amt,
RefundTimeout: testHTLCEntry.RefundTimeout.Val,
OutputIndex: int32(testHTLCEntry.OutputIndex.Val),
HtlcIndex: uint64(
testHTLCEntry.HtlcIndex.ValOpt().
UnsafeFromSome(),
),
Incoming: testHTLCEntry.Incoming.Val,
Amt: lnwire.NewMSatFromSatoshis(
testHTLCEntry.Amt.Val.Int(),
),
CustomRecords: customRecords,
}},
CustomBlob: fn.Some(blobBytes),
}
testRevocationLogNoAmts = RevocationLog{
OurOutputIndex: 0,
TheirOutputIndex: 1,
CommitTxHash: testChannelCommit.CommitTx.TxHash(),
HTLCEntries: []*HTLCEntry{&testHTLCEntry},
}
testRevocationLogNoAmts = NewRevocationLog(
0, 1, testChannelCommit.CommitTx.TxHash(),
fn.None[lnwire.MilliSatoshi](), fn.None[lnwire.MilliSatoshi](),
[]*HTLCEntry{&testHTLCEntry}, fn.Some(blobBytes),
)
testRevocationLogNoAmtsBytes = []byte{
// Body length 42.
0x2a,
// Body length 61.
0x3d,
// OurOutputIndex tlv.
0x0, 0x2, 0x0, 0x0,
// TheirOutputIndex tlv.
@ -96,19 +162,19 @@ var (
0x6e, 0x60, 0x29, 0x23, 0x1d, 0x5e, 0xc5, 0xe6,
0xbd, 0xf7, 0xd3, 0x9b, 0x16, 0x7d, 0x0, 0xff,
0xc8, 0x22, 0x51, 0xb1, 0x5b, 0xa0, 0xbf, 0xd,
// Custom blob tlv.
0x5, 0x11, 0xfe, 0x00, 0x01, 0x00, 0x01, 0x0b, 0x63, 0x75, 0x73,
0x74, 0x6f, 0x6d, 0x20, 0x64, 0x61, 0x74, 0x61,
}
testRevocationLogWithAmts = RevocationLog{
OurOutputIndex: 0,
TheirOutputIndex: 1,
CommitTxHash: testChannelCommit.CommitTx.TxHash(),
HTLCEntries: []*HTLCEntry{&testHTLCEntry},
OurBalance: &localBalance,
TheirBalance: &remoteBalance,
}
testRevocationLogWithAmts = NewRevocationLog(
0, 1, testChannelCommit.CommitTx.TxHash(),
fn.Some(localBalance), fn.Some(remoteBalance),
[]*HTLCEntry{&testHTLCEntry}, fn.Some(blobBytes),
)
testRevocationLogWithAmtsBytes = []byte{
// Body length 52.
0x34,
// Body length 71.
0x47,
// OurOutputIndex tlv.
0x0, 0x2, 0x0, 0x0,
// TheirOutputIndex tlv.
@ -123,6 +189,9 @@ var (
0x3, 0x3, 0xfd, 0x23, 0x28,
// Remote Balance.
0x4, 0x3, 0xfd, 0x0b, 0xb8,
// Custom blob tlv.
0x5, 0x11, 0xfe, 0x00, 0x01, 0x00, 0x01, 0x0b, 0x63, 0x75, 0x73,
0x74, 0x6f, 0x6d, 0x20, 0x64, 0x61, 0x74, 0x61,
}
)
@ -193,11 +262,6 @@ func TestSerializeHTLCEntriesEmptyRHash(t *testing.T) {
// Copy the testHTLCEntry.
entry := testHTLCEntry
// Set the internal fields to empty values so we can test the bytes are
// padded.
entry.incomingTlv = 0
entry.amtTlv = 0
// Write the tlv stream.
buf := bytes.NewBuffer([]byte{})
err := serializeHTLCEntries(buf, []*HTLCEntry{&entry})
@ -207,6 +271,21 @@ func TestSerializeHTLCEntriesEmptyRHash(t *testing.T) {
require.Equal(t, testHTLCEntryBytes, buf.Bytes())
}
func TestSerializeHTLCEntriesWithRHash(t *testing.T) {
t.Parallel()
// Copy the testHTLCEntry.
entry := testHTLCEntryHash
// Write the tlv stream.
buf := bytes.NewBuffer([]byte{})
err := serializeHTLCEntries(buf, []*HTLCEntry{&entry})
require.NoError(t, err)
// Check the bytes are read as expected.
require.Equal(t, testHTLCEntryHashBytes, buf.Bytes())
}
func TestSerializeHTLCEntries(t *testing.T) {
t.Parallel()
@ -215,7 +294,7 @@ func TestSerializeHTLCEntries(t *testing.T) {
// Create a fake rHash.
rHashBytes := bytes.Repeat([]byte{10}, 32)
copy(entry.RHash[:], rHashBytes)
copy(entry.RHash.Val[:], rHashBytes)
// Construct the serialized bytes.
//
@ -224,7 +303,7 @@ func TestSerializeHTLCEntries(t *testing.T) {
partialBytes := testHTLCEntryBytes[3:]
// Write the total length and RHash tlv.
expectedBytes := []byte{0x36, 0x0, 0x20}
expectedBytes := []byte{0x4d, 0x0, 0x20}
expectedBytes = append(expectedBytes, rHashBytes...)
// Append the rest.
@ -269,7 +348,7 @@ func TestSerializeAndDeserializeRevLog(t *testing.T) {
t, &test.revLog, test.revLogBytes,
)
testDerializeRevocationLog(
testDeserializeRevocationLog(
t, &test.revLog, test.revLogBytes,
)
})
@ -293,7 +372,7 @@ func testSerializeRevocationLog(t *testing.T, rl *RevocationLog,
require.Equal(t, revLogBytes, buf.Bytes()[:bodyIndex])
}
func testDerializeRevocationLog(t *testing.T, revLog *RevocationLog,
func testDeserializeRevocationLog(t *testing.T, revLog *RevocationLog,
revLogBytes []byte) {
// Construct the full bytes.
@ -309,7 +388,7 @@ func testDerializeRevocationLog(t *testing.T, revLog *RevocationLog,
require.Equal(t, *revLog, rl)
}
func TestDerializeHTLCEntriesEmptyRHash(t *testing.T) {
func TestDeserializeHTLCEntriesEmptyRHash(t *testing.T) {
t.Parallel()
// Read the tlv stream.
@ -322,7 +401,7 @@ func TestDerializeHTLCEntriesEmptyRHash(t *testing.T) {
require.Equal(t, &testHTLCEntry, htlcs[0])
}
func TestDerializeHTLCEntries(t *testing.T) {
func TestDeserializeHTLCEntries(t *testing.T) {
t.Parallel()
// Copy the testHTLCEntry.
@ -330,7 +409,7 @@ func TestDerializeHTLCEntries(t *testing.T) {
// Create a fake rHash.
rHashBytes := bytes.Repeat([]byte{10}, 32)
copy(entry.RHash[:], rHashBytes)
copy(entry.RHash.Val[:], rHashBytes)
// Construct the serialized bytes.
//
@ -339,7 +418,7 @@ func TestDerializeHTLCEntries(t *testing.T) {
partialBytes := testHTLCEntryBytes[3:]
// Write the total length and RHash tlv.
testBytes := append([]byte{0x36, 0x0, 0x20}, rHashBytes...)
testBytes := append([]byte{0x4d, 0x0, 0x20}, rHashBytes...)
// Append the rest.
testBytes = append(testBytes, partialBytes...)
@ -398,11 +477,11 @@ func TestDeleteLogBucket(t *testing.T) {
err = kvdb.Update(backend, func(tx kvdb.RwTx) error {
// Create the buckets.
chanBucket, _, err := createTestRevocatoinLogBuckets(tx)
chanBucket, _, err := createTestRevocationLogBuckets(tx)
require.NoError(t, err)
// Create the buckets again should give us an error.
_, _, err = createTestRevocatoinLogBuckets(tx)
_, _, err = createTestRevocationLogBuckets(tx)
require.ErrorIs(t, err, kvdb.ErrBucketExists)
// Delete both buckets.
@ -410,7 +489,7 @@ func TestDeleteLogBucket(t *testing.T) {
require.NoError(t, err)
// Create the buckets again should give us NO error.
_, _, err = createTestRevocatoinLogBuckets(tx)
_, _, err = createTestRevocationLogBuckets(tx)
return err
}, func() {})
require.NoError(t, err)
@ -516,7 +595,7 @@ func TestPutRevocationLog(t *testing.T) {
// Construct the testing db transaction.
dbTx := func(tx kvdb.RwTx) (RevocationLog, error) {
// Create the buckets.
_, bucket, err := createTestRevocatoinLogBuckets(tx)
_, bucket, err := createTestRevocationLogBuckets(tx)
require.NoError(t, err)
// Save the log.
@ -686,7 +765,7 @@ func TestFetchRevocationLogCompatible(t *testing.T) {
}
}
func createTestRevocatoinLogBuckets(tx kvdb.RwTx) (kvdb.RwBucket,
func createTestRevocationLogBuckets(tx kvdb.RwTx) (kvdb.RwBucket,
kvdb.RwBucket, error) {
chanBucket, err := tx.CreateTopLevelBucket(openChannelBucket)

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"regexp"
@ -42,7 +42,7 @@ func parseTime(s string, base time.Time) (uint64, error) {
var lightningPrefix = "lightning:"
// stripPrefix removes accidentally copied 'lightning:' prefix.
func stripPrefix(s string) string {
// StripPrefix removes accidentally copied 'lightning:' prefix.
func StripPrefix(s string) string {
return strings.TrimSpace(strings.TrimPrefix(s, lightningPrefix))
}

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"testing"
@ -111,7 +111,7 @@ func TestStripPrefix(t *testing.T) {
t.Parallel()
for _, test := range stripPrefixTests {
actual := stripPrefix(test.in)
actual := StripPrefix(test.in)
require.Equal(t, test.expected, actual)
}
}

View File

@ -1,7 +1,7 @@
//go:build autopilotrpc
// +build autopilotrpc
package main
package commands
import (
"github.com/lightningnetwork/lnd/lnrpc/autopilotrpc"

View File

@ -1,7 +1,7 @@
//go:build !autopilotrpc
// +build !autopilotrpc
package main
package commands
import "github.com/urfave/cli"

View File

@ -1,7 +1,7 @@
//go:build chainrpc
// +build chainrpc
package main
package commands
import (
"bytes"

View File

@ -1,7 +1,7 @@
//go:build !chainrpc
// +build !chainrpc
package main
package commands
import "github.com/urfave/cli"

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"encoding/hex"

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"bytes"

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"context"

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"encoding/hex"
@ -9,7 +9,7 @@ import (
"github.com/urfave/cli"
)
var addInvoiceCommand = cli.Command{
var AddInvoiceCommand = cli.Command{
Name: "addinvoice",
Category: "Invoices",
Usage: "Add a new invoice.",
@ -408,7 +408,7 @@ func decodePayReq(ctx *cli.Context) error {
}
resp, err := client.DecodePayReq(ctxc, &lnrpc.PayReqString{
PayReq: stripPrefix(payreq),
PayReq: StripPrefix(payreq),
})
if err != nil {
return err

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"bytes"

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"fmt"
@ -265,6 +265,7 @@ func setCfg(ctx *cli.Context) error {
Config: mcCfg.Config,
},
)
return err
}
@ -366,5 +367,6 @@ func resetMissionControl(ctx *cli.Context) error {
req := &routerrpc.ResetMissionControlRequest{}
_, err := client.ResetMissionControl(ctxc, req)
return err
}

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"bytes"

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"bytes"
@ -25,6 +25,7 @@ import (
"github.com/lightningnetwork/lnd/record"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/urfave/cli"
"google.golang.org/grpc"
)
const (
@ -152,8 +153,8 @@ var (
}
)
// paymentFlags returns common flags for sendpayment and payinvoice.
func paymentFlags() []cli.Flag {
// PaymentFlags returns common flags for sendpayment and payinvoice.
func PaymentFlags() []cli.Flag {
return []cli.Flag{
cli.StringFlag{
Name: "pay_req",
@ -202,7 +203,7 @@ func paymentFlags() []cli.Flag {
}
}
var sendPaymentCommand = cli.Command{
var SendPaymentCommand = cli.Command{
Name: "sendpayment",
Category: "Payments",
Usage: "Send a payment over lightning.",
@ -226,7 +227,7 @@ var sendPaymentCommand = cli.Command{
`,
ArgsUsage: "dest amt payment_hash final_cltv_delta pay_addr | " +
"--pay_req=R [--pay_addr=H]",
Flags: append(paymentFlags(),
Flags: append(PaymentFlags(),
cli.StringFlag{
Name: "dest, d",
Usage: "the compressed identity pubkey of the " +
@ -253,7 +254,7 @@ var sendPaymentCommand = cli.Command{
Usage: "will generate a pre-image and encode it in the sphinx packet, a dest must be set [experimental]",
},
),
Action: sendPayment,
Action: SendPayment,
}
// retrieveFeeLimit retrieves the fee limit based on the different fee limit
@ -324,20 +325,23 @@ func parsePayAddr(ctx *cli.Context, args cli.Args) ([]byte, error) {
return payAddr, nil
}
func sendPayment(ctx *cli.Context) error {
func SendPayment(ctx *cli.Context) error {
// Show command help if no arguments provided
if ctx.NArg() == 0 && ctx.NumFlags() == 0 {
_ = cli.ShowCommandHelp(ctx, "sendpayment")
return nil
}
conn := getClientConn(ctx, false)
defer conn.Close()
args := ctx.Args()
// If a payment request was provided, we can exit early since all of the
// details of the payment are encoded within the request.
if ctx.IsSet("pay_req") {
req := &routerrpc.SendPaymentRequest{
PaymentRequest: stripPrefix(ctx.String("pay_req")),
PaymentRequest: StripPrefix(ctx.String("pay_req")),
Amt: ctx.Int64("amt"),
DestCustomRecords: make(map[uint64][]byte),
Amp: ctx.Bool(ampFlag.Name),
@ -357,7 +361,9 @@ func sendPayment(ctx *cli.Context) error {
req.PaymentAddr = payAddr
return sendPaymentRequest(ctx, req)
return SendPaymentRequest(
ctx, req, conn, conn, routerRPCSendPayment,
)
}
var (
@ -466,19 +472,29 @@ func sendPayment(ctx *cli.Context) error {
req.PaymentAddr = payAddr
return sendPaymentRequest(ctx, req)
return SendPaymentRequest(ctx, req, conn, conn, routerRPCSendPayment)
}
func sendPaymentRequest(ctx *cli.Context,
req *routerrpc.SendPaymentRequest) error {
// SendPaymentFn is a function type that abstracts the SendPaymentV2 call of the
// router client.
type SendPaymentFn func(ctx context.Context, payConn grpc.ClientConnInterface,
req *routerrpc.SendPaymentRequest) (PaymentResultStream, error)
// routerRPCSendPayment is the default implementation of the SendPaymentFn type
// that uses the lnd routerrpc.SendPaymentV2 call.
func routerRPCSendPayment(ctx context.Context, payConn grpc.ClientConnInterface,
req *routerrpc.SendPaymentRequest) (PaymentResultStream, error) {
return routerrpc.NewRouterClient(payConn).SendPaymentV2(ctx, req)
}
func SendPaymentRequest(ctx *cli.Context, req *routerrpc.SendPaymentRequest,
lnConn, paymentConn grpc.ClientConnInterface,
callSendPayment SendPaymentFn) error {
ctxc := getContext()
conn := getClientConn(ctx, false)
defer conn.Close()
client := lnrpc.NewLightningClient(conn)
routerClient := routerrpc.NewRouterClient(conn)
lnClient := lnrpc.NewLightningClient(lnConn)
outChan := ctx.Int64Slice("outgoing_chan_id")
if len(outChan) != 0 {
@ -558,7 +574,7 @@ func sendPaymentRequest(ctx *cli.Context,
if req.PaymentRequest != "" {
// Decode payment request to find out the amount.
decodeReq := &lnrpc.PayReqString{PayReq: req.PaymentRequest}
decodeResp, err := client.DecodePayReq(ctxc, decodeReq)
decodeResp, err := lnClient.DecodePayReq(ctxc, decodeReq)
if err != nil {
return err
}
@ -602,14 +618,12 @@ func sendPaymentRequest(ctx *cli.Context,
printJSON := ctx.Bool(jsonFlag.Name)
req.NoInflightUpdates = !ctx.Bool(inflightUpdatesFlag.Name) && printJSON
stream, err := routerClient.SendPaymentV2(ctxc, req)
stream, err := callSendPayment(ctxc, paymentConn, req)
if err != nil {
return err
}
finalState, err := printLivePayment(
ctxc, stream, client, printJSON,
)
finalState, err := PrintLivePayment(ctxc, stream, lnClient, printJSON)
if err != nil {
return err
}
@ -667,24 +681,29 @@ func trackPayment(ctx *cli.Context) error {
}
client := lnrpc.NewLightningClient(conn)
_, err = printLivePayment(ctxc, stream, client, ctx.Bool(jsonFlag.Name))
_, err = PrintLivePayment(ctxc, stream, client, ctx.Bool(jsonFlag.Name))
return err
}
// printLivePayment receives payment updates from the given stream and either
// PaymentResultStream is an interface that abstracts the Recv method of the
// SendPaymentV2 or TrackPaymentV2 client stream.
type PaymentResultStream interface {
Recv() (*lnrpc.Payment, error)
}
// PrintLivePayment receives payment updates from the given stream and either
// outputs them as json or as a more user-friendly formatted table. The table
// option uses terminal control codes to rewrite the output. This call
// terminates when the payment reaches a final state.
func printLivePayment(ctxc context.Context,
stream routerrpc.Router_TrackPaymentV2Client,
client lnrpc.LightningClient, json bool) (*lnrpc.Payment, error) {
func PrintLivePayment(ctxc context.Context, stream PaymentResultStream,
lnClient lnrpc.LightningClient, json bool) (*lnrpc.Payment, error) {
// Terminal escape codes aren't supported on Windows, fall back to json.
if !json && runtime.GOOS == "windows" {
json = true
}
aliases := newAliasCache(client)
aliases := newAliasCache(lnClient)
first := true
var lastLineCount int
@ -706,17 +725,17 @@ func printLivePayment(ctxc context.Context,
// Write raw json to stdout.
printRespJSON(payment)
} else {
table := formatPayment(ctxc, payment, aliases)
resultTable := formatPayment(ctxc, payment, aliases)
// Clear all previously written lines and print the
// updated table.
clearLines(lastLineCount)
fmt.Print(table)
fmt.Print(resultTable)
// Store the number of lines written for the next update
// pass.
lastLineCount = 0
for _, b := range table {
for _, b := range resultTable {
if b == '\n' {
lastLineCount++
}
@ -874,7 +893,7 @@ var payInvoiceCommand = cli.Command{
This command is a shortcut for 'sendpayment --pay_req='.
`,
ArgsUsage: "pay_req",
Flags: append(paymentFlags(),
Flags: append(PaymentFlags(),
cli.Int64Flag{
Name: "amt",
Usage: "(optional) number of satoshis to fulfill the " +
@ -885,6 +904,9 @@ var payInvoiceCommand = cli.Command{
}
func payInvoice(ctx *cli.Context) error {
conn := getClientConn(ctx, false)
defer conn.Close()
args := ctx.Args()
var payReq string
@ -898,14 +920,14 @@ func payInvoice(ctx *cli.Context) error {
}
req := &routerrpc.SendPaymentRequest{
PaymentRequest: stripPrefix(payReq),
PaymentRequest: StripPrefix(payReq),
Amt: ctx.Int64("amt"),
DestCustomRecords: make(map[uint64][]byte),
Amp: ctx.Bool(ampFlag.Name),
Cancelable: ctx.Bool(cancelableFlag.Name),
}
return sendPaymentRequest(ctx, req)
return SendPaymentRequest(ctx, req, conn, conn, routerRPCSendPayment)
}
var sendToRouteCommand = cli.Command{
@ -1900,7 +1922,7 @@ func estimateRouteFee(ctx *cli.Context) error {
req.AmtSat = amtSat
case ctx.IsSet("pay_req"):
req.PaymentRequest = stripPrefix(ctx.String("pay_req"))
req.PaymentRequest = StripPrefix(ctx.String("pay_req"))
if ctx.IsSet("timeout") {
req.Timeout = uint32(ctx.Duration("timeout").Seconds())
}

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"fmt"

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"context"

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"errors"

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"fmt"

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"bufio"

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"bufio"
@ -11,6 +11,7 @@ import (
"io"
"math"
"os"
"regexp"
"strconv"
"strings"
"sync"
@ -41,8 +42,49 @@ const (
defaultUtxoMinConf = 1
)
var errBadChanPoint = errors.New("expecting chan_point to be in format of: " +
"txid:index")
var (
errBadChanPoint = errors.New(
"expecting chan_point to be in format of: txid:index",
)
customDataPattern = regexp.MustCompile(
`"custom_channel_data":\s*"([0-9a-f]+)"`,
)
)
// replaceCustomData replaces the custom channel data hex string with the
// decoded custom channel data in the JSON response.
func replaceCustomData(jsonBytes []byte) []byte {
// If there's nothing to replace, return the original JSON.
if !customDataPattern.Match(jsonBytes) {
return jsonBytes
}
replacedBytes := customDataPattern.ReplaceAllFunc(
jsonBytes, func(match []byte) []byte {
encoded := customDataPattern.FindStringSubmatch(
string(match),
)[1]
decoded, err := hex.DecodeString(encoded)
if err != nil {
return match
}
return []byte("\"custom_channel_data\":" +
string(decoded))
},
)
var buf bytes.Buffer
err := json.Indent(&buf, replacedBytes, "", " ")
if err != nil {
// If we can't indent the JSON, it likely means the replacement
// data wasn't correct, so we return the original JSON.
return jsonBytes
}
return buf.Bytes()
}
func getContext() context.Context {
shutdownInterceptor, err := signal.Intercept()
@ -66,9 +108,9 @@ func printJSON(resp interface{}) {
}
var out bytes.Buffer
json.Indent(&out, b, "", "\t")
out.WriteString("\n")
out.WriteTo(os.Stdout)
_ = json.Indent(&out, b, "", " ")
_, _ = out.WriteString("\n")
_, _ = out.WriteTo(os.Stdout)
}
func printRespJSON(resp proto.Message) {
@ -78,7 +120,9 @@ func printRespJSON(resp proto.Message) {
return
}
fmt.Printf("%s\n", jsonBytes)
jsonBytesReplaced := replaceCustomData(jsonBytes)
fmt.Printf("%s\n", jsonBytesReplaced)
}
// actionDecorator is used to add additional information and error handling
@ -1442,15 +1486,15 @@ func walletBalance(ctx *cli.Context) error {
return nil
}
var channelBalanceCommand = cli.Command{
var ChannelBalanceCommand = cli.Command{
Name: "channelbalance",
Category: "Channels",
Usage: "Returns the sum of the total available channel balance across " +
"all open channels.",
Action: actionDecorator(channelBalance),
Action: actionDecorator(ChannelBalance),
}
func channelBalance(ctx *cli.Context) error {
func ChannelBalance(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -1575,7 +1619,7 @@ func pendingChannels(ctx *cli.Context) error {
return nil
}
var listChannelsCommand = cli.Command{
var ListChannelsCommand = cli.Command{
Name: "listchannels",
Category: "Channels",
Usage: "List all open channels.",
@ -1608,7 +1652,7 @@ var listChannelsCommand = cli.Command{
"order to improve performance",
},
},
Action: actionDecorator(listChannels),
Action: actionDecorator(ListChannels),
}
var listAliasesCommand = cli.Command{
@ -1616,10 +1660,10 @@ var listAliasesCommand = cli.Command{
Category: "Channels",
Usage: "List all aliases.",
Flags: []cli.Flag{},
Action: actionDecorator(listaliases),
Action: actionDecorator(listAliases),
}
func listaliases(ctx *cli.Context) error {
func listAliases(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()
@ -1636,7 +1680,7 @@ func listaliases(ctx *cli.Context) error {
return nil
}
func listChannels(ctx *cli.Context) error {
func ListChannels(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"encoding/hex"
@ -120,3 +120,74 @@ func TestParseTimeLockDelta(t *testing.T) {
}
}
}
// TestReplaceCustomData tests that hex encoded custom data can be formatted as
// JSON in the console output.
func TestReplaceCustomData(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
data string
replaceData string
expected string
}{
{
name: "no replacement necessary",
data: "foo",
expected: "foo",
},
{
name: "valid json with replacement",
data: "{\"foo\":\"bar\",\"custom_channel_data\":\"" +
hex.EncodeToString([]byte(
"{\"bar\":\"baz\"}",
)) + "\"}",
expected: `{
"foo": "bar",
"custom_channel_data": {
"bar": "baz"
}
}`,
},
{
name: "valid json with replacement and space",
data: "{\"foo\":\"bar\",\"custom_channel_data\": \"" +
hex.EncodeToString([]byte(
"{\"bar\":\"baz\"}",
)) + "\"}",
expected: `{
"foo": "bar",
"custom_channel_data": {
"bar": "baz"
}
}`,
},
{
name: "doesn't match pattern, returned identical",
data: "this ain't even json, and no custom data " +
"either",
expected: "this ain't even json, and no custom data " +
"either",
},
{
name: "invalid json",
data: "this ain't json, " +
"\"custom_channel_data\":\"a\"",
expected: "this ain't json, " +
"\"custom_channel_data\":\"a\"",
},
{
name: "valid json, invalid hex, just formatted",
data: "{\"custom_channel_data\":\"f\"}",
expected: "{\n \"custom_channel_data\": \"f\"\n}",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := replaceCustomData([]byte(tc.data))
require.Equal(t, tc.expected, string(result))
})
}
}

View File

@ -1,7 +1,7 @@
//go:build dev
// +build dev
package main
package commands
import (
"fmt"

View File

@ -1,7 +1,7 @@
//go:build !dev
// +build !dev
package main
package commands
import "github.com/urfave/cli"

View File

@ -1,7 +1,7 @@
//go:build invoicesrpc
// +build invoicesrpc
package main
package commands
import (
"encoding/hex"

View File

@ -1,7 +1,7 @@
//go:build !invoicesrpc
// +build !invoicesrpc
package main
package commands
import "github.com/urfave/cli"

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"encoding/base64"

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"encoding/hex"

601
cmd/commands/main.go Normal file
View File

@ -0,0 +1,601 @@
// Copyright (c) 2013-2017 The btcsuite developers
// Copyright (c) 2015-2016 The Decred developers
// Copyright (C) 2015-2024 The Lightning Network Developers
package commands
import (
"context"
"crypto/tls"
"fmt"
"net"
"os"
"path/filepath"
"strings"
"syscall"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/build"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/macaroons"
"github.com/lightningnetwork/lnd/tor"
"github.com/urfave/cli"
"golang.org/x/term"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
)
const (
defaultDataDir = "data"
defaultChainSubDir = "chain"
defaultTLSCertFilename = "tls.cert"
defaultMacaroonFilename = "admin.macaroon"
defaultRPCPort = "10009"
defaultRPCHostPort = "localhost:" + defaultRPCPort
envVarRPCServer = "LNCLI_RPCSERVER"
envVarLNDDir = "LNCLI_LNDDIR"
envVarSOCKSProxy = "LNCLI_SOCKSPROXY"
envVarTLSCertPath = "LNCLI_TLSCERTPATH"
envVarChain = "LNCLI_CHAIN"
envVarNetwork = "LNCLI_NETWORK"
envVarMacaroonPath = "LNCLI_MACAROONPATH"
envVarMacaroonTimeout = "LNCLI_MACAROONTIMEOUT"
envVarMacaroonIP = "LNCLI_MACAROONIP"
envVarProfile = "LNCLI_PROFILE"
envVarMacFromJar = "LNCLI_MACFROMJAR"
)
var (
DefaultLndDir = btcutil.AppDataDir("lnd", false)
defaultTLSCertPath = filepath.Join(
DefaultLndDir, defaultTLSCertFilename,
)
// maxMsgRecvSize is the largest message our client will receive. We
// set this to 200MiB atm.
maxMsgRecvSize = grpc.MaxCallRecvMsgSize(lnrpc.MaxGrpcMsgSize)
)
func fatal(err error) {
fmt.Fprintf(os.Stderr, "[lncli] %v\n", err)
os.Exit(1)
}
func getWalletUnlockerClient(ctx *cli.Context) (lnrpc.WalletUnlockerClient,
func()) {
conn := getClientConn(ctx, true)
cleanUp := func() {
conn.Close()
}
return lnrpc.NewWalletUnlockerClient(conn), cleanUp
}
func getStateServiceClient(ctx *cli.Context) (lnrpc.StateClient, func()) {
conn := getClientConn(ctx, true)
cleanUp := func() {
conn.Close()
}
return lnrpc.NewStateClient(conn), cleanUp
}
func getClient(ctx *cli.Context) (lnrpc.LightningClient, func()) {
conn := getClientConn(ctx, false)
cleanUp := func() {
conn.Close()
}
return lnrpc.NewLightningClient(conn), cleanUp
}
func getClientConn(ctx *cli.Context, skipMacaroons bool) *grpc.ClientConn {
// First, we'll get the selected stored profile or an ephemeral one
// created from the global options in the CLI context.
profile, err := getGlobalOptions(ctx, skipMacaroons)
if err != nil {
fatal(fmt.Errorf("could not load global options: %w", err))
}
// Create a dial options array.
opts := []grpc.DialOption{
grpc.WithUnaryInterceptor(
addMetadataUnaryInterceptor(profile.Metadata),
),
grpc.WithStreamInterceptor(
addMetaDataStreamInterceptor(profile.Metadata),
),
}
if profile.Insecure {
opts = append(opts, grpc.WithInsecure())
} else {
// Load the specified TLS certificate.
certPool, err := profile.cert()
if err != nil {
fatal(fmt.Errorf("could not create cert pool: %w", err))
}
// Build transport credentials from the certificate pool. If
// there is no certificate pool, we expect the server to use a
// non-self-signed certificate such as a certificate obtained
// from Let's Encrypt.
var creds credentials.TransportCredentials
if certPool != nil {
creds = credentials.NewClientTLSFromCert(certPool, "")
} else {
// Fallback to the system pool. Using an empty tls
// config is an alternative to x509.SystemCertPool().
// That call is not supported on Windows.
creds = credentials.NewTLS(&tls.Config{})
}
opts = append(opts, grpc.WithTransportCredentials(creds))
}
// Only process macaroon credentials if --no-macaroons isn't set and
// if we're not skipping macaroon processing.
if !profile.NoMacaroons && !skipMacaroons {
// Find out which macaroon to load.
macName := profile.Macaroons.Default
if ctx.GlobalIsSet("macfromjar") {
macName = ctx.GlobalString("macfromjar")
}
var macEntry *macaroonEntry
for _, entry := range profile.Macaroons.Jar {
if entry.Name == macName {
macEntry = entry
break
}
}
if macEntry == nil {
fatal(fmt.Errorf("macaroon with name '%s' not found "+
"in profile", macName))
}
// Get and possibly decrypt the specified macaroon.
//
// TODO(guggero): Make it possible to cache the password so we
// don't need to ask for it every time.
mac, err := macEntry.loadMacaroon(readPassword)
if err != nil {
fatal(fmt.Errorf("could not load macaroon: %w", err))
}
macConstraints := []macaroons.Constraint{
// We add a time-based constraint to prevent replay of
// the macaroon. It's good for 60 seconds by default to
// make up for any discrepancy between client and server
// clocks, but leaking the macaroon before it becomes
// invalid makes it possible for an attacker to reuse
// the macaroon. In addition, the validity time of the
// macaroon is extended by the time the server clock is
// behind the client clock, or shortened by the time the
// server clock is ahead of the client clock (or invalid
// altogether if, in the latter case, this time is more
// than 60 seconds).
// TODO(aakselrod): add better anti-replay protection.
macaroons.TimeoutConstraint(profile.Macaroons.Timeout),
// Lock macaroon down to a specific IP address.
macaroons.IPLockConstraint(profile.Macaroons.IP),
// ... Add more constraints if needed.
}
// Apply constraints to the macaroon.
constrainedMac, err := macaroons.AddConstraints(
mac, macConstraints...,
)
if err != nil {
fatal(err)
}
// Now we append the macaroon credentials to the dial options.
cred, err := macaroons.NewMacaroonCredential(constrainedMac)
if err != nil {
fatal(fmt.Errorf("error cloning mac: %w", err))
}
opts = append(opts, grpc.WithPerRPCCredentials(cred))
}
// If a socksproxy server is specified we use a tor dialer
// to connect to the grpc server.
if ctx.GlobalIsSet("socksproxy") {
socksProxy := ctx.GlobalString("socksproxy")
torDialer := func(_ context.Context, addr string) (net.Conn,
error) {
return tor.Dial(
addr, socksProxy, false, false,
tor.DefaultConnTimeout,
)
}
opts = append(opts, grpc.WithContextDialer(torDialer))
} else {
// We need to use a custom dialer so we can also connect to
// unix sockets and not just TCP addresses.
genericDialer := lncfg.ClientAddressDialer(defaultRPCPort)
opts = append(opts, grpc.WithContextDialer(genericDialer))
}
opts = append(opts, grpc.WithDefaultCallOptions(maxMsgRecvSize))
conn, err := grpc.Dial(profile.RPCServer, opts...)
if err != nil {
fatal(fmt.Errorf("unable to connect to RPC server: %w", err))
}
return conn
}
// addMetadataUnaryInterceptor returns a grpc client side interceptor that
// appends any key-value metadata strings to the outgoing context of a grpc
// unary call.
func addMetadataUnaryInterceptor(
md map[string]string) grpc.UnaryClientInterceptor {
return func(ctx context.Context, method string, req, reply interface{},
cc *grpc.ClientConn, invoker grpc.UnaryInvoker,
opts ...grpc.CallOption) error {
outCtx := contextWithMetadata(ctx, md)
return invoker(outCtx, method, req, reply, cc, opts...)
}
}
// addMetaDataStreamInterceptor returns a grpc client side interceptor that
// appends any key-value metadata strings to the outgoing context of a grpc
// stream call.
func addMetaDataStreamInterceptor(
md map[string]string) grpc.StreamClientInterceptor {
return func(ctx context.Context, desc *grpc.StreamDesc,
cc *grpc.ClientConn, method string, streamer grpc.Streamer,
opts ...grpc.CallOption) (grpc.ClientStream, error) {
outCtx := contextWithMetadata(ctx, md)
return streamer(outCtx, desc, cc, method, opts...)
}
}
// contextWithMetaData appends the given metadata key-value pairs to the given
// context.
func contextWithMetadata(ctx context.Context,
md map[string]string) context.Context {
kvPairs := make([]string, 0, 2*len(md))
for k, v := range md {
kvPairs = append(kvPairs, k, v)
}
return metadata.AppendToOutgoingContext(ctx, kvPairs...)
}
// extractPathArgs parses the TLS certificate and macaroon paths from the
// command.
func extractPathArgs(ctx *cli.Context) (string, string, error) {
network := strings.ToLower(ctx.GlobalString("network"))
switch network {
case "mainnet", "testnet", "regtest", "simnet", "signet":
default:
return "", "", fmt.Errorf("unknown network: %v", network)
}
// We'll now fetch the lnddir so we can make a decision on how to
// properly read the macaroons (if needed) and also the cert. This will
// either be the default, or will have been overwritten by the end
// user.
lndDir := lncfg.CleanAndExpandPath(ctx.GlobalString("lnddir"))
// If the macaroon path as been manually provided, then we'll only
// target the specified file.
var macPath string
if ctx.GlobalString("macaroonpath") != "" {
macPath = lncfg.CleanAndExpandPath(ctx.GlobalString(
"macaroonpath",
))
} else {
// Otherwise, we'll go into the path:
// lnddir/data/chain/<chain>/<network> in order to fetch the
// macaroon that we need.
macPath = filepath.Join(
lndDir, defaultDataDir, defaultChainSubDir,
lnd.BitcoinChainName, network, defaultMacaroonFilename,
)
}
tlsCertPath := lncfg.CleanAndExpandPath(ctx.GlobalString("tlscertpath"))
// If a custom lnd directory was set, we'll also check if custom paths
// for the TLS cert and macaroon file were set as well. If not, we'll
// override their paths so they can be found within the custom lnd
// directory set. This allows us to set a custom lnd directory, along
// with custom paths to the TLS cert and macaroon file.
if lndDir != DefaultLndDir {
tlsCertPath = filepath.Join(lndDir, defaultTLSCertFilename)
}
return tlsCertPath, macPath, nil
}
// checkNotBothSet accepts two flag names, a and b, and checks that only flag a
// or flag b can be set, but not both. It returns the name of the flag or an
// error.
func checkNotBothSet(ctx *cli.Context, a, b string) (string, error) {
if ctx.IsSet(a) && ctx.IsSet(b) {
return "", fmt.Errorf(
"either %s or %s should be set, but not both", a, b,
)
}
if ctx.IsSet(a) {
return a, nil
}
return b, nil
}
func Main() {
app := cli.NewApp()
app.Name = "lncli"
app.Version = build.Version() + " commit=" + build.Commit
app.Usage = "control plane for your Lightning Network Daemon (lnd)"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "rpcserver",
Value: defaultRPCHostPort,
Usage: "The host:port of LN daemon.",
EnvVar: envVarRPCServer,
},
cli.StringFlag{
Name: "lnddir",
Value: DefaultLndDir,
Usage: "The path to lnd's base directory.",
TakesFile: true,
EnvVar: envVarLNDDir,
},
cli.StringFlag{
Name: "socksproxy",
Usage: "The host:port of a SOCKS proxy through " +
"which all connections to the LN " +
"daemon will be established over.",
EnvVar: envVarSOCKSProxy,
},
cli.StringFlag{
Name: "tlscertpath",
Value: defaultTLSCertPath,
Usage: "The path to lnd's TLS certificate.",
TakesFile: true,
EnvVar: envVarTLSCertPath,
},
cli.StringFlag{
Name: "chain, c",
Usage: "The chain lnd is running on, e.g. bitcoin.",
Value: "bitcoin",
EnvVar: envVarChain,
},
cli.StringFlag{
Name: "network, n",
Usage: "The network lnd is running on, e.g. mainnet, " +
"testnet, etc.",
Value: "mainnet",
EnvVar: envVarNetwork,
},
cli.BoolFlag{
Name: "no-macaroons",
Usage: "Disable macaroon authentication.",
},
cli.StringFlag{
Name: "macaroonpath",
Usage: "The path to macaroon file.",
TakesFile: true,
EnvVar: envVarMacaroonPath,
},
cli.Int64Flag{
Name: "macaroontimeout",
Value: 60,
Usage: "Anti-replay macaroon validity time in " +
"seconds.",
EnvVar: envVarMacaroonTimeout,
},
cli.StringFlag{
Name: "macaroonip",
Usage: "If set, lock macaroon to specific IP address.",
EnvVar: envVarMacaroonIP,
},
cli.StringFlag{
Name: "profile, p",
Usage: "Instead of reading settings from command " +
"line parameters or using the default " +
"profile, use a specific profile. If " +
"a default profile is set, this flag can be " +
"set to an empty string to disable reading " +
"values from the profiles file.",
EnvVar: envVarProfile,
},
cli.StringFlag{
Name: "macfromjar",
Usage: "Use this macaroon from the profile's " +
"macaroon jar instead of the default one. " +
"Can only be used if profiles are defined.",
EnvVar: envVarMacFromJar,
},
cli.StringSliceFlag{
Name: "metadata",
Usage: "This flag can be used to specify a key-value " +
"pair that should be appended to the " +
"outgoing context before the request is sent " +
"to lnd. This flag may be specified multiple " +
"times. The format is: \"key:value\".",
},
cli.BoolFlag{
Name: "insecure",
Usage: "Connect to the rpc server without TLS " +
"authentication",
Hidden: true,
},
}
app.Commands = []cli.Command{
createCommand,
createWatchOnlyCommand,
unlockCommand,
changePasswordCommand,
newAddressCommand,
estimateFeeCommand,
sendManyCommand,
sendCoinsCommand,
listUnspentCommand,
connectCommand,
disconnectCommand,
openChannelCommand,
batchOpenChannelCommand,
closeChannelCommand,
closeAllChannelsCommand,
abandonChannelCommand,
listPeersCommand,
walletBalanceCommand,
ChannelBalanceCommand,
getInfoCommand,
getDebugInfoCommand,
encryptDebugPackageCommand,
decryptDebugPackageCommand,
getRecoveryInfoCommand,
pendingChannelsCommand,
SendPaymentCommand,
payInvoiceCommand,
sendToRouteCommand,
AddInvoiceCommand,
lookupInvoiceCommand,
listInvoicesCommand,
ListChannelsCommand,
closedChannelsCommand,
listPaymentsCommand,
describeGraphCommand,
getNodeMetricsCommand,
getChanInfoCommand,
getNodeInfoCommand,
queryRoutesCommand,
getNetworkInfoCommand,
debugLevelCommand,
decodePayReqCommand,
listChainTxnsCommand,
stopCommand,
signMessageCommand,
verifyMessageCommand,
feeReportCommand,
updateChannelPolicyCommand,
forwardingHistoryCommand,
exportChanBackupCommand,
verifyChanBackupCommand,
restoreChanBackupCommand,
bakeMacaroonCommand,
listMacaroonIDsCommand,
deleteMacaroonIDCommand,
listPermissionsCommand,
printMacaroonCommand,
constrainMacaroonCommand,
trackPaymentCommand,
versionCommand,
profileSubCommand,
getStateCommand,
deletePaymentsCommand,
sendCustomCommand,
subscribeCustomCommand,
fishCompletionCommand,
listAliasesCommand,
estimateRouteFeeCommand,
generateManPageCommand,
}
// Add any extra commands determined by build flags.
app.Commands = append(app.Commands, autopilotCommands()...)
app.Commands = append(app.Commands, invoicesCommands()...)
app.Commands = append(app.Commands, neutrinoCommands()...)
app.Commands = append(app.Commands, routerCommands()...)
app.Commands = append(app.Commands, walletCommands()...)
app.Commands = append(app.Commands, watchtowerCommands()...)
app.Commands = append(app.Commands, wtclientCommands()...)
app.Commands = append(app.Commands, devCommands()...)
app.Commands = append(app.Commands, peersCommands()...)
app.Commands = append(app.Commands, chainCommands()...)
if err := app.Run(os.Args); err != nil {
fatal(err)
}
}
// readPassword reads a password from the terminal. This requires there to be an
// actual TTY so passing in a password from stdin won't work.
func readPassword(text string) ([]byte, error) {
fmt.Print(text)
// The variable syscall.Stdin is of a different type in the Windows API
// that's why we need the explicit cast. And of course the linter
// doesn't like it either.
pw, err := term.ReadPassword(int(syscall.Stdin)) //nolint:unconvert
fmt.Println()
return pw, err
}
// networkParams parses the global network flag into a chaincfg.Params.
func networkParams(ctx *cli.Context) (*chaincfg.Params, error) {
network := strings.ToLower(ctx.GlobalString("network"))
switch network {
case "mainnet":
return &chaincfg.MainNetParams, nil
case "testnet":
return &chaincfg.TestNet3Params, nil
case "regtest":
return &chaincfg.RegressionNetParams, nil
case "simnet":
return &chaincfg.SimNetParams, nil
case "signet":
return &chaincfg.SigNetParams, nil
default:
return nil, fmt.Errorf("unknown network: %v", network)
}
}
// parseCoinSelectionStrategy parses a coin selection strategy string
// from the CLI to its lnrpc.CoinSelectionStrategy counterpart proto type.
func parseCoinSelectionStrategy(ctx *cli.Context) (
lnrpc.CoinSelectionStrategy, error) {
strategy := ctx.String(coinSelectionStrategyFlag.Name)
if !ctx.IsSet(coinSelectionStrategyFlag.Name) {
return lnrpc.CoinSelectionStrategy_STRATEGY_USE_GLOBAL_CONFIG,
nil
}
switch strategy {
case "global-config":
return lnrpc.CoinSelectionStrategy_STRATEGY_USE_GLOBAL_CONFIG,
nil
case "largest":
return lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST, nil
case "random":
return lnrpc.CoinSelectionStrategy_STRATEGY_RANDOM, nil
default:
return 0, fmt.Errorf("unknown coin selection strategy "+
"%v", strategy)
}
}

View File

@ -1,11 +1,13 @@
//go:build neutrinorpc
// +build neutrinorpc
package main
package commands
import (
"github.com/lightningnetwork/lnd/lnrpc/neutrinorpc"
"github.com/urfave/cli"
"strconv"
)
func getNeutrinoKitClient(ctx *cli.Context) (neutrinorpc.NeutrinoKitClient, func()) {
@ -225,6 +227,47 @@ func getCFilter(ctx *cli.Context) error {
return nil
}
var getBlockHashCommand = cli.Command{
Name: "getblockhash",
Usage: "Get a block hash.",
Category: "Neutrino",
Description: "Returns the header hash of a block at a given height.",
ArgsUsage: "height",
Action: actionDecorator(getBlockHash),
}
func getBlockHash(ctx *cli.Context) error {
ctxc := getContext()
args := ctx.Args()
// Display the command's help message if we do not have the expected
// number of arguments/flags.
if !args.Present() {
return cli.ShowCommandHelp(ctx, "getblockhash")
}
client, cleanUp := getNeutrinoKitClient(ctx)
defer cleanUp()
height, err := strconv.ParseInt(args.First(), 10, 32)
if err != nil {
return err
}
req := &neutrinorpc.GetBlockHashRequest{
Height: int32(height),
}
resp, err := client.GetBlockHash(ctxc, req)
if err != nil {
return err
}
printRespJSON(resp)
return nil
}
// neutrinoCommands will return the set of commands to enable for neutrinorpc
// builds.
func neutrinoCommands() []cli.Command {
@ -241,6 +284,7 @@ func neutrinoCommands() []cli.Command {
isBannedCommand,
getBlockHeaderNeutrinoCommand,
getCFilterCommand,
getBlockHashCommand,
},
},
}

View File

@ -1,7 +1,7 @@
//go:build !neutrinorpc
// +build !neutrinorpc
package main
package commands
import "github.com/urfave/cli"

View File

@ -1,7 +1,7 @@
//go:build peersrpc
// +build peersrpc
package main
package commands
import (
"fmt"

View File

@ -1,7 +1,7 @@
//go:build !peersrpc
// +build !peersrpc
package main
package commands
import "github.com/urfave/cli"

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"bytes"

View File

@ -1,4 +1,4 @@
package main
package commands
import "github.com/urfave/cli"

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"encoding/hex"

View File

@ -1,7 +1,7 @@
//go:build walletrpc
// +build walletrpc
package main
package commands
import (
"bytes"

View File

@ -1,7 +1,7 @@
//go:build !walletrpc
// +build !walletrpc
package main
package commands
import "github.com/urfave/cli"

View File

@ -1,4 +1,4 @@
package main
package commands
import "github.com/lightningnetwork/lnd/lnrpc/walletrpc"

View File

@ -1,7 +1,7 @@
//go:build watchtowerrpc
// +build watchtowerrpc
package main
package commands
import (
"github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc"

View File

@ -1,7 +1,7 @@
//go:build !watchtowerrpc
// +build !watchtowerrpc
package main
package commands
import "github.com/urfave/cli"

View File

@ -1,4 +1,4 @@
package main
package commands
import (
"encoding/hex"

View File

@ -1,594 +1,11 @@
// Copyright (c) 2013-2017 The btcsuite developers
// Copyright (c) 2015-2016 The Decred developers
// Copyright (C) 2015-2022 The Lightning Network Developers
// Copyright (C) 2015-2024 The Lightning Network Developers
package main
import (
"context"
"crypto/tls"
"fmt"
"net"
"os"
"path/filepath"
"strings"
"syscall"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
"github.com/lightningnetwork/lnd"
"github.com/lightningnetwork/lnd/build"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/macaroons"
"github.com/lightningnetwork/lnd/tor"
"github.com/urfave/cli"
"golang.org/x/term"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/metadata"
)
const (
defaultDataDir = "data"
defaultChainSubDir = "chain"
defaultTLSCertFilename = "tls.cert"
defaultMacaroonFilename = "admin.macaroon"
defaultRPCPort = "10009"
defaultRPCHostPort = "localhost:" + defaultRPCPort
envVarRPCServer = "LNCLI_RPCSERVER"
envVarLNDDir = "LNCLI_LNDDIR"
envVarSOCKSProxy = "LNCLI_SOCKSPROXY"
envVarTLSCertPath = "LNCLI_TLSCERTPATH"
envVarChain = "LNCLI_CHAIN"
envVarNetwork = "LNCLI_NETWORK"
envVarMacaroonPath = "LNCLI_MACAROONPATH"
envVarMacaroonTimeout = "LNCLI_MACAROONTIMEOUT"
envVarMacaroonIP = "LNCLI_MACAROONIP"
envVarProfile = "LNCLI_PROFILE"
envVarMacFromJar = "LNCLI_MACFROMJAR"
)
var (
defaultLndDir = btcutil.AppDataDir("lnd", false)
defaultTLSCertPath = filepath.Join(defaultLndDir, defaultTLSCertFilename)
// maxMsgRecvSize is the largest message our client will receive. We
// set this to 200MiB atm.
maxMsgRecvSize = grpc.MaxCallRecvMsgSize(lnrpc.MaxGrpcMsgSize)
)
func fatal(err error) {
fmt.Fprintf(os.Stderr, "[lncli] %v\n", err)
os.Exit(1)
}
func getWalletUnlockerClient(ctx *cli.Context) (lnrpc.WalletUnlockerClient, func()) {
conn := getClientConn(ctx, true)
cleanUp := func() {
conn.Close()
}
return lnrpc.NewWalletUnlockerClient(conn), cleanUp
}
func getStateServiceClient(ctx *cli.Context) (lnrpc.StateClient, func()) {
conn := getClientConn(ctx, true)
cleanUp := func() {
conn.Close()
}
return lnrpc.NewStateClient(conn), cleanUp
}
func getClient(ctx *cli.Context) (lnrpc.LightningClient, func()) {
conn := getClientConn(ctx, false)
cleanUp := func() {
conn.Close()
}
return lnrpc.NewLightningClient(conn), cleanUp
}
func getClientConn(ctx *cli.Context, skipMacaroons bool) *grpc.ClientConn {
// First, we'll get the selected stored profile or an ephemeral one
// created from the global options in the CLI context.
profile, err := getGlobalOptions(ctx, skipMacaroons)
if err != nil {
fatal(fmt.Errorf("could not load global options: %w", err))
}
// Create a dial options array.
opts := []grpc.DialOption{
grpc.WithUnaryInterceptor(
addMetadataUnaryInterceptor(profile.Metadata),
),
grpc.WithStreamInterceptor(
addMetaDataStreamInterceptor(profile.Metadata),
),
}
if profile.Insecure {
opts = append(opts, grpc.WithInsecure())
} else {
// Load the specified TLS certificate.
certPool, err := profile.cert()
if err != nil {
fatal(fmt.Errorf("could not create cert pool: %w", err))
}
// Build transport credentials from the certificate pool. If
// there is no certificate pool, we expect the server to use a
// non-self-signed certificate such as a certificate obtained
// from Let's Encrypt.
var creds credentials.TransportCredentials
if certPool != nil {
creds = credentials.NewClientTLSFromCert(certPool, "")
} else {
// Fallback to the system pool. Using an empty tls
// config is an alternative to x509.SystemCertPool().
// That call is not supported on Windows.
creds = credentials.NewTLS(&tls.Config{})
}
opts = append(opts, grpc.WithTransportCredentials(creds))
}
// Only process macaroon credentials if --no-macaroons isn't set and
// if we're not skipping macaroon processing.
if !profile.NoMacaroons && !skipMacaroons {
// Find out which macaroon to load.
macName := profile.Macaroons.Default
if ctx.GlobalIsSet("macfromjar") {
macName = ctx.GlobalString("macfromjar")
}
var macEntry *macaroonEntry
for _, entry := range profile.Macaroons.Jar {
if entry.Name == macName {
macEntry = entry
break
}
}
if macEntry == nil {
fatal(fmt.Errorf("macaroon with name '%s' not found "+
"in profile", macName))
}
// Get and possibly decrypt the specified macaroon.
//
// TODO(guggero): Make it possible to cache the password so we
// don't need to ask for it every time.
mac, err := macEntry.loadMacaroon(readPassword)
if err != nil {
fatal(fmt.Errorf("could not load macaroon: %w", err))
}
macConstraints := []macaroons.Constraint{
// We add a time-based constraint to prevent replay of
// the macaroon. It's good for 60 seconds by default to
// make up for any discrepancy between client and server
// clocks, but leaking the macaroon before it becomes
// invalid makes it possible for an attacker to reuse
// the macaroon. In addition, the validity time of the
// macaroon is extended by the time the server clock is
// behind the client clock, or shortened by the time the
// server clock is ahead of the client clock (or invalid
// altogether if, in the latter case, this time is more
// than 60 seconds).
// TODO(aakselrod): add better anti-replay protection.
macaroons.TimeoutConstraint(profile.Macaroons.Timeout),
// Lock macaroon down to a specific IP address.
macaroons.IPLockConstraint(profile.Macaroons.IP),
// ... Add more constraints if needed.
}
// Apply constraints to the macaroon.
constrainedMac, err := macaroons.AddConstraints(
mac, macConstraints...,
)
if err != nil {
fatal(err)
}
// Now we append the macaroon credentials to the dial options.
cred, err := macaroons.NewMacaroonCredential(constrainedMac)
if err != nil {
fatal(fmt.Errorf("error cloning mac: %w", err))
}
opts = append(opts, grpc.WithPerRPCCredentials(cred))
}
// If a socksproxy server is specified we use a tor dialer
// to connect to the grpc server.
if ctx.GlobalIsSet("socksproxy") {
socksProxy := ctx.GlobalString("socksproxy")
torDialer := func(_ context.Context, addr string) (net.Conn,
error) {
return tor.Dial(
addr, socksProxy, false, false,
tor.DefaultConnTimeout,
)
}
opts = append(opts, grpc.WithContextDialer(torDialer))
} else {
// We need to use a custom dialer so we can also connect to
// unix sockets and not just TCP addresses.
genericDialer := lncfg.ClientAddressDialer(defaultRPCPort)
opts = append(opts, grpc.WithContextDialer(genericDialer))
}
opts = append(opts, grpc.WithDefaultCallOptions(maxMsgRecvSize))
conn, err := grpc.Dial(profile.RPCServer, opts...)
if err != nil {
fatal(fmt.Errorf("unable to connect to RPC server: %w", err))
}
return conn
}
// addMetadataUnaryInterceptor returns a grpc client side interceptor that
// appends any key-value metadata strings to the outgoing context of a grpc
// unary call.
func addMetadataUnaryInterceptor(
md map[string]string) grpc.UnaryClientInterceptor {
return func(ctx context.Context, method string, req, reply interface{},
cc *grpc.ClientConn, invoker grpc.UnaryInvoker,
opts ...grpc.CallOption) error {
outCtx := contextWithMetadata(ctx, md)
return invoker(outCtx, method, req, reply, cc, opts...)
}
}
// addMetaDataStreamInterceptor returns a grpc client side interceptor that
// appends any key-value metadata strings to the outgoing context of a grpc
// stream call.
func addMetaDataStreamInterceptor(
md map[string]string) grpc.StreamClientInterceptor {
return func(ctx context.Context, desc *grpc.StreamDesc,
cc *grpc.ClientConn, method string, streamer grpc.Streamer,
opts ...grpc.CallOption) (grpc.ClientStream, error) {
outCtx := contextWithMetadata(ctx, md)
return streamer(outCtx, desc, cc, method, opts...)
}
}
// contextWithMetaData appends the given metadata key-value pairs to the given
// context.
func contextWithMetadata(ctx context.Context,
md map[string]string) context.Context {
kvPairs := make([]string, 0, 2*len(md))
for k, v := range md {
kvPairs = append(kvPairs, k, v)
}
return metadata.AppendToOutgoingContext(ctx, kvPairs...)
}
// extractPathArgs parses the TLS certificate and macaroon paths from the
// command.
func extractPathArgs(ctx *cli.Context) (string, string, error) {
network := strings.ToLower(ctx.GlobalString("network"))
switch network {
case "mainnet", "testnet", "regtest", "simnet", "signet":
default:
return "", "", fmt.Errorf("unknown network: %v", network)
}
// We'll now fetch the lnddir so we can make a decision on how to
// properly read the macaroons (if needed) and also the cert. This will
// either be the default, or will have been overwritten by the end
// user.
lndDir := lncfg.CleanAndExpandPath(ctx.GlobalString("lnddir"))
// If the macaroon path as been manually provided, then we'll only
// target the specified file.
var macPath string
if ctx.GlobalString("macaroonpath") != "" {
macPath = lncfg.CleanAndExpandPath(ctx.GlobalString("macaroonpath"))
} else {
// Otherwise, we'll go into the path:
// lnddir/data/chain/<chain>/<network> in order to fetch the
// macaroon that we need.
macPath = filepath.Join(
lndDir, defaultDataDir, defaultChainSubDir,
lnd.BitcoinChainName, network, defaultMacaroonFilename,
)
}
tlsCertPath := lncfg.CleanAndExpandPath(ctx.GlobalString("tlscertpath"))
// If a custom lnd directory was set, we'll also check if custom paths
// for the TLS cert and macaroon file were set as well. If not, we'll
// override their paths so they can be found within the custom lnd
// directory set. This allows us to set a custom lnd directory, along
// with custom paths to the TLS cert and macaroon file.
if lndDir != defaultLndDir {
tlsCertPath = filepath.Join(lndDir, defaultTLSCertFilename)
}
return tlsCertPath, macPath, nil
}
// checkNotBothSet accepts two flag names, a and b, and checks that only flag a
// or flag b can be set, but not both. It returns the name of the flag or an
// error.
func checkNotBothSet(ctx *cli.Context, a, b string) (string, error) {
if ctx.IsSet(a) && ctx.IsSet(b) {
return "", fmt.Errorf(
"either %s or %s should be set, but not both", a, b,
)
}
if ctx.IsSet(a) {
return a, nil
}
return b, nil
}
import "github.com/lightningnetwork/lnd/cmd/commands"
func main() {
app := cli.NewApp()
app.Name = "lncli"
app.Version = build.Version() + " commit=" + build.Commit
app.Usage = "control plane for your Lightning Network Daemon (lnd)"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "rpcserver",
Value: defaultRPCHostPort,
Usage: "The host:port of LN daemon.",
EnvVar: envVarRPCServer,
},
cli.StringFlag{
Name: "lnddir",
Value: defaultLndDir,
Usage: "The path to lnd's base directory.",
TakesFile: true,
EnvVar: envVarLNDDir,
},
cli.StringFlag{
Name: "socksproxy",
Usage: "The host:port of a SOCKS proxy through " +
"which all connections to the LN " +
"daemon will be established over.",
EnvVar: envVarSOCKSProxy,
},
cli.StringFlag{
Name: "tlscertpath",
Value: defaultTLSCertPath,
Usage: "The path to lnd's TLS certificate.",
TakesFile: true,
EnvVar: envVarTLSCertPath,
},
cli.StringFlag{
Name: "chain, c",
Usage: "The chain lnd is running on, e.g. bitcoin.",
Value: "bitcoin",
EnvVar: envVarChain,
},
cli.StringFlag{
Name: "network, n",
Usage: "The network lnd is running on, e.g. mainnet, " +
"testnet, etc.",
Value: "mainnet",
EnvVar: envVarNetwork,
},
cli.BoolFlag{
Name: "no-macaroons",
Usage: "Disable macaroon authentication.",
},
cli.StringFlag{
Name: "macaroonpath",
Usage: "The path to macaroon file.",
TakesFile: true,
EnvVar: envVarMacaroonPath,
},
cli.Int64Flag{
Name: "macaroontimeout",
Value: 60,
Usage: "Anti-replay macaroon validity time in " +
"seconds.",
EnvVar: envVarMacaroonTimeout,
},
cli.StringFlag{
Name: "macaroonip",
Usage: "If set, lock macaroon to specific IP address.",
EnvVar: envVarMacaroonIP,
},
cli.StringFlag{
Name: "profile, p",
Usage: "Instead of reading settings from command " +
"line parameters or using the default " +
"profile, use a specific profile. If " +
"a default profile is set, this flag can be " +
"set to an empty string to disable reading " +
"values from the profiles file.",
EnvVar: envVarProfile,
},
cli.StringFlag{
Name: "macfromjar",
Usage: "Use this macaroon from the profile's " +
"macaroon jar instead of the default one. " +
"Can only be used if profiles are defined.",
EnvVar: envVarMacFromJar,
},
cli.StringSliceFlag{
Name: "metadata",
Usage: "This flag can be used to specify a key-value " +
"pair that should be appended to the " +
"outgoing context before the request is sent " +
"to lnd. This flag may be specified multiple " +
"times. The format is: \"key:value\".",
},
cli.BoolFlag{
Name: "insecure",
Usage: "Connect to the rpc server without TLS " +
"authentication",
Hidden: true,
},
}
app.Commands = []cli.Command{
createCommand,
createWatchOnlyCommand,
unlockCommand,
changePasswordCommand,
newAddressCommand,
estimateFeeCommand,
sendManyCommand,
sendCoinsCommand,
listUnspentCommand,
connectCommand,
disconnectCommand,
openChannelCommand,
batchOpenChannelCommand,
closeChannelCommand,
closeAllChannelsCommand,
abandonChannelCommand,
listPeersCommand,
walletBalanceCommand,
channelBalanceCommand,
getInfoCommand,
getDebugInfoCommand,
encryptDebugPackageCommand,
decryptDebugPackageCommand,
getRecoveryInfoCommand,
pendingChannelsCommand,
sendPaymentCommand,
payInvoiceCommand,
sendToRouteCommand,
addInvoiceCommand,
lookupInvoiceCommand,
listInvoicesCommand,
listChannelsCommand,
closedChannelsCommand,
listPaymentsCommand,
describeGraphCommand,
getNodeMetricsCommand,
getChanInfoCommand,
getNodeInfoCommand,
queryRoutesCommand,
getNetworkInfoCommand,
debugLevelCommand,
decodePayReqCommand,
listChainTxnsCommand,
stopCommand,
signMessageCommand,
verifyMessageCommand,
feeReportCommand,
updateChannelPolicyCommand,
forwardingHistoryCommand,
exportChanBackupCommand,
verifyChanBackupCommand,
restoreChanBackupCommand,
bakeMacaroonCommand,
listMacaroonIDsCommand,
deleteMacaroonIDCommand,
listPermissionsCommand,
printMacaroonCommand,
constrainMacaroonCommand,
trackPaymentCommand,
versionCommand,
profileSubCommand,
getStateCommand,
deletePaymentsCommand,
sendCustomCommand,
subscribeCustomCommand,
fishCompletionCommand,
listAliasesCommand,
estimateRouteFeeCommand,
generateManPageCommand,
}
// Add any extra commands determined by build flags.
app.Commands = append(app.Commands, autopilotCommands()...)
app.Commands = append(app.Commands, invoicesCommands()...)
app.Commands = append(app.Commands, neutrinoCommands()...)
app.Commands = append(app.Commands, routerCommands()...)
app.Commands = append(app.Commands, walletCommands()...)
app.Commands = append(app.Commands, watchtowerCommands()...)
app.Commands = append(app.Commands, wtclientCommands()...)
app.Commands = append(app.Commands, devCommands()...)
app.Commands = append(app.Commands, peersCommands()...)
app.Commands = append(app.Commands, chainCommands()...)
if err := app.Run(os.Args); err != nil {
fatal(err)
}
}
// readPassword reads a password from the terminal. This requires there to be an
// actual TTY so passing in a password from stdin won't work.
func readPassword(text string) ([]byte, error) {
fmt.Print(text)
// The variable syscall.Stdin is of a different type in the Windows API
// that's why we need the explicit cast. And of course the linter
// doesn't like it either.
pw, err := term.ReadPassword(int(syscall.Stdin)) // nolint:unconvert
fmt.Println()
return pw, err
}
// networkParams parses the global network flag into a chaincfg.Params.
func networkParams(ctx *cli.Context) (*chaincfg.Params, error) {
network := strings.ToLower(ctx.GlobalString("network"))
switch network {
case "mainnet":
return &chaincfg.MainNetParams, nil
case "testnet":
return &chaincfg.TestNet3Params, nil
case "regtest":
return &chaincfg.RegressionNetParams, nil
case "simnet":
return &chaincfg.SimNetParams, nil
case "signet":
return &chaincfg.SigNetParams, nil
default:
return nil, fmt.Errorf("unknown network: %v", network)
}
}
// parseCoinSelectionStrategy parses a coin selection strategy string
// from the CLI to its lnrpc.CoinSelectionStrategy counterpart proto type.
func parseCoinSelectionStrategy(ctx *cli.Context) (
lnrpc.CoinSelectionStrategy, error) {
strategy := ctx.String(coinSelectionStrategyFlag.Name)
if !ctx.IsSet(coinSelectionStrategyFlag.Name) {
return lnrpc.CoinSelectionStrategy_STRATEGY_USE_GLOBAL_CONFIG,
nil
}
switch strategy {
case "global-config":
return lnrpc.CoinSelectionStrategy_STRATEGY_USE_GLOBAL_CONFIG,
nil
case "largest":
return lnrpc.CoinSelectionStrategy_STRATEGY_LARGEST, nil
case "random":
return lnrpc.CoinSelectionStrategy_STRATEGY_RANDOM, nil
default:
return 0, fmt.Errorf("unknown coin selection strategy "+
"%v", strategy)
}
commands.Main()
}

View File

@ -33,6 +33,9 @@ import (
"github.com/lightningnetwork/lnd/chainreg"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/clock"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/funding"
"github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/invoices"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/kvdb"
@ -40,11 +43,14 @@ import (
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
"github.com/lightningnetwork/lnd/lnwallet/chancloser"
"github.com/lightningnetwork/lnd/lnwallet/rpcwallet"
"github.com/lightningnetwork/lnd/macaroons"
"github.com/lightningnetwork/lnd/msgmux"
"github.com/lightningnetwork/lnd/rpcperms"
"github.com/lightningnetwork/lnd/signal"
"github.com/lightningnetwork/lnd/sqldb"
"github.com/lightningnetwork/lnd/sweep"
"github.com/lightningnetwork/lnd/walletunlocker"
"github.com/lightningnetwork/lnd/watchtower"
"github.com/lightningnetwork/lnd/watchtower/wtclient"
@ -103,7 +109,7 @@ type DatabaseBuilder interface {
type WalletConfigBuilder interface {
// BuildWalletConfig is responsible for creating or unlocking and then
// fully initializing a wallet.
BuildWalletConfig(context.Context, *DatabaseInstances,
BuildWalletConfig(context.Context, *DatabaseInstances, *AuxComponents,
*rpcperms.InterceptorChain,
[]*ListenerWithSignal) (*chainreg.PartialChainControl,
*btcwallet.Config, func(), error)
@ -144,6 +150,52 @@ type ImplementationCfg struct {
// ChainControlBuilder is a type that can provide a custom wallet
// implementation.
ChainControlBuilder
// AuxComponents is a set of auxiliary components that can be used by
// lnd for certain custom channel types.
AuxComponents
}
// AuxComponents is a set of auxiliary components that can be used by lnd for
// certain custom channel types.
type AuxComponents struct {
// AuxLeafStore is an optional data source that can be used by custom
// channels to fetch+store various data.
AuxLeafStore fn.Option[lnwallet.AuxLeafStore]
// TrafficShaper is an optional traffic shaper that can be used to
// control the outgoing channel of a payment.
TrafficShaper fn.Option[htlcswitch.AuxTrafficShaper]
// MsgRouter is an optional message router that if set will be used in
// place of a new blank default message router.
MsgRouter fn.Option[msgmux.Router]
// AuxFundingController is an optional controller that can be used to
// modify the way we handle certain custom channel types. It's also
// able to automatically handle new custom protocol messages related to
// the funding process.
AuxFundingController fn.Option[funding.AuxFundingController]
// AuxSigner is an optional signer that can be used to sign auxiliary
// leaves for certain custom channel types.
AuxSigner fn.Option[lnwallet.AuxSigner]
// AuxDataParser is an optional data parser that can be used to parse
// auxiliary data for certain custom channel types.
AuxDataParser fn.Option[AuxDataParser]
// AuxChanCloser is an optional channel closer that can be used to
// modify the way a coop-close transaction is constructed.
AuxChanCloser fn.Option[chancloser.AuxChanCloser]
// AuxSweeper is an optional interface that can be used to modify the
// way sweep transaction are generated.
AuxSweeper fn.Option[sweep.AuxSweeper]
// AuxContractResolver is an optional interface that can be used to
// modify the way contracts are resolved.
AuxContractResolver fn.Option[lnwallet.AuxContractResolver]
}
// DefaultWalletImpl is the default implementation of our normal, btcwallet
@ -228,7 +280,8 @@ func (d *DefaultWalletImpl) Permissions() map[string][]bakery.Op {
//
// NOTE: This is part of the WalletConfigBuilder interface.
func (d *DefaultWalletImpl) BuildWalletConfig(ctx context.Context,
dbs *DatabaseInstances, interceptorChain *rpcperms.InterceptorChain,
dbs *DatabaseInstances, aux *AuxComponents,
interceptorChain *rpcperms.InterceptorChain,
grpcListeners []*ListenerWithSignal) (*chainreg.PartialChainControl,
*btcwallet.Config, func(), error) {
@ -548,6 +601,8 @@ func (d *DefaultWalletImpl) BuildWalletConfig(ctx context.Context,
HeightHintDB: dbs.HeightHintDB,
ChanStateDB: dbs.ChanStateDB.ChannelStateDB(),
NeutrinoCS: neutrinoCS,
AuxLeafStore: aux.AuxLeafStore,
AuxSigner: aux.AuxSigner,
ActiveNetParams: d.cfg.ActiveNetParams,
FeeURL: d.cfg.FeeURL,
Fee: &lncfg.Fee{
@ -611,8 +666,9 @@ func (d *DefaultWalletImpl) BuildWalletConfig(ctx context.Context,
// proxyBlockEpoch proxies a block epoch subsections to the underlying neutrino
// rebroadcaster client.
func proxyBlockEpoch(notifier chainntnfs.ChainNotifier,
) func() (*blockntfns.Subscription, error) {
func proxyBlockEpoch(
notifier chainntnfs.ChainNotifier) func() (*blockntfns.Subscription,
error) {
return func() (*blockntfns.Subscription, error) {
blockEpoch, err := notifier.RegisterBlockEpochNtfn(
@ -703,6 +759,8 @@ func (d *DefaultWalletImpl) BuildChainControl(
ChainIO: walletController,
NetParams: *walletConfig.NetParams,
CoinSelectionStrategy: walletConfig.CoinSelectionStrategy,
AuxLeafStore: partialChainControl.Cfg.AuxLeafStore,
AuxSigner: partialChainControl.Cfg.AuxSigner,
}
// The broadcast is already always active for neutrino nodes, so we

View File

@ -15,6 +15,7 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/labels"
@ -22,6 +23,8 @@ import (
"github.com/lightningnetwork/lnd/lnutils"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/sweep"
"github.com/lightningnetwork/lnd/tlv"
)
const (
@ -147,7 +150,7 @@ type BreachConfig struct {
Estimator chainfee.Estimator
// GenSweepScript generates the receiving scripts for swept outputs.
GenSweepScript func() ([]byte, error)
GenSweepScript func() fn.Result[lnwallet.AddrWithKey]
// Notifier provides a publish/subscribe interface for event driven
// notifications regarding the confirmation of txids.
@ -172,6 +175,10 @@ type BreachConfig struct {
// breached channels. This is used in conjunction with DB to recover
// from crashes, restarts, or other failures.
Store RetributionStorer
// AuxSweeper is an optional interface that can be used to modify the
// way sweep transaction are generated.
AuxSweeper fn.Option[sweep.AuxSweeper]
}
// BreachArbitrator is a special subsystem which is responsible for watching and
@ -735,10 +742,28 @@ justiceTxBroadcast:
brarLog.Debugf("Broadcasting justice tx: %v", lnutils.SpewLogClosure(
finalTx))
// As we're about to broadcast our breach transaction, we'll notify the
// aux sweeper of our broadcast attempt first.
err = fn.MapOptionZ(b.cfg.AuxSweeper, func(aux sweep.AuxSweeper) error {
bumpReq := sweep.BumpRequest{
Inputs: finalTx.inputs,
DeliveryAddress: finalTx.sweepAddr,
ExtraTxOut: finalTx.extraTxOut,
}
return aux.NotifyBroadcast(
&bumpReq, finalTx.justiceTx, finalTx.fee, nil,
)
})
if err != nil {
brarLog.Errorf("unable to notify broadcast: %w", err)
return
}
// We'll now attempt to broadcast the transaction which finalized the
// channel's retribution against the cheating counter party.
label := labels.MakeLabel(labels.LabelTypeJusticeTransaction, nil)
err = b.cfg.PublishTransaction(finalTx, label)
err = b.cfg.PublishTransaction(finalTx.justiceTx, label)
if err != nil {
brarLog.Errorf("Unable to broadcast justice tx: %v", err)
}
@ -858,7 +883,9 @@ Loop:
"spending commitment outs: %v",
lnutils.SpewLogClosure(tx))
err = b.cfg.PublishTransaction(tx, label)
err = b.cfg.PublishTransaction(
tx.justiceTx, label,
)
if err != nil {
brarLog.Warnf("Unable to broadcast "+
"commit out spending justice "+
@ -873,7 +900,9 @@ Loop:
"spending HTLC outs: %v",
lnutils.SpewLogClosure(tx))
err = b.cfg.PublishTransaction(tx, label)
err = b.cfg.PublishTransaction(
tx.justiceTx, label,
)
if err != nil {
brarLog.Warnf("Unable to broadcast "+
"HTLC out spending justice "+
@ -888,7 +917,9 @@ Loop:
"spending second-level HTLC output: %v",
lnutils.SpewLogClosure(tx))
err = b.cfg.PublishTransaction(tx, label)
err = b.cfg.PublishTransaction(
tx.justiceTx, label,
)
if err != nil {
brarLog.Warnf("Unable to broadcast "+
"second-level HTLC out "+
@ -1067,15 +1098,18 @@ type breachedOutput struct {
secondLevelTapTweak [32]byte
witnessFunc input.WitnessGenerator
resolutionBlob fn.Option[tlv.Blob]
// TODO(roasbeef): function opt and hook into brar
}
// makeBreachedOutput assembles a new breachedOutput that can be used by the
// breach arbiter to construct a justice or sweep transaction.
func makeBreachedOutput(outpoint *wire.OutPoint,
witnessType input.StandardWitnessType,
secondLevelScript []byte,
signDescriptor *input.SignDescriptor,
confHeight uint32) breachedOutput {
witnessType input.StandardWitnessType, secondLevelScript []byte,
signDescriptor *input.SignDescriptor, confHeight uint32,
resolutionBlob fn.Option[tlv.Blob]) breachedOutput {
amount := signDescriptor.Output.Value
@ -1086,6 +1120,7 @@ func makeBreachedOutput(outpoint *wire.OutPoint,
witnessType: witnessType,
signDesc: *signDescriptor,
confHeight: confHeight,
resolutionBlob: resolutionBlob,
}
}
@ -1125,6 +1160,11 @@ func (bo *breachedOutput) SignDesc() *input.SignDescriptor {
return &bo.signDesc
}
// Preimage returns the preimage that was used to create the breached output.
func (bo *breachedOutput) Preimage() fn.Option[lntypes.Preimage] {
return fn.None[lntypes.Preimage]()
}
// CraftInputScript computes a valid witness that allows us to spend from the
// breached output. It does so by first generating and memoizing the witness
// generation function, which parameterized primarily by the witness type and
@ -1174,6 +1214,12 @@ func (bo *breachedOutput) UnconfParent() *input.TxInfo {
return nil
}
// ResolutionBlob returns a special opaque blob to be used to sweep/resolve this
// input.
func (bo *breachedOutput) ResolutionBlob() fn.Option[tlv.Blob] {
return bo.resolutionBlob
}
// Add compile-time constraint ensuring breachedOutput implements the Input
// interface.
var _ input.Input = (*breachedOutput)(nil)
@ -1258,6 +1304,7 @@ func newRetributionInfo(chanPoint *wire.OutPoint,
nil,
breachInfo.LocalOutputSignDesc,
breachInfo.BreachHeight,
breachInfo.LocalResolutionBlob,
)
breachedOutputs = append(breachedOutputs, localOutput)
@ -1284,6 +1331,7 @@ func newRetributionInfo(chanPoint *wire.OutPoint,
nil,
breachInfo.RemoteOutputSignDesc,
breachInfo.BreachHeight,
breachInfo.RemoteResolutionBlob,
)
breachedOutputs = append(breachedOutputs, remoteOutput)
@ -1318,6 +1366,7 @@ func newRetributionInfo(chanPoint *wire.OutPoint,
breachInfo.HtlcRetributions[i].SecondLevelWitnessScript,
&breachInfo.HtlcRetributions[i].SignDesc,
breachInfo.BreachHeight,
breachInfo.HtlcRetributions[i].ResolutionBlob,
)
// For taproot outputs, we also need to hold onto the second
@ -1357,10 +1406,10 @@ func newRetributionInfo(chanPoint *wire.OutPoint,
// spend the to_local output and commitment level HTLC outputs separately,
// before the CSV locks expire.
type justiceTxVariants struct {
spendAll *wire.MsgTx
spendCommitOuts *wire.MsgTx
spendHTLCs *wire.MsgTx
spendSecondLevelHTLCs []*wire.MsgTx
spendAll *justiceTxCtx
spendCommitOuts *justiceTxCtx
spendHTLCs *justiceTxCtx
spendSecondLevelHTLCs []*justiceTxCtx
}
// createJusticeTx creates transactions which exacts "justice" by sweeping ALL
@ -1424,7 +1473,9 @@ func (b *BreachArbitrator) createJusticeTx(
err)
}
secondLevelSweeps := make([]*wire.MsgTx, 0, len(secondLevelInputs))
// TODO(roasbeef): only register one of them?
secondLevelSweeps := make([]*justiceTxCtx, 0, len(secondLevelInputs))
for _, input := range secondLevelInputs {
sweepTx, err := b.createSweepTx(input)
if err != nil {
@ -1441,9 +1492,23 @@ func (b *BreachArbitrator) createJusticeTx(
return txs, nil
}
// justiceTxCtx contains the justice transaction along with other related meta
// data.
type justiceTxCtx struct {
justiceTx *wire.MsgTx
sweepAddr lnwallet.AddrWithKey
extraTxOut fn.Option[sweep.SweepOutput]
fee btcutil.Amount
inputs []input.Input
}
// createSweepTx creates a tx that sweeps the passed inputs back to our wallet.
func (b *BreachArbitrator) createSweepTx(inputs ...input.Input) (*wire.MsgTx,
error) {
func (b *BreachArbitrator) createSweepTx(
inputs ...input.Input) (*justiceTxCtx, error) {
if len(inputs) == 0 {
return nil, nil
@ -1466,6 +1531,18 @@ func (b *BreachArbitrator) createSweepTx(inputs ...input.Input) (*wire.MsgTx,
// nLockTime, and output are already included in the TxWeightEstimator.
weightEstimate.AddP2TROutput()
// If any of our inputs has a resolution blob, then we'll add another
// P2TR _output_, since we'll want to separate the custom channel
// outputs from the regular, BTC only outputs. So we only need one such
// output, which'll carry the custom channel "valuables" from both the
// breached commitment and HTLC outputs.
hasBlobs := fn.Any(func(i input.Input) bool {
return i.ResolutionBlob().IsSome()
}, inputs)
if hasBlobs {
weightEstimate.AddP2TROutput()
}
// Next, we iterate over the breached outputs contained in the
// retribution info. For each, we switch over the witness type such
// that we contribute the appropriate weight for each input and
@ -1499,13 +1576,13 @@ func (b *BreachArbitrator) createSweepTx(inputs ...input.Input) (*wire.MsgTx,
// sweepSpendableOutputsTxn creates a signed transaction from a sequence of
// spendable outputs by sweeping the funds into a single p2wkh output.
func (b *BreachArbitrator) sweepSpendableOutputsTxn(txWeight lntypes.WeightUnit,
inputs ...input.Input) (*wire.MsgTx, error) {
inputs ...input.Input) (*justiceTxCtx, error) {
// First, we obtain a new public key script from the wallet which we'll
// sweep the funds to.
// TODO(roasbeef): possibly create many outputs to minimize change in
// the future?
pkScript, err := b.cfg.GenSweepScript()
pkScript, err := b.cfg.GenSweepScript().Unpack()
if err != nil {
return nil, err
}
@ -1524,6 +1601,18 @@ func (b *BreachArbitrator) sweepSpendableOutputsTxn(txWeight lntypes.WeightUnit,
}
txFee := feePerKw.FeeForWeight(txWeight)
// At this point, we'll check to see if we have any extra outputs to
// add from the aux sweeper.
extraChangeOut := fn.MapOptionZ(
b.cfg.AuxSweeper,
func(aux sweep.AuxSweeper) fn.Result[sweep.SweepOutput] {
return aux.DeriveSweepAddr(inputs, pkScript)
},
)
if err := extraChangeOut.Err(); err != nil {
return nil, err
}
// TODO(roasbeef): already start to siphon their funds into fees
sweepAmt := int64(totalAmt - txFee)
@ -1531,12 +1620,24 @@ func (b *BreachArbitrator) sweepSpendableOutputsTxn(txWeight lntypes.WeightUnit,
// information gathered above and the provided retribution information.
txn := wire.NewMsgTx(2)
// We begin by adding the output to which our funds will be deposited.
// First, we'll add the extra sweep output if it exists, subtracting the
// amount from the sweep amt.
if b.cfg.AuxSweeper.IsSome() {
extraChangeOut.WhenResult(func(o sweep.SweepOutput) {
sweepAmt -= o.Value
txn.AddTxOut(&o.TxOut)
})
}
// Next, we'll add the output to which our funds will be deposited.
txn.AddTxOut(&wire.TxOut{
PkScript: pkScript,
PkScript: pkScript.DeliveryAddress,
Value: sweepAmt,
})
// TODO(roasbeef): add other output change modify sweep amt
// Next, we add all of the spendable outputs as inputs to the
// transaction.
for _, inp := range inputs {
@ -1592,7 +1693,13 @@ func (b *BreachArbitrator) sweepSpendableOutputsTxn(txWeight lntypes.WeightUnit,
}
}
return txn, nil
return &justiceTxCtx{
justiceTx: txn,
sweepAddr: pkScript,
extraTxOut: extraChangeOut.Option(),
fee: txFee,
inputs: inputs,
}, nil
}
// RetributionStore handles persistence of retribution states to disk and is
@ -1622,13 +1729,29 @@ func taprootBriefcaseFromRetInfo(retInfo *retributionInfo) *taprootBriefcase {
// commitment, we'll need to stash the control block.
case input.TaprootRemoteCommitSpend:
//nolint:lll
tapCase.CtrlBlocks.CommitSweepCtrlBlock = bo.signDesc.ControlBlock
tapCase.CtrlBlocks.Val.CommitSweepCtrlBlock = bo.signDesc.ControlBlock
bo.resolutionBlob.WhenSome(func(blob tlv.Blob) {
tapCase.SettledCommitBlob = tlv.SomeRecordT(
tlv.NewPrimitiveRecord[tlv.TlvType2](
blob,
),
)
})
// To spend the revoked output again, we'll store the same
// control block value as above, but in a different place.
case input.TaprootCommitmentRevoke:
//nolint:lll
tapCase.CtrlBlocks.RevokeSweepCtrlBlock = bo.signDesc.ControlBlock
tapCase.CtrlBlocks.Val.RevokeSweepCtrlBlock = bo.signDesc.ControlBlock
bo.resolutionBlob.WhenSome(func(blob tlv.Blob) {
tapCase.BreachedCommitBlob = tlv.SomeRecordT(
tlv.NewPrimitiveRecord[tlv.TlvType3](
blob,
),
)
})
// For spending the HTLC outputs, we'll store the first and
// second level tweak values.
@ -1642,10 +1765,10 @@ func taprootBriefcaseFromRetInfo(retInfo *retributionInfo) *taprootBriefcase {
secondLevelTweak := bo.secondLevelTapTweak
//nolint:lll
tapCase.TapTweaks.BreachedHtlcTweaks[resID] = firstLevelTweak
tapCase.TapTweaks.Val.BreachedHtlcTweaks[resID] = firstLevelTweak
//nolint:lll
tapCase.TapTweaks.BreachedSecondLevelHltcTweaks[resID] = secondLevelTweak
tapCase.TapTweaks.Val.BreachedSecondLevelHltcTweaks[resID] = secondLevelTweak
}
}
@ -1665,13 +1788,25 @@ func applyTaprootRetInfo(tapCase *taprootBriefcase,
// commitment, we'll apply the control block.
case input.TaprootRemoteCommitSpend:
//nolint:lll
bo.signDesc.ControlBlock = tapCase.CtrlBlocks.CommitSweepCtrlBlock
bo.signDesc.ControlBlock = tapCase.CtrlBlocks.Val.CommitSweepCtrlBlock
tapCase.SettledCommitBlob.WhenSomeV(
func(blob tlv.Blob) {
bo.resolutionBlob = fn.Some(blob)
},
)
// To spend the revoked output again, we'll apply the same
// control block value as above, but to a different place.
case input.TaprootCommitmentRevoke:
//nolint:lll
bo.signDesc.ControlBlock = tapCase.CtrlBlocks.RevokeSweepCtrlBlock
bo.signDesc.ControlBlock = tapCase.CtrlBlocks.Val.RevokeSweepCtrlBlock
tapCase.BreachedCommitBlob.WhenSomeV(
func(blob tlv.Blob) {
bo.resolutionBlob = fn.Some(blob)
},
)
// For spending the HTLC outputs, we'll apply the first and
// second level tweak values.
@ -1680,7 +1815,8 @@ func applyTaprootRetInfo(tapCase *taprootBriefcase,
case input.TaprootHtlcOfferedRevoke:
resID := newResolverID(bo.OutPoint())
tap1, ok := tapCase.TapTweaks.BreachedHtlcTweaks[resID]
//nolint:lll
tap1, ok := tapCase.TapTweaks.Val.BreachedHtlcTweaks[resID]
if !ok {
return fmt.Errorf("unable to find taproot "+
"tweak for: %v", bo.OutPoint())
@ -1688,7 +1824,7 @@ func applyTaprootRetInfo(tapCase *taprootBriefcase,
bo.signDesc.TapTweak = tap1[:]
//nolint:lll
tap2, ok := tapCase.TapTweaks.BreachedSecondLevelHltcTweaks[resID]
tap2, ok := tapCase.TapTweaks.Val.BreachedSecondLevelHltcTweaks[resID]
if !ok {
return fmt.Errorf("unable to find taproot "+
"tweak for: %v", bo.OutPoint())

View File

@ -22,6 +22,7 @@ import (
"github.com/go-errors/errors"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/lntest/channels"
@ -1198,6 +1199,8 @@ func TestBreachCreateJusticeTx(t *testing.T) {
input.HtlcSecondLevelRevoke,
}
rBlob := fn.Some([]byte{0x01})
breachedOutputs := make([]breachedOutput, len(outputTypes))
for i, wt := range outputTypes {
// Create a fake breached output for each type, ensuring they
@ -1216,6 +1219,7 @@ func TestBreachCreateJusticeTx(t *testing.T) {
nil,
signDesc,
1,
rBlob,
)
}
@ -1226,16 +1230,16 @@ func TestBreachCreateJusticeTx(t *testing.T) {
// The spendAll tx should be spending all the outputs. This is the
// "regular" justice transaction type.
require.Len(t, justiceTxs.spendAll.TxIn, len(breachedOutputs))
require.Len(t, justiceTxs.spendAll.justiceTx.TxIn, len(breachedOutputs))
// The spendCommitOuts tx should be spending the 4 types of commit outs
// (note that in practice there will be at most two commit outputs per
// commit, but we test all 4 types here).
require.Len(t, justiceTxs.spendCommitOuts.TxIn, 4)
require.Len(t, justiceTxs.spendCommitOuts.justiceTx.TxIn, 4)
// Check that the spendHTLCs tx is spending the two revoked commitment
// level HTLC output types.
require.Len(t, justiceTxs.spendHTLCs.TxIn, 2)
require.Len(t, justiceTxs.spendHTLCs.justiceTx.TxIn, 2)
// Finally, check that the spendSecondLevelHTLCs txs are spending the
// second level type.
@ -1590,6 +1594,10 @@ func testBreachSpends(t *testing.T, test breachTest) {
// Notify the breach arbiter about the breach.
retribution, err := lnwallet.NewBreachRetribution(
alice.State(), height, 1, forceCloseTx,
fn.Some[lnwallet.AuxLeafStore](&lnwallet.MockAuxLeafStore{}),
fn.Some[lnwallet.AuxContractResolver](
&lnwallet.MockAuxContractResolver{},
),
)
require.NoError(t, err, "unable to create breach retribution")
@ -1799,6 +1807,10 @@ func TestBreachDelayedJusticeConfirmation(t *testing.T) {
// Notify the breach arbiter about the breach.
retribution, err := lnwallet.NewBreachRetribution(
alice.State(), height, uint32(blockHeight), forceCloseTx,
fn.Some[lnwallet.AuxLeafStore](&lnwallet.MockAuxLeafStore{}),
fn.Some[lnwallet.AuxContractResolver](
&lnwallet.MockAuxContractResolver{},
),
)
require.NoError(t, err, "unable to create breach retribution")
@ -2126,15 +2138,19 @@ func createTestArbiter(t *testing.T, contractBreaches chan *ContractBreachEvent,
// Assemble our test arbiter.
notifier := mock.MakeMockSpendNotifier()
ba := NewBreachArbitrator(&BreachConfig{
CloseLink: func(_ *wire.OutPoint, _ ChannelCloseType) {},
DB: db.ChannelStateDB(),
Estimator: chainfee.NewStaticEstimator(12500, 0),
GenSweepScript: func() ([]byte, error) { return nil, nil },
ContractBreaches: contractBreaches,
Signer: signer,
Notifier: notifier,
PublishTransaction: func(_ *wire.MsgTx, _ string) error { return nil },
Store: store,
CloseLink: func(_ *wire.OutPoint, _ ChannelCloseType) {},
DB: db.ChannelStateDB(),
Estimator: chainfee.NewStaticEstimator(12500, 0),
GenSweepScript: func() fn.Result[lnwallet.AddrWithKey] {
return fn.Ok(lnwallet.AddrWithKey{})
},
ContractBreaches: contractBreaches,
Signer: signer,
Notifier: notifier,
PublishTransaction: func(_ *wire.MsgTx, _ string) error {
return nil
},
Store: store,
})
if err := ba.Start(); err != nil {
@ -2357,9 +2373,12 @@ func createInitChannels(t *testing.T) (
)
bobSigner := input.NewMockSigner([]*btcec.PrivateKey{bobKeyPriv}, nil)
signerMock := lnwallet.NewDefaultAuxSignerMock(t)
alicePool := lnwallet.NewSigPool(1, aliceSigner)
channelAlice, err := lnwallet.NewLightningChannel(
aliceSigner, aliceChannelState, alicePool,
lnwallet.WithLeafStore(&lnwallet.MockAuxLeafStore{}),
lnwallet.WithAuxSigner(signerMock),
)
if err != nil {
return nil, nil, err
@ -2372,6 +2391,8 @@ func createInitChannels(t *testing.T) (
bobPool := lnwallet.NewSigPool(1, bobSigner)
channelBob, err := lnwallet.NewLightningChannel(
bobSigner, bobChannelState, bobPool,
lnwallet.WithLeafStore(&lnwallet.MockAuxLeafStore{}),
lnwallet.WithAuxSigner(signerMock),
)
if err != nil {
return nil, nil, err

View File

@ -10,9 +10,11 @@ import (
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/tlv"
)
// ContractResolutions is a wrapper struct around the two forms of resolutions
@ -1553,9 +1555,16 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
commitResolution := c.CommitResolution
commitSignDesc := commitResolution.SelfOutputSignDesc
//nolint:lll
tapCase.CtrlBlocks.CommitSweepCtrlBlock = commitSignDesc.ControlBlock
tapCase.CtrlBlocks.Val.CommitSweepCtrlBlock = commitSignDesc.ControlBlock
c.CommitResolution.ResolutionBlob.WhenSome(func(b []byte) {
tapCase.SettledCommitBlob = tlv.SomeRecordT(
tlv.NewPrimitiveRecord[tlv.TlvType2](b),
)
})
}
htlcBlobs := newAuxHtlcBlobs()
for _, htlc := range c.HtlcResolutions.IncomingHTLCs {
htlc := htlc
@ -1566,12 +1575,13 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
continue
}
var resID resolverID
if htlc.SignedSuccessTx != nil {
resID := newResolverID(
resID = newResolverID(
htlc.SignedSuccessTx.TxIn[0].PreviousOutPoint,
)
//nolint:lll
tapCase.CtrlBlocks.SecondLevelCtrlBlocks[resID] = ctrlBlock
tapCase.CtrlBlocks.Val.SecondLevelCtrlBlocks[resID] = ctrlBlock
// For HTLCs we need to go to the second level for, we
// also need to store the control block needed to
@ -1580,13 +1590,17 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
//nolint:lll
bridgeCtrlBlock := htlc.SignDetails.SignDesc.ControlBlock
//nolint:lll
tapCase.CtrlBlocks.IncomingHtlcCtrlBlocks[resID] = bridgeCtrlBlock
tapCase.CtrlBlocks.Val.IncomingHtlcCtrlBlocks[resID] = bridgeCtrlBlock
}
} else {
resID := newResolverID(htlc.ClaimOutpoint)
resID = newResolverID(htlc.ClaimOutpoint)
//nolint:lll
tapCase.CtrlBlocks.IncomingHtlcCtrlBlocks[resID] = ctrlBlock
tapCase.CtrlBlocks.Val.IncomingHtlcCtrlBlocks[resID] = ctrlBlock
}
htlc.ResolutionBlob.WhenSome(func(b []byte) {
htlcBlobs[resID] = b
})
}
for _, htlc := range c.HtlcResolutions.OutgoingHTLCs {
htlc := htlc
@ -1598,12 +1612,13 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
continue
}
var resID resolverID
if htlc.SignedTimeoutTx != nil {
resID := newResolverID(
resID = newResolverID(
htlc.SignedTimeoutTx.TxIn[0].PreviousOutPoint,
)
//nolint:lll
tapCase.CtrlBlocks.SecondLevelCtrlBlocks[resID] = ctrlBlock
tapCase.CtrlBlocks.Val.SecondLevelCtrlBlocks[resID] = ctrlBlock
// For HTLCs we need to go to the second level for, we
// also need to store the control block needed to
@ -1614,18 +1629,28 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
//nolint:lll
bridgeCtrlBlock := htlc.SignDetails.SignDesc.ControlBlock
//nolint:lll
tapCase.CtrlBlocks.OutgoingHtlcCtrlBlocks[resID] = bridgeCtrlBlock
tapCase.CtrlBlocks.Val.OutgoingHtlcCtrlBlocks[resID] = bridgeCtrlBlock
}
} else {
resID := newResolverID(htlc.ClaimOutpoint)
resID = newResolverID(htlc.ClaimOutpoint)
//nolint:lll
tapCase.CtrlBlocks.OutgoingHtlcCtrlBlocks[resID] = ctrlBlock
tapCase.CtrlBlocks.Val.OutgoingHtlcCtrlBlocks[resID] = ctrlBlock
}
htlc.ResolutionBlob.WhenSome(func(b []byte) {
htlcBlobs[resID] = b
})
}
if c.AnchorResolution != nil {
anchorSignDesc := c.AnchorResolution.AnchorSignDescriptor
tapCase.TapTweaks.AnchorTweak = anchorSignDesc.TapTweak
tapCase.TapTweaks.Val.AnchorTweak = anchorSignDesc.TapTweak
}
if len(htlcBlobs) != 0 {
tapCase.HtlcBlobs = tlv.SomeRecordT(
tlv.NewRecordT[tlv.TlvType4](htlcBlobs),
)
}
return tapCase.Encode(w)
@ -1639,9 +1664,15 @@ func decodeTapRootAuxData(r io.Reader, c *ContractResolutions) error {
if c.CommitResolution != nil {
c.CommitResolution.SelfOutputSignDesc.ControlBlock =
tapCase.CtrlBlocks.CommitSweepCtrlBlock
tapCase.CtrlBlocks.Val.CommitSweepCtrlBlock
tapCase.SettledCommitBlob.WhenSomeV(func(b []byte) {
c.CommitResolution.ResolutionBlob = fn.Some(b)
})
}
htlcBlobs := tapCase.HtlcBlobs.ValOpt().UnwrapOr(newAuxHtlcBlobs())
for i := range c.HtlcResolutions.IncomingHTLCs {
htlc := c.HtlcResolutions.IncomingHTLCs[i]
@ -1652,23 +1683,28 @@ func decodeTapRootAuxData(r io.Reader, c *ContractResolutions) error {
)
//nolint:lll
ctrlBlock := tapCase.CtrlBlocks.SecondLevelCtrlBlocks[resID]
ctrlBlock := tapCase.CtrlBlocks.Val.SecondLevelCtrlBlocks[resID]
htlc.SweepSignDesc.ControlBlock = ctrlBlock
//nolint:lll
if htlc.SignDetails != nil {
bridgeCtrlBlock := tapCase.CtrlBlocks.IncomingHtlcCtrlBlocks[resID]
bridgeCtrlBlock := tapCase.CtrlBlocks.Val.IncomingHtlcCtrlBlocks[resID]
htlc.SignDetails.SignDesc.ControlBlock = bridgeCtrlBlock
}
} else {
resID = newResolverID(htlc.ClaimOutpoint)
//nolint:lll
ctrlBlock := tapCase.CtrlBlocks.IncomingHtlcCtrlBlocks[resID]
ctrlBlock := tapCase.CtrlBlocks.Val.IncomingHtlcCtrlBlocks[resID]
htlc.SweepSignDesc.ControlBlock = ctrlBlock
}
if htlcBlob, ok := htlcBlobs[resID]; ok {
htlc.ResolutionBlob = fn.Some(htlcBlob)
}
c.HtlcResolutions.IncomingHTLCs[i] = htlc
}
for i := range c.HtlcResolutions.OutgoingHTLCs {
htlc := c.HtlcResolutions.OutgoingHTLCs[i]
@ -1680,28 +1716,32 @@ func decodeTapRootAuxData(r io.Reader, c *ContractResolutions) error {
)
//nolint:lll
ctrlBlock := tapCase.CtrlBlocks.SecondLevelCtrlBlocks[resID]
ctrlBlock := tapCase.CtrlBlocks.Val.SecondLevelCtrlBlocks[resID]
htlc.SweepSignDesc.ControlBlock = ctrlBlock
//nolint:lll
if htlc.SignDetails != nil {
bridgeCtrlBlock := tapCase.CtrlBlocks.OutgoingHtlcCtrlBlocks[resID]
bridgeCtrlBlock := tapCase.CtrlBlocks.Val.OutgoingHtlcCtrlBlocks[resID]
htlc.SignDetails.SignDesc.ControlBlock = bridgeCtrlBlock
}
} else {
resID = newResolverID(htlc.ClaimOutpoint)
//nolint:lll
ctrlBlock := tapCase.CtrlBlocks.OutgoingHtlcCtrlBlocks[resID]
ctrlBlock := tapCase.CtrlBlocks.Val.OutgoingHtlcCtrlBlocks[resID]
htlc.SweepSignDesc.ControlBlock = ctrlBlock
}
if htlcBlob, ok := htlcBlobs[resID]; ok {
htlc.ResolutionBlob = fn.Some(htlcBlob)
}
c.HtlcResolutions.OutgoingHTLCs[i] = htlc
}
if c.AnchorResolution != nil {
c.AnchorResolution.AnchorSignDescriptor.TapTweak =
tapCase.TapTweaks.AnchorTweak
tapCase.TapTweaks.Val.AnchorTweak
}
return nil

View File

@ -217,6 +217,18 @@ type ChainArbitratorConfig struct {
// meanwhile, turn `PaymentCircuit` into an interface or bring it to a
// lower package.
QueryIncomingCircuit func(circuit models.CircuitKey) *models.CircuitKey
// AuxLeafStore is an optional store that can be used to store auxiliary
// leaves for certain custom channel types.
AuxLeafStore fn.Option[lnwallet.AuxLeafStore]
// AuxSigner is an optional signer that can be used to sign auxiliary
// leaves for certain custom channel types.
AuxSigner fn.Option[lnwallet.AuxSigner]
// AuxResolver is an optional interface that can be used to modify the
// way contracts are resolved.
AuxResolver fn.Option[lnwallet.AuxContractResolver]
}
// ChainArbitrator is a sub-system that oversees the on-chain resolution of all
@ -299,8 +311,19 @@ func (a *arbChannel) NewAnchorResolutions() (*lnwallet.AnchorResolutions,
return nil, err
}
var chanOpts []lnwallet.ChannelOpt
a.c.cfg.AuxLeafStore.WhenSome(func(s lnwallet.AuxLeafStore) {
chanOpts = append(chanOpts, lnwallet.WithLeafStore(s))
})
a.c.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) {
chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s))
})
a.c.cfg.AuxResolver.WhenSome(func(s lnwallet.AuxContractResolver) {
chanOpts = append(chanOpts, lnwallet.WithAuxResolver(s))
})
chanMachine, err := lnwallet.NewLightningChannel(
a.c.cfg.Signer, channel, nil,
a.c.cfg.Signer, channel, nil, chanOpts...,
)
if err != nil {
return nil, err
@ -312,11 +335,10 @@ func (a *arbChannel) NewAnchorResolutions() (*lnwallet.AnchorResolutions,
// ForceCloseChan should force close the contract that this attendant is
// watching over. We'll use this when we decide that we need to go to chain. It
// should in addition tell the switch to remove the corresponding link, such
// that we won't accept any new updates. The returned summary contains all items
// needed to eventually resolve all outputs on chain.
// that we won't accept any new updates.
//
// NOTE: Part of the ArbChannel interface.
func (a *arbChannel) ForceCloseChan() (*lnwallet.LocalForceCloseSummary, error) {
func (a *arbChannel) ForceCloseChan() (*wire.MsgTx, error) {
// First, we mark the channel as borked, this ensure
// that no new state transitions can happen, and also
// that the link won't be loaded into the switch.
@ -344,15 +366,34 @@ func (a *arbChannel) ForceCloseChan() (*lnwallet.LocalForceCloseSummary, error)
return nil, err
}
var chanOpts []lnwallet.ChannelOpt
a.c.cfg.AuxLeafStore.WhenSome(func(s lnwallet.AuxLeafStore) {
chanOpts = append(chanOpts, lnwallet.WithLeafStore(s))
})
a.c.cfg.AuxSigner.WhenSome(func(s lnwallet.AuxSigner) {
chanOpts = append(chanOpts, lnwallet.WithAuxSigner(s))
})
a.c.cfg.AuxResolver.WhenSome(func(s lnwallet.AuxContractResolver) {
chanOpts = append(chanOpts, lnwallet.WithAuxResolver(s))
})
// Finally, we'll force close the channel completing
// the force close workflow.
chanMachine, err := lnwallet.NewLightningChannel(
a.c.cfg.Signer, channel, nil,
a.c.cfg.Signer, channel, nil, chanOpts...,
)
if err != nil {
return nil, err
}
return chanMachine.ForceClose()
closeSummary, err := chanMachine.ForceClose(
lnwallet.WithSkipContractResolutions(),
)
if err != nil {
return nil, err
}
return closeSummary.CloseTx, nil
}
// newActiveChannelArbitrator creates a new instance of an active channel
@ -557,6 +598,8 @@ func (c *ChainArbitrator) Start() error {
isOurAddr: c.cfg.IsOurAddress,
contractBreach: breachClosure,
extractStateNumHint: lnwallet.GetStateNumHint,
auxLeafStore: c.cfg.AuxLeafStore,
auxResolver: c.cfg.AuxResolver,
},
)
if err != nil {
@ -1186,6 +1229,8 @@ func (c *ChainArbitrator) WatchNewChannel(newChan *channeldb.OpenChannel) error
)
},
extractStateNumHint: lnwallet.GetStateNumHint,
auxLeafStore: c.cfg.AuxLeafStore,
auxResolver: c.cfg.AuxResolver,
},
)
if err != nil {

View File

@ -193,6 +193,12 @@ type chainWatcherConfig struct {
// obfuscater. This is used by the chain watcher to identify which
// state was broadcast and confirmed on-chain.
extractStateNumHint func(*wire.MsgTx, [lnwallet.StateHintSize]byte) uint64
// auxLeafStore can be used to fetch information for custom channels.
auxLeafStore fn.Option[lnwallet.AuxLeafStore]
// auxResolver is used to supplement contract resolution.
auxResolver fn.Option[lnwallet.AuxContractResolver]
}
// chainWatcher is a system that's assigned to every active channel. The duty
@ -308,7 +314,7 @@ func (c *chainWatcher) Start() error {
)
if chanState.ChanType.IsTaproot() {
c.fundingPkScript, _, err = input.GenTaprootFundingScript(
localKey, remoteKey, 0,
localKey, remoteKey, 0, chanState.TapscriptRoot,
)
if err != nil {
return err
@ -423,15 +429,37 @@ func (c *chainWatcher) handleUnknownLocalState(
&c.cfg.chanState.LocalChanCfg, &c.cfg.chanState.RemoteChanCfg,
)
auxResult, err := fn.MapOptionZ(
c.cfg.auxLeafStore,
//nolint:lll
func(s lnwallet.AuxLeafStore) fn.Result[lnwallet.CommitDiffAuxResult] {
return s.FetchLeavesFromCommit(
lnwallet.NewAuxChanState(c.cfg.chanState),
c.cfg.chanState.LocalCommitment, *commitKeyRing,
lntypes.Local,
)
},
).Unpack()
if err != nil {
return false, fmt.Errorf("unable to fetch aux leaves: %w", err)
}
// With the keys derived, we'll construct the remote script that'll be
// present if they have a non-dust balance on the commitment.
var leaseExpiry uint32
if c.cfg.chanState.ChanType.HasLeaseExpiration() {
leaseExpiry = c.cfg.chanState.ThawHeight
}
remoteAuxLeaf := fn.ChainOption(
func(l lnwallet.CommitAuxLeaves) input.AuxTapLeaf {
return l.RemoteAuxLeaf
},
)(auxResult.AuxLeaves)
remoteScript, _, err := lnwallet.CommitScriptToRemote(
c.cfg.chanState.ChanType, c.cfg.chanState.IsInitiator,
commitKeyRing.ToRemoteKey, leaseExpiry,
remoteAuxLeaf,
)
if err != nil {
return false, err
@ -440,10 +468,16 @@ func (c *chainWatcher) handleUnknownLocalState(
// Next, we'll derive our script that includes the revocation base for
// the remote party allowing them to claim this output before the CSV
// delay if we breach.
localAuxLeaf := fn.ChainOption(
func(l lnwallet.CommitAuxLeaves) input.AuxTapLeaf {
return l.LocalAuxLeaf
},
)(auxResult.AuxLeaves)
localScript, err := lnwallet.CommitScriptToSelf(
c.cfg.chanState.ChanType, c.cfg.chanState.IsInitiator,
commitKeyRing.ToLocalKey, commitKeyRing.RevocationKey,
uint32(c.cfg.chanState.LocalChanCfg.CsvDelay), leaseExpiry,
localAuxLeaf,
)
if err != nil {
return false, err
@ -866,7 +900,7 @@ func (c *chainWatcher) handlePossibleBreach(commitSpend *chainntnfs.SpendDetail,
spendHeight := uint32(commitSpend.SpendingHeight)
retribution, err := lnwallet.NewBreachRetribution(
c.cfg.chanState, broadcastStateNum, spendHeight,
commitSpend.SpendingTx,
commitSpend.SpendingTx, c.cfg.auxLeafStore, c.cfg.auxResolver,
)
switch {
@ -1116,8 +1150,8 @@ func (c *chainWatcher) dispatchLocalForceClose(
"detected", c.cfg.chanState.FundingOutpoint)
forceClose, err := lnwallet.NewLocalForceCloseSummary(
c.cfg.chanState, c.cfg.signer,
commitSpend.SpendingTx, stateNum,
c.cfg.chanState, c.cfg.signer, commitSpend.SpendingTx, stateNum,
c.cfg.auxLeafStore, c.cfg.auxResolver,
)
if err != nil {
return err
@ -1141,16 +1175,29 @@ func (c *chainWatcher) dispatchLocalForceClose(
LocalChanConfig: c.cfg.chanState.LocalChanCfg,
}
resolutions, err := forceClose.ContractResolutions.UnwrapOrErr(
fmt.Errorf("resolutions not found"),
)
if err != nil {
return err
}
// If our commitment output isn't dust or we have active HTLC's on the
// commitment transaction, then we'll populate the balances on the
// close channel summary.
if forceClose.CommitResolution != nil {
closeSummary.SettledBalance = chanSnapshot.LocalBalance.ToSatoshis()
closeSummary.TimeLockedBalance = chanSnapshot.LocalBalance.ToSatoshis()
if resolutions.CommitResolution != nil {
localBalance := chanSnapshot.LocalBalance.ToSatoshis()
closeSummary.SettledBalance = localBalance
closeSummary.TimeLockedBalance = localBalance
}
for _, htlc := range forceClose.HtlcResolutions.OutgoingHTLCs {
htlcValue := btcutil.Amount(htlc.SweepSignDesc.Output.Value)
closeSummary.TimeLockedBalance += htlcValue
if resolutions.HtlcResolutions != nil {
for _, htlc := range resolutions.HtlcResolutions.OutgoingHTLCs {
htlcValue := btcutil.Amount(
htlc.SweepSignDesc.Output.Value,
)
closeSummary.TimeLockedBalance += htlcValue
}
}
// Attempt to add a channel sync message to the close summary.
@ -1209,8 +1256,8 @@ func (c *chainWatcher) dispatchRemoteForceClose(
// materials required to let each subscriber sweep the funds in the
// channel on-chain.
uniClose, err := lnwallet.NewUnilateralCloseSummary(
c.cfg.chanState, c.cfg.signer, commitSpend,
remoteCommit, commitPoint,
c.cfg.chanState, c.cfg.signer, commitSpend, remoteCommit,
commitPoint, c.cfg.auxLeafStore, c.cfg.auxResolver,
)
if err != nil {
return err

View File

@ -2,6 +2,7 @@ package contractcourt
import (
"bytes"
"context"
"crypto/sha256"
"fmt"
"testing"
@ -145,17 +146,15 @@ func TestChainWatcherRemoteUnilateralClosePendingCommit(t *testing.T) {
// With the HTLC added, we'll now manually initiate a state transition
// from Alice to Bob.
_, err = aliceChannel.SignNextCommitment()
if err != nil {
t.Fatal(err)
}
testQuit, testQuitFunc := context.WithCancel(context.Background())
t.Cleanup(testQuitFunc)
_, err = aliceChannel.SignNextCommitment(testQuit)
require.NoError(t, err)
// At this point, we'll now Bob broadcasting this new pending unrevoked
// commitment.
bobPendingCommit, err := aliceChannel.State().RemoteCommitChainTip()
if err != nil {
t.Fatal(err)
}
require.NoError(t, err)
// We'll craft a fake spend notification with Bob's actual commitment.
// The chain watcher should be able to detect that this is a pending
@ -505,14 +504,24 @@ func TestChainWatcherLocalForceCloseDetect(t *testing.T) {
// outputs.
select {
case summary := <-chanEvents.LocalUnilateralClosure:
resOpt := summary.LocalForceCloseSummary.
ContractResolutions
resolutions, err := resOpt.UnwrapOrErr(
fmt.Errorf("resolutions not found"),
)
if err != nil {
t.Fatalf("unable to get resolutions: %v", err)
}
// Make sure we correctly extracted the commit
// resolution if we had a local output.
if remoteOutputOnly {
if summary.CommitResolution != nil {
if resolutions.CommitResolution != nil {
t.Fatalf("expected no commit resolution")
}
} else {
if summary.CommitResolution == nil {
if resolutions.CommitResolution == nil {
t.Fatalf("expected commit resolution")
}
}

View File

@ -98,7 +98,7 @@ type ArbChannel interface {
// corresponding link, such that we won't accept any new updates. The
// returned summary contains all items needed to eventually resolve all
// outputs on chain.
ForceCloseChan() (*lnwallet.LocalForceCloseSummary, error)
ForceCloseChan() (*wire.MsgTx, error)
// NewAnchorResolutions returns the anchor resolutions for currently
// valid commitment transactions.
@ -482,6 +482,20 @@ func (c *ChannelArbitrator) Start(state *chanArbStartState) error {
return err
}
c.wg.Add(1)
go c.channelAttendant(bestHeight, state.commitSet)
return nil
}
// progressStateMachineAfterRestart attempts to progress the state machine
// after a restart. This makes sure that if the state transition failed, we
// will try to progress the state machine again. Moreover it will relaunch
// resolvers if the channel is still in the pending close state and has not
// been fully resolved yet.
func (c *ChannelArbitrator) progressStateMachineAfterRestart(bestHeight int32,
commitSet *CommitSet) error {
// If the channel has been marked pending close in the database, and we
// haven't transitioned the state machine to StateContractClosed (or a
// succeeding state), then a state transition most likely failed. We'll
@ -527,7 +541,7 @@ func (c *ChannelArbitrator) Start(state *chanArbStartState) error {
// on-chain state, and our set of active contracts.
startingState := c.state
nextState, _, err := c.advanceState(
triggerHeight, trigger, state.commitSet,
triggerHeight, trigger, commitSet,
)
if err != nil {
switch err {
@ -564,14 +578,12 @@ func (c *ChannelArbitrator) Start(state *chanArbStartState) error {
// receive a chain event from the chain watcher that the
// commitment has been confirmed on chain, and before we
// advance our state step, we call InsertConfirmedCommitSet.
err := c.relaunchResolvers(state.commitSet, triggerHeight)
err := c.relaunchResolvers(commitSet, triggerHeight)
if err != nil {
return err
}
}
c.wg.Add(1)
go c.channelAttendant(bestHeight)
return nil
}
@ -1058,7 +1070,7 @@ func (c *ChannelArbitrator) stateStep(
// We'll tell the switch that it should remove the link for
// this channel, in addition to fetching the force close
// summary needed to close this channel on chain.
closeSummary, err := c.cfg.Channel.ForceCloseChan()
forceCloseTx, err := c.cfg.Channel.ForceCloseChan()
if err != nil {
log.Errorf("ChannelArbitrator(%v): unable to "+
"force close: %v", c.cfg.ChanPoint, err)
@ -1078,7 +1090,7 @@ func (c *ChannelArbitrator) stateStep(
return StateError, closeTx, err
}
closeTx = closeSummary.CloseTx
closeTx = forceCloseTx
// Before publishing the transaction, we store it to the
// database, such that we can re-publish later in case it
@ -1982,9 +1994,11 @@ func (c *ChannelArbitrator) isPreimageAvailable(hash lntypes.Hash) (bool,
// have the incoming contest resolver decide that we don't want to
// settle this invoice.
invoice, err := c.cfg.Registry.LookupInvoice(context.Background(), hash)
switch err {
case nil:
case invoices.ErrInvoiceNotFound, invoices.ErrNoInvoicesCreated:
switch {
case err == nil:
case errors.Is(err, invoices.ErrInvoiceNotFound) ||
errors.Is(err, invoices.ErrNoInvoicesCreated):
return false, nil
default:
return false, err
@ -2773,13 +2787,28 @@ func (c *ChannelArbitrator) updateActiveHTLCs() {
// Nursery for incubation, and ultimate sweeping.
//
// NOTE: This MUST be run as a goroutine.
func (c *ChannelArbitrator) channelAttendant(bestHeight int32) {
//
//nolint:funlen
func (c *ChannelArbitrator) channelAttendant(bestHeight int32,
commitSet *CommitSet) {
// TODO(roasbeef): tell top chain arb we're done
defer func() {
c.wg.Done()
}()
err := c.progressStateMachineAfterRestart(bestHeight, commitSet)
if err != nil {
// In case of an error, we return early but we do not shutdown
// LND, because there might be other channels that still can be
// resolved and we don't want to interfere with that.
// We continue to run the channel attendant in case the channel
// closes via other means for example the remote pary force
// closes the channel. So we log the error and continue.
log.Errorf("Unable to progress state machine after "+
"restart: %v", err)
}
for {
select {
@ -2869,11 +2898,36 @@ func (c *ChannelArbitrator) channelAttendant(bestHeight int32) {
}
closeTx := closeInfo.CloseTx
resolutions, err := closeInfo.ContractResolutions.
UnwrapOrErr(
fmt.Errorf("resolutions not found"),
)
if err != nil {
log.Errorf("ChannelArbitrator(%v): unable to "+
"get resolutions: %v", c.cfg.ChanPoint,
err)
return
}
// We make sure that the htlc resolutions are present
// otherwise we would panic dereferencing the pointer.
//
// TODO(ziggie): Refactor ContractResolutions to use
// options.
if resolutions.HtlcResolutions == nil {
log.Errorf("ChannelArbitrator(%v): htlc "+
"resolutions not found",
c.cfg.ChanPoint)
return
}
contractRes := &ContractResolutions{
CommitHash: closeTx.TxHash(),
CommitResolution: closeInfo.CommitResolution,
HtlcResolutions: *closeInfo.HtlcResolutions,
AnchorResolution: closeInfo.AnchorResolution,
CommitResolution: resolutions.CommitResolution,
HtlcResolutions: *resolutions.HtlcResolutions,
AnchorResolution: resolutions.AnchorResolution,
}
// When processing a unilateral close event, we'll
@ -2882,7 +2936,7 @@ func (c *ChannelArbitrator) channelAttendant(bestHeight int32) {
// available to fetch in that state, we'll also write
// the commit set so we can reconstruct our chain
// actions on restart.
err := c.log.LogContractResolutions(contractRes)
err = c.log.LogContractResolutions(contractRes)
if err != nil {
log.Errorf("Unable to write resolutions: %v",
err)

View File

@ -21,6 +21,7 @@ import (
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lntest/mock"
"github.com/lightningnetwork/lnd/lntest/wait"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire"
@ -693,11 +694,15 @@ func TestChannelArbitratorLocalForceClose(t *testing.T) {
chanArbCtx.AssertState(StateCommitmentBroadcasted)
// Now notify about the local force close getting confirmed.
//
//nolint:lll
chanArb.cfg.ChainEvents.LocalUnilateralClosure <- &LocalUnilateralCloseInfo{
SpendDetail: &chainntnfs.SpendDetail{},
LocalForceCloseSummary: &lnwallet.LocalForceCloseSummary{
CloseTx: &wire.MsgTx{},
HtlcResolutions: &lnwallet.HtlcResolutions{},
CloseTx: &wire.MsgTx{},
ContractResolutions: fn.Some(lnwallet.ContractResolutions{
HtlcResolutions: &lnwallet.HtlcResolutions{},
}),
},
ChannelCloseSummary: &channeldb.ChannelCloseSummary{},
}
@ -969,15 +974,18 @@ func TestChannelArbitratorLocalForceClosePendingHtlc(t *testing.T) {
},
}
//nolint:lll
chanArb.cfg.ChainEvents.LocalUnilateralClosure <- &LocalUnilateralCloseInfo{
SpendDetail: &chainntnfs.SpendDetail{},
LocalForceCloseSummary: &lnwallet.LocalForceCloseSummary{
CloseTx: closeTx,
HtlcResolutions: &lnwallet.HtlcResolutions{
OutgoingHTLCs: []lnwallet.OutgoingHtlcResolution{
outgoingRes,
ContractResolutions: fn.Some(lnwallet.ContractResolutions{
HtlcResolutions: &lnwallet.HtlcResolutions{
OutgoingHTLCs: []lnwallet.OutgoingHtlcResolution{
outgoingRes,
},
},
},
}),
},
ChannelCloseSummary: &channeldb.ChannelCloseSummary{},
CommitSet: CommitSet{
@ -1036,10 +1044,19 @@ func TestChannelArbitratorLocalForceClosePendingHtlc(t *testing.T) {
// Post restart, it should be the case that our resolver was properly
// supplemented, and we only have a single resolver in the final set.
if len(chanArb.activeResolvers) != 1 {
t.Fatalf("expected single resolver, instead got: %v",
len(chanArb.activeResolvers))
}
// The resolvers are added concurrently so we need to wait here.
err = wait.NoError(func() error {
chanArb.activeResolversLock.Lock()
defer chanArb.activeResolversLock.Unlock()
if len(chanArb.activeResolvers) != 1 {
return fmt.Errorf("expected single resolver, instead "+
"got: %v", len(chanArb.activeResolvers))
}
return nil
}, defaultTimeout)
require.NoError(t, err)
// We'll now examine the in-memory state of the active resolvers to
// ensure t hey were populated properly.
@ -1611,12 +1628,15 @@ func TestChannelArbitratorCommitFailure(t *testing.T) {
},
{
closeType: channeldb.LocalForceClose,
//nolint:lll
sendEvent: func(chanArb *ChannelArbitrator) {
chanArb.cfg.ChainEvents.LocalUnilateralClosure <- &LocalUnilateralCloseInfo{
SpendDetail: &chainntnfs.SpendDetail{},
LocalForceCloseSummary: &lnwallet.LocalForceCloseSummary{
CloseTx: &wire.MsgTx{},
HtlcResolutions: &lnwallet.HtlcResolutions{},
CloseTx: &wire.MsgTx{},
ContractResolutions: fn.Some(lnwallet.ContractResolutions{
HtlcResolutions: &lnwallet.HtlcResolutions{},
}),
},
ChannelCloseSummary: &channeldb.ChannelCloseSummary{},
}
@ -1944,11 +1964,15 @@ func TestChannelArbitratorDanglingCommitForceClose(t *testing.T) {
// being canalled back. Also note that there're no HTLC
// resolutions sent since we have none on our
// commitment transaction.
//
//nolint:lll
uniCloseInfo := &LocalUnilateralCloseInfo{
SpendDetail: &chainntnfs.SpendDetail{},
LocalForceCloseSummary: &lnwallet.LocalForceCloseSummary{
CloseTx: closeTx,
HtlcResolutions: &lnwallet.HtlcResolutions{},
CloseTx: closeTx,
ContractResolutions: fn.Some(lnwallet.ContractResolutions{
HtlcResolutions: &lnwallet.HtlcResolutions{},
}),
},
ChannelCloseSummary: &channeldb.ChannelCloseSummary{},
CommitSet: CommitSet{
@ -2754,12 +2778,15 @@ func TestChannelArbitratorAnchors(t *testing.T) {
},
}
//nolint:lll
chanArb.cfg.ChainEvents.LocalUnilateralClosure <- &LocalUnilateralCloseInfo{
SpendDetail: &chainntnfs.SpendDetail{},
LocalForceCloseSummary: &lnwallet.LocalForceCloseSummary{
CloseTx: closeTx,
HtlcResolutions: &lnwallet.HtlcResolutions{},
AnchorResolution: anchorResolution,
CloseTx: closeTx,
ContractResolutions: fn.Some(lnwallet.ContractResolutions{
HtlcResolutions: &lnwallet.HtlcResolutions{},
AnchorResolution: anchorResolution,
}),
},
ChannelCloseSummary: &channeldb.ChannelCloseSummary{},
CommitSet: CommitSet{
@ -2867,9 +2894,12 @@ func TestChannelArbitratorStartForceCloseFail(t *testing.T) {
{
name: "Commitment is rejected with an " +
"unmatched error",
broadcastErr: fmt.Errorf("Reject Commitment Tx"),
expectedState: StateBroadcastCommit,
expectedStartup: false,
broadcastErr: fmt.Errorf("Reject Commitment Tx"),
expectedState: StateBroadcastCommit,
// We should still be able to start up since we other
// channels might be closing as well and we should
// resolve the contracts.
expectedStartup: true,
},
// We started after the DLP was triggered, and try to force
@ -2993,14 +3023,10 @@ func (m *mockChannel) NewAnchorResolutions() (*lnwallet.AnchorResolutions,
return &lnwallet.AnchorResolutions{}, nil
}
func (m *mockChannel) ForceCloseChan() (*lnwallet.LocalForceCloseSummary, error) {
func (m *mockChannel) ForceCloseChan() (*wire.MsgTx, error) {
if m.forceCloseErr != nil {
return nil, m.forceCloseErr
}
summary := &lnwallet.LocalForceCloseSummary{
CloseTx: &wire.MsgTx{},
HtlcResolutions: &lnwallet.HtlcResolutions{},
}
return summary, nil
return &wire.MsgTx{}, nil
}

View File

@ -345,12 +345,18 @@ func (c *commitSweepResolver) Resolve(_ bool) (ContractResolver, error) {
&c.commitResolution.SelfOutputSignDesc,
c.broadcastHeight, c.commitResolution.MaturityDelay,
c.leaseExpiry,
input.WithResolutionBlob(
c.commitResolution.ResolutionBlob,
),
)
} else {
inp = input.NewCsvInput(
&c.commitResolution.SelfOutPoint, witnessType,
&c.commitResolution.SelfOutputSignDesc,
c.broadcastHeight, c.commitResolution.MaturityDelay,
input.WithResolutionBlob(
c.commitResolution.ResolutionBlob,
),
)
}

View File

@ -308,7 +308,8 @@ func (h *htlcIncomingContestResolver) Resolve(
resolution, err := h.Registry.NotifyExitHopHtlc(
h.htlc.RHash, h.htlc.Amt, h.htlcExpiry, currentHeight,
circuitKey, hodlQueue.ChanIn(), payload,
circuitKey, hodlQueue.ChanIn(), h.htlc.CustomRecords,
payload,
)
if err != nil {
return nil, err

View File

@ -6,7 +6,9 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/tlv"
)
// htlcLeaseResolver is a struct that houses the lease specific HTLC resolution
@ -52,8 +54,8 @@ func (h *htlcLeaseResolver) deriveWaitHeight(csvDelay uint32,
// send to the sweeper so the output can ultimately be swept.
func (h *htlcLeaseResolver) makeSweepInput(op *wire.OutPoint,
wType, cltvWtype input.StandardWitnessType,
signDesc *input.SignDescriptor,
csvDelay, broadcastHeight uint32, payHash [32]byte) *input.BaseInput {
signDesc *input.SignDescriptor, csvDelay, broadcastHeight uint32,
payHash [32]byte, resBlob fn.Option[tlv.Blob]) *input.BaseInput {
if h.hasCLTV() {
log.Infof("%T(%x): CSV and CLTV locks expired, offering "+
@ -63,13 +65,17 @@ func (h *htlcLeaseResolver) makeSweepInput(op *wire.OutPoint,
op, cltvWtype, signDesc,
broadcastHeight, csvDelay,
h.leaseExpiry,
input.WithResolutionBlob(resBlob),
)
}
log.Infof("%T(%x): CSV lock expired, offering second-layer output to "+
"sweeper: %v", h, payHash, op)
return input.NewCsvInput(op, wType, signDesc, broadcastHeight, csvDelay)
return input.NewCsvInput(
op, wType, signDesc, broadcastHeight, csvDelay,
input.WithResolutionBlob(resBlob),
)
}
// SupplementState allows the user of a ContractResolver to supplement it with

View File

@ -247,6 +247,9 @@ func (h *htlcSuccessResolver) broadcastReSignedSuccessTx(immediate bool) (
h.htlcResolution.SignedSuccessTx,
h.htlcResolution.SignDetails, h.htlcResolution.Preimage,
h.broadcastHeight,
input.WithResolutionBlob(
h.htlcResolution.ResolutionBlob,
),
)
} else {
//nolint:lll
@ -403,7 +406,7 @@ func (h *htlcSuccessResolver) broadcastReSignedSuccessTx(immediate bool) (
input.LeaseHtlcAcceptedSuccessSecondLevel,
&h.htlcResolution.SweepSignDesc,
h.htlcResolution.CsvDelay, uint32(commitSpend.SpendingHeight),
h.htlc.RHash,
h.htlc.RHash, h.htlcResolution.ResolutionBlob,
)
// Calculate the budget for this sweep.
@ -459,6 +462,9 @@ func (h *htlcSuccessResolver) resolveRemoteCommitOutput(immediate bool) (
h.htlcResolution.Preimage[:],
h.broadcastHeight,
h.htlcResolution.CsvDelay,
input.WithResolutionBlob(
h.htlcResolution.ResolutionBlob,
),
))
} else {
inp = lnutils.Ptr(input.MakeHtlcSucceedInput(

View File

@ -484,6 +484,9 @@ func (h *htlcTimeoutResolver) sweepSecondLevelTx(immediate bool) error {
h.htlcResolution.SignedTimeoutTx,
h.htlcResolution.SignDetails,
h.broadcastHeight,
input.WithResolutionBlob(
h.htlcResolution.ResolutionBlob,
),
))
} else {
inp = lnutils.Ptr(input.MakeHtlcSecondLevelTimeoutAnchorInput(
@ -538,7 +541,6 @@ func (h *htlcTimeoutResolver) sweepSecondLevelTx(immediate bool) error {
return err
}
// TODO(yy): checkpoint here?
return err
}
@ -562,6 +564,60 @@ func (h *htlcTimeoutResolver) sendSecondLevelTxLegacy() error {
return h.Checkpoint(h)
}
// sweepDirectHtlcOutput sends the direct spend of the HTLC output to the
// sweeper. This is used when the remote party goes on chain, and we're able to
// sweep an HTLC we offered after a timeout. Only the CLTV encumbered outputs
// are resolved via this path.
func (h *htlcTimeoutResolver) sweepDirectHtlcOutput(immediate bool) error {
var htlcWitnessType input.StandardWitnessType
if h.isTaproot() {
htlcWitnessType = input.TaprootHtlcOfferedRemoteTimeout
} else {
htlcWitnessType = input.HtlcOfferedRemoteTimeout
}
sweepInput := input.NewCsvInputWithCltv(
&h.htlcResolution.ClaimOutpoint, htlcWitnessType,
&h.htlcResolution.SweepSignDesc, h.broadcastHeight,
h.htlcResolution.CsvDelay, h.htlcResolution.Expiry,
input.WithResolutionBlob(h.htlcResolution.ResolutionBlob),
)
// Calculate the budget.
//
// TODO(yy): the budget is twice the output's value, which is needed as
// we don't force sweep the output now. To prevent cascading force
// closes, we use all its output value plus a wallet input as the
// budget. This is a temporary solution until we can optionally cancel
// the incoming HTLC, more details in,
// - https://github.com/lightningnetwork/lnd/issues/7969
budget := calculateBudget(
btcutil.Amount(sweepInput.SignDesc().Output.Value), 2, 0,
)
log.Infof("%T(%x): offering offered remote timeout HTLC output to "+
"sweeper with deadline %v and budget=%v at height=%v",
h, h.htlc.RHash[:], h.incomingHTLCExpiryHeight, budget,
h.broadcastHeight)
_, err := h.Sweeper.SweepInput(
sweepInput,
sweep.Params{
Budget: budget,
// This is an outgoing HTLC, so we want to make sure
// that we sweep it before the incoming HTLC expires.
DeadlineHeight: h.incomingHTLCExpiryHeight,
Immediate: immediate,
},
)
if err != nil {
return err
}
return nil
}
// spendHtlcOutput handles the initial spend of an HTLC output via the timeout
// clause. If this is our local commitment, the second-level timeout TX will be
// used to spend the output into the next stage. If this is the remote
@ -582,8 +638,18 @@ func (h *htlcTimeoutResolver) spendHtlcOutput(
return nil, err
}
// If we have no SignDetails, and we haven't already sent the output to
// the utxo nursery, then we'll do so now.
// If this is a remote commitment there's no second level timeout txn,
// and we can just send this directly to the sweeper.
case h.htlcResolution.SignedTimeoutTx == nil && !h.outputIncubating:
if err := h.sweepDirectHtlcOutput(immediate); err != nil {
log.Errorf("Sending direct spend to sweeper: %v", err)
return nil, err
}
// If we have a SignedTimeoutTx but no SignDetails, this is a local
// commitment for a non-anchor channel, so we'll send it to the utxo
// nursery.
case h.htlcResolution.SignDetails == nil && !h.outputIncubating:
if err := h.sendSecondLevelTxLegacy(); err != nil {
log.Errorf("Sending timeout tx to nursery: %v", err)
@ -690,6 +756,13 @@ func (h *htlcTimeoutResolver) handleCommitSpend(
)
switch {
// If we swept an HTLC directly off the remote party's commitment
// transaction, then we can exit here as there's no second level sweep
// to do.
case h.htlcResolution.SignedTimeoutTx == nil:
break
// If the sweeper is handling the second level transaction, wait for
// the CSV and possible CLTV lock to expire, before sweeping the output
// on the second-level.
@ -762,7 +835,9 @@ func (h *htlcTimeoutResolver) handleCommitSpend(
&h.htlcResolution.SweepSignDesc,
h.htlcResolution.CsvDelay,
uint32(commitSpend.SpendingHeight), h.htlc.RHash,
h.htlcResolution.ResolutionBlob,
)
// Calculate the budget for this sweep.
budget := calculateBudget(
btcutil.Amount(inp.SignDesc().Output.Value),
@ -800,6 +875,7 @@ func (h *htlcTimeoutResolver) handleCommitSpend(
case h.htlcResolution.SignedTimeoutTx != nil:
log.Infof("%T(%v): waiting for nursery/sweeper to spend CSV "+
"delayed output", h, claimOutpoint)
sweepTx, err := waitForSpend(
&claimOutpoint,
h.htlcResolution.SweepSignDesc.Output.PkScript,
@ -866,9 +942,11 @@ func (h *htlcTimeoutResolver) IsResolved() bool {
// report returns a report on the resolution state of the contract.
func (h *htlcTimeoutResolver) report() *ContractReport {
// If the sign details are nil, the report will be created by handled
// by the nursery.
if h.htlcResolution.SignDetails == nil {
// If we have a SignedTimeoutTx but no SignDetails, this is a local
// commitment for a non-anchor channel, which was handled by the utxo
// nursery.
if h.htlcResolution.SignDetails == nil && h.
htlcResolution.SignedTimeoutTx != nil {
return nil
}
@ -888,13 +966,20 @@ func (h *htlcTimeoutResolver) initReport() {
)
}
// If there's no timeout transaction, then we're already effectively in
// level two.
stage := uint32(1)
if h.htlcResolution.SignedTimeoutTx == nil {
stage = 2
}
h.currentReport = ContractReport{
Outpoint: h.htlcResolution.ClaimOutpoint,
Type: ReportOutputOutgoingHtlc,
Amount: finalAmt,
MaturityHeight: h.htlcResolution.Expiry,
LimboBalance: finalAmt,
Stage: 1,
Stage: stage,
}
}

View File

@ -69,11 +69,31 @@ func (m *mockWitnessBeacon) AddPreimages(preimages ...lntypes.Preimage) error {
return nil
}
// TestHtlcTimeoutResolver tests that the timeout resolver properly handles all
// variations of possible local+remote spends.
func TestHtlcTimeoutResolver(t *testing.T) {
t.Parallel()
type htlcTimeoutTestCase struct {
// name is a human readable description of the test case.
name string
// remoteCommit denotes if the commitment broadcast was the remote
// commitment or not.
remoteCommit bool
// timeout denotes if the HTLC should be let timeout, or if the "remote"
// party should sweep it on-chain. This also affects what type of
// resolution message we expect.
timeout bool
// txToBroadcast is a function closure that should generate the
// transaction that should spend the HTLC output. Test authors can use
// this to customize the witness used when spending to trigger various
// redemption cases.
txToBroadcast func() (*wire.MsgTx, error)
// outcome is the resolver outcome that we expect to be reported once
// the contract is fully resolved.
outcome channeldb.ResolverOutcome
}
func genHtlcTimeoutTestCases() []htlcTimeoutTestCase {
fakePreimageBytes := bytes.Repeat([]byte{1}, lntypes.HashSize)
var (
@ -105,29 +125,7 @@ func TestHtlcTimeoutResolver(t *testing.T) {
},
}
testCases := []struct {
// name is a human readable description of the test case.
name string
// remoteCommit denotes if the commitment broadcast was the
// remote commitment or not.
remoteCommit bool
// timeout denotes if the HTLC should be let timeout, or if the
// "remote" party should sweep it on-chain. This also affects
// what type of resolution message we expect.
timeout bool
// txToBroadcast is a function closure that should generate the
// transaction that should spend the HTLC output. Test authors
// can use this to customize the witness used when spending to
// trigger various redemption cases.
txToBroadcast func() (*wire.MsgTx, error)
// outcome is the resolver outcome that we expect to be reported
// once the contract is fully resolved.
outcome channeldb.ResolverOutcome
}{
return []htlcTimeoutTestCase{
// Remote commitment is broadcast, we time out the HTLC on
// chain, and should expect a fail HTLC resolution.
{
@ -149,7 +147,8 @@ func TestHtlcTimeoutResolver(t *testing.T) {
// immediately if the witness is already set
// correctly.
if reflect.DeepEqual(
templateTx.TxIn[0].Witness, witness,
templateTx.TxIn[0].Witness,
witness,
) {
return templateTx, nil
@ -219,7 +218,8 @@ func TestHtlcTimeoutResolver(t *testing.T) {
// immediately if the witness is already set
// correctly.
if reflect.DeepEqual(
templateTx.TxIn[0].Witness, witness,
templateTx.TxIn[0].Witness,
witness,
) {
return templateTx, nil
@ -253,7 +253,8 @@ func TestHtlcTimeoutResolver(t *testing.T) {
// immediately if the witness is already set
// correctly.
if reflect.DeepEqual(
templateTx.TxIn[0].Witness, witness,
templateTx.TxIn[0].Witness,
witness,
) {
return templateTx, nil
@ -265,243 +266,280 @@ func TestHtlcTimeoutResolver(t *testing.T) {
outcome: channeldb.ResolverOutcomeClaimed,
},
}
}
func testHtlcTimeoutResolver(t *testing.T, testCase htlcTimeoutTestCase) {
fakePreimageBytes := bytes.Repeat([]byte{1}, lntypes.HashSize)
var fakePreimage lntypes.Preimage
fakeSignDesc := &input.SignDescriptor{
Output: &wire.TxOut{},
}
copy(fakePreimage[:], fakePreimageBytes)
notifier := &mock.ChainNotifier{
EpochChan: make(chan *chainntnfs.BlockEpoch),
SpendChan: make(chan *chainntnfs.SpendDetail),
ConfChan: make(chan *chainntnfs.TxConfirmation),
}
witnessBeacon := newMockWitnessBeacon()
checkPointChan := make(chan struct{}, 1)
incubateChan := make(chan struct{}, 1)
resolutionChan := make(chan ResolutionMsg, 1)
reportChan := make(chan *channeldb.ResolverReport)
//nolint:lll
chainCfg := ChannelArbitratorConfig{
ChainArbitratorConfig: ChainArbitratorConfig{
Notifier: notifier,
Sweeper: newMockSweeper(),
PreimageDB: witnessBeacon,
IncubateOutputs: func(wire.OutPoint,
fn.Option[lnwallet.OutgoingHtlcResolution],
fn.Option[lnwallet.IncomingHtlcResolution],
uint32, fn.Option[int32]) error {
incubateChan <- struct{}{}
return nil
},
DeliverResolutionMsg: func(msgs ...ResolutionMsg) error {
if len(msgs) != 1 {
return fmt.Errorf("expected 1 "+
"resolution msg, instead got %v",
len(msgs))
}
resolutionChan <- msgs[0]
return nil
},
Budget: *DefaultBudgetConfig(),
QueryIncomingCircuit: func(circuit models.CircuitKey,
) *models.CircuitKey {
return nil
},
},
PutResolverReport: func(_ kvdb.RwTx,
_ *channeldb.ResolverReport) error {
return nil
},
}
cfg := ResolverConfig{
ChannelArbitratorConfig: chainCfg,
Checkpoint: func(_ ContractResolver,
reports ...*channeldb.ResolverReport) error {
checkPointChan <- struct{}{}
// Send all of our reports into the channel.
for _, report := range reports {
reportChan <- report
}
return nil
},
}
resolver := &htlcTimeoutResolver{
htlcResolution: lnwallet.OutgoingHtlcResolution{
ClaimOutpoint: testChanPoint2,
SweepSignDesc: *fakeSignDesc,
},
contractResolverKit: *newContractResolverKit(
cfg,
),
htlc: channeldb.HTLC{
Amt: testHtlcAmt,
},
}
var reports []*channeldb.ResolverReport
// If the test case needs the remote commitment to be
// broadcast, then we'll set the timeout commit to a fake
// transaction to force the code path.
if !testCase.remoteCommit {
timeoutTx, err := testCase.txToBroadcast()
require.NoError(t, err)
resolver.htlcResolution.SignedTimeoutTx = timeoutTx
if testCase.timeout {
timeoutTxID := timeoutTx.TxHash()
report := &channeldb.ResolverReport{
OutPoint: timeoutTx.TxIn[0].PreviousOutPoint, //nolint:lll
Amount: testHtlcAmt.ToSatoshis(),
ResolverType: channeldb.ResolverTypeOutgoingHtlc, //nolint:lll
ResolverOutcome: channeldb.ResolverOutcomeFirstStage, //nolint:lll
SpendTxID: &timeoutTxID,
}
reports = append(reports, report)
}
}
// With all the setup above complete, we can initiate the
// resolution process, and the bulk of our test.
var wg sync.WaitGroup
resolveErr := make(chan error, 1)
wg.Add(1)
go func() {
defer wg.Done()
_, err := resolver.Resolve(false)
if err != nil {
resolveErr <- err
}
}()
// If this is a remote commit, then we expct the outputs should receive
// an incubation request to go through the sweeper, otherwise the
// nursery.
var sweepChan chan input.Input
if testCase.remoteCommit {
mockSweeper, ok := resolver.Sweeper.(*mockSweeper)
require.True(t, ok)
sweepChan = mockSweeper.sweptInputs
}
// The output should be offered to either the sweeper or
// the nursery.
select {
case <-incubateChan:
case <-sweepChan:
case err := <-resolveErr:
t.Fatalf("unable to resolve HTLC: %v", err)
case <-time.After(time.Second * 5):
t.Fatalf("failed to receive incubation request")
}
// Next, the resolver should request a spend notification for
// the direct HTLC output. We'll use the txToBroadcast closure
// for the test case to generate the transaction that we'll
// send to the resolver.
spendingTx, err := testCase.txToBroadcast()
if err != nil {
t.Fatalf("unable to generate tx: %v", err)
}
spendTxHash := spendingTx.TxHash()
select {
case notifier.SpendChan <- &chainntnfs.SpendDetail{
SpendingTx: spendingTx,
SpenderTxHash: &spendTxHash,
}:
case <-time.After(time.Second * 5):
t.Fatalf("failed to request spend ntfn")
}
if !testCase.timeout {
// If the resolver should settle now, then we'll
// extract the pre-image to be extracted and the
// resolution message sent.
select {
case newPreimage := <-witnessBeacon.newPreimages:
if newPreimage[0] != fakePreimage {
t.Fatalf("wrong pre-image: "+
"expected %v, got %v",
fakePreimage, newPreimage)
}
case <-time.After(time.Second * 5):
t.Fatalf("pre-image not added")
}
// Finally, we should get a resolution message with the
// pre-image set within the message.
select {
case resolutionMsg := <-resolutionChan:
// Once again, the pre-images should match up.
if *resolutionMsg.PreImage != fakePreimage {
t.Fatalf("wrong pre-image: "+
"expected %v, got %v",
fakePreimage, resolutionMsg.PreImage)
}
case <-time.After(time.Second * 5):
t.Fatalf("resolution not sent")
}
} else {
// Otherwise, the HTLC should now timeout. First, we
// should get a resolution message with a populated
// failure message.
select {
case resolutionMsg := <-resolutionChan:
if resolutionMsg.Failure == nil {
t.Fatalf("expected failure resolution msg")
}
case <-time.After(time.Second * 5):
t.Fatalf("resolution not sent")
}
// We should also get another request for the spend
// notification of the second-level transaction to
// indicate that it's been swept by the nursery, but
// only if this is a local commitment transaction.
if !testCase.remoteCommit {
select {
case notifier.SpendChan <- &chainntnfs.SpendDetail{
SpendingTx: spendingTx,
SpenderTxHash: &spendTxHash,
}:
case <-time.After(time.Second * 5):
t.Fatalf("failed to request spend ntfn")
}
}
}
// In any case, before the resolver exits, it should checkpoint
// its final state.
select {
case <-checkPointChan:
case err := <-resolveErr:
t.Fatalf("unable to resolve HTLC: %v", err)
case <-time.After(time.Second * 5):
t.Fatalf("check point not received")
}
// Add a report to our set of expected reports with the outcome
// that the test specifies (either success or timeout).
spendTxID := spendingTx.TxHash()
amt := btcutil.Amount(fakeSignDesc.Output.Value)
reports = append(reports, &channeldb.ResolverReport{
OutPoint: testChanPoint2,
Amount: amt,
ResolverType: channeldb.ResolverTypeOutgoingHtlc,
ResolverOutcome: testCase.outcome,
SpendTxID: &spendTxID,
})
for _, report := range reports {
assertResolverReport(t, reportChan, report)
}
wg.Wait()
// Finally, the resolver should be marked as resolved.
if !resolver.resolved {
t.Fatalf("resolver should be marked as resolved")
}
}
// TestHtlcTimeoutResolver tests that the timeout resolver properly handles all
// variations of possible local+remote spends.
func TestHtlcTimeoutResolver(t *testing.T) {
t.Parallel()
testCases := genHtlcTimeoutTestCases()
for _, testCase := range testCases {
t.Logf("Running test case: %v", testCase.name)
checkPointChan := make(chan struct{}, 1)
incubateChan := make(chan struct{}, 1)
resolutionChan := make(chan ResolutionMsg, 1)
reportChan := make(chan *channeldb.ResolverReport)
//nolint:lll
chainCfg := ChannelArbitratorConfig{
ChainArbitratorConfig: ChainArbitratorConfig{
Notifier: notifier,
PreimageDB: witnessBeacon,
IncubateOutputs: func(wire.OutPoint,
fn.Option[lnwallet.OutgoingHtlcResolution],
fn.Option[lnwallet.IncomingHtlcResolution],
uint32, fn.Option[int32]) error {
incubateChan <- struct{}{}
return nil
},
DeliverResolutionMsg: func(msgs ...ResolutionMsg) error {
if len(msgs) != 1 {
return fmt.Errorf("expected 1 "+
"resolution msg, instead got %v",
len(msgs))
}
resolutionChan <- msgs[0]
return nil
},
Budget: *DefaultBudgetConfig(),
QueryIncomingCircuit: func(circuit models.CircuitKey) *models.CircuitKey {
return nil
},
},
PutResolverReport: func(_ kvdb.RwTx,
_ *channeldb.ResolverReport) error {
return nil
},
}
cfg := ResolverConfig{
ChannelArbitratorConfig: chainCfg,
Checkpoint: func(_ ContractResolver,
reports ...*channeldb.ResolverReport) error {
checkPointChan <- struct{}{}
// Send all of our reports into the channel.
for _, report := range reports {
reportChan <- report
}
return nil
},
}
resolver := &htlcTimeoutResolver{
htlcResolution: lnwallet.OutgoingHtlcResolution{
ClaimOutpoint: testChanPoint2,
SweepSignDesc: *fakeSignDesc,
},
contractResolverKit: *newContractResolverKit(
cfg,
),
htlc: channeldb.HTLC{
Amt: testHtlcAmt,
},
}
var reports []*channeldb.ResolverReport
// If the test case needs the remote commitment to be
// broadcast, then we'll set the timeout commit to a fake
// transaction to force the code path.
if !testCase.remoteCommit {
timeoutTx, err := testCase.txToBroadcast()
require.NoError(t, err)
resolver.htlcResolution.SignedTimeoutTx = timeoutTx
if testCase.timeout {
timeoutTxID := timeoutTx.TxHash()
reports = append(reports, &channeldb.ResolverReport{
OutPoint: timeoutTx.TxIn[0].PreviousOutPoint,
Amount: testHtlcAmt.ToSatoshis(),
ResolverType: channeldb.ResolverTypeOutgoingHtlc,
ResolverOutcome: channeldb.ResolverOutcomeFirstStage,
SpendTxID: &timeoutTxID,
})
}
}
// With all the setup above complete, we can initiate the
// resolution process, and the bulk of our test.
var wg sync.WaitGroup
resolveErr := make(chan error, 1)
wg.Add(1)
go func() {
defer wg.Done()
_, err := resolver.Resolve(false)
if err != nil {
resolveErr <- err
}
}()
// At the output isn't yet in the nursery, we expect that we
// should receive an incubation request.
select {
case <-incubateChan:
case err := <-resolveErr:
t.Fatalf("unable to resolve HTLC: %v", err)
case <-time.After(time.Second * 5):
t.Fatalf("failed to receive incubation request")
}
// Next, the resolver should request a spend notification for
// the direct HTLC output. We'll use the txToBroadcast closure
// for the test case to generate the transaction that we'll
// send to the resolver.
spendingTx, err := testCase.txToBroadcast()
if err != nil {
t.Fatalf("unable to generate tx: %v", err)
}
spendTxHash := spendingTx.TxHash()
select {
case notifier.SpendChan <- &chainntnfs.SpendDetail{
SpendingTx: spendingTx,
SpenderTxHash: &spendTxHash,
}:
case <-time.After(time.Second * 5):
t.Fatalf("failed to request spend ntfn")
}
if !testCase.timeout {
// If the resolver should settle now, then we'll
// extract the pre-image to be extracted and the
// resolution message sent.
select {
case newPreimage := <-witnessBeacon.newPreimages:
if newPreimage[0] != fakePreimage {
t.Fatalf("wrong pre-image: "+
"expected %v, got %v",
fakePreimage, newPreimage)
}
case <-time.After(time.Second * 5):
t.Fatalf("pre-image not added")
}
// Finally, we should get a resolution message with the
// pre-image set within the message.
select {
case resolutionMsg := <-resolutionChan:
// Once again, the pre-images should match up.
if *resolutionMsg.PreImage != fakePreimage {
t.Fatalf("wrong pre-image: "+
"expected %v, got %v",
fakePreimage, resolutionMsg.PreImage)
}
case <-time.After(time.Second * 5):
t.Fatalf("resolution not sent")
}
} else {
// Otherwise, the HTLC should now timeout. First, we
// should get a resolution message with a populated
// failure message.
select {
case resolutionMsg := <-resolutionChan:
if resolutionMsg.Failure == nil {
t.Fatalf("expected failure resolution msg")
}
case <-time.After(time.Second * 5):
t.Fatalf("resolution not sent")
}
// We should also get another request for the spend
// notification of the second-level transaction to
// indicate that it's been swept by the nursery, but
// only if this is a local commitment transaction.
if !testCase.remoteCommit {
select {
case notifier.SpendChan <- &chainntnfs.SpendDetail{
SpendingTx: spendingTx,
SpenderTxHash: &spendTxHash,
}:
case <-time.After(time.Second * 5):
t.Fatalf("failed to request spend ntfn")
}
}
}
// In any case, before the resolver exits, it should checkpoint
// its final state.
select {
case <-checkPointChan:
case err := <-resolveErr:
t.Fatalf("unable to resolve HTLC: %v", err)
case <-time.After(time.Second * 5):
t.Fatalf("check point not received")
}
// Add a report to our set of expected reports with the outcome
// that the test specifies (either success or timeout).
spendTxID := spendingTx.TxHash()
amt := btcutil.Amount(fakeSignDesc.Output.Value)
reports = append(reports, &channeldb.ResolverReport{
OutPoint: testChanPoint2,
Amount: amt,
ResolverType: channeldb.ResolverTypeOutgoingHtlc,
ResolverOutcome: testCase.outcome,
SpendTxID: &spendTxID,
t.Run(testCase.name, func(t *testing.T) {
testHtlcTimeoutResolver(t, testCase)
})
for _, report := range reports {
assertResolverReport(t, reportChan, report)
}
wg.Wait()
// Finally, the resolver should be marked as resolved.
if !resolver.resolved {
t.Fatalf("resolver should be marked as resolved")
}
}
}
@ -536,15 +574,12 @@ func TestHtlcTimeoutSingleStage(t *testing.T) {
}
checkpoints := []checkpoint{
{
// Output should be handed off to the nursery.
incubating: true,
},
{
// We send a confirmation the sweep tx from published
// by the nursery.
preCheckpoint: func(ctx *htlcResolverTestContext,
_ bool) error {
// The nursery will create and publish a sweep
// tx.
ctx.notifier.SpendChan <- &chainntnfs.SpendDetail{
@ -570,7 +605,7 @@ func TestHtlcTimeoutSingleStage(t *testing.T) {
// After the sweep has confirmed, we expect the
// checkpoint to be resolved, and with the above
// report.
incubating: true,
incubating: false,
resolved: true,
reports: []*channeldb.ResolverReport{
claim,
@ -653,6 +688,7 @@ func TestHtlcTimeoutSecondStage(t *testing.T) {
// that our sweep succeeded.
preCheckpoint: func(ctx *htlcResolverTestContext,
_ bool) error {
// The nursery will publish the timeout tx.
ctx.notifier.SpendChan <- &chainntnfs.SpendDetail{
SpendingTx: timeoutTx,
@ -824,9 +860,9 @@ func TestHtlcTimeoutSingleStageRemoteSpend(t *testing.T) {
)
}
// TestHtlcTimeoutSecondStageRemoteSpend tests that when a remite commitment
// confirms, and the remote spends the output using the success tx, we
// properly detect this and extract the preimage.
// TestHtlcTimeoutSecondStageRemoteSpend tests that when a remote commitment
// confirms, and the remote spends the output using the success tx, we properly
// detect this and extract the preimage.
func TestHtlcTimeoutSecondStageRemoteSpend(t *testing.T) {
commitOutpoint := wire.OutPoint{Index: 2}
@ -870,10 +906,6 @@ func TestHtlcTimeoutSecondStageRemoteSpend(t *testing.T) {
}
checkpoints := []checkpoint{
{
// Output should be handed off to the nursery.
incubating: true,
},
{
// We send a confirmation for the remote's second layer
// success transcation.
@ -919,7 +951,7 @@ func TestHtlcTimeoutSecondStageRemoteSpend(t *testing.T) {
// After the sweep has confirmed, we expect the
// checkpoint to be resolved, and with the above
// report.
incubating: true,
incubating: false,
resolved: true,
reports: []*channeldb.ResolverReport{
claim,
@ -1298,6 +1330,8 @@ func TestHtlcTimeoutSecondStageSweeperRemoteSpend(t *testing.T) {
func testHtlcTimeout(t *testing.T, resolution lnwallet.OutgoingHtlcResolution,
checkpoints []checkpoint) {
t.Helper()
defer timeout()()
// We first run the resolver from start to finish, ensuring it gets

View File

@ -30,6 +30,7 @@ type Registry interface {
NotifyExitHopHtlc(payHash lntypes.Hash, paidAmount lnwire.MilliSatoshi,
expiry uint32, currentHeight int32,
circuitKey models.CircuitKey, hodlChan chan<- interface{},
wireCustomRecords lnwire.CustomRecords,
payload invoices.Payload) (invoices.HtlcResolution, error)
// HodlUnsubscribeAll unsubscribes from all htlc resolutions.

View File

@ -10,5 +10,6 @@ type mockHTLCNotifier struct {
}
func (m *mockHTLCNotifier) NotifyFinalHtlcEvent(key models.CircuitKey,
info channeldb.FinalHtlcInfo) { //nolint:whitespace
info channeldb.FinalHtlcInfo) {
}

View File

@ -26,6 +26,7 @@ type mockRegistry struct {
func (r *mockRegistry) NotifyExitHopHtlc(payHash lntypes.Hash,
paidAmount lnwire.MilliSatoshi, expiry uint32, currentHeight int32,
circuitKey models.CircuitKey, hodlChan chan<- interface{},
wireCustomRecords lnwire.CustomRecords,
payload invoices.Payload) (invoices.HtlcResolution, error) {
r.notifyChan <- notifyExitHopData{

View File

@ -8,9 +8,6 @@ import (
)
const (
taprootCtrlBlockType tlv.Type = 0
taprootTapTweakType tlv.Type = 1
commitCtrlBlockType tlv.Type = 0
revokeCtrlBlockType tlv.Type = 1
outgoingHtlcCtrlBlockType tlv.Type = 2
@ -26,36 +23,67 @@ const (
// information we need to sweep taproot outputs.
type taprootBriefcase struct {
// CtrlBlock is the set of control block for the taproot outputs.
CtrlBlocks *ctrlBlocks
CtrlBlocks tlv.RecordT[tlv.TlvType0, ctrlBlocks]
// TapTweaks is the set of taproot tweaks for the taproot outputs that
// are to be spent via a keyspend path. This includes anchors, and any
// revocation paths.
TapTweaks *tapTweaks
TapTweaks tlv.RecordT[tlv.TlvType1, tapTweaks]
// SettledCommitBlob is an optional record that contains an opaque blob
// that may be used to properly sweep commitment outputs on a force
// close transaction.
SettledCommitBlob tlv.OptionalRecordT[tlv.TlvType2, tlv.Blob]
// BreachCommitBlob is an optional record that contains an opaque blob
// used to sweep a remote party's breached output.
BreachedCommitBlob tlv.OptionalRecordT[tlv.TlvType3, tlv.Blob]
// HtlcBlobs is an optikonal record that contains the opaque blobs for
// the set of active HTLCs on the commitment transaction.
HtlcBlobs tlv.OptionalRecordT[tlv.TlvType4, htlcAuxBlobs]
}
// TODO(roasbeef): morph into new tlv record
// newTaprootBriefcase returns a new instance of the taproot specific briefcase
// variant.
func newTaprootBriefcase() *taprootBriefcase {
return &taprootBriefcase{
CtrlBlocks: newCtrlBlocks(),
TapTweaks: newTapTweaks(),
CtrlBlocks: tlv.NewRecordT[tlv.TlvType0](newCtrlBlocks()),
TapTweaks: tlv.NewRecordT[tlv.TlvType1](newTapTweaks()),
}
}
// EncodeRecords returns a slice of TLV records that should be encoded.
func (t *taprootBriefcase) EncodeRecords() []tlv.Record {
return []tlv.Record{
newCtrlBlocksRecord(&t.CtrlBlocks),
newTapTweaksRecord(&t.TapTweaks),
records := []tlv.Record{
t.CtrlBlocks.Record(),
t.TapTweaks.Record(),
}
t.SettledCommitBlob.WhenSome(
func(r tlv.RecordT[tlv.TlvType2, tlv.Blob]) {
records = append(records, r.Record())
},
)
t.BreachedCommitBlob.WhenSome(
func(r tlv.RecordT[tlv.TlvType3, tlv.Blob]) {
records = append(records, r.Record())
},
)
t.HtlcBlobs.WhenSome(func(r tlv.RecordT[tlv.TlvType4, htlcAuxBlobs]) {
records = append(records, r.Record())
})
return records
}
// DecodeRecords returns a slice of TLV records that should be decoded.
func (t *taprootBriefcase) DecodeRecords() []tlv.Record {
return []tlv.Record{
newCtrlBlocksRecord(&t.CtrlBlocks),
newTapTweaksRecord(&t.TapTweaks),
t.CtrlBlocks.Record(),
t.TapTweaks.Record(),
}
}
@ -71,12 +99,35 @@ func (t *taprootBriefcase) Encode(w io.Writer) error {
// Decode decodes the given reader into the target struct.
func (t *taprootBriefcase) Decode(r io.Reader) error {
stream, err := tlv.NewStream(t.DecodeRecords()...)
settledCommitBlob := t.SettledCommitBlob.Zero()
breachedCommitBlob := t.BreachedCommitBlob.Zero()
htlcBlobs := t.HtlcBlobs.Zero()
records := append(
t.DecodeRecords(), settledCommitBlob.Record(),
breachedCommitBlob.Record(), htlcBlobs.Record(),
)
stream, err := tlv.NewStream(records...)
if err != nil {
return err
}
return stream.Decode(r)
typeMap, err := stream.DecodeWithParsedTypes(r)
if err != nil {
return err
}
if val, ok := typeMap[t.SettledCommitBlob.TlvType()]; ok && val == nil {
t.SettledCommitBlob = tlv.SomeRecordT(settledCommitBlob)
}
if v, ok := typeMap[t.BreachedCommitBlob.TlvType()]; ok && v == nil {
t.BreachedCommitBlob = tlv.SomeRecordT(breachedCommitBlob)
}
if v, ok := typeMap[t.HtlcBlobs.TlvType()]; ok && v == nil {
t.HtlcBlobs = tlv.SomeRecordT(htlcBlobs)
}
return nil
}
// resolverCtrlBlocks is a map of resolver IDs to their corresponding control
@ -216,8 +267,8 @@ type ctrlBlocks struct {
}
// newCtrlBlocks returns a new instance of the ctrlBlocks struct.
func newCtrlBlocks() *ctrlBlocks {
return &ctrlBlocks{
func newCtrlBlocks() ctrlBlocks {
return ctrlBlocks{
OutgoingHtlcCtrlBlocks: newResolverCtrlBlocks(),
IncomingHtlcCtrlBlocks: newResolverCtrlBlocks(),
SecondLevelCtrlBlocks: newResolverCtrlBlocks(),
@ -260,7 +311,7 @@ func varBytesDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error {
// ctrlBlockEncoder is a custom TLV encoder for the ctrlBlocks struct.
func ctrlBlockEncoder(w io.Writer, val any, _ *[8]byte) error {
if t, ok := val.(**ctrlBlocks); ok {
if t, ok := val.(*ctrlBlocks); ok {
return (*t).Encode(w)
}
@ -269,7 +320,7 @@ func ctrlBlockEncoder(w io.Writer, val any, _ *[8]byte) error {
// ctrlBlockDecoder is a custom TLV decoder for the ctrlBlocks struct.
func ctrlBlockDecoder(r io.Reader, val any, _ *[8]byte, l uint64) error {
if typ, ok := val.(**ctrlBlocks); ok {
if typ, ok := val.(*ctrlBlocks); ok {
ctrlReader := io.LimitReader(r, int64(l))
var ctrlBlocks ctrlBlocks
@ -278,7 +329,7 @@ func ctrlBlockDecoder(r io.Reader, val any, _ *[8]byte, l uint64) error {
return err
}
*typ = &ctrlBlocks
*typ = ctrlBlocks
return nil
}
@ -286,28 +337,6 @@ func ctrlBlockDecoder(r io.Reader, val any, _ *[8]byte, l uint64) error {
return tlv.NewTypeForDecodingErr(val, "ctrlBlocks", l, l)
}
// newCtrlBlocksRecord returns a new TLV record that can be used to
// encode/decode the set of cotrol blocks for the taproot outputs for a
// channel.
func newCtrlBlocksRecord(blks **ctrlBlocks) tlv.Record {
recordSize := func() uint64 {
var (
b bytes.Buffer
buf [8]byte
)
if err := ctrlBlockEncoder(&b, blks, &buf); err != nil {
panic(err)
}
return uint64(len(b.Bytes()))
}
return tlv.MakeDynamicRecord(
taprootCtrlBlockType, blks, recordSize, ctrlBlockEncoder,
ctrlBlockDecoder,
)
}
// EncodeRecords returns the set of TLV records that encode the control block
// for the commitment transaction.
func (c *ctrlBlocks) EncodeRecords() []tlv.Record {
@ -382,7 +411,21 @@ func (c *ctrlBlocks) DecodeRecords() []tlv.Record {
// Record returns a TLV record that can be used to encode/decode the control
// blocks. type from a given TLV stream.
func (c *ctrlBlocks) Record() tlv.Record {
return tlv.MakePrimitiveRecord(commitCtrlBlockType, c)
recordSize := func() uint64 {
var (
b bytes.Buffer
buf [8]byte
)
if err := ctrlBlockEncoder(&b, c, &buf); err != nil {
panic(err)
}
return uint64(len(b.Bytes()))
}
return tlv.MakeDynamicRecord(
0, c, recordSize, ctrlBlockEncoder, ctrlBlockDecoder,
)
}
// Encode encodes the set of control blocks.
@ -530,8 +573,8 @@ type tapTweaks struct {
}
// newTapTweaks returns a new tapTweaks struct.
func newTapTweaks() *tapTweaks {
return &tapTweaks{
func newTapTweaks() tapTweaks {
return tapTweaks{
BreachedHtlcTweaks: make(htlcTapTweaks),
BreachedSecondLevelHltcTweaks: make(htlcTapTweaks),
}
@ -539,7 +582,7 @@ func newTapTweaks() *tapTweaks {
// tapTweaksEncoder is a custom TLV encoder for the tapTweaks struct.
func tapTweaksEncoder(w io.Writer, val any, _ *[8]byte) error {
if t, ok := val.(**tapTweaks); ok {
if t, ok := val.(*tapTweaks); ok {
return (*t).Encode(w)
}
@ -548,7 +591,7 @@ func tapTweaksEncoder(w io.Writer, val any, _ *[8]byte) error {
// tapTweaksDecoder is a custom TLV decoder for the tapTweaks struct.
func tapTweaksDecoder(r io.Reader, val any, _ *[8]byte, l uint64) error {
if typ, ok := val.(**tapTweaks); ok {
if typ, ok := val.(*tapTweaks); ok {
tweakReader := io.LimitReader(r, int64(l))
var tapTweaks tapTweaks
@ -557,7 +600,7 @@ func tapTweaksDecoder(r io.Reader, val any, _ *[8]byte, l uint64) error {
return err
}
*typ = &tapTweaks
*typ = tapTweaks
return nil
}
@ -565,27 +608,6 @@ func tapTweaksDecoder(r io.Reader, val any, _ *[8]byte, l uint64) error {
return tlv.NewTypeForDecodingErr(val, "tapTweaks", l, l)
}
// newTapTweaksRecord returns a new TLV record that can be used to
// encode/decode the tap tweak structs.
func newTapTweaksRecord(tweaks **tapTweaks) tlv.Record {
recordSize := func() uint64 {
var (
b bytes.Buffer
buf [8]byte
)
if err := tapTweaksEncoder(&b, tweaks, &buf); err != nil {
panic(err)
}
return uint64(len(b.Bytes()))
}
return tlv.MakeDynamicRecord(
taprootTapTweakType, tweaks, recordSize, tapTweaksEncoder,
tapTweaksDecoder,
)
}
// EncodeRecords returns the set of TLV records that encode the tweaks.
func (t *tapTweaks) EncodeRecords() []tlv.Record {
var records []tlv.Record
@ -637,7 +659,21 @@ func (t *tapTweaks) DecodeRecords() []tlv.Record {
// Record returns a TLV record that can be used to encode/decode the tap
// tweaks.
func (t *tapTweaks) Record() tlv.Record {
return tlv.MakePrimitiveRecord(taprootTapTweakType, t)
recordSize := func() uint64 {
var (
b bytes.Buffer
buf [8]byte
)
if err := tapTweaksEncoder(&b, t, &buf); err != nil {
panic(err)
}
return uint64(len(b.Bytes()))
}
return tlv.MakeDynamicRecord(
0, t, recordSize, tapTweaksEncoder, tapTweaksDecoder,
)
}
// Encode encodes the set of tap tweaks.
@ -659,3 +695,110 @@ func (t *tapTweaks) Decode(r io.Reader) error {
return stream.Decode(r)
}
// htlcAuxBlobs is a map of resolver IDs to their corresponding HTLC blobs.
// This is used to store the resolution blobs for HTLCs that are not yet
// resolved.
type htlcAuxBlobs map[resolverID]tlv.Blob
// newAuxHtlcBlobs returns a new instance of the htlcAuxBlobs struct.
func newAuxHtlcBlobs() htlcAuxBlobs {
return make(htlcAuxBlobs)
}
// Encode encodes the set of HTLC blobs into the target writer.
func (h *htlcAuxBlobs) Encode(w io.Writer) error {
var buf [8]byte
numBlobs := uint64(len(*h))
if err := tlv.WriteVarInt(w, numBlobs, &buf); err != nil {
return err
}
for id, blob := range *h {
if _, err := w.Write(id[:]); err != nil {
return err
}
if err := varBytesEncoder(w, &blob, &buf); err != nil {
return err
}
}
return nil
}
// Decode decodes the set of HTLC blobs from the target reader.
func (h *htlcAuxBlobs) Decode(r io.Reader) error {
var buf [8]byte
numBlobs, err := tlv.ReadVarInt(r, &buf)
if err != nil {
return err
}
for i := uint64(0); i < numBlobs; i++ {
var id resolverID
if _, err := io.ReadFull(r, id[:]); err != nil {
return err
}
var blob tlv.Blob
if err := varBytesDecoder(r, &blob, &buf, 0); err != nil {
return err
}
(*h)[id] = blob
}
return nil
}
// eHtlcAuxBlobsEncoder is a custom TLV encoder for the htlcAuxBlobs struct.
func htlcAuxBlobsEncoder(w io.Writer, val any, _ *[8]byte) error {
if t, ok := val.(*htlcAuxBlobs); ok {
return (*t).Encode(w)
}
return tlv.NewTypeForEncodingErr(val, "htlcAuxBlobs")
}
// dHtlcAuxBlobsDecoder is a custom TLV decoder for the htlcAuxBlobs struct.
func htlcAuxBlobsDecoder(r io.Reader, val any, _ *[8]byte,
l uint64) error {
if typ, ok := val.(*htlcAuxBlobs); ok {
blobReader := io.LimitReader(r, int64(l))
htlcBlobs := newAuxHtlcBlobs()
err := htlcBlobs.Decode(blobReader)
if err != nil {
return err
}
*typ = htlcBlobs
return nil
}
return tlv.NewTypeForDecodingErr(val, "htlcAuxBlobs", l, l)
}
// Record returns a tlv.Record for the htlcAuxBlobs struct.
func (h *htlcAuxBlobs) Record() tlv.Record {
recordSize := func() uint64 {
var (
b bytes.Buffer
buf [8]byte
)
if err := htlcAuxBlobsEncoder(&b, h, &buf); err != nil {
panic(err)
}
return uint64(len(b.Bytes()))
}
return tlv.MakeDynamicRecord(
0, h, recordSize, htlcAuxBlobsEncoder, htlcAuxBlobsDecoder,
)
}

View File

@ -5,7 +5,9 @@ import (
"math/rand"
"testing"
"github.com/lightningnetwork/lnd/tlv"
"github.com/stretchr/testify/require"
"pgregory.net/rapid"
)
func randResolverCtrlBlocks(t *testing.T) resolverCtrlBlocks {
@ -52,6 +54,25 @@ func randHtlcTweaks(t *testing.T) htlcTapTweaks {
return tweaks
}
func randHtlcAuxBlobs(t *testing.T) htlcAuxBlobs {
numBlobs := rand.Int() % 256
blobs := make(htlcAuxBlobs, numBlobs)
for i := 0; i < numBlobs; i++ {
var id resolverID
_, err := rand.Read(id[:])
require.NoError(t, err)
var blob [100]byte
_, err = rand.Read(blob[:])
require.NoError(t, err)
blobs[id] = blob[:]
}
return blobs
}
// TestTaprootBriefcase tests the encode/decode methods of the taproot
// briefcase extension.
func TestTaprootBriefcase(t *testing.T) {
@ -69,19 +90,32 @@ func TestTaprootBriefcase(t *testing.T) {
_, err = rand.Read(anchorTweak[:])
require.NoError(t, err)
var commitBlob [100]byte
_, err = rand.Read(commitBlob[:])
require.NoError(t, err)
testCase := &taprootBriefcase{
CtrlBlocks: &ctrlBlocks{
CtrlBlocks: tlv.NewRecordT[tlv.TlvType0](ctrlBlocks{
CommitSweepCtrlBlock: sweepCtrlBlock[:],
RevokeSweepCtrlBlock: revokeCtrlBlock[:],
OutgoingHtlcCtrlBlocks: randResolverCtrlBlocks(t),
IncomingHtlcCtrlBlocks: randResolverCtrlBlocks(t),
SecondLevelCtrlBlocks: randResolverCtrlBlocks(t),
},
TapTweaks: &tapTweaks{
}),
TapTweaks: tlv.NewRecordT[tlv.TlvType1](tapTweaks{
AnchorTweak: anchorTweak[:],
BreachedHtlcTweaks: randHtlcTweaks(t),
BreachedSecondLevelHltcTweaks: randHtlcTweaks(t),
},
}),
SettledCommitBlob: tlv.SomeRecordT(
tlv.NewPrimitiveRecord[tlv.TlvType2](commitBlob[:]),
),
BreachedCommitBlob: tlv.SomeRecordT(
tlv.NewPrimitiveRecord[tlv.TlvType3](commitBlob[:]),
),
HtlcBlobs: tlv.SomeRecordT(
tlv.NewRecordT[tlv.TlvType4](randHtlcAuxBlobs(t)),
),
}
var b bytes.Buffer
@ -92,3 +126,21 @@ func TestTaprootBriefcase(t *testing.T) {
require.Equal(t, testCase, &decodedCase)
}
// TestHtlcAuxBlobEncodeDecode tests the encode/decode methods of the HTLC aux
// blobs.
func TestHtlcAuxBlobEncodeDecode(t *testing.T) {
t.Parallel()
rapid.Check(t, func(t *rapid.T) {
htlcBlobs := rapid.Make[htlcAuxBlobs]().Draw(t, "htlcAuxBlobs")
var b bytes.Buffer
require.NoError(t, htlcBlobs.Encode(&b))
decodedBlobs := newAuxHtlcBlobs()
require.NoError(t, decodedBlobs.Decode(&b))
require.Equal(t, htlcBlobs, decodedBlobs)
})
}

View File

@ -0,0 +1,78 @@
# 2024/09/02 14:02:53.354676 [TestHtlcAuxBlobEncodeDecode] [rapid] draw htlcAuxBlobs: contractcourt.htlcAuxBlobs{contractcourt.resolverID{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}:[]uint8{}}
#
v0.4.8#15807814492030881602
0x5555555555555
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0
0x0

View File

@ -21,6 +21,7 @@ import (
"github.com/lightningnetwork/lnd/lnutils"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/sweep"
"github.com/lightningnetwork/lnd/tlv"
)
// SUMMARY OF OUTPUT STATES
@ -1423,6 +1424,7 @@ func makeKidOutput(outpoint, originChanPoint *wire.OutPoint,
return kidOutput{
breachedOutput: makeBreachedOutput(
outpoint, witnessType, nil, signDescriptor, heightHint,
fn.None[tlv.Blob](),
),
isHtlc: isHtlc,
originChanPoint: *originChanPoint,

View File

@ -3,7 +3,7 @@
# /make/builder.Dockerfile
# /.github/workflows/main.yml
# /.github/workflows/release.yml
FROM golang:1.22.5-alpine as builder
FROM golang:1.22.6-alpine as builder
LABEL maintainer="Olaoluwa Osuntokun <laolu@lightning.engineering>"

View File

@ -20,6 +20,7 @@ import (
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/channeldb/models"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/graph"
"github.com/lightningnetwork/lnd/keychain"
"github.com/lightningnetwork/lnd/kvdb"
@ -82,9 +83,10 @@ var (
// can provide that serve useful when processing a specific network
// announcement.
type optionalMsgFields struct {
capacity *btcutil.Amount
channelPoint *wire.OutPoint
remoteAlias *lnwire.ShortChannelID
capacity *btcutil.Amount
channelPoint *wire.OutPoint
remoteAlias *lnwire.ShortChannelID
tapscriptRoot fn.Option[chainhash.Hash]
}
// apply applies the optional fields within the functional options.
@ -115,6 +117,14 @@ func ChannelPoint(op wire.OutPoint) OptionalMsgField {
}
}
// TapscriptRoot is an optional field that lets the gossiper know of the root of
// the tapscript tree for a custom channel.
func TapscriptRoot(root fn.Option[chainhash.Hash]) OptionalMsgField {
return func(f *optionalMsgFields) {
f.tapscriptRoot = root
}
}
// RemoteAlias is an optional field that lets the gossiper know that a locally
// sent channel update is actually an update for the peer that should replace
// the ShortChannelID field with the remote's alias. This is only used for
@ -2578,6 +2588,9 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
cp := *nMsg.optionalMsgFields.channelPoint
edge.ChannelPoint = cp
}
// Optional tapscript root for custom channels.
edge.TapscriptRoot = nMsg.optionalMsgFields.tapscriptRoot
}
log.Debugf("Adding edge for short_chan_id: %v", scid.ToUint64())

View File

@ -835,12 +835,6 @@ func (g *GossipSyncer) processChanRangeReply(msg *lnwire.ReplyChannelRange) erro
}
g.prevReplyChannelRange = msg
if len(msg.Timestamps) != 0 &&
len(msg.Timestamps) != len(msg.ShortChanIDs) {
return fmt.Errorf("number of timestamps not equal to " +
"number of SCIDs")
}
for i, scid := range msg.ShortChanIDs {
info := channeldb.NewChannelUpdateInfo(

View File

@ -1,4 +1,4 @@
FROM golang:1.22.5-alpine as builder
FROM golang:1.22.6-alpine as builder
LABEL maintainer="Olaoluwa Osuntokun <laolu@lightning.engineering>"

View File

@ -100,12 +100,12 @@ the following commands for your OS:
<summary>Linux (x86-64)</summary>
```
wget https://dl.google.com/go/go1.22.5.linux-amd64.tar.gz
wget https://dl.google.com/go/go1.22.6.linux-amd64.tar.gz
sha256sum go1.22.5.linux-amd64.tar.gz | awk -F " " '{ print $1 }'
```
The final output of the command above should be
`904b924d435eaea086515bc63235b192ea441bd8c9b198c507e85009e6e4c7f0`. If it
`999805bed7d9039ec3da1a53bfbcafc13e367da52aa823cb60b68ba22d44c616`. If it
isn't, then the target REPO HAS BEEN MODIFIED, and you shouldn't install
this version of Go. If it matches, then proceed to install Go:
```
@ -123,7 +123,7 @@ the following commands for your OS:
```
The final output of the command above should be
`8c4587cf3e63c9aefbcafa92818c4d9d51683af93ea687bf6c7508d6fa36f85e`. If it
`b566484fe89a54c525dd1a4cbfec903c1f6e8f0b7b3dbaf94c79bc9145391083`. If it
isn't, then the target REPO HAS BEEN MODIFIED, and you shouldn't install
this version of Go. If it matches, then proceed to install Go:
```

View File

@ -0,0 +1,7 @@
# Bug Fixes
* Fixed a memory leak found in mempool management handled by
[`btcwallet`](https://github.com/lightningnetwork/lnd/pull/7767).
# Contributors (Alphabetical Order)
* Yong Yu

View File

@ -0,0 +1,51 @@
# Release Notes
- [Bug Fixes](#bug-fixes)
- [New Features](#new-features)
- [Functional Enhancements](#functional-enhancements)
- [RPC Additions](#rpc-additions)
- [lncli Additions](#lncli-additions)
- [Improvements](#improvements)
- [Functional Updates](#functional-updates)
- [RPC Updates](#rpc-updates)
- [lncli Updates](#lncli-updates)
- [Breaking Changes](#breaking-changes)
- [Performance Improvements](#performance-improvements)
- [Technical and Architectural Updates](#technical-and-architectural-updates)
- [BOLT Spec Updates](#bolt-spec-updates)
- [Testing](#testing)
- [Database](#database)
- [Code Health](#code-health)
- [Tooling and Documentation](#tooling-and-documentation)
# Bug Fixes
* A bug that would cause the peer goroutine to panic if SCB related messages
needed to be retransmitted [has been
fixed](https://github.com/lightningnetwork/lnd/pull/8186).
# New Features
## Functional Enhancements
## RPC Additions
## lncli Additions
# Improvements
## Functional Updates
## RPC Updates
## lncli Updates
## Code Health
## Breaking Changes
## Performance Improvements
# Technical and Architectural Updates
## BOLT Spec Updates
## Testing
## Database
## Code Health
## Tooling and Documentation
# Contributors (Alphabetical Order)
* Eugene Siegel
* Matt Morehouse

View File

@ -0,0 +1,132 @@
# Release Notes
- [Bug Fixes](#bug-fixes)
- [New Features](#new-features)
- [Functional Enhancements](#functional-enhancements)
- [RPC Additions](#rpc-additions)
- [lncli Additions](#lncli-additions)
- [Improvements](#improvements)
- [Functional Updates](#functional-updates)
- [RPC Updates](#rpc-updates)
- [lncli Updates](#lncli-updates)
- [Breaking Changes](#breaking-changes)
- [Performance Improvements](#performance-improvements)
- [Technical and Architectural Updates](#technical-and-architectural-updates)
- [BOLT Spec Updates](#bolt-spec-updates)
- [Testing](#testing)
- [Database](#database)
- [Code Health](#code-health)
- [Tooling and Documentation](#tooling-and-documentation)
# Bug Fixes
* [Fix a bug](https://github.com/lightningnetwork/lnd/pull/9134) that would
cause a nil pointer dereference during the probing of a payment request that
does not contain a payment address.
* [Make the contract resolutions for the channel arbitrator optional](
https://github.com/lightningnetwork/lnd/pull/9253).
* [Fixed a bug](https://github.com/lightningnetwork/lnd/pull/9324) to prevent
potential deadlocks when LND depends on external components (e.g. aux
components, hooks).
* [Make sure blinded payment failures are handled correctly in the mission
controller](https://github.com/lightningnetwork/lnd/pull/9316).
# New Features
The main channel state machine and database now allow for processing and storing
custom Taproot script leaves, allowing the implementation of custom channel
types in a series of changes:
* https://github.com/lightningnetwork/lnd/pull/9025
* https://github.com/lightningnetwork/lnd/pull/9030
* https://github.com/lightningnetwork/lnd/pull/9049
* https://github.com/lightningnetwork/lnd/pull/9072
* https://github.com/lightningnetwork/lnd/pull/9095
* https://github.com/lightningnetwork/lnd/pull/8960
* https://github.com/lightningnetwork/lnd/pull/9194
* https://github.com/lightningnetwork/lnd/pull/9288
## Functional Enhancements
* A new `protocol.simple-taproot-overlay-chans` configuration item/CLI flag was
added [to turn on custom channel
functionality](https://github.com/lightningnetwork/lnd/pull/8960).
* Compatibility with [`bitcoind
v28.0`](https://github.com/lightningnetwork/lnd/pull/9059) was ensured by
updating the version the CI pipeline is running against.
## RPC Additions
* Some new experimental [RPCs for managing SCID
aliases](https://github.com/lightningnetwork/lnd/pull/8960) were added under
the `routerrpc` package. These methods allow manually adding and deleting SCID
aliases locally to your node.
> NOTE: these new RPC methods are marked as experimental
(`XAddLocalChanAliases` & `XDeleteLocalChanAliases`) and upon calling
them the aliases will not be communicated with the channel peer.
* The responses for the `ListChannels`, `PendingChannels` and `ChannelBalance`
RPCs now include [a new `custom_channel_data` field that is only set for
custom channels](https://github.com/lightningnetwork/lnd/pull/8960).
* The `routerrpc.SendPaymentV2` RPC has a new field [`first_hop_custom_records`
that allows the user to send custom p2p wire message TLV types to the first
hop of a payment](https://github.com/lightningnetwork/lnd/pull/8960).
That new field is also exposed in the `routerrpc.HtlcInterceptor`, so it can
be read and interpreted by external software.
* The `routerrpc.HtlcInterceptor` now [allows some values of the HTLC to be
modified before they're validated by the state
machine](https://github.com/lightningnetwork/lnd/pull/8960). The fields that
can be modified are `outgoing_amount_msat` (if transported overlaid value of
HTLC doesn't match the actual BTC amount being transferred) and
`outgoing_htlc_wire_custom_records` (allow adding custom TLV values to the
p2p wire message of the forwarded HTLC).
* A new [`invoicesrpc.HtlcModifier` RPC now allows incoming HTLCs that attempt
to satisfy an invoice to be modified before they're
validated](https://github.com/lightningnetwork/lnd/pull/8960). This allows
custom channels to determine what the actual (overlaid) value of an HTLC is,
even if that value doesn't match the actual BTC amount being transferred by
the HTLC.
## lncli Additions
# Improvements
## Functional Updates
## RPC Updates
## lncli Updates
## Code Health
## Breaking Changes
## Performance Improvements
* [A new method](https://github.com/lightningnetwork/lnd/pull/9195)
`AssertTxnsNotInMempool` has been added to `lntest` package to allow batch
exclusion check in itest.
# Technical and Architectural Updates
## BOLT Spec Updates
## Testing
## Database
## Code Health
## Tooling and Documentation
# Contributors (Alphabetical Order)
* Elle Mouton
* ffranr
* George Tsagkarelis
* Olaoluwa Osuntokun
* Oliver Gugger
* Ziggie

View File

@ -92,7 +92,8 @@ var defaultSetDesc = setDesc{
SetInit: {}, // I
SetNodeAnn: {}, // N
},
lnwire.Bolt11BlindedPathsOptional: {
SetInvoice: {}, // I
lnwire.SimpleTaprootOverlayChansOptional: {
SetInit: {}, // I
SetNodeAnn: {}, // N
},
}

View File

@ -79,6 +79,11 @@ var deps = depDesc{
lnwire.AnchorsZeroFeeHtlcTxOptional: {},
lnwire.ExplicitChannelTypeOptional: {},
},
lnwire.SimpleTaprootOverlayChansOptional: {
lnwire.SimpleTaprootChannelsOptionalStaging: {},
lnwire.TLVOnionPayloadOptional: {},
lnwire.ScidAliasOptional: {},
},
lnwire.RouteBlindingOptional: {
lnwire.TLVOnionPayloadOptional: {},
},

View File

@ -63,6 +63,9 @@ type Config struct {
// NoRouteBlinding unsets route blinding feature bits.
NoRouteBlinding bool
// NoTaprootOverlay unsets the taproot overlay channel feature bits.
NoTaprootOverlay bool
// CustomFeatures is a set of custom features to advertise in each
// set.
CustomFeatures map[Set][]lnwire.FeatureBit
@ -192,6 +195,10 @@ func newManager(cfg Config, desc setDesc) (*Manager, error) {
raw.Unset(lnwire.Bolt11BlindedPathsOptional)
raw.Unset(lnwire.Bolt11BlindedPathsRequired)
}
if cfg.NoTaprootOverlay {
raw.Unset(lnwire.SimpleTaprootOverlayChansOptional)
raw.Unset(lnwire.SimpleTaprootOverlayChansRequired)
}
for _, custom := range cfg.CustomFeatures[set] {
if custom > set.Maximum() {
return nil, fmt.Errorf("feature bit: %v "+

51
funding/aux_funding.go Normal file
View File

@ -0,0 +1,51 @@
package funding
import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/msgmux"
)
// AuxFundingDescResult is a type alias for a function that returns an optional
// aux funding desc.
type AuxFundingDescResult = fn.Result[fn.Option[lnwallet.AuxFundingDesc]]
// AuxTapscriptResult is a type alias for a function that returns an optional
// tapscript root.
type AuxTapscriptResult = fn.Result[fn.Option[chainhash.Hash]]
// AuxFundingController permits the implementation of the funding of custom
// channels types. The controller serves as a MsgEndpoint which allows it to
// intercept custom messages, or even the regular funding messages. The
// controller might also pass along an aux funding desc based on an existing
// pending channel ID.
type AuxFundingController interface {
// Endpoint is the embedded interface that signals that the funding
// controller is also a message endpoint. This'll allow it to handle
// custom messages specific to the funding type.
msgmux.Endpoint
// DescFromPendingChanID takes a pending channel ID, that may already be
// known due to prior custom channel messages, and maybe returns an aux
// funding desc which can be used to modify how a channel is funded.
DescFromPendingChanID(pid PendingChanID, openChan lnwallet.AuxChanState,
keyRing lntypes.Dual[lnwallet.CommitmentKeyRing],
initiator bool) AuxFundingDescResult
// DeriveTapscriptRoot takes a pending channel ID and maybe returns a
// tapscript root that should be used when creating any MuSig2 sessions
// for a channel.
DeriveTapscriptRoot(PendingChanID) AuxTapscriptResult
// ChannelReady is called when a channel has been fully opened (multiple
// confirmations) and is ready to be used. This can be used to perform
// any final setup or cleanup.
ChannelReady(openChan lnwallet.AuxChanState) error
// ChannelFinalized is called when a channel has been fully finalized.
// In this state, we've received the commitment sig from the remote
// party, so we are safe to broadcast the funding transaction.
ChannelFinalized(PendingChanID) error
}

View File

@ -307,6 +307,74 @@ func explicitNegotiateCommitmentType(channelType lnwire.ChannelType, local,
return lnwallet.CommitmentTypeSimpleTaproot, nil
// Simple taproot channels overlay only.
case channelFeatures.OnlyContains(
lnwire.SimpleTaprootOverlayChansRequired,
):
if !hasFeatures(
local, remote,
lnwire.SimpleTaprootOverlayChansOptional,
) {
return 0, errUnsupportedChannelType
}
return lnwallet.CommitmentTypeSimpleTaprootOverlay, nil
// Simple taproot overlay channels with scid only.
case channelFeatures.OnlyContains(
lnwire.SimpleTaprootOverlayChansRequired,
lnwire.ScidAliasRequired,
):
if !hasFeatures(
local, remote,
lnwire.SimpleTaprootOverlayChansOptional,
lnwire.ScidAliasOptional,
) {
return 0, errUnsupportedChannelType
}
return lnwallet.CommitmentTypeSimpleTaprootOverlay, nil
// Simple taproot overlay channels with zero conf only.
case channelFeatures.OnlyContains(
lnwire.SimpleTaprootOverlayChansRequired,
lnwire.ZeroConfRequired,
):
if !hasFeatures(
local, remote,
lnwire.SimpleTaprootOverlayChansOptional,
lnwire.ZeroConfOptional,
) {
return 0, errUnsupportedChannelType
}
return lnwallet.CommitmentTypeSimpleTaprootOverlay, nil
// Simple taproot overlay channels with scid and zero conf.
case channelFeatures.OnlyContains(
lnwire.SimpleTaprootOverlayChansRequired,
lnwire.ZeroConfRequired,
lnwire.ScidAliasRequired,
):
if !hasFeatures(
local, remote,
lnwire.SimpleTaprootOverlayChansOptional,
lnwire.ZeroConfOptional,
lnwire.ScidAliasOptional,
) {
return 0, errUnsupportedChannelType
}
return lnwallet.CommitmentTypeSimpleTaprootOverlay, nil
// No features, use legacy commitment type.
case channelFeatures.IsEmpty():
return lnwallet.CommitmentTypeLegacy, nil

Some files were not shown because too many files have changed in this diff Show More