Skip to content

Commit 8dbb2c5

Browse files
author
MarcoFalke
committed
Merge #15680: Remove resendwallettransactions RPC method
ea1a2d8 [wallet] Remove ResendWalletTransactionsBefore (John Newbery) f516245 [rpc] remove resendwallettransactions RPC (John Newbery) Pull request description: Remove resendwallettransactions RPC method This RPC was added for testing wallet rebroadcasts. Since we now have a real test for wallet rebroadcasts, it's no longer needed. The call in wallet_basic.py can be removed because wallet_resendwallettransactions.py tests wallet rebroadcast. ACKs for commit ea1a2d: MarcoFalke: re-utACK ea1a2d8 promag: utACK ea1a2d8. Tree-SHA512: 48245d947be1a2d2b8c30d2946105818c454a03b70b63534ecadf2144da64dafe1c9527ea670a5f4d1acd05ccdfc6c9be43ca636ee2ba58a8b7a7b2fc7bc88fd
2 parents 5a2a9b5 + ea1a2d8 commit 8dbb2c5

File tree

4 files changed

+22
-100
lines changed

4 files changed

+22
-100
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,50 +2668,6 @@ static UniValue unloadwallet(const JSONRPCRequest& request)
26682668
return NullUniValue;
26692669
}
26702670

