ElementsProject / lightning

Core Lightning — Lightning Network implementation focusing on spec compliance and performance
Other
2.85k stars 901 forks source link

Unable to update database #6700

Closed hMsats closed 1 year ago

hMsats commented 1 year ago

Issue and Steps to Reproduce

2023-09-21T06:53:21.924Z INFO    plugin-clnrest.py: Killing plugin: disabled itself: No module named 'flask'
2023-09-21T06:53:21.937Z INFO    lightningd: Updating database from version 234 to 235
2023-09-21T06:53:21.937Z **BROKEN** lightningd: query failed: wallet/wallet.c:5721: SELECT rune, last_used_nsec FROM runes
query failed: wallet/wallet.c:5721: SELECT rune, last_used_nsec FROM runes

getinfo output

Master (a0f4eb9)

vincenzopalazzo commented 1 year ago

Thanks for the bug report

Maybe this is relate to this https://github.com/ElementsProject/lightning/issues/6696

ddustin commented 1 year ago

I believe this was caused by a migration issue from this commit: https://github.com/ElementsProject/lightning/commit/eacf0b502c28662b515eaec2f3e975ac51423f20#diff-1abcdf1b9d822b30079d6450b790274bdfb7c7fa04baa43ad2d9bd449865d4c9R978

Meaning the alter table query ALTER TABLE runes ADD last_used_nsec BIGINT DEFAULT NULL was never run on your database.

Artifacts of running on bleeding edge master 😅. You probably should be able to run the command manually and get up and running but screwing with your DB is risky. Maybe shut it down and back it all up first? Caveat emptor 😬

hMsats commented 1 year ago

@vincenzopalazzo as suggested above, executing the line: ALTER TABLE runes ADD last_used_nsec BIGINT DEFAULT NULL by hand on the database solved the issue. So for some (strange) reason it was never executed during the database update.

hMsats commented 1 year ago

@vincenzopalazzo I think I found the reason for this issue in the source code. See my pull request.

ShahanaFarooqui commented 1 year ago

The error message and the PR (#6713) do not seem to be related. IMHO, @ddustin suggestion solved your issue and then you found another issue which you resolved with the PR.

No further action is required, so closing this issue now.

ddustin commented 1 year ago

@ShahanaFarooqui the issue was caused because a database command was added second-to-last instead of last in the dbmigration array here: https://github.com/ElementsProject/lightning/commit/eacf0b502c28662b515eaec2f3e975ac51423f20#diff-1abcdf1b9d822b30079d6450b790274bdfb7c7fa04baa43ad2d9bd449865d4c9R978

The result of this is people updating from before this commit to after will never get the ALTER TABLE runes command and instead will have migrate_runes_idfix run a second time.

ShahanaFarooqui commented 1 year ago

@ShahanaFarooqui the issue was caused because a database command was added second-to-last instead of last in the dbmigration array here: eacf0b5#diff-1abcdf1b9d822b30079d6450b790274bdfb7c7fa04baa43ad2d9bd449865d4c9R978

The result of this is people updating from before this commit to after will never get the ALTER TABLE runes command and instead will have migrate_runes_idfix run a second time.

Ohh I remember now. It happened because when I rebased the PR, it merged it in the wrong direction. And fixed that in further commits :)

vincenzopalazzo commented 1 year ago

What is the solution here?

as suggested above, executing the line: ALTER TABLE runes ADD last_used_nsec BIGINT DEFAULT NULL by hand on the database solved the issue.

I really hope it is not this