Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions db/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,39 @@ s64 db_get_intvar(struct db *db, const char *varname, s64 defval)
return res;
}

void db_set_blobvar(struct db *db, const char *varname, const u8 *val, size_t len)
{
size_t changes;
struct db_stmt *stmt = db_prepare_v2(db, SQL("UPDATE vars SET blobval=? WHERE name=?;"));
db_bind_blob(stmt, val, len);
db_bind_text(stmt, varname);
db_exec_prepared_v2(stmt);
changes = db_count_changes(stmt);
tal_free(stmt);

if (changes == 0) {
stmt = db_prepare_v2(db, SQL("INSERT INTO vars (name, blobval) VALUES (?, ?);"));
db_bind_text(stmt, varname);
db_bind_blob(stmt, val, len);
db_exec_prepared_v2(stmt);
tal_free(stmt);
}
}

const u8 *db_get_blobvar(const tal_t *ctx, struct db *db, const char *varname)
{
struct db_stmt *stmt = db_prepare_v2(
db, SQL("SELECT blobval FROM vars WHERE name=? LIMIT 1"));
db_bind_text(stmt, varname);

const u8 *res = NULL;
if (db_query_prepared_canfail(stmt) && db_step(stmt))
res = db_col_arr(ctx, stmt, "blobval", u8);

tal_free(stmt);
return res;
}

/* Leak tracking. */

/* By making the update conditional on the current value we expect we
Expand Down
5 changes: 5 additions & 0 deletions db/exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <ccan/short_types/short_types.h>
#include <ccan/take/take.h>
#include <ccan/tal/tal.h>

struct db;

Expand All @@ -23,6 +24,10 @@ void db_set_intvar(struct db *db, const char *varname, s64 val);
*/
s64 db_get_intvar(struct db *db, const char *varname, s64 defval);

void db_set_blobvar(struct db *db, const char *varname, const u8 *val, size_t len);
/* Returns a tal-allocated blob, or NULL if not found. */
const u8 *db_get_blobvar(const tal_t *ctx, struct db *db, const char *varname);

/* Get the current data version (entries). */
u32 db_data_version_get(struct db *db);

Expand Down
1 change: 1 addition & 0 deletions lightningd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ LIGHTNINGD_SRC := \
lightningd/anchorspend.c \
lightningd/bitcoind.c \
lightningd/chaintopology.c \
lightningd/watchman.c \
lightningd/channel.c \
lightningd/channel_control.c \
lightningd/channel_gossip.c \
Expand Down
5 changes: 5 additions & 0 deletions lightningd/lightningd.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include <lightningd/plugin_hook.h>
#include <lightningd/runes.h>
#include <lightningd/subd.h>
#include <lightningd/watchman.h>
#include <sys/resource.h>
#include <wallet/invoices.h>
#include <wally_bip32.h>
Expand Down Expand Up @@ -1347,6 +1348,10 @@ int main(int argc, char *argv[])
setup_topology(ld->topology);
trace_span_end(ld->topology);

/*~ Stand up the watchman: it queues bwatch RPC requests until the
* bwatch plugin reports ready, then replays them. */
ld->watchman = watchman_new(ld, ld);

db_begin_transaction(ld->wallet->db);
trace_span_start("delete_old_htlcs", ld->wallet);
wallet_delete_old_htlcs(ld->wallet);
Expand Down
2 changes: 2 additions & 0 deletions lightningd/lightningd.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <wallet/wallet.h>

struct amount_msat;
struct watchman;

/* Various adjustable things. */
struct config {
Expand Down Expand Up @@ -244,6 +245,7 @@ struct lightningd {
/* Derive all our BIP86 keys from here */
struct ext_key *bip86_base;
struct wallet *wallet;
struct watchman *watchman;

/* Outstanding waitsendpay commands. */
struct list_head waitsendpay_commands;
Expand Down
2 changes: 2 additions & 0 deletions lightningd/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <lightningd/plugin_control.h>
#include <lightningd/plugin_hook.h>
#include <lightningd/subd.h>
#include <lightningd/watchman.h>

/* Only this file can include this generated header! */
# include <plugins/list_of_builtin_plugins_gen.h>
Expand Down Expand Up @@ -2087,6 +2088,7 @@ static void plugin_config_cb(const char *buffer,
}
if (tal_count(plugin->custom_msgs))
tell_connectd_custommsgs(plugin->plugins);
watchman_notify_plugin_ready(plugin->plugins->ld, plugin);
notify_plugin_started(plugin->plugins->ld, plugin);
check_plugins_initted(plugin->plugins);
}
Expand Down
3 changes: 3 additions & 0 deletions lightningd/test/run-find_my_abspath.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ struct wallet *wallet_new(struct lightningd *ld UNNEEDED, struct timers *timers
/* Generated stub for wallet_sanity_check */
bool wallet_sanity_check(struct wallet *w UNNEEDED)
{ fprintf(stderr, "wallet_sanity_check called!\n"); abort(); }
/* Generated stub for watchman_new */
struct watchman *watchman_new(const tal_t *ctx UNNEEDED, struct lightningd *ld UNNEEDED)
{ fprintf(stderr, "watchman_new called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */

struct logger *crashlog;
Expand Down
6 changes: 0 additions & 6 deletions lightningd/test/run-invoice-select-inchan.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,6 @@ bool command_deprecated_in_ok(struct command *cmd UNNEEDED,
const char *depr_start UNNEEDED,
const char *depr_end UNNEEDED)
{ fprintf(stderr, "command_deprecated_in_ok called!\n"); abort(); }
/* Generated stub for command_deprecated_out_ok */
bool command_deprecated_out_ok(struct command *cmd UNNEEDED,
const char *fieldname UNNEEDED,
const char *depr_start UNNEEDED,
const char *depr_end UNNEEDED)
{ fprintf(stderr, "command_deprecated_out_ok called!\n"); abort(); }
/* Generated stub for command_dev_apis */
bool command_dev_apis(const struct command *cmd UNNEEDED)
{ fprintf(stderr, "command_dev_apis called!\n"); abort(); }
Expand Down
Loading
Loading