Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL
net_processing.cpp
netgroup.cpp
node/abort.cpp
node/block_template_manager.cpp
node/blockmanager_args.cpp
node/blockstorage.cpp
node/caches.cpp
Expand Down
9 changes: 6 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include <netaddress.h>
#include <netbase.h>
#include <netgroup.h>
#include <node/block_template_manager.h>
#include <node/blockmanager_args.h>
#include <node/blockstorage.h>
#include <node/caches.h>
Expand Down Expand Up @@ -429,6 +430,7 @@ void Shutdown(NodeContext& node)
if (node.validation_signals) {
node.validation_signals->UnregisterAllValidationInterfaces();
}
node.block_template_manager.reset();
node.mempool.reset();
node.fee_estimator.reset();
node.chainman.reset();
Expand Down Expand Up @@ -1325,6 +1327,7 @@ static ChainstateLoadResult InitAndLoadChainstate(
{
// This function may be called twice, so any dirty state must be reset.
node.notifications->setChainstateLoaded(false); // Drop state, such as a cached tip block
node.block_template_manager.reset();
node.mempool.reset();
node.chainman.reset(); // Drop state, such as an initialized m_block_tree_db

Expand All @@ -1341,9 +1344,6 @@ static ChainstateLoadResult InitAndLoadChainstate(
if (!mempool_error.empty()) {
return {ChainstateLoadStatus::FAILURE_FATAL, mempool_error};
}
auto mining_args{node::ReadMiningArgs(args)};
Assert(mining_args); // no error can happen, already checked in AppInitParameterInteraction
node.mining_args = std::move(*mining_args);
LogInfo("* Using %.1f MiB for in-memory UTXO set (plus up to %.1f MiB of unused mempool space)",
cache_sizes.coins / double(1_MiB),
mempool_opts.max_size_bytes / double(1_MiB));
Expand Down Expand Up @@ -1433,6 +1433,9 @@ static ChainstateLoadResult InitAndLoadChainstate(
std::tie(status, error) = catch_exceptions([&] { return VerifyLoadedChainstate(chainman, options); });
if (status == node::ChainstateLoadStatus::SUCCESS) {
LogInfo("Block index and chainstate loaded");
auto mining_args{node::ReadMiningArgs(args)};
Assert(mining_args); // no error can happen, already checked in AppInitParameterInteraction
node.block_template_manager = std::make_unique<node::BlockTemplateManager>(*node.mempool, chainman, *node.notifications, std::move(*mining_args));
node.notifications->setChainstateLoaded(true);
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/interfaces/mining.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ class BlockTemplate
virtual void interruptWait() = 0;
};

//! Tracks memory usage for template-bound transactions.
struct MemoryLoad
{
uint64_t usage{0};
};

//! Interface giving clients (RPC, Stratum v2 Template Provider in the future)
//! ability to create block templates.
class Mining
Expand Down Expand Up @@ -198,6 +204,15 @@ class Mining
*/
virtual std::vector<CTransactionRef> getTransactionsByWitnessID(const std::vector<Wtxid>& wtxids) = 0;

/**
* Returns the current memory load for template transactions outside the
* mempool.
*
* Only counts templates created through this interface. The template
* cached by the getblocktemplate RPC is excluded.
*/
virtual MemoryLoad getMemoryLoad() = 0;

//! Get internal node context. Useful for RPC and testing,
//! but not accessible across processes.
virtual const node::NodeContext* context() { return nullptr; }
Expand Down
5 changes: 5 additions & 0 deletions src/ipc/capnp/mining.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface Mining $Proxy.wrap("interfaces::Mining") {
submitBlock @7 (context :Proxy.Context, block: Data) -> (reason: Text, debug: Text, result: Bool);
getTransactionsByTxID @8 (context :Proxy.Context, txids: List(Data)) -> (result: List(Data));
getTransactionsByWitnessID @9 (context :Proxy.Context, wtxids: List(Data)) -> (result: List(Data));
getMemoryLoad @10 (context :Proxy.Context) -> (result: MemoryLoad);
}

interface BlockTemplate $Proxy.wrap("interfaces::BlockTemplate") {
Expand All @@ -49,6 +50,10 @@ struct BlockCreateOptions $Proxy.wrap("node::BlockCreateOptions") {
coinbaseOutputMaxAdditionalSigops @2 :UInt64 = .defaultCoinbaseOutputMaxAdditionalSigops $Proxy.name("coinbase_output_max_additional_sigops");
}

struct MemoryLoad $Proxy.wrap("interfaces::MemoryLoad") {
usage @0 :UInt64;
}

struct BlockWaitOptions $Proxy.wrap("node::BlockWaitOptions") {
timeout @0 : Float64 = .maxDouble $Proxy.name("timeout");
feeThreshold @1 : Int64 = .maxMoney $Proxy.name("fee_threshold");
Expand Down
Loading
Loading