mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
lease_rates: parse them out of node_announcements
When we get a node announcement out, we can now pull out its offer characteristic
This commit is contained in:
parent
5b3c02f401
commit
49bae2a873
@ -26,7 +26,8 @@
|
||||
* between the dummy creation and the call with a signature. */
|
||||
static u8 *create_node_announcement(const tal_t *ctx, struct daemon *daemon,
|
||||
const secp256k1_ecdsa_signature *sig,
|
||||
u32 timestamp)
|
||||
u32 timestamp,
|
||||
const struct lease_rates *rates)
|
||||
{
|
||||
u8 *addresses = tal_arr(tmpctx, u8, 0);
|
||||
u8 *announcement;
|
||||
@ -40,6 +41,8 @@ static u8 *create_node_announcement(const tal_t *ctx, struct daemon *daemon,
|
||||
towire_wireaddr(&addresses, &daemon->announcable[i]);
|
||||
|
||||
na_tlv = tlv_node_ann_tlvs_new(tmpctx);
|
||||
na_tlv->option_will_fund = cast_const(struct lease_rates *, rates);
|
||||
|
||||
announcement =
|
||||
towire_node_announcement(ctx, sig,
|
||||
daemon->our_features->bits
|
||||
@ -165,7 +168,10 @@ static void update_own_node_announcement(struct daemon *daemon)
|
||||
timestamp++;
|
||||
|
||||
/* Make unsigned announcement. */
|
||||
nannounce = create_node_announcement(tmpctx, daemon, NULL, timestamp);
|
||||
nannounce = create_node_announcement(tmpctx, daemon, NULL,
|
||||
timestamp,
|
||||
daemon->rates);
|
||||
|
||||
|
||||
/* If it's the same as the previous, nothing to do. */
|
||||
if (self && self->bcast.index) {
|
||||
@ -208,7 +214,8 @@ static void update_own_node_announcement(struct daemon *daemon)
|
||||
/* We got the signature for our provisional node_announcement back
|
||||
* from the HSM, create the real announcement and forward it to
|
||||
* gossipd so it can take care of forwarding it. */
|
||||
nannounce = create_node_announcement(NULL, daemon, &sig, timestamp);
|
||||
nannounce = create_node_announcement(NULL, daemon, &sig,
|
||||
timestamp, daemon->rates);
|
||||
|
||||
/* This injects it into the routing code in routing.c; it should not
|
||||
* reject it! */
|
||||
|
@ -157,7 +157,8 @@ static bool get_node_announcement(const tal_t *ctx,
|
||||
u8 rgb_color[3],
|
||||
u8 alias[32],
|
||||
u8 **features,
|
||||
struct wireaddr **wireaddrs)
|
||||
struct wireaddr **wireaddrs,
|
||||
struct lease_rates **rates)
|
||||
{
|
||||
const u8 *msg;
|
||||
struct node_id id;
|
||||
@ -197,6 +198,8 @@ static bool get_node_announcement(const tal_t *ctx,
|
||||
}
|
||||
|
||||
*wireaddrs = fromwire_wireaddr_array(ctx, addresses);
|
||||
*rates = tal_steal(ctx, na_tlvs->option_will_fund);
|
||||
|
||||
tal_free(addresses);
|
||||
return true;
|
||||
}
|
||||
@ -208,14 +211,15 @@ static bool get_node_announcement_by_id(const tal_t *ctx,
|
||||
u8 rgb_color[3],
|
||||
u8 alias[32],
|
||||
u8 **features,
|
||||
struct wireaddr **wireaddrs)
|
||||
struct wireaddr **wireaddrs,
|
||||
struct lease_rates **rates)
|
||||
{
|
||||
struct node *n = get_node(daemon->rstate, node_id);
|
||||
if (!n)
|
||||
return false;
|
||||
|
||||
return get_node_announcement(ctx, daemon, n, rgb_color, alias,
|
||||
features, wireaddrs);
|
||||
features, wireaddrs, rates);
|
||||
}
|
||||
|
||||
/*~Routines to handle gossip messages from peer, forwarded by subdaemons.
|
||||
@ -922,6 +926,7 @@ static struct io_plan *connectd_get_address(struct io_conn *conn,
|
||||
u8 alias[32];
|
||||
u8 *features;
|
||||
struct wireaddr *addrs;
|
||||
struct lease_rates *rates;
|
||||
|
||||
if (!fromwire_gossipd_get_addrs(msg, &id)) {
|
||||
status_broken("Bad gossipd_get_addrs msg from connectd: %s",
|
||||
@ -930,7 +935,8 @@ static struct io_plan *connectd_get_address(struct io_conn *conn,
|
||||
}
|
||||
|
||||
if (!get_node_announcement_by_id(tmpctx, daemon, &id,
|
||||
rgb_color, alias, &features, &addrs))
|
||||
rgb_color, alias, &features, &addrs,
|
||||
&rates))
|
||||
addrs = NULL;
|
||||
|
||||
daemon_conn_send(daemon->connectd,
|
||||
@ -1552,6 +1558,7 @@ int main(int argc, char *argv[])
|
||||
daemon->deferred_txouts = tal_arr(daemon, struct short_channel_id, 0);
|
||||
daemon->node_announce_timer = NULL;
|
||||
daemon->current_blockheight = 0; /* i.e. unknown */
|
||||
daemon->rates = NULL;
|
||||
|
||||
/* Tell the ecdh() function how to talk to hsmd */
|
||||
ecdh_hsmd_setup(HSM_FD, status_failed);
|
||||
|
@ -17,6 +17,7 @@
|
||||
struct chan;
|
||||
struct channel_update_timestamps;
|
||||
struct broadcastable;
|
||||
struct lease_rates;
|
||||
struct seeker;
|
||||
|
||||
/*~ The core daemon structure: */
|
||||
@ -60,6 +61,9 @@ struct daemon {
|
||||
|
||||
/* Features lightningd told us to set. */
|
||||
struct feature_set *our_features;
|
||||
|
||||
/* The channel lease rates we're advertising */
|
||||
const struct lease_rates *rates;
|
||||
};
|
||||
|
||||
struct range_query_reply {
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <common/bolt11.h>
|
||||
#include <common/wireaddr.h>
|
||||
#include <lightningd/gossip_msg.h>
|
||||
#include <wire/peer_wire.h>
|
||||
#include <wire/wire.h>
|
||||
|
||||
struct gossip_getnodes_entry *fromwire_gossip_getnodes_entry(const tal_t *ctx,
|
||||
@ -10,6 +11,7 @@ struct gossip_getnodes_entry *fromwire_gossip_getnodes_entry(const tal_t *ctx,
|
||||
u8 numaddresses, i;
|
||||
struct gossip_getnodes_entry *entry;
|
||||
u16 flen;
|
||||
bool has_rates;
|
||||
|
||||
entry = tal(ctx, struct gossip_getnodes_entry);
|
||||
fromwire_node_id(pptr, max, &entry->nodeid);
|
||||
@ -34,6 +36,13 @@ struct gossip_getnodes_entry *fromwire_gossip_getnodes_entry(const tal_t *ctx,
|
||||
fromwire(pptr, max, entry->alias, ARRAY_SIZE(entry->alias));
|
||||
fromwire(pptr, max, entry->color, ARRAY_SIZE(entry->color));
|
||||
|
||||
has_rates = fromwire_u8(pptr, max);
|
||||
if (has_rates) {
|
||||
entry->rates = tal(entry, struct lease_rates);
|
||||
fromwire_lease_rates(pptr, max, entry->rates);
|
||||
} else
|
||||
entry->rates = NULL;
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
@ -54,6 +63,12 @@ void towire_gossip_getnodes_entry(u8 **pptr,
|
||||
}
|
||||
towire(pptr, entry->alias, ARRAY_SIZE(entry->alias));
|
||||
towire(pptr, entry->color, ARRAY_SIZE(entry->color));
|
||||
|
||||
if (entry->rates) {
|
||||
towire_u8(pptr, 1);
|
||||
towire_lease_rates(pptr, entry->rates);
|
||||
} else
|
||||
towire_u8(pptr, 0);
|
||||
}
|
||||
|
||||
struct route_hop *fromwire_route_hop(const tal_t *ctx,
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <gossipd/routing.h>
|
||||
|
||||
struct route_info;
|
||||
struct lease_rates;
|
||||
|
||||
struct gossip_getnodes_entry {
|
||||
struct node_id nodeid;
|
||||
@ -13,6 +14,7 @@ struct gossip_getnodes_entry {
|
||||
struct wireaddr *addresses;
|
||||
u8 alias[32];
|
||||
u8 color[3];
|
||||
struct lease_rates *rates;
|
||||
};
|
||||
|
||||
struct gossip_halfchannel_entry {
|
||||
|
Loading…
Reference in New Issue
Block a user