-
Notifications
You must be signed in to change notification settings - Fork 912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Lightweight lightningd.sqlite3 database #4824
Comments
⚠ A warning to users: Never ever manually edit the database unless developers tell you to, you may risk losing funds. ⚠ Notice that in order to ensure consistency you'll have to run In particular deleting all of |
@cdecker Thank you. Can there be any in-flight HTLCs when the daemon has stopped? Would it be possible to add an option which would remove an obsolete entry (as soon as it is known that if it stays in the database, its use would be only as a historical record)? |
Numbers of rows for all the table records (not taking into account the row length yet) for my current
|
Yes, definitely; the daemon is written such that it expects to be HTLCs being in-flight are a normal part of operation and that state can persist for days; we cannot delay daemon shutdown until there are no in-flight HTLCs when in-flight HTLCs can persist for days at a time. Indeed the only time we reliably "drain" all in-flight HTLCs on a channel are when we mutually close, and mutual closes can be delayed for days because of that, which is why we have a
There are no obsolete HTLCs until you close the channel, unless you trust your peer(s) not to hurt you EVER. The attack to be done as follows:
The attacker cannot steal from you (if it publishes the HTLC claim, you can revoke the claim, since the revocation keys are stored in an O(1) structure called the shachain), but if the attacker is willing to pay so that you are hurt financially, then the attacker simply never publishes the HTLC claim. Then the output is unspendable forever, and you lose access to part of your funds (equal to the value of the "obsolete" HTLC you deleted). They do not win, but you definitely lose, and potentially lose more than the attacker does. Only when the channel is closed and done with can you safely delete old HTLCs involving that channel (and IIRC this is done automatically). This will change with Decker-Russell-Osuntokun, but current channels require all old HTLCs to be retained for safety. If you want to delete them, be warned that you risk funds loss. Poon-Dryja can be modified to also not require retaining old HTLCs, but that modification requires an additional 1-input-1-output transaction on unilateral closes and is non-standard, and if you need to change the standard you might as well hold out for Decker-Russell-Osuntokun. |
Thank you @ZmnSCPxj for this in-depth explanation. Greatly appreciated! I have a few more questions now. Does the omission mean I can safely delete the contents of Why does the table |
Not sure; probably better to ask @rustyrussell, as the HTLC state machine is foreign to me and I believe that is what uses that table.
Because our design of UTXO tracking sucks? (^^.;;;;;)v See the confusion I have in #3858 (comment) (EDIT: or this one: #3858 (comment) ). Our spending-ness trackers were all kinda tacked on variously in various bits and pieces. Off the top of my head, I think |
Okay, looking over the code again, it looks like There are vague proposals to include UTXO set proofs in gossip (basically a Merkle proof of inclusion of the tx in a block, plus the tx itself so we can check the txo), but that requires two proofs --- proof the TXO was created, and proof it was spent, and liars have an incentive to suppress the propagation of the proof-it-was-spent. But if LN can switch to that then there is no need to track the UTXO set oursleves, and if everyone switches to P2TR then the UTXO set we have to keep track is going to be very large, about as large as the full UTXO set of the |
Re: So I got one of my regular db backups and did the following:
As you can see, that is a fairly large drop in size (note that due to the way SQLITE3 manages storage), not doing a (Do NOT do this in production, note the above that this was a backup copy and that I made a separate copy of that copy before doing anything.) As noted, However, we can observe that:
Perhaps we can do something like:
(Note that the 50% reduction in size is an asymptote: we have to keep track of channels, and thus some Thoughts @rustyrussell ? |
Thank you @ZmnSCPxj ! I really appreciate your time and effort here. The production-safe (VACUUM-only), which I run now on my backups (i.e. PRAGMA foreign_keys = ON;
VACUUM; |
Just wanted to mention that we merged #4850 which is a first step towards reducing the DB size. It drops the large encrypted blobs as soon as HTLCs are definitely settled. According to rusty this already takes a huge chunk out of his database, without impacting the operation of the node. |
Thank you @cdecker !!! :-) |
And @rustyrussell of course! :-) Thank you! |
My In backup I keep only the vacuumed version of it ( There was recently no visible activity (no noticable balance changes), but probably many failed forwarding attempts, though cleaning Ideas:
|
This should be automatically managed by SQLITE3; if not, then that would be a bug in SQLITE3. Note that this is not the only index, either; there are other indexes as well, probably larger. Possibly what is happening is fragmentation of usable space, which My snapshotted backups are smaller than my "main" file as well by a similar degree as youquoted, and I do |
Re growth, also remember the earlier discussion; |
Thank you @ZmnSCPxj! If it is just |
@jsarenik SQLITE3 has a built-in autovacuum -- you could try this on your
You could try that and see if it slows down the growth or not. |
@ZmnSCPxj Thank you for sharing! Everything works well for me. |
Okay. Let us know if it seems to slow down the growth of the file; I am writing a |
@jsarenik also note that auto-vacuum is not a "pure" optimization, it is a tradeoff: you get a smaller database file in general, but queries (both read-only ones and updates) get slower: (SQLITE3 has to put back-references in each stored row so it can immediately track deleted rows, it has to periodically vacuum, and it is now more likely that tables get fragmented due to deleted rows being moved to the end of the file (i.e. rows of other tables get moved into the space of the deleted row of the table). But you were asking for smaller db size, so... |
@ZmnSCPxj Thanks for explanation. Yes, that is quite important. I will revert back to how it was originally (and do a manual vacuum on backup files). |
Description
As discussed in one of the recent Monday meetings, I would like to know what are the minimum data in
lightningd.sqlite3
file in order to keep the basic functionality of the node and all its channels, but being able to forget the history of all the forwards at least.My node is routing for free (0 base and 0 proportional) no matter what. So I think all that is needed in the DB should be some channel states and balances. Anything else?
Currently I am experimenting with wiping out the contents of
forwarded_payments
andchannel_htlcs
tables.The above reduces the size of
lightningd.sqlite3
file significantly (from 380MB to 120MB). What other table contents would be safe to delete?The text was updated successfully, but these errors were encountered: