Skip to content

Conversation

@jtimon
Copy link
Contributor

@jtimon jtimon commented Feb 21, 2015

Introduce a Consensus::Params struct with only consensus specific params. This will be useful for more consensus refactors (see https://github.com/jtimon/bitcoin/commits/consensus_tip).
Then use it in proof of work related methods (which are part of the consensus).

@theuni
Copy link
Member

theuni commented Feb 21, 2015

Looks good, but I still don't see why fSkipProofOfWorkCheck is moved into Consensus::Params.

I've been carrying the 2nd patch in one of my refactor trees (without the change to Consensus::Params though, of course). So ACK that part for sure.

@jtimon
Copy link
Contributor Author

jtimon commented Feb 21, 2015

As discussed on IRC it is used by CUnitTestParams (which switches this param on and off during tests).
It could become a parameter of ContextualCheckBlockHeader() and CheckBlockHeader(), and all the other calls to CheckProofOfWork() can check this outside that function.
This is cleaner and it's not clear to me why fSkipProofOfWorkCheck should not be part of it.
Maybe @SergioDemianLerner who created CUnitTestParams has a stronger opinion on this.

@theuni
Copy link
Member

theuni commented Feb 22, 2015

After an IRC discussion, I drop my objection to fSkipProofOfWorkCheck in Params. It's odd, but reasonable.

Copy link
Member

Choose a reason for hiding this comment

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

I guess we can get rid of these later, by having callers use Params().GetConsensus().GetX(), rather than Params().GetX(). It's fine for now though, assuming it minimizes diffs.

@sipa
Copy link
Member

sipa commented Mar 1, 2015

utACK

@jtimon
Copy link
Contributor Author

jtimon commented Mar 2, 2015

Well, the plan is actually to have the methods that require consensus params take the struct as a parameter, getting called function(..., Params().GetConsensus()) and then inside access the fields of the struct directly, params.consensusParam.
Like in jtimon@1164199

After that is done with enough functions, all these methods can be removed from CChainParams, like in jtimon@bfda15f

@sipa
Copy link
Member

sipa commented Mar 3, 2015

@jtimon Even better; but let's do that later.

@gavinandresen
Copy link
Contributor

Looks good to me, but should be combined with simple POW unit tests to exercise/demonstrate the code.

On Mar 2, 2015, at 10:54 AM, Jorge Timón [email protected] wrote:

Well, the plan is actually to have the methods that require consensus params take the struct as a parameter, getting called function(..., Params().GetConsensus()) and then inside access the fields of the struct directly, params.consensusParam.
Like in jtimon/bitcoin@1164199

After that is done with enough functions, all these methods can be removed from CChainParams, like in jtimon/bitcoin@bfda15f


Reply to this email directly or view it on GitHub.

@jgarzik
Copy link
Contributor

jgarzik commented Mar 11, 2015

ut ACK

@jtimon
Copy link
Contributor Author

jtimon commented Mar 11, 2015

Needed rebase.
After #5871, no more doubts about fSkipProofOfWork...

@gavinandresen yes, it would be nice to have more tests for pow, incidentally I just found out that someone already started that by separating CalculateNextWorkRequired from GetNextWorkRequired and testing it (I would have preferred that GetNextWorkRequired was tested directly but better is better).
In any case that seems out of scope for this simple refactor, probably better to do it with something that changes the interface more like #5171 (if I ever reopen that) or to just do it independently.

@jtimon
Copy link
Contributor Author

jtimon commented Mar 13, 2015

Rebased after #5883 has been merged to make travis happy.

@jtimon
Copy link
Contributor Author

jtimon commented Mar 25, 2015

Needed rebase.

@theuni
Copy link
Member

theuni commented Mar 25, 2015

ACK.

@jtimon
Copy link
Contributor Author

jtimon commented Mar 25, 2015

Oops, good call. First commit edited with @gavinandresen 's suggestion to correct the documentation.

src/main.cpp Outdated
Copy link
Member

Choose a reason for hiding this comment

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

There's a duplicate include

@jtimon
Copy link
Contributor Author

jtimon commented Mar 25, 2015

Fixed include duplication reported by @laanwj

@laanwj
Copy link
Member

laanwj commented Mar 26, 2015

utACK

Copy link
Member

Choose a reason for hiding this comment

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

Kudos for passing these parameters explicitly instead of referring to global Params(), breaking the dependency on a global parameter setting will make e.g. testing easier.

@laanwj laanwj merged commit d698ef6 into bitcoin:master Mar 26, 2015
laanwj added a commit that referenced this pull request Mar 26, 2015
d698ef6 Consensus: Refactor: Decouple pow.o from chainparams.o (Jorge Timón)
bd00611 Consensus: Refactor: Introduce Consensus::Params class (Jorge Timón)
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.

6 participants