Browse Source

CreateNewBlock() now takes scriptPubKey argument,

rather than a key.

CreateNewBlockWithKey() helper is added to restore existing functionality,
making this an equivalent-transformation change.

Conflicts:
	src/miner.cpp
	src/miner.h

Rebased-from: fcc32b7b9ce5bc310cbad677da7e7bca3a01459a
0.8
Jeff Garzik 11 years ago committed by Warren Togami
parent
commit
b3060a26d0
  1. 18
      src/main.cpp
  2. 3
      src/main.h
  3. 4
      src/rpcmining.cpp
  4. 22
      src/test/miner_tests.cpp

18
src/main.cpp

@ -4186,7 +4186,7 @@ public:
} }
}; };
CBlockTemplate* CreateNewBlock(CReserveKey& reservekey) CBlockTemplate* CreateNewBlock(CScript& scriptPubKeyIn)
{ {
// Create new block // Create new block
auto_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate()); auto_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
@ -4199,10 +4199,7 @@ CBlockTemplate* CreateNewBlock(CReserveKey& reservekey)
txNew.vin.resize(1); txNew.vin.resize(1);
txNew.vin[0].prevout.SetNull(); txNew.vin[0].prevout.SetNull();
txNew.vout.resize(1); txNew.vout.resize(1);
CPubKey pubkey; txNew.vout[0].scriptPubKey = scriptPubKeyIn;
if (!reservekey.GetReservedKey(pubkey))
return NULL;
txNew.vout[0].scriptPubKey << pubkey << OP_CHECKSIG;
// Add our coinbase tx as first transaction // Add our coinbase tx as first transaction
pblock->vtx.push_back(txNew); pblock->vtx.push_back(txNew);
@ -4428,6 +4425,15 @@ CBlockTemplate* CreateNewBlock(CReserveKey& reservekey)
return pblocktemplate.release(); return pblocktemplate.release();
} }
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey)
{
CPubKey pubkey;
if (!reservekey.GetReservedKey(pubkey))
return NULL;
CScript scriptPubKey = CScript() << pubkey << OP_CHECKSIG;
return CreateNewBlock(scriptPubKey);
}
void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce) void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
{ {
@ -4551,7 +4557,7 @@ void static LitecoinMiner(CWallet *pwallet)
unsigned int nTransactionsUpdatedLast = nTransactionsUpdated; unsigned int nTransactionsUpdatedLast = nTransactionsUpdated;
CBlockIndex* pindexPrev = pindexBest; CBlockIndex* pindexPrev = pindexBest;
auto_ptr<CBlockTemplate> pblocktemplate(CreateNewBlock(reservekey)); auto_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey));
if (!pblocktemplate.get()) if (!pblocktemplate.get())
return; return;
CBlock *pblock = &pblocktemplate->block; CBlock *pblock = &pblocktemplate->block;

3
src/main.h

@ -157,7 +157,8 @@ void ThreadScriptCheck();
/** Run the miner threads */ /** Run the miner threads */
void GenerateBitcoins(bool fGenerate, CWallet* pwallet); void GenerateBitcoins(bool fGenerate, CWallet* pwallet);
/** Generate a new block, without valid proof-of-work */ /** Generate a new block, without valid proof-of-work */
CBlockTemplate* CreateNewBlock(CReserveKey& reservekey); CBlockTemplate* CreateNewBlock(CScript& scriptPubKeyIn);
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey);
/** Modify the extranonce in a block */ /** Modify the extranonce in a block */
void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce); void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
/** Do mining precalculation */ /** Do mining precalculation */

4
src/rpcmining.cpp

@ -338,7 +338,7 @@ Value getwork(const Array& params, bool fHelp)
nStart = GetTime(); nStart = GetTime();
// Create new block // Create new block
pblocktemplate = CreateNewBlock(*pMiningKey); pblocktemplate = CreateNewBlockWithKey(*pMiningKey);
if (!pblocktemplate) if (!pblocktemplate)
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory"); throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
vNewBlockTemplate.push_back(pblocktemplate); vNewBlockTemplate.push_back(pblocktemplate);
@ -469,7 +469,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
delete pblocktemplate; delete pblocktemplate;
pblocktemplate = NULL; pblocktemplate = NULL;
} }
pblocktemplate = CreateNewBlock(*pMiningKey); pblocktemplate = CreateNewBlockWithKey(*pMiningKey);
if (!pblocktemplate) if (!pblocktemplate)
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory"); throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");

