From 93e8cd6f1e0df1b05fd8f647d1a92243eeb9130e Mon Sep 17 00:00:00 2001 From: CryptoManiac Date: Mon, 19 Jan 2015 22:42:10 +0300 Subject: [PATCH] Try to broadcast transactions before saving it into the wallet. --- src/wallet.cpp | 29 ++++++++++++++++------------- 1 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/wallet.cpp b/src/wallet.cpp index f62bb18..dc609b8 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -2046,9 +2046,24 @@ bool CWallet::CreateCoinStake(const CKeyStore& keystore, unsigned int nBits, uin bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey) { { - LOCK2(cs_main, cs_wallet); printf("CommitTransaction:\n%s", wtxNew.ToString().c_str()); + + // Track how many getdata requests our transaction gets + mapRequestCount[wtxNew.GetHash()] = 0; + + // Try to broadcast before saving + if (!wtxNew.AcceptToMemoryPool()) + { + // This must not fail. The transaction has already been signed. + printf("CommitTransaction() : Error: Transaction not valid"); + return false; + } + + wtxNew.RelayWalletTransaction(); + { + LOCK2(cs_main, cs_wallet); + // This is only to keep the database open to defeat the auto-flush for the // duration of this scope. This is the only place where this optimization // maybe makes sense; please don't do it anywhere else. @@ -2076,18 +2091,6 @@ bool CWallet::CommitTransaction(CWalletTx& wtxNew, CReserveKey& reservekey) if (fFileBacked) delete pwalletdb; } - - // Track how many getdata requests our transaction gets - mapRequestCount[wtxNew.GetHash()] = 0; - - // Broadcast - if (!wtxNew.AcceptToMemoryPool()) - { - // This must not fail. The transaction has already been signed and recorded. - printf("CommitTransaction() : Error: Transaction not valid"); - return false; - } - wtxNew.RelayWalletTransaction(); } return true; } -- 1.7.1