Commit Graph

999 Commits

Author SHA1 Message Date
yyforyongyu
271c36d348
channeldb: move payment status code into new file
This prepares the following expansion of the payment status codes.
2022-12-07 18:38:01 +08:00
yyforyongyu
2fd4c1e318
channeldb+routing: fix format 2022-12-07 18:38:01 +08:00
yyforyongyu
e9269c2093
channeldb+lnd: rpc server filters payments by date 2022-12-05 20:04:47 +08:00
yyforyongyu
234b9a3d97
channeldb+lnd: rpc server filters invoices by date 2022-12-05 20:03:58 +08:00
Joost Jager
4c8ea29336
lnwire: allow longer failure messages
This fixes an incompatibility where lnd enforces a strict 256 byte
failure message, where as the spec sets this only as the recommended
length.
2022-12-02 14:27:59 +01:00
yyforyongyu
84fd911b47
multi: fix make lint
Fixes new lint errors caught by the latest version.
2022-11-18 20:48:23 +08:00
habibitcoin
0b1e881d18
scripted-diff: replace ⛰ emoji with $ [skip ci]
-BEGIN VERIFY SCRIPT-
sed -i 's/⛰/$/g' $(git grep -l '⛰')
-END VERIFY SCRIPT-
2022-10-28 12:06:49 -04:00
Joost Jager
3a89a84744
rpcserver: add LookupHtlc call 2022-10-27 16:43:09 +02:00
Joost Jager
28256b7ea8
htlcswitch: keep final htlc outcome 2022-10-27 16:42:36 +02:00
Eng Zer Jun
c70e39cd21
multi: replace defer cleanup with t.Cleanup
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-10-13 17:46:54 +08:00
Oliver Gugger
fc2d652261
channeldb: check for tombstone before opening DB
To avoid running a channel DB that was successfully migrated to another
system by accident, we check if there is a tombstone marker before we
open the DB for use.
2022-10-13 09:45:07 +02:00
Oliver Gugger
7e76326b97
channeldb: export DB migration related functions
We'll need to know whether a database was migrated to the latest version
in our upcoming data migration tool. To be able to determine the current
version of a DB and the total number of migrations in existence, we need
to export some of the functions in channeldb.
We also add some helper functions for adding tombstone and other markers
to a database.
2022-10-13 09:45:07 +02:00
Oliver Gugger
28c8e8b6dd
channeldb: remove unused tx argument 2022-10-13 09:37:53 +02:00
Slyghtning
e87412bd63 funding+channeldb: handle and persist channel fees 2022-09-29 08:21:06 -04:00
Eng Zer Jun
dd07cb850d
channeldb: use T.TempDir to create temporary test directory
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-08-24 08:58:16 +08:00
yyforyongyu
0735522194
multi: fix make fmt 2022-08-23 22:10:24 +08:00
yyforyongyu
ac6e1a836c
channeldb: skip dry run mode for optional migrations 2022-07-12 21:01:15 +08:00
yyforyongyu
b391503ddf
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-07-12 21:01:12 +08:00
yyforyongyu
78a73f9761
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-07-12 21:01:12 +08:00
yyforyongyu
afb2f72ce2
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-07-12 21:01:11 +08:00
yyforyongyu
1832a93d19
migration30: add benchmark test 2022-07-12 21:01:11 +08:00
yyforyongyu
5316fcd6c9
migration30+migtest: add unit tests for migration 2022-07-12 21:01:11 +08:00
yyforyongyu
61bff6086c
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-07-12 21:01:08 +08:00
yyforyongyu
2a06145137
migration30: add unit tests for iterator 2022-07-12 20:51:48 +08:00
yyforyongyu
75dbbb55ad
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-07-12 20:51:48 +08:00
yyforyongyu
ebbdf78d52
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-07-12 20:51:45 +08:00
yyforyongyu
674b0ec5fb
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-07-08 13:17:57 +08:00
eugene
1aa9626606
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-07-07 17:10:28 -04:00
eugene
01f28ba540
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-07-07 17:10:28 -04:00
eugene
c9f5912601
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-07-07 17:10:27 -04:00
Tommy Volk
834756c53c multi: migrate assert.NoError to require.NoError 2022-07-05 16:41:08 +00:00
Tommy Volk
2dd11ed249 channeldb+routing: htlcs are pruned on settle 2022-07-03 21:04:34 +00:00
Tommy Volk
8291e8a170 multi: add keep-failed-payment-attempts flag 2022-07-03 21:04:27 +00:00
yyforyongyu
0e12a91715
channeldb: fix data race in TestSerializeHTLCEntries 2022-06-28 21:28:04 +08:00
Tommy Volk
9a10c80bcb multi: move many t.Fatalf calls to require.NoError 2022-06-17 04:26:55 +00:00
yyforyongyu
2b5d535208
channeldb: fix data race in TestSerializeRevocationLog
When testing serializing revocation log, we need to also copy its
`HTLCEntries` as the serialization of the HTLC involves a writing to the
`htlc.amtTlv` field.
2022-06-01 02:20:44 +08:00
yyforyongyu
d7bb7cd9a7
migration27: add unit test to cover ChanStatusRestored 2022-05-23 05:13:56 +08:00
yyforyongyu
7cf28773bf
multi: export channel status field in migration25
Previously, in `migration25.OpenChannel`, there was a private field
`chanStatus` used to keep track of the channel status. The following
migrations, `migration26` and `migration27` also have their own
`OpenChannel` defined, with `migration26` inherited from `migration25`,
and `migration27` inherited from `migration26`. The private field
`chanStatus`, however, is NOT inherited and each of the migrations uses
its own. This is fine for reading and writing as, under the hood, the
`chanStatus` is just a `uint8` value. Because each migration has its own
fetcher and putter, it can safely access its private field to read and
write it correctly.

