mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
Add submitSolution to BlockTemplate interface
This commit is contained in:
parent
47b4875ef0
commit
525e9dcba0
3 changed files with 35 additions and 2 deletions
|
@ -49,6 +49,13 @@ public:
|
||||||
* @return merkle path ordered from the deepest
|
* @return merkle path ordered from the deepest
|
||||||
*/
|
*/
|
||||||
virtual std::vector<uint256> getCoinbaseMerklePath() = 0;
|
virtual std::vector<uint256> getCoinbaseMerklePath() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct and broadcast the block.
|
||||||
|
*
|
||||||
|
* @returns if the block was processed, independent of block validity
|
||||||
|
*/
|
||||||
|
virtual bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CMutableTransaction coinbase) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Interface giving clients (RPC, Stratum v2 Template Provider in the future)
|
//! Interface giving clients (RPC, Stratum v2 Template Provider in the future)
|
||||||
|
|
|
@ -32,6 +32,7 @@ interface BlockTemplate $Proxy.wrap("interfaces::BlockTemplate") {
|
||||||
getCoinbaseCommitment @5 (context: Proxy.Context) -> (result: Data);
|
getCoinbaseCommitment @5 (context: Proxy.Context) -> (result: Data);
|
||||||
getWitnessCommitmentIndex @6 (context: Proxy.Context) -> (result: Int32);
|
getWitnessCommitmentIndex @6 (context: Proxy.Context) -> (result: Int32);
|
||||||
getCoinbaseMerklePath @7 (context: Proxy.Context) -> (result: List(Data));
|
getCoinbaseMerklePath @7 (context: Proxy.Context) -> (result: List(Data));
|
||||||
|
submitSolution@8 (context: Proxy.Context, version: UInt32, timestamp: UInt32, nonce: UInt32, coinbase :Data) -> (result: Bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BlockCreateOptions $Proxy.wrap("node::BlockCreateOptions") {
|
struct BlockCreateOptions $Proxy.wrap("node::BlockCreateOptions") {
|
||||||
|
|
|
@ -871,7 +871,7 @@ public:
|
||||||
class BlockTemplateImpl : public BlockTemplate
|
class BlockTemplateImpl : public BlockTemplate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit BlockTemplateImpl(std::unique_ptr<CBlockTemplate> block_template) : m_block_template(std::move(block_template))
|
explicit BlockTemplateImpl(std::unique_ptr<CBlockTemplate> block_template, NodeContext& node) : m_block_template(std::move(block_template)), m_node(node)
|
||||||
{
|
{
|
||||||
assert(m_block_template);
|
assert(m_block_template);
|
||||||
}
|
}
|
||||||
|
@ -916,7 +916,32 @@ public:
|
||||||
return BlockMerkleBranch(m_block_template->block);
|
return BlockMerkleBranch(m_block_template->block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool submitSolution(uint32_t version, uint32_t timestamp, uint32_t nonce, CMutableTransaction coinbase) override
|
||||||
|
{
|
||||||
|
CBlock block{m_block_template->block};
|
||||||
|
|
||||||
|
auto cb = MakeTransactionRef(std::move(coinbase));
|
||||||
|
|
||||||
|
if (block.vtx.size() == 0) {
|
||||||
|
block.vtx.push_back(cb);
|
||||||
|
} else {
|
||||||
|
block.vtx[0] = cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
const std::unique_ptr<CBlockTemplate> m_block_template;
|
const std::unique_ptr<CBlockTemplate> m_block_template;
|
||||||
|
|
||||||
|
ChainstateManager& chainman() { return *Assert(m_node.chainman); }
|
||||||
|
NodeContext& m_node;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MinerImpl : public Mining
|
class MinerImpl : public Mining
|
||||||
|
@ -990,7 +1015,7 @@ public:
|
||||||
{
|
{
|
||||||
BlockAssembler::Options assemble_options{options};
|
BlockAssembler::Options assemble_options{options};
|
||||||
ApplyArgsManOptions(*Assert(m_node.args), assemble_options);
|
ApplyArgsManOptions(*Assert(m_node.args), assemble_options);
|
||||||
return std::make_unique<BlockTemplateImpl>(BlockAssembler{chainman().ActiveChainstate(), context()->mempool.get(), assemble_options}.CreateNewBlock(script_pub_key));
|
return std::make_unique<BlockTemplateImpl>(BlockAssembler{chainman().ActiveChainstate(), context()->mempool.get(), assemble_options}.CreateNewBlock(script_pub_key), m_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeContext* context() override { return &m_node; }
|
NodeContext* context() override { return &m_node; }
|
||||||
|
|
Loading…
Add table
Reference in a new issue