Skip to content

Commit

Permalink
wallet: insert address into peers table
Browse files Browse the repository at this point in the history
It looks like we were missing the address on insert into the peers table. This
will insert the address formatted by fmt_wireaddr. This happens to include the
ip and port.

This is fine, since parse_wireaddr has been updated to parse ports in ip address
strings.

Signed-off-by: William Casarin <[email protected]>
  • Loading branch information
jb55 authored and rustyrussell committed Dec 21, 2017
1 parent 3e7aabe commit d89eb32
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <ccan/tal/str/str.h>
#include <inttypes.h>
#include <lightningd/lightningd.h>
#include <common/wireaddr.h>
#include <lightningd/log.h>
#include <lightningd/peer_control.h>
#include <lightningd/peer_htlcs.h>
Expand Down Expand Up @@ -386,14 +387,25 @@ bool wallet_shachain_load(struct wallet *wallet, u64 id,
static bool wallet_peer_load(struct wallet *w, const u64 id, struct peer *peer)
{
bool ok = true;
sqlite3_stmt *stmt = db_query(__func__, w->db, "SELECT id, node_id FROM peers WHERE id=%"PRIu64";", id);
const unsigned char *addrstr;

sqlite3_stmt *stmt =
db_query(__func__, w->db,
"SELECT id, node_id, address FROM peers WHERE id=%"PRIu64";", id);

if (!stmt || sqlite3_step(stmt) != SQLITE_ROW) {
sqlite3_finalize(stmt);
return false;
}
peer->dbid = sqlite3_column_int64(stmt, 0);
ok &= sqlite3_column_pubkey(stmt, 1, &peer->id);
addrstr = sqlite3_column_text(stmt, 2);

if (addrstr)
parse_wireaddr((const char*)addrstr, &peer->addr, DEFAULT_PORT);

sqlite3_finalize(stmt);

return ok;
}

Expand Down Expand Up @@ -662,8 +674,11 @@ void wallet_channel_save(struct wallet *w, struct wallet_channel *chan){

if (p->dbid == 0) {
/* Need to store the peer first */
stmt = db_prepare(w->db, "INSERT INTO peers (node_id) VALUES (?);");
stmt = db_prepare(w->db, "INSERT INTO peers (node_id, address) VALUES (?, ?);");
sqlite3_bind_pubkey(stmt, 1, &chan->peer->id);
sqlite3_bind_text(stmt, 2,
type_to_string(tmpctx, struct wireaddr, &chan->peer->addr),
-1, SQLITE_TRANSIENT);
db_exec_prepared(w->db, stmt);
p->dbid = sqlite3_last_insert_rowid(w->db->sql);
}
Expand Down

0 comments on commit d89eb32

Please sign in to comment.