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

Function wallet_sanity_check

wallet/wallet.c:3686–3748  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3684}
3685
3686bool wallet_sanity_check(struct wallet *w)
3687{
3688 struct bitcoin_blkid chainhash;
3689 struct db_stmt *stmt = db_prepare_v2(
3690 w->db, SQL("SELECT blobval FROM vars WHERE name='genesis_hash'"));
3691 db_query_prepared(stmt);
3692
3693 if (db_step(stmt)) {
3694 db_col_sha256d(stmt, "blobval", &chainhash.shad);
3695 tal_free(stmt);
3696 if (!bitcoin_blkid_eq(&chainhash,
3697 &chainparams->genesis_blockhash)) {
3698 log_broken(w->log, "Wallet blockchain hash does not "
3699 "match network blockchain hash: %s "
3700 "!= %s. "
3701 "Are you on the right network? "
3702 "(--network={one of %s})",
3703 type_to_string(w, struct bitcoin_blkid,
3704 &chainhash),
3705 type_to_string(w, struct bitcoin_blkid,
3706 &chainparams->genesis_blockhash),
3707 chainparams_get_network_names(tmpctx));
3708 return false;
3709 }
3710 } else {
3711 tal_free(stmt);
3712 /* Still a pristine wallet, claim it for the chain
3713 * that we are running */
3714 stmt = db_prepare_v2(w->db, SQL("INSERT INTO vars (name, blobval) "
3715 "VALUES ('genesis_hash', ?);"));
3716 db_bind_sha256d(stmt, 0, &chainparams->genesis_blockhash.shad);
3717 db_exec_prepared_v2(take(stmt));
3718 }
3719
3720 stmt = db_prepare_v2(w->db,
3721 SQL("SELECT blobval FROM vars WHERE name='node_id'"));
3722 db_query_prepared(stmt);
3723
3724 if (db_step(stmt)) {
3725 struct node_id id;
3726 db_col_node_id(stmt, "blobval", &id);
3727 tal_free(stmt);
3728
3729 if (!node_id_eq(&id, &w->ld->id)) {
3730 log_broken(w->log, "Wallet node_id does not "
3731 "match HSM: %s "
3732 "!= %s. "
3733 "Did your hsm_secret change?",
3734 type_to_string(tmpctx, struct node_id, &id),
3735 type_to_string(tmpctx, struct node_id,
3736 &w->ld->id));
3737 return false;
3738 }
3739 } else {
3740 tal_free(stmt);
3741 /* Still a pristine wallet, claim it for the node_id we are now */
3742 stmt = db_prepare_v2(w->db, SQL("INSERT INTO vars (name, blobval) "
3743 "VALUES ('node_id', ?);"));

Callers

nothing calls this directly

Calls 11

db_query_preparedFunction · 0.85
db_stepFunction · 0.85
db_col_sha256dFunction · 0.85
tal_freeFunction · 0.85
db_bind_sha256dFunction · 0.85
db_exec_prepared_v2Function · 0.85
db_col_node_idFunction · 0.85
node_id_eqFunction · 0.85
db_bind_node_idFunction · 0.85
type_to_stringClass · 0.50

Tested by

no test coverage detected