Skip to content

Commit

Permalink
Suggested interfaces::Chain cleanups from bitcoin#15288
Browse files Browse the repository at this point in the history
Mostly documentation improvements requested in the last review of bitcoin#15288 before
it was merged
(bitcoin#15288 (review))
  • Loading branch information
ryanofsky authored and Michael Polzer committed Aug 27, 2019
1 parent 3645a54 commit ec60141
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/interfaces/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

The following interfaces are defined here:

* [`Chain`](chain.h) — used by wallet to access blockchain and mempool state. Added in [#10973](https://github.com/bitcoin/bitcoin/pull/10973).
* [`Chain`](chain.h) — used by wallet to access blockchain and mempool state. Added in [#14437](https://github.com/bitcoin/bitcoin/pull/14437), [#14711](https://github.com/bitcoin/bitcoin/pull/14711), [#15288](https://github.com/bitcoin/bitcoin/pull/15288), and [#10973](https://github.com/bitcoin/bitcoin/pull/10973).

* [`ChainClient`](chain.h) — used by node to start & stop `Chain` clients. Added in [#10973](https://github.com/bitcoin/bitcoin/pull/10973).
* [`ChainClient`](chain.h) — used by node to start & stop `Chain` clients. Added in [#14437](https://github.com/bitcoin/bitcoin/pull/14437).

* [`Node`](node.h) — used by GUI to start & stop bitcoin node. Added in [#10244](https://github.com/bitcoin/bitcoin/pull/10244).

Expand Down
8 changes: 4 additions & 4 deletions src/interfaces/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class LockImpl : public Chain::Lock
LockAnnotation lock(::cs_main);
return CheckFinalTx(tx);
}
bool submitToMemoryPool(CTransactionRef tx, CAmount absurd_fee, CValidationState& state) override
bool submitToMemoryPool(const CTransactionRef& tx, CAmount absurd_fee, CValidationState& state) override
{
LockAnnotation lock(::cs_main);
return AcceptToMemoryPool(::mempool, state, tx, nullptr /* missing inputs */, nullptr /* txn replaced */,
Expand Down Expand Up @@ -208,8 +208,8 @@ class ChainImpl : public Chain
bool hasDescendantsInMempool(const uint256& txid) override
{
LOCK(::mempool.cs);
auto it_mp = ::mempool.mapTx.find(txid);
return it_mp != ::mempool.mapTx.end() && it_mp->GetCountWithDescendants() > 1;
auto it = ::mempool.GetIter(txid);
return it && (*it)->GetCountWithDescendants() > 1;
}
void relayTransaction(const uint256& txid) override
{
Expand All @@ -220,7 +220,7 @@ class ChainImpl : public Chain
{
::mempool.GetTransactionAncestry(txid, ancestors, descendants);
}
bool checkChainLimits(CTransactionRef tx) override
bool checkChainLimits(const CTransactionRef& tx) override
{
LockPoints lp;
CTxMemPoolEntry entry(tx, 0, 0, 0, false, 0, lp);
Expand Down
38 changes: 30 additions & 8 deletions src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <script/standard.h> // For CTxDestination
#include <optional.h>
#include <optional.h> // For Optional and nullopt
#include <policy/rbf.h> // For RBFTransactionState
#include <primitives/transaction.h> // For CTransactionRef

#include <memory>
Expand All @@ -20,9 +19,11 @@
class CKey;
class CNode;
class CBlock;
class CFeeRate;
class CScheduler;
class CValidationState;
class uint256;
enum class RBFTransactionState;
struct CBlockLocator;
struct FeeCalculation;
struct masternode_info_t;
Expand All @@ -33,7 +34,27 @@ namespace interfaces {

class Wallet;

//! Interface for giving wallet processes access to blockchain state.
//! Interface giving clients (wallet processes, maybe other analysis tools in
//! the future) ability to access to the chain state, receive notifications,
//! estimate fees, and submit transactions.
//!
//! TODO: Current chain methods are too low level, exposing too much of the
//! internal workings of the bitcoin node, and not being very convenient to use.
//! Chain methods should be cleaned up and simplified over time. Examples:
//!
//! * The Chain::lock() method, which lets clients delay chain tip updates
//! should be removed when clients are able to respond to updates
//! asynchronously
//! (https://github.com/bitcoin/bitcoin/pull/10973#issuecomment-380101269).
//!
//! * The relayTransactions() and submitToMemoryPool() methods could be replaced
//! with a higher-level broadcastTransaction method
//! (https://github.com/bitcoin/bitcoin/pull/14978#issuecomment-459373984).
//!
//! * The initMessages() and loadWallet() methods which the wallet uses to send
//! notifications to the GUI should go away when GUI and wallet can directly
//! communicate with each other without going through the node
//! (https://github.com/bitcoin/bitcoin/pull/15288#discussion_r253321096).
class Chain
{
public:
Expand Down Expand Up @@ -121,8 +142,9 @@ class Chain
virtual bool checkFinalTx(const CTransaction& tx) = 0;

//! Add transaction to memory pool if the transaction fee is below the
//! amount specified by absurd_fee (as a safeguard). */
virtual bool submitToMemoryPool(CTransactionRef tx, CAmount absurd_fee, CValidationState& state) = 0;
//! amount specified by absurd_fee. Returns false if the transaction
//! could not be added due to the fee or for another reason.
virtual bool submitToMemoryPool(const CTransactionRef& tx, CAmount absurd_fee, CValidationState& state) = 0;
};

//! Return Lock interface. Chain is locked when this is called, and
Expand Down Expand Up @@ -161,19 +183,19 @@ class Chain
//! Calculate mempool ancestor and descendant counts for the given transaction.
virtual void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) = 0;

//! Check chain limits.
virtual bool checkChainLimits(CTransactionRef tx) = 0;
//! Check if transaction will pass the mempool's chain limits.
virtual bool checkChainLimits(const CTransactionRef& tx) = 0;

//! Estimate smart fee.
virtual CFeeRate estimateSmartFee(int num_blocks, bool conservative, FeeCalculation* calc = nullptr) = 0;

//! Fee estimator max target.
virtual unsigned int estimateMaxBlocks() = 0;

//! Pool min fee.
//! Mempool minimum fee.
virtual CFeeRate mempoolMinFee() = 0;

//! Get node max tx fee setting (-maxtxfee).
//! Node max tx fee setting (-maxtxfee).
//! This could be replaced by a per-wallet max fee, as proposed at
//! https://github.com/bitcoin/bitcoin/issues/15355
//! But for the time being, wallets call this to access the node setting.
Expand Down

0 comments on commit ec60141

Please sign in to comment.