Skip to content

Commit 6bc9e40

Browse files
committed
Chainparams: Explicit CChainParams arg for miner:
-BitcoinMiner -CreateNewBlock -GenerateBitcoins -ProcessBlockFound
1 parent 598e494 commit 6bc9e40

File tree

6 files changed

+23
-24
lines changed

6 files changed

+23
-24
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
15761576
scheduler.scheduleEvery(f, nPowTargetSpacing);
15771577

15781578
// Generate coins in the background
1579-
GenerateBitcoins(GetBoolArg("-gen", false), GetArg("-genproclimit", DEFAULT_GENERATE_THREADS), Params());
1579+
GenerateBitcoins(GetBoolArg("-gen", false), GetArg("-genproclimit", DEFAULT_GENERATE_THREADS), chainparams);
15801580

15811581
// ********************************************************* Step 12: finished
15821582

src/miner.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam
9999
return nNewTime - nOldTime;
100100
}
101101

102-
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
102+
CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& scriptPubKeyIn)
103103
{
104-
const CChainParams& chainparams = Params();
105104
// Create new block
106105
auto_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
107106
if(!pblocktemplate.get())
@@ -110,7 +109,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
110109

111110
// -regtest only: allow overriding block.nVersion with
112111
// -blockversion=N to test forking scenarios
113-
if (Params().MineBlocksOnDemand())
112+
if (chainparams.MineBlocksOnDemand())
114113
pblock->nVersion = GetArg("-blockversion", pblock->nVersion);
115114

116115
// Create coinbase tx
@@ -345,8 +344,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
345344

346345
// Fill in header
347346
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
348-
UpdateTime(pblock, Params().GetConsensus(), pindexPrev);
349-
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus());
347+
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
348+
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus());
350349
pblock->nNonce = 0;
351350
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
352351

@@ -478,7 +477,7 @@ void static BitcoinMiner(const CChainParams& chainparams)
478477
unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
479478
CBlockIndex* pindexPrev = chainActive.Tip();
480479

481-
auto_ptr<CBlockTemplate> pblocktemplate(CreateNewBlock(coinbaseScript->reserveScript));
480+
auto_ptr<CBlockTemplate> pblocktemplate(CreateNewBlock(chainparams, coinbaseScript->reserveScript));
482481
if (!pblocktemplate.get())
483482
{
484483
LogPrintf("Error in BitcoinMiner: Keypool ran out, please call keypoolrefill before restarting the mining thread\n");

src/miner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct CBlockTemplate
2929
/** Run the miner threads */
3030
void GenerateBitcoins(bool fGenerate, int nThreads, const CChainParams& chainparams);
3131
/** Generate a new block, without valid proof-of-work */
32-
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn);
32+
CBlockTemplate* CreateNewBlock(const CChainParams& chainparams, const CScript& scriptPubKeyIn);
3333
/** Modify the extranonce in a block */
3434
void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
3535
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);

src/rpcmining.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ UniValue generate(const UniValue& params, bool fHelp)
157157
UniValue blockHashes(UniValue::VARR);
158158
while (nHeight < nHeightEnd)
159159
{
160-
auto_ptr<CBlockTemplate> pblocktemplate(CreateNewBlock(coinbaseScript->reserveScript));
160+
auto_ptr<CBlockTemplate> pblocktemplate(CreateNewBlock(Params(), coinbaseScript->reserveScript));
161161
if (!pblocktemplate.get())
162162
throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block");
163163
CBlock *pblock = &pblocktemplate->block;
@@ -510,7 +510,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp)
510510
pblocktemplate = NULL;
511511
}
512512
CScript scriptDummy = CScript() << OP_TRUE;
513-
pblocktemplate = CreateNewBlock(scriptDummy);
513+
pblocktemplate = CreateNewBlock(Params(), scriptDummy);
514514
if (!pblocktemplate)
515515
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
516516

src/test/miner_tests.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
7070
fCheckpointsEnabled = false;
7171

7272
// Simple block creation, nothing special yet:
73-
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
73+
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
7474

7575
// We can't make transactions until we have inputs
7676
// Therefore, load 100 blocks :)
@@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
9999
delete pblocktemplate;
100100

101101
// Just to make sure we can still make simple blocks
102-
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
102+
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
103103
delete pblocktemplate;
104104

105105
// block sigops > limit: 1000 CHECKMULTISIG + 1
@@ -117,7 +117,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
117117
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
118118
tx.vin[0].prevout.hash = hash;
119119
}
120-
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
120+
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
121121
delete pblocktemplate;
122122
mempool.clear();
123123

@@ -137,14 +137,14 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
137137
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
138138
tx.vin[0].prevout.hash = hash;
139139
}
140-
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
140+
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
141141
delete pblocktemplate;
142142
mempool.clear();
143143

144144
// orphan in mempool
145145
hash = tx.GetHash();
146146
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
147-
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
147+
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
148148
delete pblocktemplate;
149149
mempool.clear();
150150

@@ -162,7 +162,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
162162
tx.vout[0].nValue = 5900000000LL;
163163
hash = tx.GetHash();
164164
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
165-
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
165+
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
166166
delete pblocktemplate;
167167
mempool.clear();
168168

@@ -173,7 +173,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
173173
tx.vout[0].nValue = 0;
174174
hash = tx.GetHash();
175175
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
176-
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
176+
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
177177
delete pblocktemplate;
178178
mempool.clear();
179179

@@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
191191
tx.vout[0].nValue -= 1000000;
192192
hash = tx.GetHash();
193193
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
194-
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
194+
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
195195
delete pblocktemplate;
196196
mempool.clear();
197197

@@ -205,17 +205,17 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
205205
tx.vout[0].scriptPubKey = CScript() << OP_2;
206206
hash = tx.GetHash();
207207
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
208-
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
208+
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
209209
delete pblocktemplate;
210210
mempool.clear();
211211

212212
// subsidy changing
213213
int nHeight = chainActive.Height();
214214
chainActive.Tip()->nHeight = 209999;
215-
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
215+
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
216216
delete pblocktemplate;
217217
chainActive.Tip()->nHeight = 210000;
218-
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
218+
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
219219
delete pblocktemplate;
220220
chainActive.Tip()->nHeight = nHeight;
221221

@@ -247,7 +247,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
247247
mempool.addUnchecked(hash, CTxMemPoolEntry(tx2, 11, GetTime(), 111.0, 11));
248248
BOOST_CHECK(!CheckFinalTx(tx2, LOCKTIME_MEDIAN_TIME_PAST));
249249

250-
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
250+
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
251251

252252
// Neither tx should have make it into the template.
253253
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 1);
@@ -262,7 +262,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
262262
//BOOST_CHECK(CheckFinalTx(tx));
263263
//BOOST_CHECK(CheckFinalTx(tx2));
264264

265-
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
265+
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
266266
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 2);
267267
delete pblocktemplate;
268268

src/test/test_bitcoin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ CBlock
115115
TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey)
116116
{
117117
const CChainParams& chainparams = Params();
118-
CBlockTemplate *pblocktemplate = CreateNewBlock(scriptPubKey);
118+
CBlockTemplate *pblocktemplate = CreateNewBlock(chainparams, scriptPubKey);
119119
CBlock& block = pblocktemplate->block;
120120

121121
// Replace mempool-selected txns with just coinbase plus passed-in txns:

0 commit comments

Comments
 (0)