From c7fb9baaf18307e0b1a189416f615cd3cef909b4 Mon Sep 17 00:00:00 2001 From: Jan <125610144+Jongjan88@users.noreply.github.com> Date: Sat, 24 Feb 2024 11:20:59 +0100 Subject: [PATCH 01/15] uint32_t to size_t --- src/policy/feerate.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/policy/feerate.cpp b/src/policy/feerate.cpp index ced012a8d8..224d160a0d 100644 --- a/src/policy/feerate.cpp +++ b/src/policy/feerate.cpp @@ -9,27 +9,34 @@ #include #include -CFeeRate::CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes) +CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t num_bytes) { - const int64_t nSize{num_bytes}; + assert(num_bytes <= uint64_t(std::numeric_limits::max())); + int64_t nSize = int64_t(num_bytes); - if (nSize > 0) { + if (nSize > 0){ nSatoshisPerK = nFeePaid * 1000 / nSize; - } else { + }else{ nSatoshisPerK = 0; } + } -CAmount CFeeRate::GetFee(uint32_t num_bytes) const +CAmount CFeeRate::GetFee(size_t num_bytes) const { - const int64_t nSize{num_bytes}; + assert(num_bytes <= uint64_t(std::numeric_limits::max())); + int64_t nSize = int64_t(num_bytes); CAmount nFee{static_cast(std::ceil(nSatoshisPerK * nSize / 1000.0))}; if (nFee == 0 && nSize != 0) { - if (nSatoshisPerK > 0) nFee = CAmount(1); - if (nSatoshisPerK < 0) nFee = CAmount(-1); - } + if (nSatoshisPerK > 0) { + nFee = CAmount(1); + } + if (nSatoshisPerK < 0) { + nFee = CAmount(-1); + } + } return nFee; } From 787de14a3cd6693e1d7839a2bf00e2ef21ea3767 Mon Sep 17 00:00:00 2001 From: Jan <125610144+Jongjan88@users.noreply.github.com> Date: Sat, 24 Feb 2024 11:23:54 +0100 Subject: [PATCH 02/15] uint32_t to size_t --- src/policy/feerate.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/policy/feerate.h b/src/policy/feerate.h index b2648e9f66..e4b2728793 100644 --- a/src/policy/feerate.h +++ b/src/policy/feerate.h @@ -46,16 +46,16 @@ class CFeeRate * e.g. (nFeePaid * 1e8 / 1e3) == (nFeePaid / 1e5), * where 1e5 is the ratio to convert from DGB/kvB to sat/vB. */ - CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes); + CFeeRate(const CAmount& nFeePaid, size_t num_bytes); /** * Return the fee in satoshis for the given size in bytes. * If the calculated fee would have fractional satoshis, then the returned fee will always be rounded up to the nearest satoshi. */ - CAmount GetFee(uint32_t num_bytes) const; + CAmount GetFee(size_t num_bytes) const; /** * Return the fee in satoshis for a size of 1000 bytes */ - CAmount GetFeePerK() const { return GetFee(100000); } + CAmount GetFeePerK() const { return GetFee(1000); } friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; } friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; } friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; } From 259c4a9325c4459ec23b5fe216d328fe9aa88381 Mon Sep 17 00:00:00 2001 From: Jan <125610144+Jongjan88@users.noreply.github.com> Date: Sat, 24 Feb 2024 12:00:39 +0100 Subject: [PATCH 03/15] 12024 to 8333 --- src/test/addrman_tests.cpp | 74 +++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/test/addrman_tests.cpp b/src/test/addrman_tests.cpp index 85d2b6a436..e9f0992dbc 100644 --- a/src/test/addrman_tests.cpp +++ b/src/test/addrman_tests.cpp @@ -143,15 +143,15 @@ BOOST_AUTO_TEST_CASE(addrman_simple) BOOST_CHECK_EQUAL(addr_null.ToString(), "[::]:0"); // Test: Does Addrman::Add work as expected. - CService addr1 = ResolveService("250.1.1.1", 12024); + CService addr1 = ResolveService("250.1.1.1", 8333); BOOST_CHECK(addrman.Add(CAddress(addr1, NODE_NONE), source)); BOOST_CHECK_EQUAL(addrman.size(), 1U); CAddrInfo addr_ret1 = addrman.Select(); - BOOST_CHECK_EQUAL(addr_ret1.ToString(), "250.1.1.1:12024"); + BOOST_CHECK_EQUAL(addr_ret1.ToString(), "250.1.1.1:8333"); // Test: Does IP address deduplication work correctly. // Expected dup IP should not be added. - CService addr1_dup = ResolveService("250.1.1.1", 12024); + CService addr1_dup = ResolveService("250.1.1.1", 8333); BOOST_CHECK(!addrman.Add(CAddress(addr1_dup, NODE_NONE), source)); BOOST_CHECK_EQUAL(addrman.size(), 1U); @@ -162,7 +162,7 @@ BOOST_AUTO_TEST_CASE(addrman_simple) // hash collisions may occur. But we can always be sure of at least one // success. - CService addr2 = ResolveService("250.1.1.2", 12024); + CService addr2 = ResolveService("250.1.1.2", 8333); BOOST_CHECK(addrman.Add(CAddress(addr2, NODE_NONE), source)); BOOST_CHECK(addrman.size() >= 1); @@ -174,8 +174,8 @@ BOOST_AUTO_TEST_CASE(addrman_simple) // Test: AddrMan::Add multiple addresses works as expected std::vector vAddr; - vAddr.push_back(CAddress(ResolveService("250.1.1.3", 12024), NODE_NONE)); - vAddr.push_back(CAddress(ResolveService("250.1.1.4", 12024), NODE_NONE)); + vAddr.push_back(CAddress(ResolveService("250.1.1.3", 8333), NODE_NONE)); + vAddr.push_back(CAddress(ResolveService("250.1.1.4", 8333), NODE_NONE)); BOOST_CHECK(addrman.Add(vAddr, source)); BOOST_CHECK(addrman.size() >= 1); } @@ -189,7 +189,7 @@ BOOST_AUTO_TEST_CASE(addrman_ports) BOOST_CHECK_EQUAL(addrman.size(), 0U); // Test 7; Addr with same IP but diff port does not replace existing addr. - CService addr1 = ResolveService("250.1.1.1", 12024); + CService addr1 = ResolveService("250.1.1.1", 8333); BOOST_CHECK(addrman.Add(CAddress(addr1, NODE_NONE), source)); BOOST_CHECK_EQUAL(addrman.size(), 1U); @@ -197,7 +197,7 @@ BOOST_AUTO_TEST_CASE(addrman_ports) BOOST_CHECK(!addrman.Add(CAddress(addr1_port, NODE_NONE), source)); BOOST_CHECK_EQUAL(addrman.size(), 1U); CAddrInfo addr_ret2 = addrman.Select(); - BOOST_CHECK_EQUAL(addr_ret2.ToString(), "250.1.1.1:12024"); + BOOST_CHECK_EQUAL(addr_ret2.ToString(), "250.1.1.1:8333"); // Test: Add same IP but diff port to tried table, it doesn't get added. // Perhaps this is not ideal behavior but it is the current behavior. @@ -205,7 +205,7 @@ BOOST_AUTO_TEST_CASE(addrman_ports) BOOST_CHECK_EQUAL(addrman.size(), 1U); bool newOnly = true; CAddrInfo addr_ret3 = addrman.Select(newOnly); - BOOST_CHECK_EQUAL(addr_ret3.ToString(), "250.1.1.1:12024"); + BOOST_CHECK_EQUAL(addr_ret3.ToString(), "250.1.1.1:8333"); } @@ -216,13 +216,13 @@ BOOST_AUTO_TEST_CASE(addrman_select) CNetAddr source = ResolveIP("252.2.2.2"); // Test: Select from new with 1 addr in new. - CService addr1 = ResolveService("250.1.1.1", 12024); + CService addr1 = ResolveService("250.1.1.1", 8333); BOOST_CHECK(addrman.Add(CAddress(addr1, NODE_NONE), source)); BOOST_CHECK_EQUAL(addrman.size(), 1U); bool newOnly = true; CAddrInfo addr_ret1 = addrman.Select(newOnly); - BOOST_CHECK_EQUAL(addr_ret1.ToString(), "250.1.1.1:12024"); + BOOST_CHECK_EQUAL(addr_ret1.ToString(), "250.1.1.1:8333"); // Test: move addr to tried, select from new expected nothing returned. addrman.Good(CAddress(addr1, NODE_NONE)); @@ -231,30 +231,30 @@ BOOST_AUTO_TEST_CASE(addrman_select) BOOST_CHECK_EQUAL(addr_ret2.ToString(), "[::]:0"); CAddrInfo addr_ret3 = addrman.Select(); - BOOST_CHECK_EQUAL(addr_ret3.ToString(), "250.1.1.1:12024"); + BOOST_CHECK_EQUAL(addr_ret3.ToString(), "250.1.1.1:8333"); BOOST_CHECK_EQUAL(addrman.size(), 1U); // Add three addresses to new table. - CService addr2 = ResolveService("250.3.1.1", 12024); + CService addr2 = ResolveService("250.3.1.1", 8333); CService addr3 = ResolveService("250.3.2.2", 9999); CService addr4 = ResolveService("250.3.3.3", 9999); - BOOST_CHECK(addrman.Add(CAddress(addr2, NODE_NONE), ResolveService("250.3.1.1", 12024))); - BOOST_CHECK(addrman.Add(CAddress(addr3, NODE_NONE), ResolveService("250.3.1.1", 12024))); - BOOST_CHECK(addrman.Add(CAddress(addr4, NODE_NONE), ResolveService("250.4.1.1", 12024))); + BOOST_CHECK(addrman.Add(CAddress(addr2, NODE_NONE), ResolveService("250.3.1.1", 8333))); + BOOST_CHECK(addrman.Add(CAddress(addr3, NODE_NONE), ResolveService("250.3.1.1", 8333))); + BOOST_CHECK(addrman.Add(CAddress(addr4, NODE_NONE), ResolveService("250.4.1.1", 8333))); // Add three addresses to tried table. - CService addr5 = ResolveService("250.4.4.4", 12024); + CService addr5 = ResolveService("250.4.4.4", 8333); CService addr6 = ResolveService("250.4.5.5", 7777); - CService addr7 = ResolveService("250.4.6.6", 12024); + CService addr7 = ResolveService("250.4.6.6", 8333); - BOOST_CHECK(addrman.Add(CAddress(addr5, NODE_NONE), ResolveService("250.3.1.1", 12024))); + BOOST_CHECK(addrman.Add(CAddress(addr5, NODE_NONE), ResolveService("250.3.1.1", 8333))); addrman.Good(CAddress(addr5, NODE_NONE)); - BOOST_CHECK(addrman.Add(CAddress(addr6, NODE_NONE), ResolveService("250.3.1.1", 12024))); + BOOST_CHECK(addrman.Add(CAddress(addr6, NODE_NONE), ResolveService("250.3.1.1", 8333))); addrman.Good(CAddress(addr6, NODE_NONE)); - BOOST_CHECK(addrman.Add(CAddress(addr7, NODE_NONE), ResolveService("250.1.1.3", 12024))); + BOOST_CHECK(addrman.Add(CAddress(addr7, NODE_NONE), ResolveService("250.1.1.3", 8333))); addrman.Good(CAddress(addr7, NODE_NONE)); // Test: 6 addrs + 1 addr from last test = 7. @@ -327,9 +327,9 @@ BOOST_AUTO_TEST_CASE(addrman_find) BOOST_CHECK_EQUAL(addrman.size(), 0U); - CAddress addr1 = CAddress(ResolveService("250.1.2.1", 12024), NODE_NONE); + CAddress addr1 = CAddress(ResolveService("250.1.2.1", 8333), NODE_NONE); CAddress addr2 = CAddress(ResolveService("250.1.2.1", 9999), NODE_NONE); - CAddress addr3 = CAddress(ResolveService("251.255.2.1", 12024), NODE_NONE); + CAddress addr3 = CAddress(ResolveService("251.255.2.1", 8333), NODE_NONE); CNetAddr source1 = ResolveIP("250.1.2.1"); CNetAddr source2 = ResolveIP("250.1.2.2"); @@ -341,7 +341,7 @@ BOOST_AUTO_TEST_CASE(addrman_find) // Test: ensure Find returns an IP matching what we searched on. CAddrInfo* info1 = addrman.Find(addr1); BOOST_REQUIRE(info1); - BOOST_CHECK_EQUAL(info1->ToString(), "250.1.2.1:12024"); + BOOST_CHECK_EQUAL(info1->ToString(), "250.1.2.1:8333"); // Test 18; Find does not discriminate by port number. CAddrInfo* info2 = addrman.Find(addr2); @@ -351,7 +351,7 @@ BOOST_AUTO_TEST_CASE(addrman_find) // Test: Find returns another IP matching what we searched on. CAddrInfo* info3 = addrman.Find(addr3); BOOST_REQUIRE(info3); - BOOST_CHECK_EQUAL(info3->ToString(), "251.255.2.1:12024"); + BOOST_CHECK_EQUAL(info3->ToString(), "251.255.2.1:8333"); } BOOST_AUTO_TEST_CASE(addrman_create) @@ -360,17 +360,17 @@ BOOST_AUTO_TEST_CASE(addrman_create) BOOST_CHECK_EQUAL(addrman.size(), 0U); - CAddress addr1 = CAddress(ResolveService("250.1.2.1", 12024), NODE_NONE); + CAddress addr1 = CAddress(ResolveService("250.1.2.1", 8333), NODE_NONE); CNetAddr source1 = ResolveIP("250.1.2.1"); int nId; CAddrInfo* pinfo = addrman.Create(addr1, source1, &nId); // Test: The result should be the same as the input addr. - BOOST_CHECK_EQUAL(pinfo->ToString(), "250.1.2.1:12024"); + BOOST_CHECK_EQUAL(pinfo->ToString(), "250.1.2.1:8333"); CAddrInfo* info2 = addrman.Find(addr1); - BOOST_CHECK_EQUAL(info2->ToString(), "250.1.2.1:12024"); + BOOST_CHECK_EQUAL(info2->ToString(), "250.1.2.1:8333"); } @@ -380,7 +380,7 @@ BOOST_AUTO_TEST_CASE(addrman_delete) BOOST_CHECK_EQUAL(addrman.size(), 0U); - CAddress addr1 = CAddress(ResolveService("250.1.2.1", 12024), NODE_NONE); + CAddress addr1 = CAddress(ResolveService("250.1.2.1", 8333), NODE_NONE); CNetAddr source1 = ResolveIP("250.1.2.1"); int nId; @@ -404,15 +404,15 @@ BOOST_AUTO_TEST_CASE(addrman_getaddr) std::vector vAddr1 = addrman.GetAddr(/* max_addresses */ 0, /* max_pct */ 0, /* network */ std::nullopt); BOOST_CHECK_EQUAL(vAddr1.size(), 0U); - CAddress addr1 = CAddress(ResolveService("250.250.2.1", 12024), NODE_NONE); + CAddress addr1 = CAddress(ResolveService("250.250.2.1", 8333), NODE_NONE); addr1.nTime = GetAdjustedTime(); // Set time so isTerrible = false CAddress addr2 = CAddress(ResolveService("250.251.2.2", 9999), NODE_NONE); addr2.nTime = GetAdjustedTime(); - CAddress addr3 = CAddress(ResolveService("251.252.2.3", 12024), NODE_NONE); + CAddress addr3 = CAddress(ResolveService("251.252.2.3", 8333), NODE_NONE); addr3.nTime = GetAdjustedTime(); - CAddress addr4 = CAddress(ResolveService("252.253.3.4", 12024), NODE_NONE); + CAddress addr4 = CAddress(ResolveService("252.253.3.4", 8333), NODE_NONE); addr4.nTime = GetAdjustedTime(); - CAddress addr5 = CAddress(ResolveService("252.254.4.5", 12024), NODE_NONE); + CAddress addr5 = CAddress(ResolveService("252.254.4.5", 8333), NODE_NONE); addr5.nTime = GetAdjustedTime(); CNetAddr source1 = ResolveIP("250.1.2.1"); CNetAddr source2 = ResolveIP("250.2.3.3"); @@ -461,7 +461,7 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket_legacy) { CAddrManTest addrman; - CAddress addr1 = CAddress(ResolveService("250.1.1.1", 12024), NODE_NONE); + CAddress addr1 = CAddress(ResolveService("250.1.1.1", 8333), NODE_NONE); CAddress addr2 = CAddress(ResolveService("250.1.1.1", 9999), NODE_NONE); CNetAddr source1 = ResolveIP("250.1.1.1"); @@ -516,7 +516,7 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket_legacy) { CAddrManTest addrman; - CAddress addr1 = CAddress(ResolveService("250.1.2.1", 12024), NODE_NONE); + CAddress addr1 = CAddress(ResolveService("250.1.2.1", 8333), NODE_NONE); CAddress addr2 = CAddress(ResolveService("250.1.2.1", 9999), NODE_NONE); CNetAddr source1 = ResolveIP("250.1.2.1"); @@ -594,7 +594,7 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_tried_bucket) { CAddrManTest addrman; - CAddress addr1 = CAddress(ResolveService("250.1.1.1", 12024), NODE_NONE); + CAddress addr1 = CAddress(ResolveService("250.1.1.1", 8333), NODE_NONE); CAddress addr2 = CAddress(ResolveService("250.1.1.1", 9999), NODE_NONE); CNetAddr source1 = ResolveIP("250.1.1.1"); @@ -649,7 +649,7 @@ BOOST_AUTO_TEST_CASE(caddrinfo_get_new_bucket) { CAddrManTest addrman; - CAddress addr1 = CAddress(ResolveService("250.1.2.1", 12024), NODE_NONE); + CAddress addr1 = CAddress(ResolveService("250.1.2.1", 8333), NODE_NONE); CAddress addr2 = CAddress(ResolveService("250.1.2.1", 9999), NODE_NONE); CNetAddr source1 = ResolveIP("250.1.2.1"); From 859e7ef5c8fa84ced1d1730cc9e25b0bfe730524 Mon Sep 17 00:00:00 2001 From: Jan <125610144+Jongjan88@users.noreply.github.com> Date: Sat, 24 Feb 2024 13:05:59 +0100 Subject: [PATCH 04/15] GetFeePerK form 0.01 to 0.1dgb/kb --- src/policy/feerate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/policy/feerate.h b/src/policy/feerate.h index e4b2728793..62f9f81f83 100644 --- a/src/policy/feerate.h +++ b/src/policy/feerate.h @@ -55,7 +55,7 @@ class CFeeRate /** * Return the fee in satoshis for a size of 1000 bytes */ - CAmount GetFeePerK() const { return GetFee(1000); } + CAmount GetFeePerK() const { return GetFee(1000000); } friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; } friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; } friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; } From ddd1863727978ed59dd1719acc522268f897fbce Mon Sep 17 00:00:00 2001 From: Jan <125610144+Jongjan88@users.noreply.github.com> Date: Sat, 24 Feb 2024 13:58:44 +0100 Subject: [PATCH 05/15] uint32_t to int64_t --- src/test/amount_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/amount_tests.cpp b/src/test/amount_tests.cpp index 1c2797c47f..82e8dddf6a 100644 --- a/src/test/amount_tests.cpp +++ b/src/test/amount_tests.cpp @@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE(GetFeeTest) BOOST_CHECK(CFeeRate(CAmount(26), 789) == CFeeRate(32)); BOOST_CHECK(CFeeRate(CAmount(27), 789) == CFeeRate(34)); // Maximum size in bytes, should not crash - CFeeRate(MAX_MONEY, std::numeric_limits::max()).GetFeePerK(); + CFeeRate(MAX_MONEY <= uint64_t(std::numeric_limits::max())).GetFeePerK(); } BOOST_AUTO_TEST_CASE(BinaryOperatorTest) From 169ec64e46ecc8297dbdf1575a0c194983f91cdf Mon Sep 17 00:00:00 2001 From: Jan <125610144+Jongjan88@users.noreply.github.com> Date: Sat, 24 Feb 2024 17:29:16 +0100 Subject: [PATCH 06/15] size_t to uint32_t --- src/policy/feerate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/policy/feerate.cpp b/src/policy/feerate.cpp index 224d160a0d..452e1a1210 100644 --- a/src/policy/feerate.cpp +++ b/src/policy/feerate.cpp @@ -9,7 +9,7 @@ #include #include -CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t num_bytes) +CFeeRate::CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes) { assert(num_bytes <= uint64_t(std::numeric_limits::max())); int64_t nSize = int64_t(num_bytes); @@ -22,7 +22,7 @@ CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t num_bytes) } -CAmount CFeeRate::GetFee(size_t num_bytes) const +CAmount CFeeRate::GetFee(uint32_t num_bytes) const { assert(num_bytes <= uint64_t(std::numeric_limits::max())); int64_t nSize = int64_t(num_bytes); From 10debff2e84fe82aea75d40b007c6c4f674cb5d6 Mon Sep 17 00:00:00 2001 From: Jan <125610144+Jongjan88@users.noreply.github.com> Date: Sat, 24 Feb 2024 17:30:17 +0100 Subject: [PATCH 07/15] size_t to uint32_t --- src/policy/feerate.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/policy/feerate.h b/src/policy/feerate.h index 62f9f81f83..5021084a56 100644 --- a/src/policy/feerate.h +++ b/src/policy/feerate.h @@ -46,12 +46,12 @@ class CFeeRate * e.g. (nFeePaid * 1e8 / 1e3) == (nFeePaid / 1e5), * where 1e5 is the ratio to convert from DGB/kvB to sat/vB. */ - CFeeRate(const CAmount& nFeePaid, size_t num_bytes); + CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes); /** * Return the fee in satoshis for the given size in bytes. * If the calculated fee would have fractional satoshis, then the returned fee will always be rounded up to the nearest satoshi. */ - CAmount GetFee(size_t num_bytes) const; + CAmount GetFee(uint32_t num_bytes) const; /** * Return the fee in satoshis for a size of 1000 bytes */ From 5d03d128aa6ef293cdab194576097a951fbd16c1 Mon Sep 17 00:00:00 2001 From: Jan <125610144+Jongjan88@users.noreply.github.com> Date: Sun, 25 Feb 2024 01:00:42 +0100 Subject: [PATCH 08/15] uint32_t --- src/test/amount_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/amount_tests.cpp b/src/test/amount_tests.cpp index 82e8dddf6a..9088bead59 100644 --- a/src/test/amount_tests.cpp +++ b/src/test/amount_tests.cpp @@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE(GetFeeTest) BOOST_CHECK(CFeeRate(CAmount(26), 789) == CFeeRate(32)); BOOST_CHECK(CFeeRate(CAmount(27), 789) == CFeeRate(34)); // Maximum size in bytes, should not crash - CFeeRate(MAX_MONEY <= uint64_t(std::numeric_limits::max())).GetFeePerK(); + CFeeRate(MAX_MONEY <= uint32_t(std::numeric_limits::max())).GetFeePerK(); } BOOST_AUTO_TEST_CASE(BinaryOperatorTest) From 8ff41df7dfaa15fac9b870988537917ed4a51f08 Mon Sep 17 00:00:00 2001 From: Jan <125610144+Jongjan88@users.noreply.github.com> Date: Sun, 25 Feb 2024 18:50:06 +0100 Subject: [PATCH 09/15] CFeeRate MAX_MONEY --- src/test/amount_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/amount_tests.cpp b/src/test/amount_tests.cpp index 9088bead59..1c2797c47f 100644 --- a/src/test/amount_tests.cpp +++ b/src/test/amount_tests.cpp @@ -85,7 +85,7 @@ BOOST_AUTO_TEST_CASE(GetFeeTest) BOOST_CHECK(CFeeRate(CAmount(26), 789) == CFeeRate(32)); BOOST_CHECK(CFeeRate(CAmount(27), 789) == CFeeRate(34)); // Maximum size in bytes, should not crash - CFeeRate(MAX_MONEY <= uint32_t(std::numeric_limits::max())).GetFeePerK(); + CFeeRate(MAX_MONEY, std::numeric_limits::max()).GetFeePerK(); } BOOST_AUTO_TEST_CASE(BinaryOperatorTest) From 28b4639b468aa608697fad035436c3c45b38f1c5 Mon Sep 17 00:00:00 2001 From: Jan <125610144+Jongjan88@users.noreply.github.com> Date: Sun, 25 Feb 2024 18:55:40 +0100 Subject: [PATCH 10/15] update --- src/policy/feerate.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/policy/feerate.cpp b/src/policy/feerate.cpp index 452e1a1210..6f1a9c78c9 100644 --- a/src/policy/feerate.cpp +++ b/src/policy/feerate.cpp @@ -13,31 +13,26 @@ CFeeRate::CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes) { assert(num_bytes <= uint64_t(std::numeric_limits::max())); int64_t nSize = int64_t(num_bytes); - if (nSize > 0){ nSatoshisPerK = nFeePaid * 1000 / nSize; }else{ nSatoshisPerK = 0; - } - + } } CAmount CFeeRate::GetFee(uint32_t num_bytes) const { assert(num_bytes <= uint64_t(std::numeric_limits::max())); int64_t nSize = int64_t(num_bytes); - CAmount nFee{static_cast(std::ceil(nSatoshisPerK * nSize / 1000.0))}; - if (nFee == 0 && nSize != 0) { - if (nSatoshisPerK > 0) { - nFee = CAmount(1); - } - if (nSatoshisPerK < 0) { - nFee = CAmount(-1); - } + if (nSatoshisPerK > 0) { + nFee = CAmount(1); } - + if (nSatoshisPerK < 0) { + nFee = CAmount(-1); + } + } return nFee; } From f24ae2c26d3cdfb32d9f79d7634076f4e3274bfe Mon Sep 17 00:00:00 2001 From: Jan <125610144+Jongjan88@users.noreply.github.com> Date: Sun, 25 Feb 2024 19:00:17 +0100 Subject: [PATCH 11/15] Update feerate.cpp --- src/policy/feerate.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/policy/feerate.cpp b/src/policy/feerate.cpp index 6f1a9c78c9..d6897c1f25 100644 --- a/src/policy/feerate.cpp +++ b/src/policy/feerate.cpp @@ -13,9 +13,9 @@ CFeeRate::CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes) { assert(num_bytes <= uint64_t(std::numeric_limits::max())); int64_t nSize = int64_t(num_bytes); - if (nSize > 0){ + if (nSize > 0) { nSatoshisPerK = nFeePaid * 1000 / nSize; - }else{ + } else { nSatoshisPerK = 0; } } From 02739644f0abf7747a6b96a27deba53f6c49c6d5 Mon Sep 17 00:00:00 2001 From: Jan <125610144+Jongjan88@users.noreply.github.com> Date: Sun, 25 Feb 2024 22:04:48 +0100 Subject: [PATCH 12/15] GetFeePerK return GetFee original value. --- src/policy/feerate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/policy/feerate.h b/src/policy/feerate.h index 5021084a56..2bd16ddbbf 100644 --- a/src/policy/feerate.h +++ b/src/policy/feerate.h @@ -55,7 +55,7 @@ class CFeeRate /** * Return the fee in satoshis for a size of 1000 bytes */ - CAmount GetFeePerK() const { return GetFee(1000000); } + CAmount GetFeePerK() const { return GetFee(1000); } friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; } friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; } friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; } From c84f73cda06012ab16c975601e3deae80ea8e696 Mon Sep 17 00:00:00 2001 From: Jan <125610144+Jongjan88@users.noreply.github.com> Date: Sun, 25 Feb 2024 23:31:06 +0100 Subject: [PATCH 13/15] Update feerate.h --- src/policy/feerate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/policy/feerate.h b/src/policy/feerate.h index 2bd16ddbbf..5021084a56 100644 --- a/src/policy/feerate.h +++ b/src/policy/feerate.h @@ -55,7 +55,7 @@ class CFeeRate /** * Return the fee in satoshis for a size of 1000 bytes */ - CAmount GetFeePerK() const { return GetFee(1000); } + CAmount GetFeePerK() const { return GetFee(1000000); } friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; } friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; } friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; } From bb186ef80505775eee052748c6e65378508b7b8a Mon Sep 17 00:00:00 2001 From: Jan <125610144+Jongjan88@users.noreply.github.com> Date: Tue, 27 Feb 2024 05:09:15 +0100 Subject: [PATCH 14/15] Update feerate.h --- src/policy/feerate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/policy/feerate.h b/src/policy/feerate.h index 5021084a56..b2648e9f66 100644 --- a/src/policy/feerate.h +++ b/src/policy/feerate.h @@ -55,7 +55,7 @@ class CFeeRate /** * Return the fee in satoshis for a size of 1000 bytes */ - CAmount GetFeePerK() const { return GetFee(1000000); } + CAmount GetFeePerK() const { return GetFee(100000); } friend bool operator<(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK < b.nSatoshisPerK; } friend bool operator>(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK > b.nSatoshisPerK; } friend bool operator==(const CFeeRate& a, const CFeeRate& b) { return a.nSatoshisPerK == b.nSatoshisPerK; } From 3904bf51ca248aa36965881e38cad9b285a43e1e Mon Sep 17 00:00:00 2001 From: Jan <125610144+Jongjan88@users.noreply.github.com> Date: Wed, 28 Feb 2024 15:45:05 +0100 Subject: [PATCH 15/15] Update feerate.cpp --- src/policy/feerate.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/policy/feerate.cpp b/src/policy/feerate.cpp index d6897c1f25..ced012a8d8 100644 --- a/src/policy/feerate.cpp +++ b/src/policy/feerate.cpp @@ -11,28 +11,26 @@ CFeeRate::CFeeRate(const CAmount& nFeePaid, uint32_t num_bytes) { - assert(num_bytes <= uint64_t(std::numeric_limits::max())); - int64_t nSize = int64_t(num_bytes); + const int64_t nSize{num_bytes}; + if (nSize > 0) { nSatoshisPerK = nFeePaid * 1000 / nSize; } else { nSatoshisPerK = 0; - } + } } CAmount CFeeRate::GetFee(uint32_t num_bytes) const { - assert(num_bytes <= uint64_t(std::numeric_limits::max())); - int64_t nSize = int64_t(num_bytes); + const int64_t nSize{num_bytes}; + CAmount nFee{static_cast(std::ceil(nSatoshisPerK * nSize / 1000.0))}; + if (nFee == 0 && nSize != 0) { - if (nSatoshisPerK > 0) { - nFee = CAmount(1); - } - if (nSatoshisPerK < 0) { - nFee = CAmount(-1); - } + if (nSatoshisPerK > 0) nFee = CAmount(1); + if (nSatoshisPerK < 0) nFee = CAmount(-1); } + return nFee; }