Page MenuHomePhabricator

refactor: Avoid double to int cast for nCheckFrequency
ClosedPublic

Authored by PiRK on Jan 19 2022, 15:08.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABC457744047921: refactor: Avoid double to int cast for nCheckFrequency
Summary

PR description:

This PR cleans up the CTxMemPool interface by including the ratio used to determine when a mempool sanity check should run in the constructor of CTxMempool instead of using nCheckFrequency which required a cast from a double to a uint32_t. Since nCheckFrequency (now called m_check_ratio) is set in the constructor and only every read from there after, it can be turned into a const and no longer needs to be guarded by the 'cs' lock.

Since nCheckFrequency/m_check_ratio no longer needs to lock the 'cs' mutux, mutex lock line in the "CTxMempool::check" function can be moved below where the m_check_ratio variable is checked. Since the variable is 0 by default (meaning that "CTxMempool::check" will most likely not run its logic) this saves us from unnecessarily grabbing the lock.

Use a ratio instead of a frequency that requires a double to int cast for determining how often a mempool sanity check should run.

This is a backport of core#20222 [1/3]
https://github.com/bitcoin/bitcoin/pull/20222/commits/9d4b4b2c2c49774523de740d6492ee5b1ee15e74

Test Plan

ninja all check-all

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable