Skip to content

Commit 6d6bcc7

Browse files
committed
Remove use of g_connman / PushInventory in wallet code
This commit does not change behavior.
1 parent 00dfb2a commit 6d6bcc7

File tree

8 files changed

+26
-21
lines changed

8 files changed

+26
-21
lines changed

src/interfaces/chain.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <policy/policy.h>
1212
#include <policy/rbf.h>
1313
#include <primitives/block.h>
14+
#include <protocol.h>
1415
#include <sync.h>
1516
#include <threadsafety.h>
1617
#include <txmempool.h>
@@ -199,6 +200,11 @@ class ChainImpl : public Chain
199200
auto it_mp = ::mempool.mapTx.find(txid);
200201
return it_mp != ::mempool.mapTx.end() && it_mp->GetCountWithDescendants() > 1;
201202
}
203+
void relayTransaction(const uint256& txid) override
204+
{
205+
CInv inv(MSG_TX, txid);
206+
g_connman->ForEachNode([&inv](CNode* node) { node->PushInventory(inv); });
207+
}
202208
void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) override
203209
{
204210
::mempool.GetTransactionAncestry(txid, ancestors, descendants);

src/interfaces/chain.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ class Chain
141141
//! Check if transaction has descendants in mempool.
142142
virtual bool hasDescendantsInMempool(const uint256& txid) = 0;
143143

144+
//! Relay transaction.
145+
virtual void relayTransaction(const uint256& txid) = 0;
146+
144147
//! Calculate mempool ancestor and descendant counts for the given transaction.
145148
virtual void getTransactionAncestry(const uint256& txid, size_t& ancestors, size_t& descendants) = 0;
146149

src/interfaces/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class PendingWalletTxImpl : public PendingWalletTx
5656
auto locked_chain = m_wallet.chain().lock();
5757
LOCK(m_wallet.cs_wallet);
5858
CValidationState state;
59-
if (!m_wallet.CommitTransaction(m_tx, std::move(value_map), std::move(order_form), m_key, g_connman.get(), state)) {
59+
if (!m_wallet.CommitTransaction(m_tx, std::move(value_map), std::move(order_form), m_key, state)) {
6060
reject_reason = state.GetRejectReason();
6161
return false;
6262
}

src/wallet/feebumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ Result CommitTransaction(CWallet* wallet, const uint256& txid, CMutableTransacti
245245

246246
CReserveKey reservekey(wallet);
247247
CValidationState state;
248-
if (!wallet->CommitTransaction(tx, std::move(mapValue), oldWtx.vOrderForm, reservekey, g_connman.get(), state)) {
248+
if (!wallet->CommitTransaction(tx, std::move(mapValue), oldWtx.vOrderForm, reservekey, state)) {
249249
// NOTE: CommitTransaction never returns false, so this should never happen.
250250
errors.push_back(strprintf("The transaction was rejected: %s", FormatStateMessage(state)));
251251
return Result::WALLET_ERROR;

src/wallet/rpcwallet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static CTransactionRef SendMoney(interfaces::Chain::Lock& locked_chain, CWallet
340340
throw JSONRPCError(RPC_WALLET_ERROR, strError);
341341
}
342342
CValidationState state;
343-
if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, reservekey, g_connman.get(), state)) {
343+
if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, reservekey, state)) {
344344
strError = strprintf("Error: The transaction was rejected! Reason given: %s", FormatStateMessage(state));
345345
throw JSONRPCError(RPC_WALLET_ERROR, strError);
346346
}
@@ -946,7 +946,7 @@ static UniValue sendmany(const JSONRPCRequest& request)
946946
if (!fCreated)
947947
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason);
948948
CValidationState state;
949-
if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, keyChange, g_connman.get(), state)) {
949+
if (!pwallet->CommitTransaction(tx, std::move(mapValue), {} /* orderForm */, keyChange, state)) {
950950
strFailReason = strprintf("Transaction commit failed:: %s", FormatStateMessage(state));
951951
throw JSONRPCError(RPC_WALLET_ERROR, strFailReason);
952952
}
@@ -2700,7 +2700,7 @@ static UniValue resendwallettransactions(const JSONRPCRequest& request)
27002700
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet transaction broadcasting is disabled with -walletbroadcast");
27012701
}
27022702

