From 34052f996021e9c5848205c2f9694026f0fd43cd Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 9 Jul 2024 18:11:44 +0930 Subject: [PATCH] bitcoin: hoist scid hash into common code. A second user is coming. Signed-off-by: Rusty Russell --- bitcoin/short_channel_id.h | 7 ++++++- plugins/renepay/chan_extra.h | 8 +------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/bitcoin/short_channel_id.h b/bitcoin/short_channel_id.h index 46133e0d9..8dd2dacb5 100644 --- a/bitcoin/short_channel_id.h +++ b/bitcoin/short_channel_id.h @@ -3,7 +3,6 @@ #include "config.h" #include #include -#include #include #include @@ -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 diff --git a/plugins/renepay/chan_extra.h b/plugins/renepay/chan_extra.h index 478e5904f..7a3982358 100644 --- a/plugins/renepay/chan_extra.h +++ b/plugins/renepay/chan_extra.h @@ -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 */