bitcoin: hoist scid hash into common code.

A second user is coming.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-07-09 18:11:44 +09:30 committed by Vincenzo Palazzo
parent fa0926148d
commit 34052f9960
2 changed files with 7 additions and 8 deletions

View file

@ -3,7 +3,6 @@
#include "config.h"
#include <ccan/compiler/compiler.h>
#include <ccan/short_types/short_types.h>
#include <ccan/structeq/structeq.h>
#include <ccan/tal/tal.h>
#include <common/gossip_constants.h>
@ -19,6 +18,12 @@ 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)
{
/* scids cost money to generate, so simple hash works here */
return (scid.u64 >> 32) ^ (scid.u64 >> 16) ^ scid.u64;
}
/* BOLT #7:
*
* - MUST set `node_id_1` and `node_id_2` to the public keys of the two nodes

View file

@ -44,19 +44,13 @@ chan_extra_scid(const struct chan_extra *cd)
return cd->scid;
}
static inline 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 chan_extra_eq_scid(const struct chan_extra *cd,
const struct short_channel_id scid)
{
return short_channel_id_eq(scid, cd->scid);
}
HTABLE_DEFINE_TYPE(struct chan_extra, chan_extra_scid, hash_scid,
HTABLE_DEFINE_TYPE(struct chan_extra, chan_extra_scid, short_channel_id_hash,
chan_extra_eq_scid, chan_extra_map);
/* Helpers for chan_extra_map */