From 40748df5054e043880952fc29cc9e72f574b72f6 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sat, 9 Jun 2012 01:33:13 -0700 Subject: [PATCH] Store completed transactions in the SQL database, indexed by accounts affected and ledger seq. --- src/LedgerConsensus.cpp | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index 72190d24a0..bd15efe5f9 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -654,6 +654,7 @@ void LedgerConsensus::accept(SHAMap::pointer set) Log(lsDEBUG) << "Previous LCL " << mPreviousLedger->getHash().GetHex(); Ledger::pointer newLCL = boost::make_shared(false, boost::ref(*mPreviousLedger)); + uint32 newLedgerSeq = newLCL->getLedgerSeq(); #ifdef DEBUG Json::StyledStreamWriter ssw; @@ -707,6 +708,7 @@ void LedgerConsensus::accept(SHAMap::pointer set) applyTransactions(theApp->getMasterLedger().getCurrentLedger()->peekTransactionMap(), newOL, failedTransactions); theApp->getMasterLedger().pushLedger(newLCL, newOL); mState = lcsACCEPTED; + sl.unlock(); #ifdef DEBUG if (1) @@ -718,8 +720,6 @@ void LedgerConsensus::accept(SHAMap::pointer set) } #endif - sl.unlock(); - SerializedValidation v(newLCLHash, mOurPosition->peekKey(), true); std::vector validation = v.getSigned(); newcoin::TMValidation val; @@ -727,6 +727,34 @@ void LedgerConsensus::accept(SHAMap::pointer set) theApp->getConnectionPool().relayMessage(NULL, boost::make_shared(val, newcoin::mtVALIDATION)); Log(lsINFO) << "Validation sent " << newLCL->getHash().GetHex(); statusChange(newcoin::neACCEPTED_LEDGER, newOL); + + // Insert the transactions in set into the AcctTxn database + Database *db = theApp->getAcctTxnDB()->getDB(); + ScopedLock dbLock = theApp->getAcctTxnDB()->getDBLock(); + db->executeSQL("BEGIN TRANSACTION"); + for (SHAMapItem::pointer item = set->peekFirstItem(); !!item; item = set->peekNextItem(item->getTag())) + { + SerializerIterator sit(item->peekSerializer()); + SerializedTransaction txn(sit); + std::vector accts = txn.getAffectedAccounts(); + + std::string sql = "INSERT INTO AccountTransactions (TransID,Account,LedgerSeq) VALUES "; + bool first = true; + for (std::vector::iterator it = accts.begin(), end = accts.end(); it != end; ++it) + { + if (!first) sql += ", ("; + else sql += "("; + sql += txn.getTransactionID().GetHex(); + sql += ","; + sql += it->humanAccountID(); + sql += ","; + sql += boost::lexical_cast(newLedgerSeq); + sql += ")"; + } + sql += ";"; + db->executeSQL(sql); + } + db->executeSQL("COMMIT TRANSACTION"); } void LedgerConsensus::endConsensus()