Skip to content

Conversation

@jtimon
Copy link
Contributor

@jtimon jtimon commented Jul 16, 2016

The mempool doesn't need to CheckInputs with fCheckScripts=false, it can call Consensus::CheckTxInputs() directly.
We could also remove the parameter from CheckInputs now, since all the remaining callers always pass fCheckScripts=true. But I have left for later, when/if we separate the function in two: one for libconsensus, the other for the multi-threaded validation (both called from ConnectBlock, the former also called from AcceptToMemeoryPool see jtimon@24a0999 ).

I've tried to do this several times, but usually combined with moveonly commits and more changes.
One of those times, @sipa suggested to remove the checks here instead, but I can't remember his reasoning or find a reference. I believe he changed his mind later.

Ping @NicolasDorier @kanzure

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, does CheckInputs change state in assert in the original code (i.e. is it against our Assertions should not have side-effects rule)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't know we had just a rule, is there a place where those "rules" are documented?
If we do, I suggest we change that rule to at least not apply to CValidationState.
In any case, this is not a change in this PR: there's no change in functionality here, it was doing the same before.

Copy link
Member

@maflcko maflcko Jul 17, 2016 via email

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.
So, yes, it seems these asserts were not complying with that rule. Neither before not after my change.
If there's an easy fix to add here, I'm all for it.
Should I launch an exception instead ?
It doesn't seem right the way CTxMemPool::check is written...
Maybe it's enough to rename the offending state local variables to dummyState ?

Copy link
Member

Choose a reason for hiding this comment

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

Assign the result to a local scope bool and assert the value of the bool?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, yeah, is as simple as that. Happy to code and squash that.

@NicolasDorier
Copy link
Contributor

NicolasDorier commented Jul 17, 2016

CheckTxInputs should return true; if it is a coinbase. (agree that in theory it should not happen, but I prefer that we don't change the semantic by mistake)

@jtimon
Copy link
Contributor Author

jtimon commented Jul 17, 2016

@NicolasDorier I'm doing that later in https://github.com/jtimon/bitcoin/commits/0.12.99-consensus , but since you refuse to review that branch...Little steps first, preparations, remember?

@jtimon
Copy link
Contributor Author

jtimon commented Jul 17, 2016

Updated solving @paveljanik 's nit as suggested by @MarcoFalke . Didn't squashed the commit yet though.

Copy link
Member

Choose a reason for hiding this comment

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

Would be better to move this into the smaller else {} scopes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I actually moved the state out. I thought this would be clearer. I will change it back and declare the bool twice in their smaller scopes. Reusing the bool actually takes one extra line.

@NicolasDorier
Copy link
Contributor

NicolasDorier commented Jul 17, 2016

@jtimon just saying the returns true if coinbase should be part of this commit, not later.
Anyway, not blocking for me ACK fa3e82563db63c6e601ccb440a11ad4ba66c9a5b

EDIT: oh I think you were responding to the first comment I made and deleted shortly before you replied. Don't take note to what I said before, my only complain on this commit is that CheckTxInputs should returns true if it is a coinbase.

@jtimon
Copy link
Contributor Author

jtimon commented Jul 17, 2016

I'm not sure I understand. Which return true if coinbase?

@NicolasDorier
Copy link
Contributor

CheckTxInputs should returns true if it is a coinbase.

@NicolasDorier
Copy link
Contributor

as the main::CheckInputs was doing.

Copy link
Contributor

Choose a reason for hiding this comment

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

here, either you should add

fCheckResult = Consensus::CheckTxInputs(tx, state, mempoolDuplicate, nSpendHeight) || tx.IsCoinbase;

Or better, CheckTxInputs should do it internally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, yeah again lost in re-write. it's even stated in the Preconditions of Consensus::CheckTxInputs in the doc I'm adding just now!

@jtimon jtimon force-pushed the 0.12.99-consensus-mempool-checks branch from 008114f to 00b4943 Compare July 18, 2016 14:27
@jtimon
Copy link
Contributor Author

jtimon commented Jul 18, 2016

Updated with more fixes and after squashing.

@instagibbs
Copy link
Member

utACK 00b4943

@NicolasDorier
Copy link
Contributor

utACK 00b4943

@btcdrak
Copy link
Contributor

btcdrak commented Jul 21, 2016

utACK 00b4943

Nice proof of work commit there :-p

@maflcko
Copy link
Member

maflcko commented Jul 21, 2016

utACK 00b4943c2794fecf93c21d3db814ea7b2e362087

@NicolasDorier
Copy link
Contributor

NicolasDorier commented Jul 28, 2016

I confirm this one can get merged before #8259. I'll need to backport to 0.13 #8259 which does not have this PR, but that's trivial change.

@sipa
Copy link
Member

sipa commented Jul 28, 2016

I'm not a fan of having the code in main.cpp while the header is in consensus.h. What is the plan afterwards? Will CheckTxInputs move to consesus/consensus.cpp as well? Will that mean that CCoinsViewCache (on which it depends) also moves to consensus?

@NicolasDorier
Copy link
Contributor

NicolasDorier commented Jul 28, 2016

@sipa most likely in the future for libconsensus, we'll need to make an interface and replace CCoinsViewCache dependencies by such interface. CCoinsViewCache would stay out of consensuslib.

The implementation of the interface in libconsensus will use user provided callbacks, while bitcoin core's implementation would use CCoinViewCache under the hood.

@sipa
Copy link
Member

sipa commented Jul 28, 2016

@NicolasDorier I mean in the immediate future. It's not a nice state that the definition for a function is inside a module where the code can't actually move yet.

@NicolasDorier
Copy link
Contributor

@sipa ah yes, I also think so.
I'm not against moving before, but I would prefer moving the declaration after as well.

@sipa
Copy link
Member

sipa commented Jul 28, 2016

I'd rather not move things until they can actually cleanly moved.

@jtimon
Copy link
Contributor Author

jtimon commented Jul 28, 2016

@sipa My plan was to move it later to tx_verify as shown in #8329, but there's many other options.
I'm happy moving the declaration to main.h (although I strongly believe the declaration doesn't belong there) or the definition to whatever place outside of main, even if it means moving the declaration outside of consensus/consensus.h.
Whatever looks easier to merge in the short term.

