Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/compactproofs.cpp
// Copyright (c) 2022 The Bitcoin developers | // Copyright (c) 2022 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <avalanche/compactproofs.h> | #include <avalanche/compactproofs.h> | ||||
#include <avalanche/proofid.h> | #include <avalanche/proofid.h> | ||||
#include <crypto/siphash.h> | #include <crypto/siphash.h> | ||||
#include <radix.h> | #include <radix.h> | ||||
namespace avalanche { | namespace avalanche { | ||||
CompactProofs::CompactProofs(const RadixTree<PeerManager::ProofElement> &proofs) | CompactProofs::CompactProofs(const RadixTree<ProofTreeElement> &proofs) | ||||
: CompactProofs() { | : CompactProofs() { | ||||
proofs.forEachLeaf([&](auto pLeaf) { | proofs.forEachLeaf([&](auto pLeaf) { | ||||
shortproofids.push_back(getShortID(pLeaf->proof->getId())); | shortproofids.push_back(getShortID(pLeaf->proof->getId())); | ||||
}); | }); | ||||
} | } | ||||
uint64_t CompactProofs::getShortID(const ProofId &proofid) const { | uint64_t CompactProofs::getShortID(const ProofId &proofid) const { | ||||
static_assert(SHORTPROOFIDS_LENGTH == 6, | static_assert(SHORTPROOFIDS_LENGTH == 6, | ||||
"shortproofids calculation assumes 6-byte shortproofids"); | "shortproofids calculation assumes 6-byte shortproofids"); | ||||
return SipHashUint256(shortproofidk0, shortproofidk1, proofid) & | return SipHashUint256(shortproofidk0, shortproofidk1, proofid) & | ||||
0xffffffffffffL; | 0xffffffffffffL; | ||||
} | } | ||||
} // namespace avalanche | } // namespace avalanche |