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 diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index 82ec0b42e5..1f6466c7ae 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -735,29 +735,32 @@ 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())) { - Log(lsINFO) << "Processing candidate transaction: " << item->getTag().GetHex(); -#ifndef TRUST_NETWORK - try + if (!checkLedger->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, applyLedger, failedTransactions, final); +#ifndef TRUST_NETWORK + } + catch (...) + { + Log(lsWARNING) << " Throws"; + } +#endif + } } int successes; @@ -800,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(); @@ -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,7 +858,8 @@ void LedgerConsensus::accept(SHAMap::pointer set) } } - applyTransactions(theApp->getMasterLedger().getCurrentLedger()->peekTransactionMap(), newOL, + Log(lsINFO) << "Applying transactions from current ledger"; + 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); 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)