Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Fees: Tests: Check CFeeRate internal precision in mempool_tests.cpp #7728
Conversation
jtimon
referenced this pull request
Mar 21, 2016
Closed
Travis test (not to merge): Introduce silent bug in CFeeRate #7727
MarcoFalke
and 1 other
commented on an outdated diff
Mar 21, 2016
| @@ -12,14 +12,14 @@ const std::string CURRENCY_UNIT = "BTC"; | ||
| CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nSize) | ||
| { | ||
| if (nSize > 0) | ||
| - nSatoshisPerK = nFeePaid*1000/nSize; | ||
| + nSatoshisPerK = nFeePaid * PRECISION_MULTIPLIER / nSize; |
MarcoFalke
Member
|
jtimon
referenced this pull request
Mar 21, 2016
Closed
Discussion: By "more precision", I don't mean using rational numbers in CFeeRate #7731
laanwj
added
the
Tests
label
Mar 24, 2016
|
Ping, should I remove constant PRECISION_MULTIPLIER (just use KB for now) as suggested by @MarcoFalke ? |
|
Yes, either remove |
laanwj
and 1 other
commented on an outdated diff
Mar 31, 2016
| @@ -15,6 +15,8 @@ typedef int64_t CAmount; | ||
| static const CAmount COIN = 100000000; | ||
| static const CAmount CENT = 1000000; | ||
| +static const size_t KB = 1000; | ||
| +static const size_t PRECISION_MULTIPLIER = KB; |
laanwj
Owner
|
|
Also you may add the tests to https://github.com/bitcoin/bitcoin/blob/28ad4d9fc2be102786a8c6c32ebecb466b2a03dd/src/test/amount_tests.cpp, so they are not "hidden" inside the mempool tests. |
|
@MarcoFalke Mhmm, you mean something like:
or something more dynamic? Sounds like a good idea, in principle. |
|
What I meant was to also test the |
|
Updated, hopefully solving nits. |
MarcoFalke
and 2 others
commented on an outdated diff
Mar 31, 2016
| @@ -37,6 +37,31 @@ BOOST_AUTO_TEST_CASE(GetFeeTest) | ||
| BOOST_CHECK_EQUAL(feeRate.GetFee(999), 122); | ||
| BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), 123); | ||
| BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), 1107); | ||
| + | ||
| + // With full constructor (allows to test internal precission) | ||
| + feeRate = CFeeRate(KB, KB * 2); |
jtimon
Member
|
MarcoFalke
and 1 other
commented on an outdated diff
Apr 2, 2016
| @@ -36,8 +37,10 @@ inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= | ||
| class CFeeRate | ||
| { | ||
| private: | ||
| - CAmount nSatoshisPerK; // unit is satoshis-per-1,000-bytes | ||
| + CAmount nSatoshisPerK; //! unit is satoshis-per-PRECISION_MULTIPLIER-bytes |
MarcoFalke
Member
|
|
I'm not renaming nSatoshisPerK in this PR. I said that I was happy with either renaming or removing the constant and I thought renaming was enough. Please @MarcoFalke @laanwj can you decide one or the other? I don't care enough to discuss about it, but I cannot have the constant and not have it at the same time. |
I tend to agree that renaming the Same for renaming the member variable |
|
So the simplest options are still to leave the constant a is or to also leave the constant for later (which is what @MarcoFalke prefers). My preference would be to leave it as it is, but I'm happy removing the constant for now as well. |
|
I'm fine with leaving the constant. |
|
I don't think the assert is necessary and I would prefer to just leave the the constant for later than adding it. |
|
Agree that the assert is overkill. Maybe just add a comment, but it seems there is too much discussion about this; Please fix the amount tests, so we can move forward with this. |
|
Rebased (1) after #7796. Surprisingly enough, #7796 makes the introduction of PRECISION_MULTIPLIER fail. I separated the failing change on the last commit labelled with ERROR ( 5ca2473 ) but I really don't understand what is happening here. In the same way, the fisrt commit fails without the fixup after it. |
MarcoFalke
and 1 other
commented on an outdated diff
Apr 14, 2016
| @@ -15,7 +15,7 @@ CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nBytes_) | ||
| int64_t nSize = int64_t(nBytes_); | ||
| if (nSize > 0) | ||
| - nSatoshisPerK = nFeePaid * 1000 / nSize; | ||
| + nSatoshisPerK = nFeePaid * PRECISION_MULTIPLIER / nSize; |
MarcoFalke
Member
|
|
Removed the PRECISION_MULTIPLIER=KB constant. |
MarcoFalke
commented on an outdated diff
Apr 29, 2016
| @@ -566,11 +566,19 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest) | ||
| BOOST_CHECK_EQUAL(pool.GetMinFee(pool.DynamicMemoryUsage() * 9 / 2).GetFeePerK(), (maxFeeRateRemoved.GetFeePerK() + 1000)/8); | ||
| // ... with a 1/4 halflife when mempool is < 1/4 its target size | ||
| - SetMockTime(42 + 7*CTxMemPool::ROLLING_FEE_HALFLIFE + CTxMemPool::ROLLING_FEE_HALFLIFE/2 + CTxMemPool::ROLLING_FEE_HALFLIFE/4); | ||
| + unsigned i = 5; | ||
| + while (pool.GetMinFee(1).GetFeePerK() > (int)(2 * KB)) { | ||
| + SetMockTime(42 + (++i)*CTxMemPool::ROLLING_FEE_HALFLIFE + CTxMemPool::ROLLING_FEE_HALFLIFE/2 + CTxMemPool::ROLLING_FEE_HALFLIFE/4); | ||
| + } | ||
| + // test increased stored precission in CFeeRate |
|
|
MarcoFalke
and 1 other
commented on an outdated diff
Apr 29, 2016
| @@ -566,11 +566,19 @@ BOOST_AUTO_TEST_CASE(MempoolSizeLimitTest) | ||
| BOOST_CHECK_EQUAL(pool.GetMinFee(pool.DynamicMemoryUsage() * 9 / 2).GetFeePerK(), (maxFeeRateRemoved.GetFeePerK() + 1000)/8); | ||
| // ... with a 1/4 halflife when mempool is < 1/4 its target size | ||
| - SetMockTime(42 + 7*CTxMemPool::ROLLING_FEE_HALFLIFE + CTxMemPool::ROLLING_FEE_HALFLIFE/2 + CTxMemPool::ROLLING_FEE_HALFLIFE/4); | ||
| + unsigned i = 5; | ||
| + while (pool.GetMinFee(1).GetFeePerK() > (int)(2 * KB)) { |
MarcoFalke
Member
|
jtimon
added some commits
Mar 20, 2016
|
Concept ACK (the test test exact precision, which is something that can change without problems, but the tests are marked as such). |
|
ping |
|
Sorry for letting this sit around for so long. Though, I'd prefer to have at least an utACK on the Preferably one of the authors of |
|
utACK everything except mempool_tests (but no objection to it either; sorry, I didn't understand what was going on there) |
In which case we probably shouldn't interwind mempool checks with internal precision checks of CFeeRate. |
|
To remind people, the initial PR contained ONLY the changes in mempool_tests. When/if we change internal precision, we will have to make this kind of changes to the mempool tests. Those tests are inherently intertwined with the feerate internal precission. We can wait for when/if we change the precision. Then marcoFalke asked for adding tests to amount_tests, which I did. Since then more tests have been merged into amount_tests, so maybe my additional tests are now redundant? |
|
I'm not sure we're ever going to change feerate internal precision. But yes, lets leave it until we do to change the mempool_tests. They are already annoyingly complicated enough as is (sorry), no reason to make them more convoluted; the next change should make them easier to understand. I don't object to the other changes, but I'm not sure they're worth bothering with. |
I tend to agree, as said new tests were added after I added those tests and now these seem kind of redundant (ie #7727 would now fail the tests as it should). Since people don't seem to like the changes on mempool, I'm leaning towards closing. |
|
Closing for now per above discussion. |
jtimon commentedMar 21, 2016
Although the risks are probably minimal or unexistent, #7727 shouldn't have passed travis' tests.
This adds a check that would fail with something like #7727.
I'm not saying there's a real risk in such a change passing review, but one more test shouldn't hurt.
A couple of constants are added that could be potentially useful if we ever intend to increase CFeeRate's internal precision multiplier above 1000 (aka KB), which I have no idea if it's the case right now, but I imagine could be something we want at some point in the future.