The issue pops up when we use the method
`migration25.FundingTxPresent()`. Because it's evaluating its channel
status using its own private field `chanStatus`, this field would always
be the default value(`ChanStatusDefault`), leading the statement
`!c.hasChanStatus(ChanStatusRestored)` to always be true. Thus a
restored channel will be mistakenly considered to have funding tx
present, causing failures in reading the channel info in the following
migrations.

We fix this by exporting the `ChanStatus` field so its value can be set
by following migrations.
2022-05-23 03:55:00 +08:00
yyforyongyu
3458b2eb7d
channeldb+migration27: patch balance fields for historical chan
This commit adds a new migration to patch the two balance fields,
`InitialLocalBalance` and `InitialRemoteBalance` for the historical
channels. Because they are not saved previously, for historical channels
prior to the revocation log PR, these fields will be empty.
2022-05-20 06:55:31 +08:00
yyforyongyu
55746e427e
channeldb+migration26: migrate balance fields into tlv records 2022-05-19 03:34:24 +08:00
yyforyongyu
de2bcbf925
migration25: export methods to be used for following migrations
This commit exports several private methods to be used in later
migrations. It's safe to do so as no actual logic or migration scheme is
changed.
2022-05-19 03:34:13 +08:00
yyforyongyu
2ec459df6c
channeldb: use TLV for InitialLocalBalance and InitialRemoteBalance
This commit changes the encoding scheme for the fields
`InitialLocalBalance` and `InitialRemoteBalance` and use TLV instead.
2022-05-18 19:46:09 +08:00
eugene
2e3246aafe
channeldb: copy value from boltdb's Get instead of using it directly
This can cause an intermittent panic otherwise if bbolt remaps itself
via munmap and mmap. From bbolt's documentation:

* Byte slices returned from Bolt are only valid during a transaction.
Once the transaction has been committed or rolled back then the memory
they point to can be reused by a new page or can be unmapped from
virtual memory and you'll see an unexpected fault address panic when
accessing it.
2022-05-17 11:14:40 -04:00
eugene
4eea395a7f
channeldb+invoices: refactor invoice logic when updating 2022-05-11 13:57:46 -04:00
Olaoluwa Osuntokun
0ec88b5346
Merge pull request #6347 from yyforyongyu/5388-rm-revc-log
lnwallet+channeldb: store minimal info in revocation log bucket
2022-05-05 15:52:59 -07:00
Oliver Gugger
bdd1c5c4e1
Merge pull request #6423 from tvolk131/fix_typos
Typo fixes and code cleanup
2022-05-05 09:42:39 +02:00
Tommy Volk
bd9904e11e channeldb: remove empty files 2022-05-03 20:56:44 +00:00
Tommy Volk
5ae2ce984e multi: typo fixes [skip ci] 2022-05-03 20:55:40 +00:00
Oliver Gugger
c42330d9c5
channeldb: add CountTotal option to payment query 2022-05-02 12:32:06 +02:00
yyforyongyu
b288284566
channeldb: use BigSize to encode htlc amount
This commit uses bigsize record to encode the htlc amount, which could
save us 3 more bytes if the encoded value is no greater than roughly
0.043 bitcoin. The uint test has been updated with a more realistic
values to reflect the actual gain.
2022-04-20 01:19:40 +08:00