Skip to content

Commit d8a62db

Browse files
author
MarcoFalke
committed
Merge #15531: Suggested interfaces::Chain cleanups from #15288
4d4e4c6 Suggested interfaces::Chain cleanups from #15288 (Russell Yanofsky) Pull request description: Mostly documentation improvements requested in the last review of #15288 before it was merged (bitcoin/bitcoin#15288 (review)) Tree-SHA512: 64e912520bbec20a44032f265a8cf3f11ad7f5126c8626b5ad5e888227b1f92ecb321522fab4bbbd613230b55450abd6ace023631d0a4f357a780d65c5638bfe
2 parents a74d588 + 4d4e4c6 commit d8a62db

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

src/interfaces/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
The following interfaces are defined here:
44

5-
* [`Chain`](chain.h) — used by wallet to access blockchain and mempool state. Added in [#10973](https://github.com/bitcoin/bitcoin/pull/10973).
5+
* [`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).
66

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

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

src/interfaces/chain.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class LockImpl : public Chain::Lock
148148
LockAnnotation lock(::cs_main);
149149
return CheckFinalTx(tx);
150150
}
151-
bool submitToMemoryPool(CTransactionRef tx, CAmount absurd_fee, CValidationState& state) override
151+
bool submitToMemoryPool(const CTransactionRef& tx, CAmount absurd_fee, CValidationState& state) override
152152
{
153153
LockAnnotation lock(::cs_main);
154154
return AcceptToMemoryPool(::mempool, state, tx, nullptr /* missing inputs */, nullptr /* txn replaced */,
@@ -207,8 +207,8 @@ class ChainImpl : public Chain
207207
bool hasDescendantsInMempool(const uint256& txid) override
208208
{
209209
LOCK(::mempool.cs);
210-
auto it_mp = ::mempool.mapTx.find(txid);
211-
return it_mp != ::mempool.mapTx.end() && it_mp->GetCountWithDescendants() > 1;
210+
auto it = ::mempool.GetIter(txid);
211+
return it && (*it)->GetCountWithDescendants() > 1;
212212
}
213213
void relayTransaction(const uint256& txid) override
214214
{
@@ -219,7 +219,7 @@ class ChainImpl : public Chain
219219
{
220220
::mempool.GetTransactionAncestry(txid, ancestors, descendants);
221221
}
222-
bool checkChainLimits(CTransactionRef tx) override
222+
bool checkChainLimits(const CTransactionRef& tx) override
223223
{
224224
LockPoints lp;
225225
CTxMemPoolEntry entry(tx, 0, 0, 0, false, 0, lp);

src/interfaces/chain.h

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#define BITCOIN_INTERFACES_CHAIN_H
77

88
#include <optional.h> // For Optional and nullopt
9-
#include <policy/rbf.h> // For RBFTransactionState
109
#include <primitives/transaction.h> // For CTransactionRef
1110

1211
#include <memory>
@@ -16,17 +15,39 @@
1615
#include <vector>
1716

1817
class CBlock;
18+
class CFeeRate;
1919
class CScheduler;
2020
class CValidationState;
2121
class uint256;
22+
enum class RBFTransactionState;
2223
struct CBlockLocator;
2324
struct FeeCalculation;
2425

2526
namespace interfaces {
2627

2728
class Wallet;
2829

29-
//! Interface for giving wallet processes access to blockchain state.
30+
//! Interface giving clients (wallet processes, maybe other analysis tools in
31+
//! the future) ability to access to the chain state, receive notifications,
32+
//! estimate fees, and submit transactions.
33+
//!
34+
//! TODO: Current chain methods are too low level, exposing too much of the
35+
//! internal workings of the bitcoin node, and not being very convenient to use.
36+
//! Chain methods should be cleaned up and simplified over time. Examples:
37+
//!
38+
//! * The Chain::lock() method, which lets clients delay chain tip updates
39+
//! should be removed when clients are able to respond to updates
40+
//! asynchronously
41+
//! (https://github.com/bitcoin/bitcoin/pull/10973#issuecomment-380101269).
42+
//!
43+
//! * The relayTransactions() and submitToMemoryPool() methods could be replaced
44+
//! with a higher-level broadcastTransaction method
45+
//! (https://github.com/bitcoin/bitcoin/pull/14978#issuecomment-459373984).
46+
//!
47+
//! * The initMessages() and loadWallet() methods which the wallet uses to send
48+
//! notifications to the GUI should go away when GUI and wallet can directly
49+
//! communicate with each other without going through the node
50+
//! (https://github.com/bitcoin/bitcoin/pull/15288#discussion_r253321096).
3051
class Chain
3152
{
3253
public:
@@ -114,8 +135,9 @@ class Chain
114135
virtual bool checkFinalTx(const CTransaction& tx) = 0;
115136

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

121143
//! Return Lock interface. Chain is locked when this is called, and
@@ -154,19 +176,19 @@ class Chain
154176
//! Calculate mempool ancestor and descendant counts for the given transaction.
155177
virtual void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) = 0;
156178

157-
//! Check chain limits.
158-
virtual bool checkChainLimits(CTransactionRef tx) = 0;
179+
//! Check if transaction will pass the mempool's chain limits.
180+
virtual bool checkChainLimits(const CTransactionRef& tx) = 0;
159181

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

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

166-
//! Pool min fee.
188+
//! Mempool minimum fee.
167189
virtual CFeeRate mempoolMinFee() = 0;
168190

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

0 commit comments

Comments
 (0)