Skip to content

Commit

Permalink
Database micro-optimization for "tx" network message
Browse files Browse the repository at this point in the history
Open database once per "tx" message, rather than multiple times,
in the case of orphan transaction presence.

As a side effect, a now-unused CTransaction::AcceptToMemoryPool()
variant is removed.
  • Loading branch information
Jeff Garzik authored and Jeff Garzik committed Apr 13, 2012
1 parent 6b8e7ee commit 9925d34
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
11 changes: 3 additions & 8 deletions src/main.cpp
Expand Up @@ -592,12 +592,6 @@ bool CTransaction::AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs, bool* pfMi
return true;
}

bool CTransaction::AcceptToMemoryPool(bool fCheckInputs, bool* pfMissingInputs)
{
CTxDB txdb("r");
return AcceptToMemoryPool(txdb, fCheckInputs, pfMissingInputs);
}

uint64 nPooledTx = 0;

bool CTransaction::AddToMemoryPoolUnchecked()
Expand Down Expand Up @@ -2522,14 +2516,15 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{
vector<uint256> vWorkQueue;
CDataStream vMsg(vRecv);
CTxDB txdb("r");
CTransaction tx;
vRecv >> tx;

CInv inv(MSG_TX, tx.GetHash());
pfrom->AddInventoryKnown(inv);

bool fMissingInputs = false;
if (tx.AcceptToMemoryPool(true, &fMissingInputs))
if (tx.AcceptToMemoryPool(txdb, true, &fMissingInputs))
{
SyncWithWallets(tx, NULL, true);
RelayMessage(inv, vMsg);
Expand All @@ -2549,7 +2544,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
CDataStream(vMsg) >> tx;
CInv inv(MSG_TX, tx.GetHash());

if (tx.AcceptToMemoryPool(true))
if (tx.AcceptToMemoryPool(txdb, true))
{
printf(" accepted orphan tx %s\n", inv.hash.ToString().substr(0,10).c_str());
SyncWithWallets(tx, NULL, true);
Expand Down
1 change: 0 additions & 1 deletion src/main.h
Expand Up @@ -684,7 +684,6 @@ class CTransaction
bool ClientConnectInputs();
bool CheckTransaction() const;
bool AcceptToMemoryPool(CTxDB& txdb, bool fCheckInputs=true, bool* pfMissingInputs=NULL);
bool AcceptToMemoryPool(bool fCheckInputs=true, bool* pfMissingInputs=NULL);

protected:
const CTxOut& GetOutputFor(const CTxIn& input, const MapPrevTx& inputs) const;
Expand Down

0 comments on commit 9925d34

Please sign in to comment.