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:
1 parent
02d4bc776b
commit
e6c2f4ce7a
3 files changed
+18
-16
No files matched your search
+2
-16
@@ -929,22 +929,8 @@ public:
|
|||||||
|
|
||||||
bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CTransactionRef coinbase) override
|
bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CTransactionRef coinbase) override
|
||||||
{
|
{
|
||||||
CBlock block{m_block_template->block};
|
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);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<BlockTemplate> waitNext(BlockWaitOptions options) override
|
std::unique_ptr<BlockTemplate> waitNext(BlockWaitOptions options) override
|
||||||
|
|||||||
@@ -434,4 +434,17 @@ void BlockAssembler::addPackageTxs(int& nPackagesSelected, int& nDescendantsUpda
|
|||||||
nDescendantsUpdated += UpdatePackagesForAdded(mempool, ancestors, mapModifiedTx);
|
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
|
} // namespace node
|
||||||
@@ -229,6 +229,9 @@ void RegenerateCommitments(CBlock& block, ChainstateManager& chainman);
|
|||||||
|
|
||||||
/** Apply -blockmintxfee and -blockmaxweight options from ArgsManager to BlockAssembler options. */
|
/** Apply -blockmintxfee and -blockmaxweight options from ArgsManager to BlockAssembler options. */
|
||||||
void ApplyArgsManOptions(const ArgsManager& gArgs, BlockAssembler::Options& 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
|
} // namespace node
|
||||||
|
|
||||||
#endif // BITCOIN_NODE_MINER_H
|
#endif // BITCOIN_NODE_MINER_H
|
||||||
Reference in new issue
Block a user