Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define LN2SQUARED 0.4804530139182014246671025263266649717305529515945455
- const uint8_t IBLT_CELL_MINIMUM = 2;
- const uint16_t APPROX_ITEMS_THRESH = 600;
- const uint16_t APPROX_ITEMS_THRESH_REDUCE_CHECK = 500;
- const uint8_t APPROX_EXCESS_RATE = 4;
- const float IBLT_DEFAULT_OVERHEAD = 1.5;
- const uint8_t FILTER_CELL_SIZE = 1;
- const uint8_t IBLT_FIXED_CELL_SIZE = 13;
- // Infer various receiver quantities
- uint64_t nReceiverExcessItems =
- std::max((int)(nReceiverUniverseItems - nItems), (int)(nSenderUniverseItems - nItems));
- nReceiverExcessItems = std::max(0, (int)nReceiverExcessItems); // must be non-negative
- nReceiverExcessItems =
- std::min((int)nReceiverUniverseItems, (int)nReceiverExcessItems); // must not exceed total mempool size
- uint64_t nReceiverMissingItems = std::max(1, (int)(nItems - (nReceiverUniverseItems - nReceiverExcessItems)));
- // Optimal symmetric differences between receiver and sender IBLTs
- // This is the parameter "a" from the graphene paper
- double optSymDiff = nReceiverMissingItems;
- if (nItems <= nReceiverUniverseItems + nReceiverMissingItems)
- optSymDiff = OptimalSymDiff(nItems, nReceiverUniverseItems, nReceiverExcessItems, nReceiverMissingItems);
- // Set false positive rate for Bloom filter based on optSymDiff
- double fpr = BloomFalsePositiveRate(optSymDiff, nReceiverExcessItems);
- // So far we have only made room for false positives in the IBLT
- // Make more room for missing items
- optSymDiff += nReceiverMissingItems;
- uint64_t nIbltCells = std::max((int)IBLT_CELL_MINIMUM, (int)ceil(optSymDiff));
- double CGrapheneSet::OptimalSymDiff(uint64_t nBlockTxs,
- uint64_t nReceiverPoolTx,
- uint64_t nReceiverExcessTxs,
- uint64_t nReceiverMissingTxs)
- {
- uint16_t approx_items_thresh = version >= 4 ? APPROX_ITEMS_THRESH_REDUCE_CHECK : APPROX_ITEMS_THRESH;
- double optSymDiff;
- if (nBlockTxs >= approx_items_thresh && nReceiverExcessTxs >= nBlockTxs / APPROX_EXCESS_RATE)
- optSymDiff = ApproxOptimalSymDiff(nBlockTxs);
- else
- optSymDiff = BruteForceSymDiff(nBlockTxs, nReceiverPoolTx, nReceiverExcessTxs, nReceiverMissingTxs, MAX_CHECKSUM_BITS);
- return optSymDiff
- }
- double CGrapheneSet::ApproxOptimalSymDiff(uint64_t nBlockTxs)
- {
- uint32_t nChecksumBits = 32;
- if (version >= 4)
- assert(nBlockTxs >= APPROX_ITEMS_THRESH_REDUCE_CHECK);
- else
- assert(nBlockTxs >= APPROX_ITEMS_THRESH);
- return std::max(1.0, std::round(FILTER_CELL_SIZE * nBlockTxs /
- ((nChecksumBits + 8 * IBLT_FIXED_CELL_SIZE) * IBLT_DEFAULT_OVERHEAD * LN2SQUARED)));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement