mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04: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
de90b47ea0
commit
d3f4e64d41
3 changed files with 18 additions and 16 deletions
|
@ -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
|
||||
|
|
|
@ -433,4 +433,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 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…
Add table
Reference in a new issue