2671-
static UniValue resendwallettransactions(const JSONRPCRequest& request)
2672-
{
2673-
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
2674-
CWallet* const pwallet = wallet.get();
2675-
2676-
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
2677-
return NullUniValue;
2678-
}
2679-
2680-
if (request.fHelp || request.params.size() != 0)
2681-
throw std::runtime_error(
2682-
RPCHelpMan{"resendwallettransactions",
2683-
"Immediately re-broadcast unconfirmed wallet transactions to all peers.\n"
2684-
"Intended only for testing; the wallet code periodically re-broadcasts\n"
2685-
"automatically.\n",
2686-
{},
2687-
RPCResult{
2688-
"Returns an RPC error if -walletbroadcast is set to false.\n"
2689-
"Returns array of transaction ids that were re-broadcast.\n"
2690-
},
2691-
RPCExamples{""},
2692-
}.ToString()
2693-
);
2694-
2695-
if (!pwallet->chain().p2pEnabled()) {
2696-
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
2697-
}
2698-
2699-
auto locked_chain = pwallet->chain().lock();
2700-
LOCK(pwallet->cs_wallet);
2701-
2702-
if (!pwallet->GetBroadcastTransactions()) {
2703-
throw JSONRPCError(RPC_WALLET_ERROR, "Error: Wallet transaction broadcasting is disabled with -walletbroadcast");
2704-
}
2705-
2706-
std::vector<uint256> txids = pwallet->ResendWalletTransactionsBefore(*locked_chain, GetTime());
2707-
UniValue result(UniValue::VARR);
2708-
for (const uint256& txid : txids)
2709-
{
2710-
result.push_back(txid.ToString());
2711-
}
2712-
return result;
2713-
}
2714-
27152671
static UniValue listunspent(const JSONRPCRequest& request)
27162672
{
27172673
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
@@ -4085,7 +4041,6 @@ UniValue importmulti(const JSONRPCRequest& request);
40854041
static const CRPCCommand commands[] =
40864042
{ // category name actor (function) argNames
40874043
// --------------------- ------------------------ ----------------------- ----------
4088-
{ "hidden", "resendwallettransactions", &resendwallettransactions, {} },
40894044
{ "rawtransactions", "fundrawtransaction", &fundrawtransaction, {"hexstring","options","iswitness"} },
40904045
{ "wallet", "abandontransaction", &abandontransaction, {"txid"} },
40914046
{ "wallet", "abortrescan", &abortrescan, {} },

src/wallet/wallet.cpp

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,53 +2110,37 @@ bool CWalletTx::IsEquivalentTo(const CWalletTx& _tx) const
21102110
return CTransaction(tx1) == CTransaction(tx2);
21112111
}
21122112

2113-
std::vector<uint256> CWallet::ResendWalletTransactionsBefore(interfaces::Chain::Lock& locked_chain, int64_t nTime)
2114-
{
2115-
std::vector<uint256> result;
2116-
2117-
LOCK(cs_wallet);
2118-
2119-
// Sort them in chronological order
2120-
std::multimap<unsigned int, CWalletTx*> mapSorted;
2121-
for (std::pair<const uint256, CWalletTx>& item : mapWallet)
2122-
{
2123-
CWalletTx& wtx = item.second;
2124-
// Don't rebroadcast if newer than nTime:
2125-
if (wtx.nTimeReceived > nTime)
2126-
continue;
2127-
mapSorted.insert(std::make_pair(wtx.nTimeReceived, &wtx));
2128-
}
2129-
for (const std::pair<const unsigned int, CWalletTx*>& item : mapSorted)
2130-
{
2131-
CWalletTx& wtx = *item.second;
2132-
if (wtx.RelayWalletTransaction(locked_chain)) {
2133-
result.push_back(wtx.GetHash());
2134-
}
2135-
}
2136-
return result;
2137-
}
2138-
21392113
void CWallet::ResendWalletTransactions(interfaces::Chain::Lock& locked_chain, int64_t nBestBlockTime)
21402114
{
21412115
// Do this infrequently and randomly to avoid giving away
21422116
// that these are our transactions.
2143-
if (GetTime() < nNextResend || !fBroadcastTransactions)
2144-
return;
2117+
if (GetTime() < nNextResend || !fBroadcastTransactions) return;
21452118
bool fFirst = (nNextResend == 0);
21462119
nNextResend = GetTime() + GetRand(30 * 60);
2147-
if (fFirst)
2148-
return;
2120+
if (fFirst) return;
21492121

21502122
// Only do it if there's been a new block since last time
2151-
if (nBestBlockTime < nLastResend)
2152-
return;
2123+
if (nBestBlockTime < nLastResend) return;
21532124
nLastResend = GetTime();
21542125

2155-
// Rebroadcast unconfirmed txes older than 5 minutes before the last
2156-
// block was found:
2157-
std::vector<uint256> relayed = ResendWalletTransactionsBefore(locked_chain, nBestBlockTime-5*60);
2158-
if (!relayed.empty())
2159-
WalletLogPrintf("%s: rebroadcast %u unconfirmed transactions\n", __func__, relayed.size());
2126+
int relayed_tx_count = 0;
2127+
2128+
{ // cs_wallet scope
2129+
LOCK(cs_wallet);
2130+
2131+
// Relay transactions
2132+
for (std::pair<const uint256, CWalletTx>& item : mapWallet) {
2133+
CWalletTx& wtx = item.second;
2134+
// only rebroadcast unconfirmed txes older than 5 minutes before the
2135+
// last block was found
2136+
if (wtx.nTimeReceived > nBestBlockTime - 5 * 60) continue;
2137+
relayed_tx_count += wtx.RelayWalletTransaction(locked_chain) ? 1 : 0;
2138+
}
2139+
} // cs_wallet
2140+
2141+
if (relayed_tx_count > 0) {
2142+
WalletLogPrintf("%s: rebroadcast %u unconfirmed transactions\n", __func__, relayed_tx_count);
2143+
}
21602144
}
21612145

21622146
/** @} */ // end of mapWallet

src/wallet/wallet.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,6 @@ class CWallet final : public CCryptoKeyStore, private interfaces::Chain::Notific
947947
void TransactionRemovedFromMempool(const CTransactionRef &ptx) override;
948948
void ReacceptWalletTransactions(interfaces::Chain::Lock& locked_chain) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
949949
void ResendWalletTransactions(interfaces::Chain::Lock& locked_chain, int64_t nBestBlockTime) override;
950-
// ResendWalletTransactionsBefore may only be called if fBroadcastTransactions!
951-
std::vector<uint256> ResendWalletTransactionsBefore(interfaces::Chain::Lock& locked_chain, int64_t nTime);
952950
CAmount GetBalance(const isminefilter& filter=ISMINE_SPENDABLE, const int min_depth=0) const;
953951
CAmount GetUnconfirmedBalance() const;
954952
CAmount GetImmatureBalance() const;

test/functional/wallet_basic.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
assert_raises_rpc_error,
1515
connect_nodes_bi,
1616
sync_blocks,
17-
sync_mempools,
1817
wait_until,
1918
)
2019

@@ -216,23 +215,9 @@ def run_test(self):
216215
assert_equal(self.nodes[2].getbalance(), node_2_bal)
217216
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), node_0_bal + Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
218217

219-
# Test ResendWalletTransactions:
220-
# Create a couple of transactions, then start up a fourth
221-
# node (nodes[3]) and ask nodes[0] to rebroadcast.
222-
# EXPECT: nodes[3] should have those transactions in its mempool.
223-
txid1 = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1)
224-
txid2 = self.nodes[1].sendtoaddress(self.nodes[0].getnewaddress(), 1)
225-
sync_mempools(self.nodes[0:2])
226-
227218
self.start_node(3)
228219
connect_nodes_bi(self.nodes, 0, 3)
229-
sync_blocks(self.nodes)
230-
231-
relayed = self.nodes[0].resendwallettransactions()
232-
assert_equal(set(relayed), {txid1, txid2})
233-
sync_mempools(self.nodes)
234-
235-
assert txid1 in self.nodes[3].getrawmempool()
220+
self.sync_all()
236221

237222
# check if we can list zero value tx as available coins
238223
# 1. create raw_tx

0 commit comments

Comments
 (0)