From bef1551543611a3661e1b1032ccb7a8d6cd0cfa1 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 1 Nov 2012 17:52:51 -0700 Subject: [PATCH 1/6] Count ledger proposals too. --- src/LedgerProposal.cpp | 2 ++ src/LedgerProposal.h | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/LedgerProposal.cpp b/src/LedgerProposal.cpp index 775f7b93dd..75e286e9e0 100644 --- a/src/LedgerProposal.cpp +++ b/src/LedgerProposal.cpp @@ -7,6 +7,8 @@ #include "Application.h" #include "HashPrefixes.h" +DECLARE_INSTANCE(LedgerProposal); + LedgerProposal::LedgerProposal(const uint256& pLgr, uint32 seq, const uint256& tx, uint32 closeTime, const RippleAddress& naPeerPublic) : mPreviousLedger(pLgr), mCurrentHash(tx), mCloseTime(closeTime), mProposeSeq(seq), mPublicKey(naPeerPublic) diff --git a/src/LedgerProposal.h b/src/LedgerProposal.h index 4119a444d6..a531de214c 100644 --- a/src/LedgerProposal.h +++ b/src/LedgerProposal.h @@ -10,8 +10,11 @@ #include "RippleAddress.h" #include "Serializer.h" +#include "InstanceCounter.h" -class LedgerProposal +DEFINE_INSTANCE(LedgerProposal); + +class LedgerProposal : private IS_INSTANCE(LedgerProposal) { protected: From fc9e2f4b4e644f1e72348750ffd07e5a42c8fd68 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 2 Nov 2012 00:04:05 -0700 Subject: [PATCH 2/6] Update a comment. --- src/TaggedCache.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/TaggedCache.h b/src/TaggedCache.h index f7a0781a1a..aee675042f 100644 --- a/src/TaggedCache.h +++ b/src/TaggedCache.h @@ -20,7 +20,8 @@ extern LogPartition TaggedCachePartition; // If it stays in memory even after it is ejected from the cache, // the map will track it. -// CAUTION: Callers must not modify data objects that are stored in the cache! +// CAUTION: Callers must not modify data objects that are stored in the cache +// unless they hold their own lock over all cache operations. template class TaggedCache { From 6394ca23411fa65d608f41ba42e07469f2ff0898 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 2 Nov 2012 09:00:29 -0700 Subject: [PATCH 3/6] x = y::pointer() -> x.reset() --- src/ConnectionPool.cpp | 6 +++--- src/Ledger.cpp | 5 +++-- src/LedgerAcquire.cpp | 2 +- src/LedgerConsensus.cpp | 2 +- src/LedgerMaster.cpp | 6 +++--- src/NetworkOPs.cpp | 4 ++-- src/Peer.cpp | 2 +- src/SHAMapDiff.cpp | 2 +- src/SHAMapNodes.cpp | 2 +- src/TransactionEngine.cpp | 2 +- src/ValidationCollection.cpp | 2 +- 11 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/ConnectionPool.cpp b/src/ConnectionPool.cpp index 6b01a14393..93fce5842c 100644 --- a/src/ConnectionPool.cpp +++ b/src/ConnectionPool.cpp @@ -304,7 +304,7 @@ void ConnectionPool::connectTo(const std::string& strIp, int iPort) Peer::pointer ConnectionPool::peerConnect(const std::string& strIp, int iPort) { ipPort pipPeer = make_pair(strIp, iPort); - Peer::pointer ppResult = Peer::pointer(); + Peer::pointer ppResult; boost::unordered_map::iterator it; @@ -545,7 +545,7 @@ void ConnectionPool::peerClosed(Peer::ref peer, const std::string& strIp, int iP { //cLog(lsINFO) << "Pool: Scan: scan fail: " << strIp << " " << iPort; - mScanning = Peer::pointer(); // No longer scanning. + mScanning.reset(); // No longer scanning. bScanRefresh = true; // Look for more to scan. } @@ -619,7 +619,7 @@ void ConnectionPool::peerVerified(Peer::ref peer) // XXX Check error. } - mScanning = Peer::pointer(); + mScanning.reset(); scanRefresh(); // Continue scanning. } diff --git a/src/Ledger.cpp b/src/Ledger.cpp index ec44a5dc96..f05e1245a5 100644 --- a/src/Ledger.cpp +++ b/src/Ledger.cpp @@ -190,7 +190,8 @@ AccountState::pointer Ledger::getAccountState(const RippleAddress& accountID) } SerializedLedgerEntry::pointer sle = boost::make_shared(item->peekSerializer(), item->getTag()); - if (sle->getType() != ltACCOUNT_ROOT) return AccountState::pointer(); + if (sle->getType() != ltACCOUNT_ROOT) + return AccountState::pointer(); return boost::make_shared(sle,accountID); } @@ -308,7 +309,7 @@ bool Ledger::getTransaction(const uint256& txID, Transaction::pointer& txn, Tran if (type == SHAMapTreeNode::tnTRANSACTION_NM) { // in tree with no metadata txn = theApp->getMasterTransaction().fetch(txID, false); - meta = TransactionMetaSet::pointer(); + meta.reset(); if (!txn) txn = Transaction::sharedTransaction(item->peekData(), true); } diff --git a/src/LedgerAcquire.cpp b/src/LedgerAcquire.cpp index a9c4cf8ca2..f9d9f1bef9 100644 --- a/src/LedgerAcquire.cpp +++ b/src/LedgerAcquire.cpp @@ -407,7 +407,7 @@ bool LedgerAcquire::takeBase(const std::string& data) { cLog(lsWARNING) << "Acquire hash mismatch"; cLog(lsWARNING) << mLedger->getHash() << "!=" << mHash; - mLedger = Ledger::pointer(); + mLedger.reset(); #ifdef TRUST_NETWORK assert(false); #endif diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index 15e4397841..876a14cc6e 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -347,7 +347,7 @@ void LedgerConsensus::handleLCL(const uint256& lclHash) cLog(lsINFO) << "Have the consensus ledger " << mPrevLedgerHash; mHaveCorrectLCL = true; - mAcquiringLedger = LedgerAcquire::pointer(); + mAcquiringLedger.reset(); theApp->getOPs().clearNeedNetworkLedger(); mCloseResolution = ContinuousLedgerTiming::getNextLedgerTimeResolution( mPreviousLedger->getCloseResolution(), mPreviousLedger->getCloseAgree(), diff --git a/src/LedgerMaster.cpp b/src/LedgerMaster.cpp index d83c72bf84..cd477b21cc 100644 --- a/src/LedgerMaster.cpp +++ b/src/LedgerMaster.cpp @@ -103,7 +103,7 @@ void LedgerMaster::acquireMissingLedger(const uint256& ledgerHash, uint32 ledger Ledger::pointer lgr = mMissingLedger->getLedger(); if (lgr && (lgr->getLedgerSeq() == ledgerSeq)) missingAcquireComplete(mMissingLedger); - mMissingLedger = LedgerAcquire::pointer(); + mMissingLedger.reset(); return; } mMissingSeq = ledgerSeq; @@ -120,7 +120,7 @@ void LedgerMaster::missingAcquireComplete(LedgerAcquire::pointer acq) cLog(lsWARNING) << "Acquire failed for " << mMissingSeq; } - mMissingLedger = LedgerAcquire::pointer(); + mMissingLedger.reset(); mMissingSeq = 0; if (!acq->isFailed()) @@ -147,7 +147,7 @@ void LedgerMaster::setFullLedger(Ledger::ref ledger) } if (mMissingLedger && mMissingLedger->isComplete()) - mMissingLedger = LedgerAcquire::pointer(); + mMissingLedger.reset(); if (mMissingLedger || !theConfig.FULL_HISTORY) return; diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index 966570be66..ce52fde7b3 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -106,7 +106,7 @@ Transaction::pointer NetworkOPs::submitTransaction(const Transaction::pointer& t assert(false); - tpTransNew = Transaction::pointer(); + tpTransNew.reset(); } return tpTransNew; @@ -571,7 +571,7 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector& peerLis { mAcquiringLedger->abort(); theApp->getMasterLedgerAcquire().dropLedger(mAcquiringLedger->getHash()); - mAcquiringLedger = LedgerAcquire::pointer(); + mAcquiringLedger.reset(); } return false; } diff --git a/src/Peer.cpp b/src/Peer.cpp index 83f8f62ad1..c9c6df5dbf 100644 --- a/src/Peer.cpp +++ b/src/Peer.cpp @@ -41,7 +41,7 @@ void Peer::handle_write(const boost::system::error_code& error, size_t bytes_tra // std::cerr << "Peer::handle_write bytes: "<< bytes_transferred << std::endl; #endif - mSendingPacket = PackedMessage::pointer(); + mSendingPacket.reset(); if (mDetaching) { diff --git a/src/SHAMapDiff.cpp b/src/SHAMapDiff.cpp index 05619df210..dd47b8375c 100644 --- a/src/SHAMapDiff.cpp +++ b/src/SHAMapDiff.cpp @@ -73,7 +73,7 @@ bool SHAMap::walkBranch(SHAMapTreeNode* node, SHAMapItem::ref otherMapItem, bool else differences.insert(std::make_pair(otherMapItem->getTag(), std::make_pair(otherMapItem, item))); if(--maxCount <= 0) return false; - item = SHAMapItem::pointer(); + item.reset(); } } else assert(false); diff --git a/src/SHAMapNodes.cpp b/src/SHAMapNodes.cpp index 9db9f4e2ce..0d4f134c45 100644 --- a/src/SHAMapNodes.cpp +++ b/src/SHAMapNodes.cpp @@ -500,7 +500,7 @@ int SHAMapTreeNode::getBranchCount() const void SHAMapTreeNode::makeInner() { - mItem = SHAMapItem::pointer(); + mItem.reset(); memset(mHashes, 0, sizeof(mHashes)); mType = tnINNER; mHash.zero(); diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index 0b29d4e858..0535029396 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -481,7 +481,7 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn, Transa } } - mTxnAccount = SLE::pointer(); + mTxnAccount.reset(); mNodes.clear(); if (!isSetBit(params, tapOPEN_LEDGER) diff --git a/src/ValidationCollection.cpp b/src/ValidationCollection.cpp index a66ca7edf1..f4c7b941ba 100644 --- a/src/ValidationCollection.cpp +++ b/src/ValidationCollection.cpp @@ -184,7 +184,7 @@ ValidationCollection::getCurrentValidations(uint256 currentLedger) else if (it->second->getSignTime() < cutoff) { // contains a stale record mStaleValidations.push_back(it->second); - it->second = SerializedValidation::pointer(); + it->second.reset(); condWrite(); it = mCurrentValidations.erase(it); } From 68dbd66aea90f02f6b860cc4a62b416a6ea7dfdd Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 2 Nov 2012 16:08:24 -0700 Subject: [PATCH 4/6] Tiny cleanup. --- src/SHAMapSync.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SHAMapSync.cpp b/src/SHAMapSync.cpp index e0ced0d8dd..a1e661cd02 100644 --- a/src/SHAMapSync.cpp +++ b/src/SHAMapSync.cpp @@ -65,7 +65,7 @@ void SHAMap::getMissingNodes(std::vector& nodeIDs, std::vectorgetNodeHash()) { cLog(lsERROR) << "Wrong hash from cached object"; - d = SHAMapTreeNode::pointer(); + d.reset(); } else { From a17e02e35fa8101eeb7875ab58e78073dbbc01fe Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 2 Nov 2012 16:53:46 -0700 Subject: [PATCH 5/6] Ack! I accidentally made some data undecodable. This will fix broken tx metadata. --- src/SerializeProto.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SerializeProto.h b/src/SerializeProto.h index 4cb17d5dc2..776e7b1099 100644 --- a/src/SerializeProto.h +++ b/src/SerializeProto.h @@ -125,22 +125,22 @@ // inner object // OBJECT/1 is reserved for end of object - FIELD(TemplateEntry, OBJECT, 1) FIELD(TransactionMetaData, OBJECT, 2) FIELD(CreatedNode, OBJECT, 3) FIELD(DeletedNode, OBJECT, 4) FIELD(ModifiedNode, OBJECT, 5) FIELD(PreviousFields, OBJECT, 6) FIELD(FinalFields, OBJECT, 7) + FIELD(TemplateEntry, OBJECT, 8) // array of objects // ARRAY/1 is reserved for end of array - FIELD(AffectedNodes, ARRAY, 1) FIELD(SigningAccounts, ARRAY, 2) FIELD(TxnSignatures, ARRAY, 3) FIELD(Signatures, ARRAY, 4) FIELD(Template, ARRAY, 5) FIELD(Necessary, ARRAY, 6) FIELD(Sufficient, ARRAY, 7) + FIELD(AffectedNodes, ARRAY, 8) // vim:ts=4 From 1af46fbe133c80bb5c1d4b6527929a8ecb3e77a1 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 2 Nov 2012 17:05:19 -0700 Subject: [PATCH 6/6] Track fields not serialized for signing hashes in a more sensible way. --- src/FieldNames.cpp | 3 +++ src/FieldNames.h | 11 +++++++++-- src/SerializedObject.cpp | 7 +------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/FieldNames.cpp b/src/FieldNames.cpp index 9b76ffe08e..2789f33aba 100644 --- a/src/FieldNames.cpp +++ b/src/FieldNames.cpp @@ -28,6 +28,9 @@ SField sfIndex(STI_HASH256, 258, "index"); static int initFields() { + sfTxnSignature.notSigningField(); sfTxnSignatures.notSigningField(); + sfSignature.notSigningField(); + sfHighQualityIn.setMeta(SFM_CHANGE); sfHighQualityOut.setMeta(SFM_CHANGE); sfLowQualityIn.setMeta(SFM_CHANGE); sfLowQualityOut.setMeta(SFM_CHANGE); diff --git a/src/FieldNames.h b/src/FieldNames.h index cdb11ad6b7..3a0ae9a3a1 100644 --- a/src/FieldNames.h +++ b/src/FieldNames.h @@ -60,16 +60,18 @@ public: const int fieldValue; // Code number for protocol std::string fieldName; SF_Meta fieldMeta; + bool signingField; SField(int fc, SerializedTypeID tid, int fv, const char* fn) : - fieldCode(fc), fieldType(tid), fieldValue(fv), fieldName(fn), fieldMeta(SFM_NEVER) + fieldCode(fc), fieldType(tid), fieldValue(fv), fieldName(fn), fieldMeta(SFM_NEVER), signingField(true) { boost::mutex::scoped_lock sl(mapMutex); codeToField[fieldCode] = this; } SField(SerializedTypeID tid, int fv, const char *fn) : - fieldCode(FIELD_CODE(tid, fv)), fieldType(tid), fieldValue(fv), fieldName(fn), fieldMeta(SFM_NEVER) + fieldCode(FIELD_CODE(tid, fv)), fieldType(tid), fieldValue(fv), fieldName(fn), + fieldMeta(SFM_NEVER), signingField(true) { boost::mutex::scoped_lock sl(mapMutex); codeToField[fieldCode] = this; @@ -97,6 +99,11 @@ public: bool shouldMetaDel() const { return (fieldMeta == SFM_DELETE) || (fieldMeta == SFM_ALWAYS); } bool shouldMetaMod() const { return (fieldMeta == SFM_CHANGE) || (fieldMeta == SFM_ALWAYS); } void setMeta(SF_Meta m) { fieldMeta = m; } + bool isSigningField() const { return signingField; } + void notSigningField() { signingField = false; } + + bool shouldInclude(bool withSigningField) const + { return (fieldValue < 256) && (withSigningField || signingField); } bool operator==(const SField& f) const { return fieldCode == f.fieldCode; } bool operator!=(const SField& f) const { return fieldCode != f.fieldCode; } diff --git a/src/SerializedObject.cpp b/src/SerializedObject.cpp index 2f90c75cba..2ef6a84f8e 100644 --- a/src/SerializedObject.cpp +++ b/src/SerializedObject.cpp @@ -283,13 +283,8 @@ void STObject::add(Serializer& s, bool withSigningFields) const BOOST_FOREACH(const SerializedType& it, mData) { // pick out the fields and sort them - if ((it.getSType() != STI_NOTPRESENT) && it.getFName().isBinary()) - { - SField::ref fName = it.getFName(); - if (withSigningFields || - ((fName != sfTxnSignature) && (fName != sfTxnSignatures) && (fName != sfSignature))) + if ((it.getSType() != STI_NOTPRESENT) && it.getFName().shouldInclude(withSigningFields)) fields.insert(std::make_pair(it.getFName().fieldCode, &it)); - } }