From 6b079cb951985b1bfbc075996644c93a529bfbd2 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 17 Jul 2012 15:55:27 -0700 Subject: [PATCH 1/4] Cleanup. --- src/Ledger.cpp | 5 ----- src/Ledger.h | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Ledger.cpp b/src/Ledger.cpp index ef85985e39..aa279f8a46 100644 --- a/src/Ledger.cpp +++ b/src/Ledger.cpp @@ -230,11 +230,6 @@ bool Ledger::addTransaction(const uint256& txID, const Serializer& txn) return true; } -bool Ledger::hasTransaction(const uint256& transID) const -{ - return mTransactionMap->hasItem(transID); -} - Transaction::pointer Ledger::getTransaction(const uint256& transID) const { SHAMapItem::pointer item = mTransactionMap->peekItem(transID); diff --git a/src/Ledger.h b/src/Ledger.h index 5ba21b74fc..e08100ac89 100644 --- a/src/Ledger.h +++ b/src/Ledger.h @@ -151,7 +151,7 @@ public: bool isAcquiringAS(void); // Transaction Functions - bool hasTransaction(const uint256& TransID) const; + bool hasTransaction(const uint256& TransID) const { return mTransactionMap->hasItem(TransID); } Transaction::pointer getTransaction(const uint256& transID) const; // high-level functions From 2898860ac88a17f854e8027ed8e737fb869dcf6c Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 17 Jul 2012 15:55:45 -0700 Subject: [PATCH 2/4] Cleanup. --- src/SHAMap.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/SHAMap.cpp b/src/SHAMap.cpp index 116cc470bf..738d1858ef 100644 --- a/src/SHAMap.cpp +++ b/src/SHAMap.cpp @@ -170,7 +170,7 @@ SHAMapTreeNode* SHAMap::walkToPointer(const uint256& id) { int branch = inNode->selectBranch(id); const uint256& nextHash = inNode->getChildHash(branch); - if (!nextHash) return NULL; + if (nextHash.isZero()) return NULL; inNode = getNodePointer(inNode->getChildNodeID(branch), nextHash); if (!inNode) throw SHAMapMissingNode(inNode->getChildNodeID(branch), nextHash); @@ -437,7 +437,7 @@ bool SHAMap::delItem(const uint256& id) SHAMapTreeNode::pointer leaf=stack.top(); stack.pop(); - if( !leaf || !leaf->hasItem() || (leaf->peekItem()->getTag()!=id) ) + if (!leaf || !leaf->hasItem() || (leaf->peekItem()->getTag() != id)) return false; SHAMapTreeNode::TNType type=leaf->getType(); @@ -446,19 +446,19 @@ bool SHAMap::delItem(const uint256& id) assert(false); uint256 prevHash; - while(!stack.empty()) + while (!stack.empty()) { SHAMapTreeNode::pointer node=stack.top(); stack.pop(); returnNode(node, true); assert(node->isInner()); - if(!node->setChildHash(node->selectBranch(id), prevHash)) + if (!node->setChildHash(node->selectBranch(id), prevHash)) { assert(false); return true; } - if(!node->isRoot()) + if (!node->isRoot()) { // we may have made this a node with 1 or 0 children int bc=node->getBranchCount(); if(bc==0) @@ -467,7 +467,7 @@ bool SHAMap::delItem(const uint256& id) std::cerr << "delItem makes empty node" << std::endl; #endif prevHash=uint256(); - if(!mTNByID.erase(*node)) + if (!mTNByID.erase(*node)) assert(false); } else if(bc==1) From 406ab0e63ddff3dc2b366876d5b628a3ae7987f6 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 17 Jul 2012 16:02:13 -0700 Subject: [PATCH 3/4] Check if the closed ledger already has a transaction before applying it. --- src/LedgerConsensus.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index 82ec0b42e5..8cb2a6dc7c 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -743,21 +743,24 @@ void LedgerConsensus::applyTransactions(SHAMap::pointer set, Ledger::pointer led for (SHAMapItem::pointer item = set->peekFirstItem(); !!item; item = set->peekNextItem(item->getTag())) { - Log(lsINFO) << "Processing candidate transaction: " << item->getTag().GetHex(); -#ifndef TRUST_NETWORK - try + if (!ledger->hasTransaction(item->getTag())) { -#endif - SerializerIterator sit(item->peekSerializer()); - SerializedTransaction::pointer txn = boost::make_shared(boost::ref(sit)); - applyTransaction(engine, txn, ledger, failedTransactions, final); + Log(lsINFO) << "Processing candidate transaction: " << item->getTag().GetHex(); #ifndef TRUST_NETWORK - } - catch (...) - { - Log(lsWARNING) << " Throws"; - } + try + { #endif + SerializerIterator sit(item->peekSerializer()); + SerializedTransaction::pointer txn = boost::make_shared(boost::ref(sit)); + applyTransaction(engine, txn, ledger, failedTransactions, final); +#ifndef TRUST_NETWORK + } + catch (...) + { + Log(lsWARNING) << " Throws"; + } +#endif + } } int successes; @@ -843,6 +846,7 @@ void LedgerConsensus::accept(SHAMap::pointer set) { // we voted NO try { + Log(lsINFO) << "Test applying disputed transaction that did not get in"; SerializerIterator sit(it->second->peekTransaction()); SerializedTransaction::pointer txn = boost::make_shared(boost::ref(sit)); applyTransaction(engine, txn, newOL, failedTransactions, false); @@ -854,6 +858,7 @@ void LedgerConsensus::accept(SHAMap::pointer set) } } + Log(lsINFO) << "Applying transactions from current ledger"; applyTransactions(theApp->getMasterLedger().getCurrentLedger()->peekTransactionMap(), newOL, failedTransactions, false); theApp->getMasterLedger().pushLedger(newLCL, newOL); From 69ff2e06ea8ef4ff5ead369613a7bc469169a9f2 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 17 Jul 2012 16:06:36 -0700 Subject: [PATCH 4/4] Don't try to rescue transactions that made it into the closed ledger. --- src/LedgerConsensus.cpp | 12 ++++++------ src/LedgerConsensus.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index 8cb2a6dc7c..1f6466c7ae 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -735,15 +735,15 @@ void LedgerConsensus::applyTransaction(TransactionEngine& engine, SerializedTran #endif } -void LedgerConsensus::applyTransactions(SHAMap::pointer set, Ledger::pointer ledger, +void LedgerConsensus::applyTransactions(SHAMap::pointer set, Ledger::pointer applyLedger, Ledger::pointer checkLedger, CanonicalTXSet& failedTransactions, bool final) { TransactionEngineParams parms = final ? (tepNO_CHECK_FEE | tepUPDATE_TOTAL) : tepNONE; - TransactionEngine engine(ledger); + TransactionEngine engine(applyLedger); for (SHAMapItem::pointer item = set->peekFirstItem(); !!item; item = set->peekNextItem(item->getTag())) { - if (!ledger->hasTransaction(item->getTag())) + if (!checkLedger->hasTransaction(item->getTag())) { Log(lsINFO) << "Processing candidate transaction: " << item->getTag().GetHex(); #ifndef TRUST_NETWORK @@ -752,7 +752,7 @@ void LedgerConsensus::applyTransactions(SHAMap::pointer set, Ledger::pointer led #endif SerializerIterator sit(item->peekSerializer()); SerializedTransaction::pointer txn = boost::make_shared(boost::ref(sit)); - applyTransaction(engine, txn, ledger, failedTransactions, final); + applyTransaction(engine, txn, applyLedger, failedTransactions, final); #ifndef TRUST_NETWORK } catch (...) @@ -803,7 +803,7 @@ void LedgerConsensus::accept(SHAMap::pointer set) newLCL->armDirty(); CanonicalTXSet failedTransactions(set->getHash()); - applyTransactions(set, newLCL, failedTransactions, true); + applyTransactions(set, newLCL, newLCL, failedTransactions, true); newLCL->setClosed(); uint32 closeTime = mOurPosition->getCloseTime(); @@ -859,7 +859,7 @@ void LedgerConsensus::accept(SHAMap::pointer set) } Log(lsINFO) << "Applying transactions from current ledger"; - applyTransactions(theApp->getMasterLedger().getCurrentLedger()->peekTransactionMap(), newOL, + applyTransactions(theApp->getMasterLedger().getCurrentLedger()->peekTransactionMap(), newOL, newLCL, failedTransactions, false); theApp->getMasterLedger().pushLedger(newLCL, newOL); mNewLedgerHash = newLCL->getHash(); diff --git a/src/LedgerConsensus.h b/src/LedgerConsensus.h index 235c670686..43fd2e9528 100644 --- a/src/LedgerConsensus.h +++ b/src/LedgerConsensus.h @@ -125,7 +125,7 @@ protected: void addPosition(LedgerProposal&, bool ours); void removePosition(LedgerProposal&, bool ours); void sendHaveTxSet(const uint256& set, bool direct); - void applyTransactions(SHAMap::pointer transactionSet, Ledger::pointer targetLedger, + void applyTransactions(SHAMap::pointer transactionSet, Ledger::pointer targetLedger, Ledger::pointer checkLedger, CanonicalTXSet& failedTransactions, bool final); void applyTransaction(TransactionEngine& engine, SerializedTransaction::pointer txn, Ledger::pointer targetLedger, CanonicalTXSet& failedTransactions, bool final);