Browse Source

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>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
36316957e3
  1. 2
      lightningd/lightningd.c
  2. 3
      lightningd/test/run-find_my_path.c
  3. 2
      wallet/test/run-wallet.c
  4. 8
      wallet/wallet.c
  5. 4
      wallet/wallet.h

2
lightningd/lightningd.c

@ -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;

3
lightningd/test/run-find_my_path.c

@ -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,

2
wallet/test/run-wallet.c

@ -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);

8
wallet/wallet.c

@ -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);

4
wallet/wallet.h

@ -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.

Loading…
Cancel
Save