p2p: Add helper to compute reconciliation tx short ids and a cache of short ids to wtxids

This commit is contained in:
Sergi Delgado Segura 2024-05-30 12:03:58 -04:00
parent bcdccad41b
commit d5404c2dc0

View file

@ -64,7 +64,28 @@ public:
*/
std::unordered_set<Wtxid, SaltedTxidHasher> m_local_set;
/**
* Reconciliation sketches are computed over short transaction IDs.
* This is a cache of these IDs enabling faster lookups of full wtxids,
* useful when peer will ask for missing transactions by short IDs
* at the end of a reconciliation round.
* We also use this to keep track of short ID collisions. In case of a
* collision, both transactions should be fanout.
*/
std::map<uint32_t, Wtxid> m_short_id_mapping;
TxReconciliationState(bool we_initiate, uint64_t k0, uint64_t k1) : m_we_initiate(we_initiate), m_k0(k0), m_k1(k1) {}
/**
* Reconciliation sketches are computed over short transaction IDs.
* Short IDs are salted with a link-specific constant value.
*/
uint32_t ComputeShortID(const uint256 wtxid) const
{
const uint64_t s = SipHashUint256(m_k0, m_k1, wtxid);
const uint32_t short_txid = 1 + (s & 0xFFFFFFFF);
return short_txid;
}
};
} // namespace