aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorluigi1111 <luigi1111w@gmail.com>2020-11-29 01:40:59 -0600
committerluigi1111 <luigi1111w@gmail.com>2020-11-29 01:40:59 -0600
commit999e797cea77c9f98fddebf8d25e3ff1b8a7d83a (patch)
treef53fafb369092c2fadbf8cba0efd00f2b8487b2c /src
parentMerge pull request #6921 (diff)
parentMake Blockchain::get_fee_quantization_mask() compile time (diff)
downloadmonero-999e797cea77c9f98fddebf8d25e3ff1b8a7d83a.tar.xz
Merge pull request #6922
a25bc71 Make Blockchain::get_fee_quantization_mask() compile time (SChernykh)
Diffstat (limited to 'src')
-rw-r--r--src/common/powerof.h26
-rw-r--r--src/cryptonote_core/blockchain.cpp13
-rw-r--r--src/cryptonote_core/blockchain.h6
3 files changed, 31 insertions, 14 deletions
diff --git a/src/common/powerof.h b/src/common/powerof.h
new file mode 100644
index 000000000..0f6c6254a
--- /dev/null
+++ b/src/common/powerof.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include <stdint.h>
+
+namespace tools
+{
+ template<uint64_t a, uint64_t b>
+ struct PowerOf
+ {
+ enum Data : uint64_t
+ {
+ // a^b = a * a^(b-1)
+ Value = a * PowerOf<a, b - 1>::Value,
+ };
+ };
+
+ template<uint64_t a>
+ struct PowerOf<a, 0>
+ {
+ enum Data : uint64_t
+ {
+ // a^0 = 1
+ Value = 1,
+ };
+ };
+}
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index f91b3d6c1..9ad9afc94 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -3629,19 +3629,6 @@ void Blockchain::check_ring_signature(const crypto::hash &tx_prefix_hash, const
}
//------------------------------------------------------------------
-uint64_t Blockchain::get_fee_quantization_mask()
-{
- static uint64_t mask = 0;
- if (mask == 0)
- {
- mask = 1;
- for (size_t n = PER_KB_FEE_QUANTIZATION_DECIMALS; n < CRYPTONOTE_DISPLAY_DECIMAL_POINT; ++n)
- mask *= 10;
- }
- return mask;
-}
-
-//------------------------------------------------------------------
uint64_t Blockchain::get_dynamic_base_fee(uint64_t block_reward, size_t median_block_weight, uint8_t version)
{
const uint64_t min_block_weight = get_min_block_weight(version);
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index a9b7ca1da..a8e251c71 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -51,6 +51,7 @@
#include "string_tools.h"
#include "rolling_median.h"
#include "cryptonote_basic/cryptonote_basic.h"
+#include "common/powerof.h"
#include "common/util.h"
#include "cryptonote_protocol/cryptonote_protocol_defs.h"
#include "rpc/core_rpc_server_commands_defs.h"
@@ -591,7 +592,10 @@ namespace cryptonote
*
* @return the fee quantized mask
*/
- static uint64_t get_fee_quantization_mask();
+ static uint64_t get_fee_quantization_mask()
+ {
+ return tools::PowerOf<10, CRYPTONOTE_DISPLAY_DECIMAL_POINT - PER_KB_FEE_QUANTIZATION_DECIMALS>::Value;
+ }
/**
* @brief get dynamic per kB or byte fee for a given block weight