Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
Show First 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | int nHeight = 0; | ||||
nHeight = ::ChainActive().Height(); | nHeight = ::ChainActive().Height(); | ||||
nHeightEnd = nHeight + nGenerate; | nHeightEnd = nHeight + nGenerate; | ||||
} | } | ||||
unsigned int nExtraNonce = 0; | unsigned int nExtraNonce = 0; | ||||
UniValue blockHashes(UniValue::VARR); | UniValue blockHashes(UniValue::VARR); | ||||
while (nHeight < nHeightEnd && !ShutdownRequested()) { | while (nHeight < nHeightEnd && !ShutdownRequested()) { | ||||
std::unique_ptr<CBlockTemplate> pblocktemplate( | std::unique_ptr<CBlockTemplate> pblocktemplate( | ||||
BlockAssembler(config, mempool) | BlockAssembler(config, chainman.ActiveChainstate(), mempool) | ||||
.CreateNewBlock(::ChainstateActive(), coinbase_script)); | .CreateNewBlock(coinbase_script)); | ||||
if (!pblocktemplate.get()) { | if (!pblocktemplate.get()) { | ||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block"); | throw JSONRPCError(RPC_INTERNAL_ERROR, "Couldn't create new block"); | ||||
} | } | ||||
CBlock *pblock = &pblocktemplate->block; | CBlock *pblock = &pblocktemplate->block; | ||||
BlockHash block_hash; | BlockHash block_hash; | ||||
▲ Show 20 Lines • Show All 229 Lines • ▼ Show 20 Lines | return RPCHelpMan{ | ||||
RPC_INVALID_ADDRESS_OR_KEY, | RPC_INVALID_ADDRESS_OR_KEY, | ||||
strprintf("Transaction %s not in mempool.", str)); | strprintf("Transaction %s not in mempool.", str)); | ||||
} | } | ||||
txs.emplace_back(tx); | txs.emplace_back(tx); | ||||
} else if (DecodeHexTx(mtx, str)) { | } else if (DecodeHexTx(mtx, str)) { | ||||
txs.push_back(MakeTransactionRef(std::move(mtx))); | txs.push_back(MakeTransactionRef(std::move(mtx))); | ||||
} else { | } else { | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
RPC_DESERIALIZATION_ERROR, | RPC_DESERIALIZATION_ERROR, | ||||
strprintf("Transaction decode failed for %s", str)); | strprintf("Transaction decode failed for %s", str)); | ||||
} | } | ||||
} | } | ||||
CBlock block; | CBlock block; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CTxMemPool empty_mempool; | CTxMemPool empty_mempool; | ||||
std::unique_ptr<CBlockTemplate> blocktemplate( | std::unique_ptr<CBlockTemplate> blocktemplate( | ||||
BlockAssembler(config, empty_mempool) | BlockAssembler(config, ::ChainstateActive(), empty_mempool) | ||||
.CreateNewBlock(::ChainstateActive(), coinbase_script)); | .CreateNewBlock(coinbase_script)); | ||||
if (!blocktemplate) { | if (!blocktemplate) { | ||||
throw JSONRPCError(RPC_INTERNAL_ERROR, | throw JSONRPCError(RPC_INTERNAL_ERROR, | ||||
"Couldn't create new block"); | "Couldn't create new block"); | ||||
} | } | ||||
block = blocktemplate->block; | block = blocktemplate->block; | ||||
} | } | ||||
CHECK_NONFATAL(block.vtx.size() == 1); | CHECK_NONFATAL(block.vtx.size() == 1); | ||||
▲ Show 20 Lines • Show All 481 Lines • ▼ Show 20 Lines | return RPCHelpMan{ | ||||
// races | // races | ||||
nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); | nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); | ||||
CBlockIndex *pindexPrevNew = ::ChainActive().Tip(); | CBlockIndex *pindexPrevNew = ::ChainActive().Tip(); | ||||
nStart = GetTime(); | nStart = GetTime(); | ||||
// Create new block | // Create new block | ||||
CScript scriptDummy = CScript() << OP_TRUE; | CScript scriptDummy = CScript() << OP_TRUE; | ||||
pblocktemplate = | pblocktemplate = | ||||
BlockAssembler(config, mempool) | BlockAssembler(config, ::ChainstateActive(), mempool) | ||||
.CreateNewBlock(::ChainstateActive(), scriptDummy); | .CreateNewBlock(scriptDummy); | ||||
if (!pblocktemplate) { | if (!pblocktemplate) { | ||||
throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory"); | throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory"); | ||||
} | } | ||||
// Need to update only after we know CreateNewBlock succeeded | // Need to update only after we know CreateNewBlock succeeded | ||||
pindexPrev = pindexPrevNew; | pindexPrev = pindexPrevNew; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 286 Lines • Show Last 20 Lines |