bitcoin: hash_scid and hash_scidd public functions.
We reimplemented this redundantly: hash_scid was called short_channel_id_hash, so I obviously missed it. Rename, and implement hash_scidd helper too. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -17,7 +17,7 @@ static inline bool short_channel_id_eq(struct short_channel_id a,
|
||||
return a.u64 == b.u64;
|
||||
}
|
||||
|
||||
static inline size_t short_channel_id_hash(struct short_channel_id scid)
|
||||
static inline size_t hash_scid(struct short_channel_id scid)
|
||||
{
|
||||
/* scids cost money to generate, so simple hash works here */
|
||||
return (scid.u64 >> 32) ^ (scid.u64 >> 16) ^ scid.u64;
|
||||
@@ -46,6 +46,12 @@ static inline bool short_channel_id_dir_eq(const struct short_channel_id_dir *a,
|
||||
return short_channel_id_eq(a->scid, b->scid) && a->dir == b->dir;
|
||||
}
|
||||
|
||||
static inline size_t hash_scidd(const struct short_channel_id_dir *scidd)
|
||||
{
|
||||
/* Bottom bit is common, so use bit 4 for direction */
|
||||
return hash_scid(scidd->scid) | (scidd->dir << 4);
|
||||
}
|
||||
|
||||
static inline u32 short_channel_id_blocknum(struct short_channel_id scid)
|
||||
{
|
||||
return scid.u64 >> 40;
|
||||
|
||||
@@ -29,7 +29,7 @@ static bool chanidx_eq_id(const ptrint_t *pidx,
|
||||
struct short_channel_id pidxid = chanidx_id(pidx);
|
||||
return short_channel_id_eq(pidxid, scid);
|
||||
}
|
||||
HTABLE_DEFINE_NODUPS_TYPE(ptrint_t, chanidx_id, short_channel_id_hash, chanidx_eq_id,
|
||||
HTABLE_DEFINE_NODUPS_TYPE(ptrint_t, chanidx_id, hash_scid, chanidx_eq_id,
|
||||
chanidx_htable);
|
||||
|
||||
static struct node_id nodeidx_id(const ptrint_t *pidx);
|
||||
|
||||
@@ -262,7 +262,7 @@ static bool scid_to_node_id_eq_scid(const struct scid_to_node_id *scid_to_node_i
|
||||
* we use this to forward onion messages which specify the next hop by scid/dir. */
|
||||
HTABLE_DEFINE_NODUPS_TYPE(struct scid_to_node_id,
|
||||
scid_to_node_id_keyof,
|
||||
short_channel_id_hash,
|
||||
hash_scid,
|
||||
scid_to_node_id_eq_scid,
|
||||
scid_htable);
|
||||
|
||||
|
||||
@@ -891,7 +891,7 @@ static inline bool scid_to_channel_eq_scid(const struct scid_to_channel *scidcha
|
||||
/* Define channel_scid_map */
|
||||
HTABLE_DEFINE_NODUPS_TYPE(struct scid_to_channel,
|
||||
scid_to_channel_key,
|
||||
short_channel_id_hash,
|
||||
hash_scid,
|
||||
scid_to_channel_eq_scid,
|
||||
channel_scid_map);
|
||||
|
||||
|
||||
@@ -95,12 +95,4 @@ static inline struct askrene *get_askrene(struct plugin *plugin)
|
||||
{
|
||||
return plugin_get_data(plugin, struct askrene);
|
||||
}
|
||||
|
||||
/* Convenience routine for hash tables */
|
||||
static inline size_t hash_scidd(const struct short_channel_id_dir *scidd)
|
||||
{
|
||||
/* scids cost money to generate, so simple hash works here */
|
||||
return (scidd->scid.u64 >> 32) ^ (scidd->scid.u64 >> 16) ^ (scidd->scid.u64 << 1) ^ scidd->dir;
|
||||
}
|
||||
|
||||
#endif /* LIGHTNING_PLUGINS_ASKRENE_ASKRENE_H */
|
||||
|
||||
@@ -81,12 +81,6 @@ local_channel_scid(const struct local_channel *lc)
|
||||
return lc->scid;
|
||||
}
|
||||
|
||||
static size_t hash_scid(const struct short_channel_id scid)
|
||||
{
|
||||
/* scids cost money to generate, so simple hash works here */
|
||||
return (scid.u64 >> 32) ^ (scid.u64 >> 16) ^ scid.u64;
|
||||
}
|
||||
|
||||
static inline bool local_channel_eq_scid(const struct local_channel *lc,
|
||||
const struct short_channel_id scid)
|
||||
{
|
||||
|
||||
@@ -3,15 +3,6 @@
|
||||
#include <common/memleak.h>
|
||||
#include <plugins/channel_hint.h>
|
||||
|
||||
size_t channel_hint_hash(const struct short_channel_id_dir *out)
|
||||
{
|
||||
struct siphash24_ctx ctx;
|
||||
siphash24_init(&ctx, siphash_seed());
|
||||
siphash24_update(&ctx, &out->scid.u64, sizeof(u64));
|
||||
siphash24_update(&ctx, &out->dir, sizeof(int));
|
||||
return siphash24_done(&ctx);
|
||||
}
|
||||
|
||||
const struct short_channel_id_dir *channel_hint_keyof(const struct channel_hint *out)
|
||||
{
|
||||
return &out->scid;
|
||||
@@ -20,8 +11,7 @@ const struct short_channel_id_dir *channel_hint_keyof(const struct channel_hint
|
||||
bool channel_hint_eq(const struct channel_hint *a,
|
||||
const struct short_channel_id_dir *b)
|
||||
{
|
||||
return short_channel_id_eq(a->scid.scid, b->scid) &&
|
||||
a->scid.dir == b->dir;
|
||||
return short_channel_id_dir_eq(&a->scid, b);
|
||||
}
|
||||
|
||||
void channel_hint_to_json(const char *name, const struct channel_hint *hint,
|
||||
|
||||
@@ -40,15 +40,13 @@ struct channel_hint {
|
||||
struct amount_msat capacity;
|
||||
};
|
||||
|
||||
size_t channel_hint_hash(const struct short_channel_id_dir *out);
|
||||
|
||||
const struct short_channel_id_dir *channel_hint_keyof(const struct channel_hint *out);
|
||||
|
||||
bool channel_hint_eq(const struct channel_hint *a,
|
||||
const struct short_channel_id_dir *b);
|
||||
|
||||
HTABLE_DEFINE_NODUPS_TYPE(struct channel_hint, channel_hint_keyof,
|
||||
channel_hint_hash, channel_hint_eq, channel_hint_map)
|
||||
hash_scidd, channel_hint_eq, channel_hint_map)
|
||||
|
||||
/* A collection of channel_hint instances, allowing us to handle and
|
||||
* update them more easily. */
|
||||
|
||||
@@ -50,7 +50,8 @@ static inline bool chan_extra_eq_scid(const struct chan_extra *cd,
|
||||
return short_channel_id_eq(scid, cd->scid);
|
||||
}
|
||||
|
||||
HTABLE_DEFINE_NODUPS_TYPE(struct chan_extra, chan_extra_scid, short_channel_id_hash,
|
||||
HTABLE_DEFINE_NODUPS_TYPE(struct chan_extra, chan_extra_scid,
|
||||
hash_scid,
|
||||
chan_extra_eq_scid,
|
||||
chan_extra_map);
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ void disabledmap_add_channel(struct disabledmap *p,
|
||||
struct short_channel_id_dir scidd)
|
||||
{
|
||||
struct short_channel_id_dir *ptr_scidd =
|
||||
scidd_map_get(p->disabled_map, scidd);
|
||||
scidd_map_get(p->disabled_map, &scidd);
|
||||
if (ptr_scidd) {
|
||||
/* htable allows for duplicates, but we don't want duplicates.
|
||||
*/
|
||||
@@ -64,7 +64,7 @@ void disabledmap_warn_channel(struct disabledmap *p,
|
||||
struct short_channel_id_dir scidd)
|
||||
{
|
||||
struct short_channel_id_dir *ptr_scidd =
|
||||
scidd_map_get(p->warned_map, scidd);
|
||||
scidd_map_get(p->warned_map, &scidd);
|
||||
if (ptr_scidd) {
|
||||
/* htable allows for duplicates, but we don't want duplicates.
|
||||
*/
|
||||
@@ -84,7 +84,7 @@ void disabledmap_add_node(struct disabledmap *p, struct node_id node)
|
||||
bool disabledmap_channel_is_warned(struct disabledmap *p,
|
||||
struct short_channel_id_dir scidd)
|
||||
{
|
||||
return scidd_map_get(p->warned_map, scidd) != NULL;
|
||||
return scidd_map_get(p->warned_map, &scidd) != NULL;
|
||||
}
|
||||
|
||||
bitmap *tal_disabledmap_get_bitmap(const tal_t *ctx, struct disabledmap *p,
|
||||
|
||||
@@ -8,31 +8,16 @@
|
||||
#include <common/gossmap.h>
|
||||
#include <common/node_id.h>
|
||||
|
||||
static inline size_t hash_scidd(const struct short_channel_id_dir scidd)
|
||||
{
|
||||
/* scids cost money to generate, so simple hash works here. Letting same
|
||||
* scid with two directions collide. */
|
||||
return (scidd.scid.u64 >> 32) ^ (scidd.scid.u64 >> 16) ^ scidd.scid.u64;
|
||||
}
|
||||
|
||||
static inline struct short_channel_id_dir
|
||||
static inline const struct short_channel_id_dir *
|
||||
self_scidd(const struct short_channel_id_dir *self)
|
||||
{
|
||||
return *self;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
my_short_channel_id_dir_eq(const struct short_channel_id_dir *scidd_a,
|
||||
const struct short_channel_id_dir scidd_b)
|
||||
{
|
||||
return short_channel_id_eq(scidd_a->scid, scidd_b.scid) &&
|
||||
scidd_a->dir == scidd_b.dir;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* A htable for short_channel_id_dir, the structure itself is the element key.
|
||||
*/
|
||||
HTABLE_DEFINE_NODUPS_TYPE(struct short_channel_id_dir, self_scidd, hash_scidd,
|
||||
my_short_channel_id_dir_eq, scidd_map);
|
||||
short_channel_id_dir_eq, scidd_map);
|
||||
|
||||
struct disabledmap {
|
||||
/* Channels we decided to disable for various reasons. */
|
||||
|
||||
Reference in New Issue
Block a user