Commit Graph

969 Commits

Author SHA1 Message Date
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
yyforyongyu
37b11c4503
channeldb+lnwallet: store revocation log using the new format
This commit removes the usage of the old revocation log bucket and
starts to perform db operations using the new sub-bucket.
2022-04-20 01:18:14 +08:00
yyforyongyu
a129930a95
channeldb: add unit test for revocation log 2022-04-20 01:18:13 +08:00
yyforyongyu
dc137bed8b
channel: move deprecated log handling into the new file 2022-04-20 01:18:13 +08:00
yyforyongyu
c41175f233
channeldb: re-introduce revocationLogBucket
This commit adds `revocationLogBucket` using the new sub-bucket key
"revocation-log" to store the minimal info needed. Two structs,
`RevocationLog` and `HTLCEntry` are created to represent the disk
records.
2022-04-20 01:18:13 +08:00
yyforyongyu
4609ac2008
channeldb: deprecate old revocation log bucket
This commit marks the sub-bucket identified by "revocation-log-key" as
deprecated.
2022-04-20 01:18:13 +08:00
yyforyongyu
f42d1f2d62
multi: remove function BalancesAtHeight
This commit deletes the function `BalancesAtHeight` since its only
usague is to find the push amount, which can be achieved by saving the
initial balances.
Another reason to remove it is to pave the way to incooperate our new
revocation log. If we ever need this function again, we can add it back
by visiting all the revocation logs to calculate the balances at a given
height.
2022-04-20 01:18:13 +08:00
yyforyongyu
7eaf0d0089
channeldb+migration: add migration test for patching balances 2022-04-20 01:18:13 +08:00
yyforyongyu
c9843fd206
channeldb+migration: add migration to save the initial balances
This commit adds a migration to patch the newly added fields,
`InitialLocalBalance` and `InitialRemoteBalance` to channel info.
2022-04-20 01:18:12 +08:00
yyforyongyu
8b289e79f5
channeldb+migration: export commonly used methods
This commit exports several commonly used methods that can be used by
later migrations. It also adds a channel commit deserializer.
2022-04-20 01:18:12 +08:00
yyforyongyu
22f8f6ed4a
channeldb+lnwallet: save initial balances during channel opening 2022-04-20 01:18:12 +08:00
yyforyongyu
5f508f9278
channeldb: replace method RevocationLogTail
This commit replaces the method RevocationLogTail which in used in our
unit test with a private method revocationLogTailCommitHeight. The new
method returns the commit height only since that's what's needed in the
test.
2022-04-20 01:18:11 +08:00
Joost Jager
9195f29e61
routing+channeldb: send payment metadata from invoice 2022-04-13 22:55:40 +02:00
eugene
4373faa818
channeldb: change to ErrTypeForDecodingErr for amp state
Was instead returning ErrTypeForEncodingErr.
2022-03-23 12:05:11 -04:00
Oliver Gugger
7dfe4018ce
multi: use btcd's btcec/v2 and btcutil modules
This commit was previously split into the following parts to ease
review:
 - 2d746f68: replace imports
 - 4008f0fd: use ecdsa.Signature
 - 849e33d1: remove btcec.S256()
 - b8f6ebbd: use v2 library correctly
 - fa80bca9: bump go modules
2022-03-09 19:02:37 +01:00
Oliver Gugger
13f187046b
multi: fix issues reported by whitespace linter 2022-02-15 16:26:08 +01:00
Oliver Gugger
895a2e497b
multi: formatting and comment fixes 2022-02-10 11:02:02 +01:00
Oliver Gugger
ffee7d1bcf
multi: fix newly detected linter issues 2022-02-10 11:02:02 +01:00
Oliver Gugger
dfdc2bff8b
multi: run gosimports 2022-02-10 11:02:01 +01:00
Rafe
62dc1b5323 multi: Update Licenses to 2022 [skip ci] 2022-02-09 00:25:20 +02:00
Dimitris Apostolou
530a2059e5
multi: Fix typos [skip ci] 2022-01-24 12:19:02 +02:00
Olaoluwa Osuntokun
d67e6d5414
Merge pull request #6111 from bottlepay/cache-loading
kvdb+channeldb: speed up graph cache
2022-01-20 17:35:04 -08:00
Olaoluwa Osuntokun
91f32ad270
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-18 09:11:13 -08:00
Joost Jager
352008a0c2
channeldb: speed up graph cache loading
Use the optimized ForEachChannel method to reduce the graph cache
loading time.
2022-01-14 14:57:29 +01:00
Joost Jager
2e2229a2e7
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-14 14:57:27 +01:00
Joost Jager
cb4703638f
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-14 14:57:25 +01:00
Joost Jager
54324d554a
channeldb: extract deserializeChanEdgePolicyRaw
Allows for pure deserialization without depending on a database connection.
2022-01-12 19:11:56 +01:00
Joost Jager
aff9685a61
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-12 19:11:54 +01:00
naveen
87a0e52464
multi: Removed deprecated interfacer linter
Removed the deprecated interfacer linter from being called for linting.

Also removed the `nolint:interfacer` within the code.

https://github.com/lightningnetwork/lnd/issues/5741
2022-01-11 14:08:18 +01:00
naveen
545e84f4ce
multi: formatting changes 2022-01-11 14:08:17 +01:00
Oliver Gugger
b147d589c1
channeldb: add NoMigration mode
In case the channeldb package is used as a library in external tools, it
can be useful to allow read-only access to a DB. This allows such a
tool to access a DB even if not all migrations were executed, which can
be useful for recovery purposes.
To make it possible to even start the DB with a read-only backend, we
need to disable the automatic migration step.
2021-12-13 12:31:49 +01:00