diff --git a/src/node/txreconciliation.cpp b/src/node/txreconciliation.cpp index 1f99adc04b6..921687f253c 100644 --- a/src/node/txreconciliation.cpp +++ b/src/node/txreconciliation.cpp @@ -64,7 +64,28 @@ public: */ std::unordered_set 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 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