mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 15:04:44 +01:00
fees: make the class FeeFilterRounder thread-safe
So that its methods can be called concurrently by different threads on the same object. Currently it has just one method (`round()`). Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
This commit is contained in:
parent
2074d7df20
commit
e7a5bf6be7
2 changed files with 7 additions and 4 deletions
|
@ -1010,8 +1010,10 @@ FeeFilterRounder::FeeFilterRounder(const CFeeRate& minIncrementalFee)
|
|||
CAmount FeeFilterRounder::round(CAmount currentMinFee)
|
||||
{
|
||||
std::set<double>::iterator it = feeset.lower_bound(currentMinFee);
|
||||
if ((it != feeset.begin() && insecure_rand.rand32() % 3 != 0) || it == feeset.end()) {
|
||||
it--;
|
||||
if (it == feeset.end() ||
|
||||
(it != feeset.begin() &&
|
||||
WITH_LOCK(m_insecure_rand_mutex, return insecure_rand.rand32()) % 3 != 0)) {
|
||||
--it;
|
||||
}
|
||||
return static_cast<CAmount>(*it);
|
||||
}
|
||||
|
|
|
@ -299,12 +299,13 @@ public:
|
|||
/** Create new FeeFilterRounder */
|
||||
explicit FeeFilterRounder(const CFeeRate& minIncrementalFee);
|
||||
|
||||
/** Quantize a minimum fee for privacy purpose before broadcast. Not thread-safe due to use of FastRandomContext */
|
||||
/** Quantize a minimum fee for privacy purpose before broadcast. */
|
||||
CAmount round(CAmount currentMinFee);
|
||||
|
||||
private:
|
||||
std::set<double> feeset;
|
||||
FastRandomContext insecure_rand;
|
||||
Mutex m_insecure_rand_mutex;
|
||||
FastRandomContext insecure_rand GUARDED_BY(m_insecure_rand_mutex);
|
||||
};
|
||||
|
||||
#endif // BITCOIN_POLICY_FEES_H
|
||||
|
|
Loading…
Add table
Reference in a new issue