Skip to content

Commit 351b899

Browse files
committed
ld: Add an outgoing_txs_map htable to avoid costly lookups
We were using a quadratic lookup to locate the transactions we broadcast, so let's use an `htable` instead, allowing for constant lookups during block processing.
1 parent c7ff3c4 commit 351b899

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lightningd/chaintopology.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ static inline bool block_eq(const struct block *b, const struct bitcoin_blkid *k
6666
}
6767
HTABLE_DEFINE_TYPE(struct block, keyof_block_map, hash_sha, block_eq, block_map);
6868

69+
/* Hash blocks by sha */
70+
static inline const struct bitcoin_txid *keyof_outgoing_tx_map(const struct outgoing_tx *t)
71+
{
72+
return &t->txid;
73+
}
74+
75+
static inline size_t outgoing_tx_hash_sha(const struct bitcoin_txid *key)
76+
{
77+
size_t ret;
78+
memcpy(&ret, key, sizeof(ret));
79+
return ret;
80+
}
81+
82+
static inline bool outgoing_tx_eq(const struct outgoing_tx *b, const struct bitcoin_txid *key)
83+
{
84+
return bitcoin_txid_eq(&b->txid, key);
85+
}
86+
HTABLE_DEFINE_TYPE(struct outgoing_tx, keyof_outgoing_tx_map,
87+
outgoing_tx_hash_sha, outgoing_tx_eq, outgoing_tx_map);
88+
6989
struct chain_topology {
7090
struct lightningd *ld;
7191
struct block *root;

0 commit comments

Comments
 (0)