lightningd: set parent correctly for loaded peers.

The current code makes the channel the parent, which is a cycle.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-01-03 15:56:44 +10:30
committed by Christian Decker
parent a5c65e2c9b
commit 36316957e3
5 changed files with 11 additions and 8 deletions

View File

@@ -275,7 +275,7 @@ int main(int argc, char *argv[])
gossip_init(ld);
/* Load peers from database */
wallet_channels_load_active(ld->wallet, &ld->peers);
wallet_channels_load_active(ld, ld->wallet, &ld->peers);
/* TODO(cdecker) Move this into common location for initialization */
struct peer *peer;

View File

@@ -97,7 +97,8 @@ const char *version(void)
u32 wallet_channels_first_blocknum(struct wallet *w UNNEEDED)
{ fprintf(stderr, "wallet_channels_first_blocknum called!\n"); abort(); }
/* Generated stub for wallet_channels_load_active */
bool wallet_channels_load_active(struct wallet *w UNNEEDED, struct list_head *peers UNNEEDED)
bool wallet_channels_load_active(const tal_t *ctx UNNEEDED,
struct wallet *w UNNEEDED, struct list_head *peers UNNEEDED)
{ fprintf(stderr, "wallet_channels_load_active called!\n"); abort(); }
/* Generated stub for wallet_htlcs_load_for_channel */
bool wallet_htlcs_load_for_channel(struct wallet *wallet UNNEEDED,

View File

@@ -263,7 +263,7 @@ static struct wallet_channel *wallet_channel_load(struct wallet *w, const u64 id
list_head_init(&peers);
/* We expect only one peer, but reuse same code */
if (!wallet_channels_load_active(w, &peers))
if (!wallet_channels_load_active(w, w, &peers))
return NULL;
peer = list_top(&peers, struct peer, list);
CHECK(peer);

View File

@@ -441,7 +441,7 @@ bool wallet_peer_by_nodeid(struct wallet *w, const struct pubkey *nodeid,
*
* Returns true on success.
*/
static bool wallet_stmt2channel(struct wallet *w, sqlite3_stmt *stmt,
static bool wallet_stmt2channel(const tal_t *ctx, struct wallet *w, sqlite3_stmt *stmt,
struct wallet_channel *chan)
{
bool ok = true;
@@ -449,7 +449,7 @@ static bool wallet_stmt2channel(struct wallet *w, sqlite3_stmt *stmt,
u64 remote_config_id;
if (!chan->peer) {
chan->peer = talz(chan, struct peer);
chan->peer = talz(ctx, struct peer);
}
chan->id = sqlite3_column_int64(stmt, 0);
chan->peer->dbid = sqlite3_column_int64(stmt, 1);
@@ -574,7 +574,7 @@ static const char *channel_fields =
"last_sent_commit_state, last_sent_commit_id, "
"last_tx, last_sig";
bool wallet_channels_load_active(struct wallet *w, struct list_head *peers)
bool wallet_channels_load_active(const tal_t *ctx, struct wallet *w, struct list_head *peers)
{
bool ok = true;
/* Channels are active if they have reached at least the
@@ -586,7 +586,7 @@ bool wallet_channels_load_active(struct wallet *w, struct list_head *peers)
int count = 0;
while (ok && stmt && sqlite3_step(stmt) == SQLITE_ROW) {
struct wallet_channel *c = talz(w, struct wallet_channel);
ok &= wallet_stmt2channel(w, stmt, c);
ok &= wallet_stmt2channel(ctx, w, stmt, c);
list_add(peers, &c->peer->list);
/* Peer owns channel. FIXME delete from db if peer freed! */
tal_steal(c->peer, c);

View File

@@ -237,13 +237,15 @@ bool wallet_peer_by_nodeid(struct wallet *w, const struct pubkey *nodeid,
/**
* wlalet_channels_load_active -- Load persisted active channels into the peers
*
* @ctx: context to allocate peers from
* @w: wallet to load from
* @peers: list_head to load channels/peers into
*
* Be sure to call this only once on startup since it'll append peers
* loaded from the database to the list without checking.
*/
bool wallet_channels_load_active(struct wallet *w, struct list_head *peers);
bool wallet_channels_load_active(const tal_t *ctx,
struct wallet *w, struct list_head *peers);
/**
* wallet_channels_first_blocknum - get first block we're interested in.