2703-
std::vector<uint256> txids = pwallet->ResendWalletTransactionsBefore(*locked_chain, GetTime(), g_connman.get());
2703+
std::vector<uint256> txids = pwallet->ResendWalletTransactionsBefore(*locked_chain, GetTime());
27042704
UniValue result(UniValue::VARR);
27052705
for (const uint256& txid : txids)
27062706
{

src/wallet/test/wallet_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ class ListCoinsTestingSetup : public TestChain100Setup
368368
CCoinControl dummy;
369369
BOOST_CHECK(wallet->CreateTransaction(*m_locked_chain, {recipient}, tx, reservekey, fee, changePos, error, dummy));
370370
CValidationState state;
371-
BOOST_CHECK(wallet->CommitTransaction(tx, {}, {}, reservekey, nullptr, state));
371+
BOOST_CHECK(wallet->CommitTransaction(tx, {}, {}, reservekey, state));
372372
CMutableTransaction blocktx;
373373
{
374374
LOCK(wallet->cs_wallet);

src/wallet/wallet.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ void CWallet::ReacceptWalletTransactions()
18901890
}
18911891
}
18921892

1893-
bool CWalletTx::RelayWalletTransaction(interfaces::Chain::Lock& locked_chain, CConnman* connman)
1893+
bool CWalletTx::RelayWalletTransaction(interfaces::Chain::Lock& locked_chain)
18941894
{
18951895
assert(pwallet->GetBroadcastTransactions());
18961896
if (!IsCoinBase() && !isAbandoned() && GetDepthInMainChain(locked_chain) == 0)
@@ -1899,12 +1899,8 @@ bool CWalletTx::RelayWalletTransaction(interfaces::Chain::Lock& locked_chain, CC
18991899
/* GetDepthInMainChain already catches known conflicts. */
19001900
if (InMempool() || AcceptToMemoryPool(locked_chain, maxTxFee, state)) {
19011901
pwallet->WalletLogPrintf("Relaying wtx %s\n", GetHash().ToString());
1902-
if (connman) {
1903-
CInv inv(MSG_TX, GetHash());
1904-
connman->ForEachNode([&inv](CNode* pnode)
1905-
{
1906-
pnode->PushInventory(inv);
1907-
});
1902+
if (pwallet->chain().p2pEnabled()) {
1903+
pwallet->chain().relayTransaction(GetHash());
19081904
return true;
19091905
}
19101906
}
@@ -2113,7 +2109,7 @@ bool CWalletTx::IsEquivalentTo(const CWalletTx& _tx) const
21132109
return CTransaction(tx1) == CTransaction(tx2);
21142110
}
21152111

2116-
std::vector<uint256> CWallet::ResendWalletTransactionsBefore(interfaces::Chain::Lock& locked_chain, int64_t nTime, CConnman* connman)
2112+
std::vector<uint256> CWallet::ResendWalletTransactionsBefore(interfaces::Chain::Lock& locked_chain, int64_t nTime)
21172113
{
21182114
std::vector<uint256> result;
21192115

@@ -2132,7 +2128,7 @@ std::vector<uint256> CWallet::ResendWalletTransactionsBefore(interfaces::Chain::
21322128
for (const std::pair<const unsigned int, CWalletTx*>& item : mapSorted)
21332129
{
21342130
CWalletTx& wtx = *item.second;
2135-
if (wtx.RelayWalletTransaction(locked_chain, connman))
2131+
if (wtx.RelayWalletTransaction(locked_chain))
21362132
result.push_back(wtx.GetHash());
21372133
}
21382134
return result;
@@ -2157,7 +2153,7 @@ void CWallet::ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman
21572153
// Rebroadcast unconfirmed txes older than 5 minutes before the last
21582154
// block was found:
21592155
auto locked_chain = chain().assumeLocked(); // Temporary. Removed in upcoming lock cleanup
2160-
std::vector<uint256> relayed = ResendWalletTransactionsBefore(*locked_chain, nBestBlockTime-5*60, connman);
2156+
std::vector<uint256> relayed = ResendWalletTransactionsBefore(*locked_chain, nBestBlockTime-5*60);
21612157
if (!relayed.empty())
21622158
WalletLogPrintf("%s: rebroadcast %u unconfirmed transactions\n", __func__, relayed.size());
21632159
}
@@ -3147,7 +3143,7 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
31473143
/**
31483144
* Call after CreateTransaction unless you want to abort
31493145
*/
3150-
bool CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm, CReserveKey& reservekey, CConnman* connman, CValidationState& state)
3146+
bool CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm, CReserveKey& reservekey, CValidationState& state)
31513147
{
31523148
{
31533149
auto locked_chain = chain().lock();
@@ -3188,7 +3184,7 @@ bool CWallet::CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::ve
31883184
WalletLogPrintf("CommitTransaction(): Transaction cannot be broadcast immediately, %s\n", FormatStateMessage(state));
31893185
// TODO: if we expect the failure to be long term or permanent, instead delete wtx from the wallet and return failure.
31903186
} else {
3191-
wtx.RelayWalletTransaction(*locked_chain, connman);
3187+
wtx.RelayWalletTransaction(*locked_chain);
31923188
}
31933189
}
31943190
}

src/wallet/wallet.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ class CWalletTx : public CMerkleTx
535535
int64_t GetTxTime() const;
536536

537537
// RelayWalletTransaction may only be called if fBroadcastTransactions!
538-
bool RelayWalletTransaction(interfaces::Chain::Lock& locked_chain, CConnman* connman);
538+
bool RelayWalletTransaction(interfaces::Chain::Lock& locked_chain);
539539

540540
/** Pass this transaction to the mempool. Fails if absolute fee exceeds absurd fee. */
541541
bool AcceptToMemoryPool(interfaces::Chain::Lock& locked_chain, const CAmount& nAbsurdFee, CValidationState& state);
@@ -944,7 +944,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
944944
void ReacceptWalletTransactions();
945945
void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman) override EXCLUSIVE_LOCKS_REQUIRED(cs_main);
946946
// ResendWalletTransactionsBefore may only be called if fBroadcastTransactions!
947-
std::vector<uint256> ResendWalletTransactionsBefore(interfaces::Chain::Lock& locked_chain, int64_t nTime, CConnman* connman);
947+
std::vector<uint256> ResendWalletTransactionsBefore(interfaces::Chain::Lock& locked_chain, int64_t nTime);
948948
CAmount GetBalance(const isminefilter& filter=ISMINE_SPENDABLE, const int min_depth=0) const;
949949
CAmount GetUnconfirmedBalance() const;
950950
CAmount GetImmatureBalance() const;
@@ -969,7 +969,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
969969
*/
970970
bool CreateTransaction(interfaces::Chain::Lock& locked_chain, const std::vector<CRecipient>& vecSend, CTransactionRef& tx, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut,
971971
std::string& strFailReason, const CCoinControl& coin_control, bool sign = true);
972-
bool CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm, CReserveKey& reservekey, CConnman* connman, CValidationState& state);
972+
bool CommitTransaction(CTransactionRef tx, mapValue_t mapValue, std::vector<std::pair<std::string, std::string>> orderForm, CReserveKey& reservekey, CValidationState& state);
973973

974974
bool DummySignTx(CMutableTransaction &txNew, const std::set<CTxOut> &txouts, bool use_max_sig = false) const
975975
{

0 commit comments

Comments
 (0)