22
src/test/miner_tests.cpp

@ -55,7 +55,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
uint256 hash; uint256 hash;
// Simple block creation, nothing special yet: // Simple block creation, nothing special yet:
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
// We can't make transactions until we have inputs // We can't make transactions until we have inputs
// Therefore, load 100 blocks :) // Therefore, load 100 blocks :)
@ -81,7 +81,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
delete pblocktemplate; delete pblocktemplate;
// Just to make sure we can still make simple blocks // Just to make sure we can still make simple blocks
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
// block sigops > limit: 1000 CHECKMULTISIG + 1 // block sigops > limit: 1000 CHECKMULTISIG + 1
tx.vin.resize(1); tx.vin.resize(1);
@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
mempool.addUnchecked(hash, tx); mempool.addUnchecked(hash, tx);
tx.vin[0].prevout.hash = hash; tx.vin[0].prevout.hash = hash;
} }
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
delete pblocktemplate; delete pblocktemplate;
mempool.clear(); mempool.clear();
@ -118,14 +118,14 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
mempool.addUnchecked(hash, tx); mempool.addUnchecked(hash, tx);
tx.vin[0].prevout.hash = hash; tx.vin[0].prevout.hash = hash;
} }
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
delete pblocktemplate; delete pblocktemplate;
mempool.clear(); mempool.clear();
// orphan in mempool // orphan in mempool
hash = tx.GetHash(); hash = tx.GetHash();
mempool.addUnchecked(hash, tx); mempool.addUnchecked(hash, tx);
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
delete pblocktemplate; delete pblocktemplate;
mempool.clear(); mempool.clear();
@ -143,7 +143,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].nValue = 5900000000LL; tx.vout[0].nValue = 5900000000LL;
hash = tx.GetHash(); hash = tx.GetHash();
mempool.addUnchecked(hash, tx); mempool.addUnchecked(hash, tx);
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
delete pblocktemplate; delete pblocktemplate;
mempool.clear(); mempool.clear();
@ -154,7 +154,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].nValue = 0; tx.vout[0].nValue = 0;
hash = tx.GetHash(); hash = tx.GetHash();
mempool.addUnchecked(hash, tx); mempool.addUnchecked(hash, tx);
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
delete pblocktemplate; delete pblocktemplate;
mempool.clear(); mempool.clear();
@ -172,7 +172,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].nValue -= 1000000; tx.vout[0].nValue -= 1000000;
hash = tx.GetHash(); hash = tx.GetHash();
mempool.addUnchecked(hash,tx); mempool.addUnchecked(hash,tx);
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
delete pblocktemplate; delete pblocktemplate;
mempool.clear(); mempool.clear();
@ -186,17 +186,17 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].scriptPubKey = CScript() << OP_2; tx.vout[0].scriptPubKey = CScript() << OP_2;
hash = tx.GetHash(); hash = tx.GetHash();
mempool.addUnchecked(hash, tx); mempool.addUnchecked(hash, tx);
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
delete pblocktemplate; delete pblocktemplate;
mempool.clear(); mempool.clear();
// subsidy changing // subsidy changing
int nHeight = pindexBest->nHeight; int nHeight = pindexBest->nHeight;
pindexBest->nHeight = 209999; pindexBest->nHeight = 209999;
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
delete pblocktemplate; delete pblocktemplate;
pindexBest->nHeight = 210000; pindexBest->nHeight = 210000;
BOOST_CHECK(pblocktemplate = CreateNewBlock(reservekey)); BOOST_CHECK(pblocktemplate = CreateNewBlockWithKey(reservekey));
delete pblocktemplate; delete pblocktemplate;
pindexBest->nHeight = nHeight; pindexBest->nHeight = nHeight;
} }

Loading…
Cancel
Save