NicolasDorier
commented at 6:05 am on July 14, 2016:
contributor
It is a work in progress, I manage to remove the CBlockIndex dependency from consensus block by adding two new types: CConsensusFlags and CConsensusContextualInfo (last block, last block mtp, now, last block height). Both of them can be trivial calculated in main() with pIndex, then passed to consensus method.
The code change is minimal and easy to review.
BlockVerify/TransactionVerify will require the user to pass the CConsensusFlags as well CConsensusContextualInfo.
A GetFlags method without too much code is difficult as it relies heavily on CBlockIndex. It is also fairly easy enough to port into other languages.
As such it is considered out of scope of this PR.
Do you plan to move GetContextInfo() to libconsensus ? If not, please don’t move consensus critical code out of consensus critical functions.
NicolasDorier
commented at 11:45 am on July 14, 2016:
I noticed that the consensus code only depends on the current majorityVersion. So I’m calculating the majorityVersion outside consensus, and I make the check inside. I’ve not found a better solution for now.
in
src/main.cpp:
in
36eb1a0e77outdated
3598@@ -3583,11 +3599,11 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const CC
3599 // already does not permit it, it is impossible to trigger in the
3600 // witness tree.
3601 if (block.vtx[0].wit.vtxinwit.size() != 1 || block.vtx[0].wit.vtxinwit[0].scriptWitness.stack.size() != 1 || block.vtx[0].wit.vtxinwit[0].scriptWitness.stack[0].size() != 32) {
3602- return state.DoS(100, error("%s : invalid witness nonce size", __func__), REJECT_INVALID, "bad-witness-nonce-size", true);
3603+ return state.DoS(100, logger.error("%s : invalid witness nonce size", __func__), REJECT_INVALID, "bad-witness-nonce-size", true);
pow is already a file containing only consensus code and ready for becoming part of the consensus module/package (see makefile) except for its CBlockIndex dependency. Just call CheckProofOfWork from the other consensus code directly, it’s ok to include pow.h
NicolasDorier
commented at 2:29 pm on July 14, 2016:
@jtimon actually, it is not ok, pow is not part of consensus (some methods are linked to CBlockIndex)
NicolasDorier
commented at 10:01 am on July 15, 2016:
Ultimately I agree, however it means we need either to put CBlockIndex as part of consensuslib or making a stripped type representing it in consensuslib.
But it involves lots of refactoring that I don’t need it for my VerifyBlock / VerifyTx so I won’t do it for now. I’ll maybe include nextWorkRequired as field in CConsensusContextInfo and calculated in GetContextualInfo() though.
NicolasDorier
commented at 11:48 am on July 14, 2016:
no, where it is used, pindex points to the block. (I ran the tests after this change, worked fine)
NicolasDorier
commented at 11:44 am on July 14, 2016:
contributor
Thanks @jtimon, it is actually moving very fast now, I’ll try to consolidate with the same base a you when the dust in my code will settle. For now I’ll fix the pow you just told. How did you do for the logging ? with CValidationState I see you just remove the “error” methods ? (I really don’t like the “Logger” abstraction, but I don’t want to remove features either :()
Also I broke the consensus somewhere :p
jtimon
commented at 11:50 am on July 14, 2016:
contributor
jonasschnelli added the label
Refactoring
on Jul 14, 2016
NicolasDorier
commented at 11:56 am on July 14, 2016:
contributor
Awesome I’ll cherry pick your commit and remove my logger.
EDIT: ho I need to do it for the new methods :(
NicolasDorier
commented at 11:57 am on July 14, 2016:
contributor
the consensus break in the time-too-old rule. (block too early)
EDIT: Found the culprit, in TestValidityBlock I was not using prevIndex for calculating the context.
NicolasDorier force-pushed
on Jul 14, 2016
NicolasDorier
commented at 12:14 pm on July 14, 2016:
contributor
@jtimon if I understand well https://github.com/bitcoin/bitcoin/pull/7287/files actually I only need to remove error and pass “false” to DoS/Invalid ValidationState methods right? Since you are already printing out stuff in the caller ?
jtimon
commented at 12:59 pm on July 14, 2016:
contributor
You need to make sure you print from all callers, yes.
You replace the error(“my message”) with false, yes, but also, at the end, you add ‘’’, false, “my message”"" so that you don’t lose the longer message.
NicolasDorier force-pushed
on Jul 14, 2016
NicolasDorier force-pushed
on Jul 14, 2016
NicolasDorier force-pushed
on Jul 14, 2016
NicolasDorier force-pushed
on Jul 14, 2016
NicolasDorier force-pushed
on Jul 14, 2016
NicolasDorier force-pushed
on Jul 14, 2016
NicolasDorier
commented at 4:31 pm on July 14, 2016:
contributor
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-22 15:12 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me