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

Add commandline flag to set genesis block script destination #55

Merged
merged 4 commits into from
Nov 22, 2015

Conversation

apoelstra
Copy link
Member

Fixes #54

@jtimon
Copy link
Contributor

jtimon commented Sep 30, 2015

Why not call ScriptDestinationFromCommandLine etc directly in CRegTestParams instead of in SelectParamsFromCommandLine() ?
Or maybe CRegTestParams's constructor could take a CScript parameter that defaults to OP_TRUE.
Certainly ChangeGenesisScriptDestination doesn't need to be a public method, all this can be a just a static function in chainparams.cpp
In fact, this PR is buggy since ChangeGenesisScriptDestination doesn't update hashGenesisBlock nor mapCheckpointsTestnet[0].

@apoelstra
Copy link
Member Author

@jtimon For "why did I structure the functions this way" I was trying to copy as best I could what is done for the -testnet/-regtest parameters. As for giving a parameter to the CRegTestParams that's tricky because the regtest paramaters are a static variable, and IIRC in C++ we have no control over what order constructors for static variables are run in.

As for the bugs, you're right, thanks.

@jtimon
Copy link
Contributor

jtimon commented Sep 30, 2015

re CRegTestParams::CRegTestParams() parameter: I was assuming some of bitcoin/bitcoin#6382 had already been merged, but some of those changes were rejected for alpha so never mind.

Anyway, the solution is still simple: just put all the new code inside CRegTestParams::CRegTestParams(), before the hash of the genesis block is calculated.

See bitcoin/bitcoin#6382 which also builds the genesis block dynamically from a command line parameter for the sizetest std::numeric_limits<uint64_t>::max() different chains.

@@ -249,7 +249,7 @@ class CRegTestParams : public CTestNetParams {
txNew.vout[1].scriptPubKey = CScript() << OP_TRUE;
genesis.vtx[0] = CTransaction(txNew);

CScript scriptDestination(CScript() << OP_TRUE);
CScript scriptDestination(CScript() << OP_2 << ParseHex("023303dedc51b9d227b17c9fb4710f96b844e1ccdc2c776e1b7274bd4e246b6202") << ParseHex("03024c3b4f830854d6d26d6e34d92aff4c703bf57e85cd42abe328d928e01d4286") << ParseHex("03fe4e8c8d99b9dcbb529a87d54f606bae0149a34018325547fa0c2239e038a1c9") << OP_3 << OP_CHECKMULTISIG);
Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, this should not have made it into the PR.

@apoelstra
Copy link
Member Author

Thanks for bitcoin/bitcoin#6382 @jtimon, there are a lot of good ideas in there. I think I'll copy your factory pattern.

@jtimon
Copy link
Contributor

jtimon commented Oct 2, 2015

Awesome! Maybe you want to utACK one of the following open little steps in bitcoin/bitcoin?

Chainparams: Translations: DRY: options and error strings #6235
Don't check the genesis block #6597

@apoelstra
Copy link
Member Author

Rebased using a factory pattern as in @jtimon's code. Need to add some unit tests before this is usable.

Like bitcoin/6382, there is an argument that this is only useful for QA and may not make sense to be merged. But in this case, I think it's reasonable to expect users to play with their own network with their own functionaries, and this makes this much easier.

@apoelstra
Copy link
Member Author

Added unit tests that confirms the genesis hash is computed correctly (for testnet and regtest, that the output of RPC getblockhash 0 matches the result of directly passes CScripts into SetParams; for mainnet and unittest I assumed the result was correct and added a check for it to catch regressions).

@apoelstra
Copy link
Member Author

@jtimon Do you have further thoughts on this PR? I know you have overlapping PRs in Core.

@gmaxwell You commented on bitcoin/bitcoin#6907 that you feel making this a factory is a bad idea. Keeping them static would mean moving the constructor into some sort of init function, have the constructor just call this, and have SelectParams call that rather than calling the factory. Would you prefer this?

In any case I'd like to move forward with this PR.

@@ -80,6 +80,14 @@ class CChainParams
const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
const std::vector<CAddress>& FixedSeeds() const { return vFixedSeeds; }
virtual const Checkpoints::CCheckpointData& Checkpoints() const = 0;
/** Change the script in the genesis hash */
void ChangeGenesisScriptDestination(CScript s) { genesis.proof = CProof(s, CScript()); }
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused method.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed

@jtimon
Copy link
Contributor

jtimon commented Nov 21, 2015

If I understood it correctly, @gmaxwell 's nit was that I was making globalChainParams and globalSwitchingChainParams extern instead of static and it's already solved (but it would be nice if he can clarify whether his nit has been solved or not in bitcoin/bitcoin#6907 ).

As said, I don't like the script being passed to SeelectParams(), the factory, nor the constructors and I would prefer ScriptDestinationFromCommandLine to be called directly within the constructors, but just a preference.
I added a couple of minor nits though.

The overlapping PR/commits in Core are contained in https://github.com/jtimon/bitcoin/tree/alpha-base-0.12 which I will maintain rebased until 0.12 is forked and is what I would l would like @TheBlueMatt to use as a base when rebasing.

@apoelstra
Copy link
Member Author

Addressed @jtimon's nits

@jtimon
Copy link
Contributor

jtimon commented Nov 22, 2015

I'm going to merge.

jtimon added a commit that referenced this pull request Nov 22, 2015
Add commandline flag to set genesis block script destination
@jtimon jtimon merged commit 2f7f3bf into ElementsProject:alpha Nov 22, 2015
@@ -139,13 +145,15 @@ const CChainParams &Params();
/** Return parameters for the given network. */
CChainParams &Params(CBaseChainParams::Network network);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait a minute...where is this function defined now?

Copy link
Member Author

Choose a reason for hiding this comment

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

chainparams.cpp:315

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I mean the parametrized version.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, hmm, this is not defined anywhere anymore (nor is it called anywhere, of course, else we would have compilation errors).

Copy link
Contributor

Choose a reason for hiding this comment

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

mhmm I would like to eventually remove it from core too.I guess when rebasing the remaining uses can be replaced with the factory i elements. It's just something I expected to happen in bitcoin core first.

Copy link
Contributor

Choose a reason for hiding this comment

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

Of course another option is to maintain it in elements until it removed in core.

apoelstra added a commit to apoelstra/elements that referenced this pull request Nov 23, 2015
instagibbs added a commit to instagibbs/elements that referenced this pull request Mar 15, 2017
getrawtransaction: scriptpubkey type is 'fee'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants