Skip to content

Commit f3f36e8

Browse files
committed
Remove use of g_connman / PushInventory in wallet code
This commit does not change behavior.
1 parent 684e807 commit f3f36e8

File tree

8 files changed

+29
-21
lines changed

8 files changed

+29
-21
lines changed

src/ipc/interfaces.h

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

127+
//! Relay transaction.
128+
virtual bool relayTransaction(const uint256& txid) = 0;
129+
127130
//! Interface to let node manage chain clients (wallets, or maybe tools for
128131
//! monitoring and analysis in the future).
129132
class Client

src/ipc/local/bitcoind.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <chainparams.h>
44
#include <ipc/util.h>
5+
#include <net.h>
56
#include <policy/policy.h>
67
#include <validation.h>
78

@@ -135,6 +136,15 @@ class ChainImpl : public Chain
135136
auto it_mp = ::mempool.mapTx.find(txid);
136137
return it_mp != ::mempool.mapTx.end() && it_mp->GetCountWithDescendants() > 1;
137138
}
139+
bool relayTransaction(const uint256& txid) override
140+
{
141+
if (g_connman) {
142+
CInv inv(MSG_TX, txid);
143+
g_connman->ForEachNode([&inv](CNode* node) { node->PushInventory(inv); });
144+
return true;
145+
}
146+
return false;
147+
}
138148
};
139149

140150
} // namespace

src/qt/walletmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran
333333

334334
CReserveKey *keyChange = transaction.getPossibleKeyChange();
335335
CValidationState state;
336-
if(!wallet->CommitTransaction(*newTx, *keyChange, g_connman.get(), state))
336+
if(!wallet->CommitTransaction(*newTx, *keyChange, state))
337337
return SendCoinsReturn(TransactionCommitFailed, QString::fromStdString(state.GetRejectReason()));
338338

339339
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);

src/wallet/feebumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ bool CFeeBumper::commit(ipc::Chain::LockedState& ipc_locked, CWallet *pWallet)
263263
wtxBumped.fTimeReceivedIsTxTime = true;
264264
wtxBumped.fFromMe = true;
265265
CValidationState state;
266-
if (!pWallet->CommitTransaction(wtxBumped, reservekey, g_connman.get(), state)) {
266+
if (!pWallet->CommitTransaction(wtxBumped, reservekey, state)) {
267267
// NOTE: CommitTransaction never returns false, so this should never happen.
268268
vErrors.push_back(strprintf("Error: The transaction was rejected! Reason given: %s", state.GetRejectReason()));
269269
return false;

src/wallet/rpcwallet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ static void SendMoney(ipc::Chain::LockedState& ipc_locked, CWallet * const pwall
415415
throw JSONRPCError(RPC_WALLET_ERROR, strError);
416416
}
417417
CValidationState state;
418-
if (!pwallet->CommitTransaction(wtxNew, reservekey, g_connman.get(), state)) {
418+
if (!pwallet->CommitTransaction(wtxNew, reservekey, state)) {
419419
strError = strprintf("Error: The transaction was rejected! Reason given: %s", state.GetRejectReason());
420420
throw JSONRPCError(RPC_WALLET_ERROR, strError);
421421
}
@@ -1120,7 +1120,7 @@ UniValue sendmany(const JSONRPCRequest& request)
11201120
if (!fCreated)
11211121
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, strFailReason);
11221122
CValidationState state;
1123-
if (!pwallet->CommitTransaction(wtx, keyChange, g_connman.get(), state)) {
1123+
if (!pwallet->CommitTransaction(wtx, keyChange, state)) {
11241124
strFailReason = strprintf("Transaction commit failed:: %s", state.GetRejectReason());
11251125
throw JSONRPCError(RPC_WALLET_ERROR, strFailReason);
11261126
}
@@ -2718,7 +2718,7 @@ UniValue resendwallettransactions(const JSONRPCRequest& request)
27182718
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet transaction broadcasting is disabled with -walletbroadcast");
27192719
}
27202720

2721-
std::vector<uint256> txids = pwallet->ResendWalletTransactionsBefore(*ipc_locked, GetTime(), g_connman.get());
2721+
std::vector<uint256> txids = pwallet->ResendWalletTransactionsBefore(*ipc_locked, GetTime());
27222722
UniValue result(UniValue::VARR);
27232723
for (const uint256& txid : txids)
27242724
{

src/wallet/test/wallet_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ class ListCoinsTestingSetup : public TestChain100Setup
630630
CCoinControl dummy;
631631
BOOST_CHECK(wallet->CreateTransaction(*m_ipc_locked, {recipient}, wtx, reservekey, fee, changePos, error, dummy));
632632
CValidationState state;
633-
BOOST_CHECK(wallet->CommitTransaction(wtx, reservekey, nullptr, state));
633+
BOOST_CHECK(wallet->CommitTransaction(wtx, reservekey, state));
634634
auto it = wallet->mapWallet.find(wtx.GetHash());
635635
BOOST_CHECK(it != wallet->mapWallet.end());
636636
CreateAndProcessBlock({CMutableTransaction(*it->second.tx)}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));

src/wallet/wallet.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,7 @@ void CWallet::ReacceptWalletTransactions()
16811681
}
16821682
}
16831683

1684-
bool CWalletTx::RelayWalletTransaction(ipc::Chain::LockedState& ipc_locked, CConnman* connman)
1684+
bool CWalletTx::RelayWalletTransaction(ipc::Chain::LockedState& ipc_locked)
16851685
{
16861686
assert(pwallet->GetBroadcastTransactions());
16871687
if (!IsCoinBase() && !isAbandoned() && GetDepthInMainChain(ipc_locked) == 0)
@@ -1690,12 +1690,7 @@ bool CWalletTx::RelayWalletTransaction(ipc::Chain::LockedState& ipc_locked, CCon
16901690
/* GetDepthInMainChain already catches known conflicts. */
16911691
if (InMempool() || AcceptToMemoryPool(ipc_locked, state)) {
16921692
LogPrintf("Relaying wtx %s\n", GetHash().ToString());
1693-
if (connman) {
1694-
CInv inv(MSG_TX, GetHash());
1695-
connman->ForEachNode([&inv](CNode* pnode)
1696-
{
1697-
pnode->PushInventory(inv);
1698-
});
1693+
if (pwallet->ipc_chain().relayTransaction(GetHash())) {
16991694
return true;
17001695
}
17011696
}
@@ -1920,7 +1915,7 @@ bool CWalletTx::IsEquivalentTo(const CWalletTx& _tx) const
19201915
return CTransaction(tx1) == CTransaction(tx2);
19211916
}
19221917

1923-
std::vector<uint256> CWallet::ResendWalletTransactionsBefore(ipc::Chain::LockedState& ipc_locked, int64_t nTime, CConnman* connman)
1918+
std::vector<uint256> CWallet::ResendWalletTransactionsBefore(ipc::Chain::LockedState& ipc_locked, int64_t nTime)
19241919
{
19251920
std::vector<uint256> result;
19261921

@@ -1939,7 +1934,7 @@ std::vector<uint256> CWallet::ResendWalletTransactionsBefore(ipc::Chain::LockedS
19391934
for (std::pair<const unsigned int, CWalletTx*>& item : mapSorted)
19401935
{
19411936
CWalletTx& wtx = *item.second;
1942-
if (wtx.RelayWalletTransaction(ipc_locked, connman))
1937+
if (wtx.RelayWalletTransaction(ipc_locked))
19431938
result.push_back(wtx.GetHash());
19441939
}
19451940
return result;
@@ -1964,7 +1959,7 @@ void CWallet::ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman
19641959
// Rebroadcast unconfirmed txes older than 5 minutes before the last
19651960
// block was found:
19661961
auto ipc_locked = m_ipc_chain->assumeLocked(); // Temporary. Removed in upcoming lock cleanup
1967-
std::vector<uint256> relayed = ResendWalletTransactionsBefore(*ipc_locked, nBestBlockTime-5*60, connman);
1962+
std::vector<uint256> relayed = ResendWalletTransactionsBefore(*ipc_locked, nBestBlockTime-5*60);
19681963
if (!relayed.empty())
19691964
LogPrintf("%s: rebroadcast %u unconfirmed transactions\n", __func__, relayed.size());
19701965
}
@@ -2973,7 +2968,7 @@ bool CWallet::CreateTransaction(ipc::Chain::LockedState& ipc_locked, const std::
29732968
/**
29742969
* Call after CreateTransaction unless you want to abort
29752970
*/
2976-
bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman, CValidationState& state)
2971+
bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CValidationState& state)
29772972
{
29782973
{
29792974
auto ipc_locked = m_ipc_chain->lockState();
@@ -3010,7 +3005,7 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CCon
30103005
LogPrintf("CommitTransaction(): Transaction cannot be broadcast immediately, %s\n", state.GetRejectReason());
30113006
// TODO: if we expect the failure to be long term or permanent, instead delete wtx from the wallet and return failure.
30123007
} else {
3013-
wtx.RelayWalletTransaction(*ipc_locked, connman);
3008+
wtx.RelayWalletTransaction(*ipc_locked);
30143009
}
30153010
}
30163011
}

src/wallet/wallet.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ class CWalletTx : public CMerkleTx
471471
int GetRequestCount() const;
472472

473473
// RelayWalletTransaction may only be called if fBroadcastTransactions!
474-
bool RelayWalletTransaction(ipc::Chain::LockedState& ipc_locked, CConnman* connman);
474+
bool RelayWalletTransaction(ipc::Chain::LockedState& ipc_locked);
475475

476476
/** Pass this transaction to the mempool. Fails if absolute fee exceeds absurd fee. */
477477
bool AcceptToMemoryPool(ipc::Chain::LockedState& ipc_locked, 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;
946946
// ResendWalletTransactionsBefore may only be called if fBroadcastTransactions!
947-
std::vector<uint256> ResendWalletTransactionsBefore(ipc::Chain::LockedState& ipc_locked, int64_t nTime, CConnman* connman);
947+
std::vector<uint256> ResendWalletTransactionsBefore(ipc::Chain::LockedState& ipc_locked, int64_t nTime);
948948
CAmount GetBalance() const;
949949
CAmount GetUnconfirmedBalance() const;
950950
CAmount GetImmatureBalance() const;
@@ -968,7 +968,7 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
968968
*/
969969
bool CreateTransaction(ipc::Chain::LockedState& ipc_locked, const std::vector<CRecipient>& vecSend, CWalletTx& wtxNew, CReserveKey& reservekey, CAmount& nFeeRet, int& nChangePosInOut,
970970
std::string& strFailReason, const CCoinControl& coin_control, bool sign = true);
971-
bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CConnman* connman, CValidationState& state);
971+
bool CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey, CValidationState& state);
972972

973973
void ListAccountCreditDebit(const std::string& strAccount, std::list<CAccountingEntry>& entries);
974974
bool AddAccountingEntry(const CAccountingEntry&);

0 commit comments

Comments
 (0)