nFees < 0
check would be safe since it is repeated in https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp#L1073 via https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp#L1471
But moving it up seems more DoS-safe.
I’ve done the refactor step by step to to help with review.
Policy: Refactor: inline main:GetMinRelayFee() in main:AcceptToMemoryPool() #5709
pull jtimon wants to merge 10 commits into bitcoin:master from jtimon:getminrelayfee changing 3 files +48 −68-
jtimon commented at 8:10 pm on January 25, 2015: contributormain::GetMinRelayFee() is only called from main::AcceptToMemoryPool(). By in-lining in we can make some code simplifications and test that no new money is being created before calling main::AreInputsStandard(), instead of doing it in https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp#L1032 after all those free transaction special cases. Even removing the
-
laanwj added the label Improvement on Jan 26, 2015
-
jtimon force-pushed on Feb 3, 2015
-
jtimon commented at 7:57 pm on February 3, 2015: contributorNeeded rebase
-
jtimon force-pushed on Feb 4, 2015
-
jtimon renamed this:
Change: Refactor: inline main:GetMinRelayFee() in main:AcceptToMemoryPool()
Policy: Change: Refactor: inline main:GetMinRelayFee() in main:AcceptToMemoryPool()
on Mar 25, 2015 -
jtimon commented at 7:29 pm on June 25, 2015: contributor@luke-jr you once said you would like GetMinRelayFee to become part of policy, I would prefer to destroy it (and then pick it up as part of a new CPolicy method) instead. Do you like this? By the way, in case it wasn’t clear, this is supposed to be a 1 commit PR, as said it is just separated for easier review.
-
jtimon commented at 4:27 pm on June 26, 2015: contributorI bet it will take very long until I have to rebase this because the refactored code is way too ugly for anyone to want to touch it. Hopefully by the time this gets any attention, +47 −67 while 0-functional-changes will be enough of an argument in favor of this single-commit refactor (I know, I have to s/SQUASHME:/fixup! but as said that may never happen because this may never need rebase). I would love to hear @morcos ’s opinion.
-
in src/main.cpp: in f03b16a53f outdated
973@@ -1003,6 +974,13 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa 974 view.SetBackend(dummy); 975 } 976 977+ CAmount nValueOut = tx.GetValueOut(); 978+ CAmount nFees = nValueIn-nValueOut; 979+ // Don't accept it if it can't get into a block 980+ if (nFees < 0) 981+ return state.DoS(0, error("%s: negative fees %s, %d", __func__, hash.ToString(), nFees), 982+ REJECT_INSUFFICIENTFEE, "insufficient fee");
jtimon commented at 4:33 pm on June 26, 2015:Probably “insufficient fee” should be replaced with “bad-txns-fee-negative” to better keep track of the validation duplication.jtimon renamed this:
Policy: Change: Refactor: inline main:GetMinRelayFee() in main:AcceptToMemoryPool()
Policy: Refactor: inline main:GetMinRelayFee() in main:AcceptToMemoryPool()
on Jun 26, 2015morcos commented at 5:16 pm on June 26, 2015: memberI took a first pass at reviewing this. I think if you’re going to do a refactor here, you should improve the readability of the code. Although I like this code better than the original in some ways, it feels like you over optimized it instead of clarifying it.
In any case, I don’t feel strongly, if you get some concept ACK’s, I’m happy to test it for you.
I don’t think your second commit is right though, why do you think minRelayTxFee is in MoneyRange already?
jtimon commented at 11:17 am on June 27, 2015: contributorWell, I was hoping that by doing the stuff change by change it could become obvious for reviewers that this doesn’t change anything functionally, but thanks for the testing offer (probably better to do it after some more review like you say).
I don’t think your second commit is right though, why do you think minRelayTxFee is in MoneyRange already?
You are right, I thought, ParseMoney had a moneyRange check. I should add one there or in https://github.com/bitcoin/bitcoin/blob/master/src/init.cpp#L817
The other place where minRelayTxFee is initialized is in https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp#L67
I will fix that commit.
Re optimizing: that’s just a nice side effect. The main goal is to reduce the amount of code before moving it to policy.
jtimon force-pushed on Jun 29, 2015jtimon commented at 9:03 am on June 29, 2015: contributorUpdated fixing the second commit. Also reword “SQUASHME:” with “fixup!” in the commit descriptions.Refactor: inline GetMinRelayFee() in AcceptToMemoryPool() 9287be6937fixup! Both minRelayTxFee and 0 are already guaranteed to be in MoneyRange() 8b5382fdbefixup! mempool.ApplyDeltas() already locks mempool.cs 63b4eb78e4fixup! Unify ifs 50e20124bcfixup! Rather not calculate nMinFee at all unless fLimitFree c7840a0fc5fixup! Get rid of nMinFee variable 9aa15aa8c8fixup! in fact, you want to check that new money is not being created sooner than that bcd1484fa0fixup! Micro-optimization: local bool variable to avoid doing the same check 3 times dc4b2082ddfixup! Move fValidateFee condition out 0ffc049354fixup! join 2 similar ifs 96141eb448jtimon force-pushed on Jul 6, 2015jtimon commented at 11:36 pm on July 6, 2015: contributorRebasedjtimon closed this on Jul 16, 2015
DrahtBot locked this on Sep 8, 2021Labels
Refactoring
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 12:12 UTC
More mirrored repositories can be found on mirror.b10c.me