Skip to content

Commit

Permalink
added interface to set fpRate (#28)
Browse files Browse the repository at this point in the history
fpRate: false positive rate for the bloomfilter
  • Loading branch information
kcw-grunt authored Mar 24, 2023
1 parent aef48df commit d09cce2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions BRPeerManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ static void _BRPeerManagerLoadBloomFilter(BRPeerManager *manager, BRPeer *peer)
BRSetApply(manager->orphans, NULL, _setApplyFreeBlock);
BRSetClear(manager->orphans); // clear out orphans that may have been received on an old filter
manager->lastOrphan = NULL;
manager->filterUpdateHeight = manager->lastBlock->height;
manager->fpRate = BLOOM_REDUCED_FALSEPOSITIVE_RATE;
manager->filterUpdateHeight = manager->lastBlock->height;

size_t addrsCount = BRWalletAllAddrs(manager->wallet, NULL, 0);
BRAddress *addrs = malloc(addrsCount*sizeof(*addrs));
Expand Down Expand Up @@ -1525,7 +1524,8 @@ static void _dummyThreadCleanup(void *info)

// returns a newly allocated BRPeerManager struct that must be freed by calling BRPeerManagerFree()
BRPeerManager *BRPeerManagerNew(const BRChainParams *params, BRWallet *wallet, uint32_t earliestKeyTime,
BRMerkleBlock *blocks[], size_t blocksCount, const BRPeer peers[], size_t peersCount)
BRMerkleBlock *blocks[], size_t blocksCount, const BRPeer peers[], size_t peersCount,
double fpRate);
{
BRPeerManager *manager = calloc(1, sizeof(*manager));
BRMerkleBlock orphan, *block = NULL;
Expand All @@ -1548,6 +1548,7 @@ BRPeerManager *BRPeerManagerNew(const BRChainParams *params, BRWallet *wallet, u
manager->blocks = BRSetNew(BRMerkleBlockHash, BRMerkleBlockEq, blocksCount);
manager->orphans = BRSetNew(_BRPrevBlockHash, _BRPrevBlockEq, blocksCount); // orphans are indexed by prevBlock
manager->checkpoints = BRSetNew(_BRBlockHeightHash, _BRBlockHeightEq, 100); // checkpoints are indexed by height
manager->fpRate = fpRate; //loading the preferred rate

for (size_t i = 0; i < manager->params->checkpointsCount; i++) {
block = BRMerkleBlockNew();
Expand Down
3 changes: 2 additions & 1 deletion BRPeerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ typedef struct BRPeerManagerStruct BRPeerManager;

// returns a newly allocated BRPeerManager struct that must be freed by calling BRPeerManagerFree()
BRPeerManager *BRPeerManagerNew(const BRChainParams *params, BRWallet *wallet, uint32_t earliestKeyTime,
BRMerkleBlock *blocks[], size_t blocksCount, const BRPeer peers[], size_t peersCount);
BRMerkleBlock *blocks[], size_t blocksCount, const BRPeer peers[], size_t peersCount,
double fpRate);

// not thread-safe, set callbacks once before calling BRPeerManagerConnect()
// info is a void pointer that will be passed along with each callback call
Expand Down

0 comments on commit d09cce2

Please sign in to comment.