Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/chain.cpp
Show First 20 Lines • Show All 314 Lines • ▼ Show 20 Lines | public: | ||||
if (block->nHeight <= min_height || !block->pprev) { | if (block->nHeight <= min_height || !block->pprev) { | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
bool hasDescendantsInMempool(const TxId &txid) override { | bool hasDescendantsInMempool(const TxId &txid) override { | ||||
LOCK(::g_mempool.cs); | if (!m_node.mempool) { | ||||
auto it = ::g_mempool.GetIter(txid); | return false; | ||||
} | |||||
LOCK(m_node.mempool->cs); | |||||
auto it = m_node.mempool->GetIter(txid); | |||||
return it && (*it)->GetCountWithDescendants() > 1; | return it && (*it)->GetCountWithDescendants() > 1; | ||||
} | } | ||||
bool broadcastTransaction(const Config &config, | bool broadcastTransaction(const Config &config, | ||||
const CTransactionRef &tx, | const CTransactionRef &tx, | ||||
const Amount &max_tx_fee, bool relay, | const Amount &max_tx_fee, bool relay, | ||||
std::string &err_string) override { | std::string &err_string) override { | ||||
const TransactionError err = BroadcastTransaction( | const TransactionError err = BroadcastTransaction( | ||||
m_node, config, tx, err_string, max_tx_fee, relay, | m_node, config, tx, err_string, max_tx_fee, relay, | ||||
/*wait_callback*/ false); | /*wait_callback*/ false); | ||||
// Chain clients only care about failures to accept the tx to the | // Chain clients only care about failures to accept the tx to the | ||||
// mempool. Disregard non-mempool related failures. Note: this will | // mempool. Disregard non-mempool related failures. Note: this will | ||||
// need to be updated if BroadcastTransactions() is updated to | // need to be updated if BroadcastTransactions() is updated to | ||||
// return other non-mempool failures that Chain clients do not need | // return other non-mempool failures that Chain clients do not need | ||||
// to know about. | // to know about. | ||||
return err == TransactionError::OK; | return err == TransactionError::OK; | ||||
} | } | ||||
void getTransactionAncestry(const TxId &txid, size_t &ancestors, | void getTransactionAncestry(const TxId &txid, size_t &ancestors, | ||||
size_t &descendants) override { | size_t &descendants) override { | ||||
::g_mempool.GetTransactionAncestry(txid, ancestors, descendants); | ancestors = descendants = 0; | ||||
if (!m_node.mempool) { | |||||
return; | |||||
} | |||||
m_node.mempool->GetTransactionAncestry(txid, ancestors, | |||||
descendants); | |||||
} | } | ||||
void getPackageLimits(size_t &limit_ancestor_count, | void getPackageLimits(size_t &limit_ancestor_count, | ||||
size_t &limit_descendant_count) override { | size_t &limit_descendant_count) override { | ||||
limit_ancestor_count = size_t( | limit_ancestor_count = size_t( | ||||
std::max<int64_t>(1, gArgs.GetArg("-limitancestorcount", | std::max<int64_t>(1, gArgs.GetArg("-limitancestorcount", | ||||
DEFAULT_ANCESTOR_LIMIT))); | DEFAULT_ANCESTOR_LIMIT))); | ||||
limit_descendant_count = size_t( | limit_descendant_count = size_t( | ||||
std::max<int64_t>(1, gArgs.GetArg("-limitdescendantcount", | std::max<int64_t>(1, gArgs.GetArg("-limitdescendantcount", | ||||
DEFAULT_DESCENDANT_LIMIT))); | DEFAULT_DESCENDANT_LIMIT))); | ||||
} | } | ||||
bool checkChainLimits(const CTransactionRef &tx) override { | bool checkChainLimits(const CTransactionRef &tx) override { | ||||
if (!m_node.mempool) { | |||||
return true; | |||||
} | |||||
LockPoints lp; | LockPoints lp; | ||||
CTxMemPoolEntry entry(tx, Amount(), 0, 0, false, 0, lp); | CTxMemPoolEntry entry(tx, Amount(), 0, 0, false, 0, lp); | ||||
CTxMemPool::setEntries ancestors; | CTxMemPool::setEntries ancestors; | ||||
auto limit_ancestor_count = | auto limit_ancestor_count = | ||||
gArgs.GetArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT); | gArgs.GetArg("-limitancestorcount", DEFAULT_ANCESTOR_LIMIT); | ||||
auto limit_ancestor_size = | auto limit_ancestor_size = | ||||
gArgs.GetArg("-limitancestorsize", | gArgs.GetArg("-limitancestorsize", | ||||
DEFAULT_ANCESTOR_SIZE_LIMIT) * | DEFAULT_ANCESTOR_SIZE_LIMIT) * | ||||
1000; | 1000; | ||||
auto limit_descendant_count = | auto limit_descendant_count = | ||||
gArgs.GetArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT); | gArgs.GetArg("-limitdescendantcount", DEFAULT_DESCENDANT_LIMIT); | ||||
auto limit_descendant_size = | auto limit_descendant_size = | ||||
gArgs.GetArg("-limitdescendantsize", | gArgs.GetArg("-limitdescendantsize", | ||||
DEFAULT_DESCENDANT_SIZE_LIMIT) * | DEFAULT_DESCENDANT_SIZE_LIMIT) * | ||||
1000; | 1000; | ||||
std::string unused_error_string; | std::string unused_error_string; | ||||
LOCK(::g_mempool.cs); | LOCK(m_node.mempool->cs); | ||||
return ::g_mempool.CalculateMemPoolAncestors( | return m_node.mempool->CalculateMemPoolAncestors( | ||||
entry, ancestors, limit_ancestor_count, limit_ancestor_size, | entry, ancestors, limit_ancestor_count, limit_ancestor_size, | ||||
limit_descendant_count, limit_descendant_size, | limit_descendant_count, limit_descendant_size, | ||||
unused_error_string); | unused_error_string); | ||||
} | } | ||||
CFeeRate estimateFee() const override { | CFeeRate estimateFee() const override { | ||||
return ::g_mempool.estimateFee(); | if (!m_node.mempool) { | ||||
return {}; | |||||
} | |||||
return m_node.mempool->estimateFee(); | |||||
} | } | ||||
CFeeRate relayMinFee() override { return ::minRelayTxFee; } | CFeeRate relayMinFee() override { return ::minRelayTxFee; } | ||||
CFeeRate relayDustFee() override { return ::dustRelayFee; } | CFeeRate relayDustFee() override { return ::dustRelayFee; } | ||||
bool havePruned() override { | bool havePruned() override { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return ::fHavePruned; | return ::fHavePruned; | ||||
} | } | ||||
bool isReadyToBroadcast() override { | bool isReadyToBroadcast() override { | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | public: | ||||
return IsDeprecatedRPCEnabled(gArgs, method); | return IsDeprecatedRPCEnabled(gArgs, method); | ||||
} | } | ||||
void rpcRunLater(const std::string &name, std::function<void()> fn, | void rpcRunLater(const std::string &name, std::function<void()> fn, | ||||
int64_t seconds) override { | int64_t seconds) override { | ||||
RPCRunLater(name, std::move(fn), seconds); | RPCRunLater(name, std::move(fn), seconds); | ||||
} | } | ||||
int rpcSerializationFlags() override { return RPCSerializationFlags(); } | int rpcSerializationFlags() override { return RPCSerializationFlags(); } | ||||
void requestMempoolTransactions(Notifications ¬ifications) override { | void requestMempoolTransactions(Notifications ¬ifications) override { | ||||
LOCK2(::cs_main, ::g_mempool.cs); | if (!m_node.mempool) { | ||||
for (const CTxMemPoolEntry &entry : ::g_mempool.mapTx) { | return; | ||||
} | |||||
LOCK2(::cs_main, m_node.mempool->cs); | |||||
for (const CTxMemPoolEntry &entry : m_node.mempool->mapTx) { | |||||
notifications.transactionAddedToMempool(entry.GetSharedTx()); | notifications.transactionAddedToMempool(entry.GetSharedTx()); | ||||
} | } | ||||
} | } | ||||
const CChainParams ¶ms() const override { return m_params; } | const CChainParams ¶ms() const override { return m_params; } | ||||
NodeContext &m_node; | NodeContext &m_node; | ||||
const CChainParams &m_params; | const CChainParams &m_params; | ||||
}; | }; | ||||
} // namespace | } // namespace | ||||
std::unique_ptr<Chain> MakeChain(NodeContext &node, | std::unique_ptr<Chain> MakeChain(NodeContext &node, | ||||
const CChainParams ¶ms) { | const CChainParams ¶ms) { | ||||
return std::make_unique<ChainImpl>(node, params); | return std::make_unique<ChainImpl>(node, params); | ||||
} | } | ||||
} // namespace interfaces | } // namespace interfaces |