From: CryptoManiac Date: Mon, 19 Jan 2015 19:42:10 +0000 (+0300) Subject: Try to broadcast transactions before saving it into the wallet. X-Git-Tag: nvc-v0.5.2~5 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=93e8cd6f1e0df1b05fd8f647d1a92243eeb9130e Try to broadcast transactions before saving it into the wallet. --- 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; }