Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests] Be more strict checking dust #6822

Merged
merged 3 commits into from
Nov 10, 2015

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Oct 13, 2015

The dust test case is too fuzzy. This PR makes transaction_tests more strict when checking dust.

@paveljanik
Copy link
Contributor

init.h: not worth to change IMO

transaction.h: NACK, the comment on spendable output is important there.

transactions_tests: ACK - I like such changes :-)

@maflcko
Copy link
Member Author

maflcko commented Oct 13, 2015

@paveljanik transaction.h: NACK, the comment on spendable output is important there.

Spendable is mentioned in L144 as well but I am happy to revert that if others agree. (Personally, I don't like magic numbers in comments)

@paveljanik
Copy link
Contributor

Don't get me wrong: the comment has to be changed. Maybe change the magic numbers to some math formula there? Something like:

// So dust is a spendable txout less than 3*(34+148)*(minRelayTxFee/1000) satoshis

@maflcko maflcko force-pushed the MarcoFalke-2015-minRelayTxFeeCleanup branch 2 times, most recently from 54d6df9 to 6351b1e Compare October 13, 2015 19:37
@maflcko maflcko changed the title [trivial] minrelaytxfee cleanup [tests] Be more strict checking dust Oct 13, 2015
@maflcko
Copy link
Member Author

maflcko commented Oct 13, 2015

Addressed comment NACK by @paveljanik

@paveljanik
Copy link
Contributor

Can you also change 2730 (ie. magic number :-) into the above mentioned math. formula?

@maflcko maflcko force-pushed the MarcoFalke-2015-minRelayTxFeeCleanup branch 3 times, most recently from f05296f to 03a7a44 Compare October 13, 2015 20:11
@sipa
Copy link
Member

sipa commented Oct 14, 2015

utACK

@TheBlueMatt
Copy link
Contributor

Is it just me or does this gratuitously conflict with another outstanding PR? When proposing a PR that isnt designed to replace another, but will make it fail CI (or otherwise not merge cleanly), can you either rebase your work on the other, or, at a minimum, mention it on the PR that it effects?

@sipa
Copy link
Member

sipa commented Oct 14, 2015 via email

@maflcko
Copy link
Member Author

maflcko commented Oct 14, 2015

@paveljanik 8d02c78 is for you but imo the tests should not replace or duplicate the documentation of the source code.

@TheBlueMatt No worries, I have this already in mind and request a rebase on your PR once this is merged.

@TheBlueMatt
Copy link
Contributor

@sipa I only bring it up because it was mentioned in the opening commit, only to not be tagged or worked around. I almost missed this.

@maflcko
Copy link
Member Author

maflcko commented Oct 14, 2015

@TheBlueMatt If you want me to change the default in this PR, making yours a little bit cleaner, I am happy to do so. (Given that dropping the minRelayTxFee for the master branch is uncontroversial)

@sipa
Copy link
Member

sipa commented Oct 14, 2015 via email

@TheBlueMatt
Copy link
Contributor

Naa, I can do it in #6722 if this is merged first... I just wanted to make sure it was tagged so that it's visible. You could include the commit that changed the min relay fee if you prefer, but if you want to do that probably wait until mempool limiting is merged anyway.

On October 14, 2015 3:16:02 AM PDT, MarcoFalke notifications@github.com wrote:

@TheBlueMatt If you want me to change the default in this PR, making
yours a little bit cleaner, I am happy to do so. (Given that dropping
the minRelayTxFee for the master branch is uncontroversial)


Reply to this email directly or view it on GitHub:
#6822 (comment)

@paveljanik
Copy link
Contributor

@MarcoFalke I just wanted to prevent this issue (forgotten update of this test) in the future. The suggested change doesn't prevent it though.

@maflcko maflcko force-pushed the MarcoFalke-2015-minRelayTxFeeCleanup branch from 8d02c78 to 0cae2f5 Compare October 14, 2015 10:42
// so dust is a spendable txout less than 546 satoshis
// with default minRelayTxFee.
// so dust is a spendable txout less than
// 546*minRelayTxFee/1000 (in satoshis)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: 546 is only accurate for pay-to-pubkey-hash outputs.

Edit: nevermind.. I guess that's covered by "a typical spendable txout ...".

@maflcko
Copy link
Member Author

maflcko commented Oct 14, 2015

Addressed nit by @paveljanik and force pushed.

@laanwj laanwj added the Tests label Oct 26, 2015
@laanwj
Copy link
Member

laanwj commented Oct 26, 2015

I just wanted to prevent this issue (forgotten update of this test) in the future. The suggested change doesn't prevent it though.

On the other hand having to update the test with fixed values was a good reminder that changing minTxFee also changes the dust threshold. At least I hadn't realized this at first.
(I think adding a test with computed, exact threshold value is a good idea, but not entirely convinced it should replace the fixed values)

@dexX7
Copy link
Contributor

dexX7 commented Oct 26, 2015

(I think adding a test with computed, exact threshold value is a good idea, but not entirely convinced it should replace the fixed values)

There are potentially a few different things to test:

  1. the global minRelayTxFee is 1000 (or 5000)
  2. the dust threshold calculation is 3*aFeeRate.GetFee(nSize)
  3. the dust threshold calculation in IsStandardTx() is based on the minRelayTxFee

Using magic numbers to ensure the calculation with reference values results in expected values can be useful to pin down issues with the calculation, and the alternative could be to temporarily overwrite the global minRelayTxFee, and then set it back after the tests, e.g.:

CFeeRate minRelayTxFeeOriginal = minRelayTxFee;
minRelayTxFee = CFeeRate(1234);
// dust:
t.vout[0].nValue = 672 - 1;
BOOST_CHECK(!IsStandardTx(t, reason));
// not dust:
t.vout[0].nValue = 672;
BOOST_CHECK(IsStandardTx(t, reason));
minRelayTxFee = minRelayTxFeeOriginal;

In fact, and as a side note, with 1234 as minRelayTxFee, the dust threshold changed from 0.9 to 0.10 by two satoshi (from 674 to 672) due to the introduction of CFeeRate and rounding effects.

@maflcko maflcko force-pushed the MarcoFalke-2015-minRelayTxFeeCleanup branch from 0cae2f5 to 3f4b5ac Compare October 27, 2015 16:38
@maflcko
Copy link
Member Author

maflcko commented Oct 28, 2015

@dexX7 Let me know if the nits are fixed so I can squash the commit.

@@ -342,11 +342,26 @@ BOOST_AUTO_TEST_CASE(test_IsStandard)
string reason;
BOOST_CHECK(IsStandardTx(t, reason));

t.vout[0].nValue = 501; // dust
// Check dust with default relay fee:
CAmount nDustThreshold = 182 * minRelayTxFee.GetFeePerK()/1000 * 3 ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an unneeded space at the end.

Other than that, for this line you may consider using:

CAmount nDustThreshold = t.vout[0].GetDustThreshold(minRelayTxFee);

It should have a similar effect. Since hardcoded values are used (such as 546), it might be good to specify the "default relay fee" in the comment one line above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetDustThreshold is called via IsStandardTx so for the tests it's better not used here, imo. But thanks for the white space nit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Travis passes. Looks merge ready.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetDustThreshold is called via IsStandardTx so for the tests it's better not used here, imo.

Yeah, I guess it doesn't make much difference.

But thanks for the white space nit.

You're welcome! :)

@maflcko maflcko force-pushed the MarcoFalke-2015-minRelayTxFeeCleanup branch from 3f4b5ac to 7ba5a4a Compare October 28, 2015 11:09
@maflcko maflcko force-pushed the MarcoFalke-2015-minRelayTxFeeCleanup branch from 7ba5a4a to 2f9f050 Compare November 5, 2015 19:43
@maflcko
Copy link
Member Author

maflcko commented Nov 5, 2015

Rebased.
Anything holding this back?

@@ -41,6 +41,8 @@ struct CNodeStateStats;

/** Default for accepting alerts from the P2P network. */
static const bool DEFAULT_ALERTS = true;
/** Default for -minrelaytxfee, minimum relay fee for transactions */
static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you define this constant, please also use it in init.cpp, for example when printing the option help or when parsing the option.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laanwj ☑️ done.

MarcoFalke added 3 commits November 9, 2015 21:00
* Don't allow off-by-one or more
* Make clear dust is coupled with minRelayTxFee
* Check rounding for odd values
@maflcko maflcko force-pushed the MarcoFalke-2015-minRelayTxFeeCleanup branch from f526958 to e20d924 Compare November 9, 2015 20:13
@laanwj laanwj merged commit e20d924 into bitcoin:master Nov 10, 2015
laanwj added a commit that referenced this pull request Nov 10, 2015
e20d924 [trivial] init: Use defaults MIN_RELAY_TX_FEE & TRANSACTION_MAXFEE (MarcoFalke)
536766c [trivial] New DEFAULT_MIN_RELAY_TX_FEE = 1000 (MarcoFalke)
5f46a7d transaction_tests: Be more strict checking dust (MarcoFalke)
@maflcko maflcko deleted the MarcoFalke-2015-minRelayTxFeeCleanup branch November 10, 2015 16:29
zkbot added a commit to zcash/zcash that referenced this pull request Dec 18, 2019
Bitcoin 0.12 cleanup PRs 2

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#6631
- bitcoin/bitcoin#6664
  - Only the first commit (we already had the second through bitcoin/bitcoin#6825).
- bitcoin/bitcoin#6669
- bitcoin/bitcoin#6887
  - Only the non-QT parts.
- bitcoin/bitcoin#6962
- bitcoin/bitcoin#6822
  - Only first and third commits (we already had the second through an earlier PR).
- bitcoin/bitcoin#7136
  - Excludes Travis CI changes, and fixes to documents we don't have anymore.
- bitcoin/bitcoin#7084
- bitcoin/bitcoin#7509
- bitcoin/bitcoin#7617
- bitcoin/bitcoin#7726

Part of #2074.
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants