From 7d8df3dddf76bb467eb9c3f226e1920f70b07bfa Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 31 Jan 2013 15:40:41 -0800 Subject: [PATCH] Save validations in a form they can actually be used. --- src/cpp/ripple/DBInit.cpp | 11 ++++++----- src/cpp/ripple/Ledger.cpp | 2 +- src/cpp/ripple/ValidationCollection.cpp | 13 +++++++++---- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/cpp/ripple/DBInit.cpp b/src/cpp/ripple/DBInit.cpp index b16ba0f41b..bdc6c29b5e 100644 --- a/src/cpp/ripple/DBInit.cpp +++ b/src/cpp/ripple/DBInit.cpp @@ -55,15 +55,16 @@ const char *LedgerDBInit[] = { );", "CREATE INDEX SeqLedger ON Ledgers(LedgerSeq);", - "CREATE TABLE LedgerValidations ( \ + "CREATE TABLE Validations ( \ LedgerHash CHARACTER(64), \ NodePubKey CHARACTER(56), \ - Flags BIGINT UNSIGNED, \ SignTime BIGINT UNSIGNED, \ - Signature BLOB \ + RawData BLOB \ );", - "CREATE INDEX ValidationByHash ON \ - LedgerValidations(LedgerHash);", + "CREATE INDEX ValidationsByHash ON \ + Validations(LedgerHash);", + "CREATE INDEX ValidationsByTime ON \ + Validations(SignTime);", "END TRANSACTION;" }; diff --git a/src/cpp/ripple/Ledger.cpp b/src/cpp/ripple/Ledger.cpp index 3f2124de3d..406a5f4e56 100644 --- a/src/cpp/ripple/Ledger.cpp +++ b/src/cpp/ripple/Ledger.cpp @@ -547,7 +547,7 @@ uint256 Ledger::getHashByIndex(uint32 ledgerIndex) { uint256 ret; - std::string sql="SELECT LedgerHash FROM Ledgers WHERE LedgerSeq='"; + std::string sql="SELECT LedgerHash FROM Ledgers INDEXED BY SeqLedger WHERE LedgerSeq='"; sql.append(boost::lexical_cast(ledgerIndex)); sql.append("';"); diff --git a/src/cpp/ripple/ValidationCollection.cpp b/src/cpp/ripple/ValidationCollection.cpp index 5d34e59ec6..84dbc8f140 100644 --- a/src/cpp/ripple/ValidationCollection.cpp +++ b/src/cpp/ripple/ValidationCollection.cpp @@ -300,8 +300,8 @@ void ValidationCollection::condWrite() void ValidationCollection::doWrite() { LoadEvent::autoptr event(theApp->getJobQueue().getLoadEventAP(jtDISK)); - static boost::format insVal("INSERT INTO LedgerValidations " - "(LedgerHash,NodePubKey,Flags,SignTime,Signature) VALUES ('%s','%s','%u','%u',%s);"); + static boost::format insVal("INSERT INTO Validations " + "(LedgerHash,NodePubKey,SignTime,RawData) VALUES ('%s','%s','%u',%s);"); boost::mutex::scoped_lock sl(mValidationLock); assert(mWriting); @@ -314,11 +314,16 @@ void ValidationCollection::doWrite() Database *db = theApp->getLedgerDB()->getDB(); ScopedLock dbl(theApp->getLedgerDB()->getDBLock()); + Serializer s(1024); db->executeSQL("BEGIN TRANSACTION;"); BOOST_FOREACH(const SerializedValidation::pointer& it, vector) + { + s.erase(); + it->add(s); db->executeSQL(boost::str(insVal % it->getLedgerHash().GetHex() - % it->getSignerPublic().humanNodePublic() % it->getFlags() % it->getSignTime() - % sqlEscape(it->getSignature()))); + % it->getSignerPublic().humanNodePublic() % it->getSignTime() + % sqlEscape(s.peekData()))); + } db->executeSQL("END TRANSACTION;"); } sl.lock();