Merge pull request #5951
77650cc
add -walletbroadcast=0 rpc test (Jonas Schnelli)6f25262
wallet: make it possible to disable transaction broadcast (Wladimir J. van der Laan)
This commit is contained in:
commit
7efc9cf672
|
@ -151,5 +151,46 @@ class WalletTest (BitcoinTestFramework):
|
||||||
|
|
||||||
assert(txid1 in self.nodes[3].getrawmempool())
|
assert(txid1 in self.nodes[3].getrawmempool())
|
||||||
|
|
||||||
|
|
||||||
|
#do some -walletbroadcast tests
|
||||||
|
stop_nodes(self.nodes)
|
||||||
|
wait_bitcoinds()
|
||||||
|
self.nodes = start_nodes(3, self.options.tmpdir, [["-walletbroadcast=0"],["-walletbroadcast=0"],["-walletbroadcast=0"]])
|
||||||
|
connect_nodes_bi(self.nodes,0,1)
|
||||||
|
connect_nodes_bi(self.nodes,1,2)
|
||||||
|
connect_nodes_bi(self.nodes,0,2)
|
||||||
|
self.sync_all()
|
||||||
|
|
||||||
|
txIdNotBroadcasted = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2);
|
||||||
|
txObjNotBroadcasted = self.nodes[0].gettransaction(txIdNotBroadcasted)
|
||||||
|
self.nodes[1].setgenerate(True, 1) #mine a block, tx should not be in there
|
||||||
|
self.sync_all()
|
||||||
|
assert_equal(self.nodes[2].getbalance(), Decimal('59.99800000')); #should not be changed because tx was not broadcasted
|
||||||
|
|
||||||
|
#now broadcast from another node, mine a block, sync, and check the balance
|
||||||
|
self.nodes[1].sendrawtransaction(txObjNotBroadcasted['hex'])
|
||||||
|
self.nodes[1].setgenerate(True, 1)
|
||||||
|
self.sync_all()
|
||||||
|
txObjNotBroadcasted = self.nodes[0].gettransaction(txIdNotBroadcasted)
|
||||||
|
assert_equal(self.nodes[2].getbalance(), Decimal('61.99800000')); #should not be
|
||||||
|
|
||||||
|
#create another tx
|
||||||
|
txIdNotBroadcasted = self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), 2);
|
||||||
|
|
||||||
|
#restart the nodes with -walletbroadcast=1
|
||||||
|
stop_nodes(self.nodes)
|
||||||
|
wait_bitcoinds()
|
||||||
|
self.nodes = start_nodes(3, self.options.tmpdir)
|
||||||
|
connect_nodes_bi(self.nodes,0,1)
|
||||||
|
connect_nodes_bi(self.nodes,1,2)
|
||||||
|
connect_nodes_bi(self.nodes,0,2)
|
||||||
|
sync_blocks(self.nodes)
|
||||||
|
|
||||||
|
self.nodes[0].setgenerate(True, 1)
|
||||||
|
sync_blocks(self.nodes)
|
||||||
|
|
||||||
|
#tx should be added to balance because after restarting the nodes tx should be broadcastet
|
||||||
|
assert_equal(self.nodes[2].getbalance(), Decimal('63.99800000')); #should not be
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
WalletTest ().main ()
|
WalletTest ().main ()
|
||||||
|
|
|
@ -337,6 +337,7 @@ std::string HelpMessage(HelpMessageMode mode)
|
||||||
FormatMoney(maxTxFee)));
|
FormatMoney(maxTxFee)));
|
||||||
strUsage += HelpMessageOpt("-upgradewallet", _("Upgrade wallet to latest format") + " " + _("on startup"));
|
strUsage += HelpMessageOpt("-upgradewallet", _("Upgrade wallet to latest format") + " " + _("on startup"));
|
||||||
strUsage += HelpMessageOpt("-wallet=<file>", _("Specify wallet file (within data directory)") + " " + strprintf(_("(default: %s)"), "wallet.dat"));
|
strUsage += HelpMessageOpt("-wallet=<file>", _("Specify wallet file (within data directory)") + " " + strprintf(_("(default: %s)"), "wallet.dat"));
|
||||||
|
strUsage += HelpMessageOpt("-walletbroadcast", _("Make the wallet broadcast transactions") + " " + strprintf(_("(default: %u)"), true));
|
||||||
strUsage += HelpMessageOpt("-walletnotify=<cmd>", _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)"));
|
strUsage += HelpMessageOpt("-walletnotify=<cmd>", _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)"));
|
||||||
strUsage += HelpMessageOpt("-zapwallettxes=<mode>", _("Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup") +
|
strUsage += HelpMessageOpt("-zapwallettxes=<mode>", _("Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup") +
|
||||||
" " + _("(1 = keep tx meta data e.g. account owner and payment request information, 2 = drop tx meta data)"));
|
" " + _("(1 = keep tx meta data e.g. account owner and payment request information, 2 = drop tx meta data)"));
|
||||||
|
@ -1243,6 +1244,7 @@ bool AppInit2(boost::thread_group& threadGroup)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pwalletMain->SetBroadcastTransactions(GetBoolArg("-walletbroadcast", true));
|
||||||
} // (!fDisableWallet)
|
} // (!fDisableWallet)
|
||||||
#else // ENABLE_WALLET
|
#else // ENABLE_WALLET
|
||||||
LogPrintf("No wallet compiled in!\n");
|
LogPrintf("No wallet compiled in!\n");
|
||||||
|
|
|
@ -1096,6 +1096,9 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
|
||||||
|
|
||||||
void CWallet::ReacceptWalletTransactions()
|
void CWallet::ReacceptWalletTransactions()
|
||||||
{
|
{
|
||||||
|
// If transcations aren't broadcasted, don't let them into local mempool either
|
||||||
|
if (!fBroadcastTransactions)
|
||||||
|
return;
|
||||||
LOCK2(cs_main, cs_wallet);
|
LOCK2(cs_main, cs_wallet);
|
||||||
BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
|
BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet)
|
||||||
{
|
{
|
||||||
|
@ -1116,6 +1119,7 @@ void CWallet::ReacceptWalletTransactions()
|
||||||
|
|
||||||
bool CWalletTx::RelayWalletTransaction()
|
bool CWalletTx::RelayWalletTransaction()
|
||||||
{
|
{
|
||||||
|
assert(pwallet->GetBroadcastTransactions());
|
||||||
if (!IsCoinBase())
|
if (!IsCoinBase())
|
||||||
{
|
{
|
||||||
if (GetDepthInMainChain() == 0) {
|
if (GetDepthInMainChain() == 0) {
|
||||||
|
@ -1354,7 +1358,7 @@ void CWallet::ResendWalletTransactions(int64_t nBestBlockTime)
|
||||||
{
|
{
|
||||||
// Do this infrequently and randomly to avoid giving away
|
// Do this infrequently and randomly to avoid giving away
|
||||||
// that these are our transactions.
|
// that these are our transactions.
|
||||||
if (GetTime() < nNextResend)
|
if (GetTime() < nNextResend || !fBroadcastTransactions)
|
||||||
return;
|
return;
|
||||||
bool fFirst = (nNextResend == 0);
|
bool fFirst = (nNextResend == 0);
|
||||||
nNextResend = GetTime() + GetRand(30 * 60);
|
nNextResend = GetTime() + GetRand(30 * 60);
|
||||||
|
@ -1979,14 +1983,17 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey)
|
||||||
// Track how many getdata requests our transaction gets
|
// Track how many getdata requests our transaction gets
|
||||||
mapRequestCount[wtxNew.GetHash()] = 0;
|
mapRequestCount[wtxNew.GetHash()] = 0;
|
||||||
|
|
||||||
// Broadcast
|
if (fBroadcastTransactions)
|
||||||
if (!wtxNew.AcceptToMemoryPool(false))
|
|
||||||
{
|
{
|
||||||
// This must not fail. The transaction has already been signed and recorded.
|
// Broadcast
|
||||||
LogPrintf("CommitTransaction(): Error: Transaction not valid");
|
if (!wtxNew.AcceptToMemoryPool(false))
|
||||||
return false;
|
{
|
||||||
|
// This must not fail. The transaction has already been signed and recorded.
|
||||||
|
LogPrintf("CommitTransaction(): Error: Transaction not valid");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
wtxNew.RelayWalletTransaction();
|
||||||
}
|
}
|
||||||
wtxNew.RelayWalletTransaction();
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -455,6 +455,7 @@ private:
|
||||||
|
|
||||||
int64_t nNextResend;
|
int64_t nNextResend;
|
||||||
int64_t nLastResend;
|
int64_t nLastResend;
|
||||||
|
bool fBroadcastTransactions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to keep track of spent outpoints, and
|
* Used to keep track of spent outpoints, and
|
||||||
|
@ -518,6 +519,7 @@ public:
|
||||||
nNextResend = 0;
|
nNextResend = 0;
|
||||||
nLastResend = 0;
|
nLastResend = 0;
|
||||||
nTimeFirstKey = 0;
|
nTimeFirstKey = 0;
|
||||||
|
fBroadcastTransactions = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<uint256, CWalletTx> mapWallet;
|
std::map<uint256, CWalletTx> mapWallet;
|
||||||
|
@ -723,6 +725,11 @@ public:
|
||||||
|
|
||||||
/** Watch-only address added */
|
/** Watch-only address added */
|
||||||
boost::signals2::signal<void (bool fHaveWatchOnly)> NotifyWatchonlyChanged;
|
boost::signals2::signal<void (bool fHaveWatchOnly)> NotifyWatchonlyChanged;
|
||||||
|
|
||||||
|
/** Inquire whether this wallet broadcasts transactions. */
|
||||||
|
bool GetBroadcastTransactions() const { return fBroadcastTransactions; }
|
||||||
|
/** Set whether this wallet broadcasts transactions. */
|
||||||
|
void SetBroadcastTransactions(bool broadcast) { fBroadcastTransactions = broadcast; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A key allocated from the key pool. */
|
/** A key allocated from the key pool. */
|
||||||
|
|
Loading…
Reference in New Issue