MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

tools/lightning-downgrade.c:201–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199}
200
201int main(int argc, char *argv[])
202{
203 char *config_filename, *base_dir, *net_dir, *rpc_filename, *wallet_dsn = NULL;
204 const struct db_version *prev_version;
205 size_t current, num_migrations;
206 struct db *db;
207 const struct db_migration *migrations;
208 struct db_stmt *stmt;
209
210 setup_locale();
211 err_set_progname(argv[0]);
212
213 minimal_config_opts(tmpctx, argc, argv, &config_filename, &base_dir,
214 &net_dir, &rpc_filename);
215 opt_register_early_arg("--wallet", opt_set_talstr, NULL,
216 &wallet_dsn,
217 "Location of the wallet database.");
218 opt_register_noarg("--help|-h", opt_usage_and_exit,
219 "A tool to downgrade an offline Core Lightning Node to " PREV_VERSION,
220 "Print this message.");
221 opt_early_parse(argc, argv, opt_log_stderr_exit_usage);
222 opt_parse(&argc, argv, opt_log_stderr_exit_usage);
223
224 if (argc != 1)
225 opt_usage_exit_fail("No arguments expected");
226
227 if (!wallet_dsn)
228 wallet_dsn = tal_fmt(tmpctx, "sqlite3://%s/lightningd.sqlite3", net_dir);
229
230 if (path_is_file(path_join(tmpctx, base_dir,
231 tal_fmt(tmpctx, "lightningd-%s.pid",
232 chainparams->network_name)))) {
233 errx(ERROR_USAGE,
234 "Lightningd PID file exists, aborting: lightningd must not be running");
235 }
236
237 migrations = get_db_migrations(&num_migrations);
238 prev_version = version_db(PREV_VERSION);
239
240 /* Do this even if the db hasn't changed. */
241 if (!version_db(PREV_VERSION)->gossip_store_compatible) {
242 printf("Deleting incompatible gossip_store\n");
243 unlink(path_join(tmpctx, net_dir, "gossip_store"));
244 }
245
246 /* Open db, check it's the expected version */
247 db = db_open(tmpctx, wallet_dsn, false, false, db_error, NULL);
248 if (!db)
249 err(1, "Could not open database %s", wallet_dsn);
250 db->report_changes_fn = NULL;
251
252 db_begin_transaction(db);
253 db->data_version = db_data_version_get(db);
254 current = db_get_version(db);
255
256 if (current < prev_version->db_height)
257 errx(ERROR_DBVERSION, "Database version %zu already less than %zu expected for %s",
258 current, prev_version->db_height, PREV_VERSION);

Callers

nothing calls this directly

Calls 15

setup_localeFunction · 0.85
err_set_prognameFunction · 0.85
minimal_config_optsFunction · 0.85
opt_early_parseFunction · 0.85
opt_parseFunction · 0.85
opt_usage_exit_failFunction · 0.85
path_is_fileFunction · 0.85
path_joinFunction · 0.85
errxFunction · 0.85
version_dbFunction · 0.85
errFunction · 0.85
db_data_version_getFunction · 0.85

Tested by

no test coverage detected