mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-17 17:02:43 +00:00
interfaces: refactor: move submitSolution implementation to miner
- Create a new function `AddMerkleRootAndCoinbase` that compute the block's merkle root, insert the coinbase transaction and the merkle root into the block.
This commit is contained in:
parent
02d4bc776b
commit
e6c2f4ce7a
@ -929,22 +929,8 @@ public:
|
||||
|
||||
bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CTransactionRef coinbase) override
|
||||
{
|
||||
CBlock block{m_block_template->block};
|
||||
|
||||
if (block.vtx.size() == 0) {
|
||||
block.vtx.push_back(coinbase);
|
||||
} else {
|
||||
block.vtx[0] = coinbase;
|
||||
}
|
||||
|
||||
block.nVersion = version;
|
||||
block.nTime = timestamp;
|
||||
block.nNonce = nonce;
|
||||
|
||||
block.hashMerkleRoot = BlockMerkleRoot(block);
|
||||
|
||||
auto block_ptr = std::make_shared<const CBlock>(block);
|
||||
return chainman().ProcessNewBlock(block_ptr, /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/nullptr);
|
||||
AddMerkleRootAndCoinbase(m_block_template->block, std::move(coinbase), version, timestamp, nonce);
|
||||
return chainman().ProcessNewBlock(std::make_shared<const CBlock>(m_block_template->block), /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/nullptr);
|
||||
}
|
||||
|
||||
std::unique_ptr<BlockTemplate> waitNext(BlockWaitOptions options) override
|
||||
|
||||
@ -434,4 +434,17 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
|
||||
nDescendantsUpdated += UpdatePackagesForAdded(mempool, ancestors, mapModifiedTx);
|
||||
}
|
||||
}
|
||||
|
||||
void AddMerkleRootAndCoinbase(CBlock& block, CTransactionRef coinbase, uint32_t version, uint32_t timestamp, uint32_t nonce)
|
||||
{
|
||||
if (block.vtx.size() == 0) {
|
||||
block.vtx.emplace_back(coinbase);
|
||||
} else {
|
||||
block.vtx[0] = coinbase;
|
||||
}
|
||||
block.nVersion = version;
|
||||
block.nTime = timestamp;
|
||||
block.nNonce = nonce;
|
||||
block.hashMerkleRoot = BlockMerkleRoot(block);
|
||||
}
|
||||
} // namespace node
|
||||
|
||||
@ -229,6 +229,9 @@ void RegenerateCommitments(CBlock& block, ChainstateManager& chainman);
|
||||
|
||||
/** Apply -blockmintxfee and -blockmaxweight options from ArgsManager to BlockAssembler options. */
|
||||
void ApplyArgsManOptions(const ArgsManager& gArgs, BlockAssembler::Options& options);
|
||||
|
||||
/* Compute the block's merkle root, insert or replace the coinbase transaction and the merkle root into the block */
|
||||
void AddMerkleRootAndCoinbase(CBlock& block, CTransactionRef coinbase, uint32_t version, uint32_t timestamp, uint32_t nonce);
|
||||
} // namespace node
|
||||
|
||||
#endif // BITCOIN_NODE_MINER_H
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user