@jtimon jtimon force-pushed the 0.12.99-consensus-mempool-checks branch from 00b4943 to a6cc299 Compare July 28, 2016 22:49
@jtimon
Copy link
Contributor Author

jtimon commented Jul 28, 2016

Updated with the new declaration in main.
Please, the sooner you nick or nack-or-at-least-nack-for-this-pr nit/NACK the new doc, the better.

@NicolasDorier
Copy link
Contributor

utACK a6cc299

@sipa
Copy link
Member

sipa commented Jul 28, 2016

utACK a6cc299

@paveljanik
Copy link
Contributor

nit: commit message typo: direclty -> directly

@paveljanik
Copy link
Contributor

utACK a6cc299

@sipa sipa merged commit a6cc299 into bitcoin:master Jul 31, 2016
sipa added a commit that referenced this pull request Jul 31, 2016
…::CheckInputs

a6cc299 Mempool: Use Consensus::CheckTxInputs direclty over main::CheckInputs (Jorge Timón)
codablock pushed a commit to codablock/dash that referenced this pull request Jan 8, 2018
…er main::CheckInputs

a6cc299 Mempool: Use Consensus::CheckTxInputs direclty over main::CheckInputs (Jorge Timón)
zkbot added a commit to zcash/zcash that referenced this pull request Feb 8, 2018
Overwinter SignatureHash

Implements zcash/zips#129.

Includes code cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#7276
- bitcoin/bitcoin#7976
- bitcoin/bitcoin#8118
- bitcoin/bitcoin#8149
  - Only amount validation and SignatureHash commits.
- bitcoin/bitcoin#6915
  - Only the rework of `mempool.check()` calls that the next PR depends on.
- bitcoin/bitcoin#8346
- bitcoin/bitcoin#8524

Part of  #2254. Closes #1408 and #2584.
zkbot added a commit to zcash/zcash that referenced this pull request Feb 19, 2018
Overwinter SignatureHash

Implements zcash/zips#129.

Includes code cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#7276
- bitcoin/bitcoin#7976
- bitcoin/bitcoin#8118
- bitcoin/bitcoin#8149
  - Only amount validation and SignatureHash commits.
- bitcoin/bitcoin#6915
  - Only the rework of `mempool.check()` calls that the next PR depends on.
- bitcoin/bitcoin#8346
- bitcoin/bitcoin#8524

Part of #2074 and #2254. Closes #1408 and #2584.
zkbot added a commit to zcash/zcash that referenced this pull request Feb 20, 2018
Overwinter SignatureHash

Implements ZIP 143.

Includes code cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#7276
- bitcoin/bitcoin#7976
- bitcoin/bitcoin#8118
- bitcoin/bitcoin#8149
  - Only amount validation and SignatureHash commits.
- bitcoin/bitcoin#8346
- bitcoin/bitcoin#8524

Part of #2074 and #2254. Closes #1408 and #2584.
zkbot added a commit to zcash/zcash that referenced this pull request Feb 20, 2018
Overwinter SignatureHash

Implements ZIP 143.

Includes code cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#7276
- bitcoin/bitcoin#7976
- bitcoin/bitcoin#8118
- bitcoin/bitcoin#8149
  - Only amount validation and SignatureHash commits.
- bitcoin/bitcoin#8346
- bitcoin/bitcoin#8524

Part of #2074 and #2254. Closes #1408 and #2584.
andvgal pushed a commit to energicryptocurrency/gen2-energi that referenced this pull request Jan 6, 2019
…er main::CheckInputs

a6cc299 Mempool: Use Consensus::CheckTxInputs direclty over main::CheckInputs (Jorge Timón)
@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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants