mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
lightningd: add find_channel_by_scid
More efficient to search a known peer than the whole set. Also, move find_channel_by_id() from channel_control.c into channel.c where we'd expect it. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
cb5dc48cab
commit
ba1242af3e
@ -678,6 +678,29 @@ struct channel *channel_by_cid(struct lightningd *ld,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct channel *find_channel_by_id(const struct peer *peer,
|
||||
const struct channel_id *cid)
|
||||
{
|
||||
struct channel *c;
|
||||
|
||||
list_for_each(&peer->channels, c, list) {
|
||||
if (channel_id_eq(&c->cid, cid))
|
||||
return c;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct channel *find_channel_by_scid(const struct peer *peer,
|
||||
const struct short_channel_id *scid)
|
||||
{
|
||||
struct channel *c;
|
||||
|
||||
list_for_each(&peer->channels, c, list) {
|
||||
if (c->scid && short_channel_id_eq(c->scid, scid))
|
||||
return c;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void channel_set_last_tx(struct channel *channel,
|
||||
struct bitcoin_tx *tx,
|
||||
|
@ -418,6 +418,10 @@ struct channel *channel_by_cid(struct lightningd *ld,
|
||||
struct channel *find_channel_by_id(const struct peer *peer,
|
||||
const struct channel_id *cid);
|
||||
|
||||
/* Find this channel within peer */
|
||||
struct channel *find_channel_by_scid(const struct peer *peer,
|
||||
const struct short_channel_id *scid);
|
||||
|
||||
void channel_set_last_tx(struct channel *channel,
|
||||
struct bitcoin_tx *tx,
|
||||
const struct bitcoin_signature *sig,
|
||||
|
@ -907,18 +907,6 @@ void channel_notify_new_block(struct lightningd *ld,
|
||||
tal_free(to_forget);
|
||||
}
|
||||
|
||||
struct channel *find_channel_by_id(const struct peer *peer,
|
||||
const struct channel_id *cid)
|
||||
{
|
||||
struct channel *c;
|
||||
|
||||
list_for_each(&peer->channels, c, list) {
|
||||
if (channel_id_eq(&c->cid, cid))
|
||||
return c;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Since this could vanish while we're checking with bitcoind, we need to save
|
||||
* the details and re-lookup.
|
||||
*
|
||||
|
@ -133,10 +133,6 @@ char *encode_scriptpubkey_to_addr(const tal_t *ctx UNNEEDED,
|
||||
/* Generated stub for fatal */
|
||||
void fatal(const char *fmt UNNEEDED, ...)
|
||||
{ fprintf(stderr, "fatal called!\n"); abort(); }
|
||||
/* Generated stub for find_channel_by_id */
|
||||
struct channel *find_channel_by_id(const struct peer *peer UNNEEDED,
|
||||
const struct channel_id *cid UNNEEDED)
|
||||
{ fprintf(stderr, "find_channel_by_id called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_channeld_dev_memleak_reply */
|
||||
bool fromwire_channeld_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_channeld_dev_memleak_reply called!\n"); abort(); }
|
||||
|
Loading…
Reference in New Issue
Block a user