diff --git a/src/LedgerEntrySet.cpp b/src/LedgerEntrySet.cpp index 4dbef407b..5408a4dca 100644 --- a/src/LedgerEntrySet.cpp +++ b/src/LedgerEntrySet.cpp @@ -291,7 +291,7 @@ SLE::pointer LedgerEntrySet::getForMod(const uint256& node, Ledger::ref ledger, } -bool LedgerEntrySet::threadTx(TransactionMetaNode& metaNode, const NewcoinAddress& threadTo, Ledger::ref ledger, +bool LedgerEntrySet::threadTx(const NewcoinAddress& threadTo, Ledger::ref ledger, boost::unordered_map& newMods) { Log(lsTRACE) << "Thread to " << threadTo.getAccountID(); @@ -301,32 +301,36 @@ bool LedgerEntrySet::threadTx(TransactionMetaNode& metaNode, const NewcoinAddres assert(false); return false; } - return threadTx(metaNode, sle, ledger, newMods); + return threadTx(sle, ledger, newMods); } -bool LedgerEntrySet::threadTx(TransactionMetaNode& metaNode, SLE::ref threadTo, Ledger::ref ledger, - boost::unordered_map& newMods) +bool LedgerEntrySet::threadTx(SLE::ref threadTo, Ledger::ref ledger, boost::unordered_map& newMods) { // node = the node that was modified/deleted/created // threadTo = the node that needs to know uint256 prevTxID; uint32 prevLgrID; if (!threadTo->thread(mSet.getTxID(), mSet.getLgrSeq(), prevTxID, prevLgrID)) return false; - if (metaNode.thread(prevTxID, prevLgrID)) + if (mSet.getAffectedNode(threadTo->getIndex(), TMNModifiedNode, false).thread(prevTxID, prevLgrID)) return true; assert(false); return false; } -bool LedgerEntrySet::threadOwners(TransactionMetaNode& metaNode, SLE::ref node, Ledger::ref ledger, - boost::unordered_map& newMods) +bool LedgerEntrySet::threadOwners(SLE::ref node, Ledger::ref ledger, boost::unordered_map& newMods) { // thread new or modified node to owner or owners if (node->hasOneOwner()) // thread to owner's account - return threadTx(metaNode, node->getOwner(), ledger, newMods); - else if (node->hasTwoOwners()) // thread to owner's accounts + { + Log(lsTRACE) << "Thread to single owner"; + return threadTx(node->getOwner(), ledger, newMods); + } + else if (node->hasTwoOwners()) // thread to owner's accounts] + { + Log(lsTRACE) << "Thread to two owners"; return - threadTx(metaNode, node->getFirstOwner(), ledger, newMods) || - threadTx(metaNode, node->getSecondOwner(), ledger, newMods); + threadTx(node->getFirstOwner(), ledger, newMods) && + threadTx(node->getSecondOwner(), ledger, newMods); + } else return false; } @@ -369,12 +373,12 @@ void LedgerEntrySet::calcRawMeta(Serializer& s) continue; SLE::pointer curNode = it->second.mEntry; - TransactionMetaNode &metaNode = mSet.getAffectedNode(it->first, nType); + TransactionMetaNode &metaNode = mSet.getAffectedNode(it->first, nType, true); if (nType == TMNDeletedNode) { assert(origNode); - threadOwners(metaNode, origNode, mLedger, newMod); + threadOwners(origNode, mLedger, newMod); if (origNode->getIFieldPresent(sfAmount)) { // node has an amount, covers ripple state nodes @@ -408,13 +412,16 @@ void LedgerEntrySet::calcRawMeta(Serializer& s) if (nType == TMNCreatedNode) // if created, thread to owner(s) { assert(!origNode); - threadOwners(metaNode, curNode, mLedger, newMod); + threadOwners(curNode, mLedger, newMod); } if ((nType == TMNCreatedNode) || (nType == TMNModifiedNode)) { if (curNode->isThreadedType()) // always thread to self - threadTx(metaNode, curNode, mLedger, newMod); + { + Log(lsTRACE) << "Thread to self"; + threadTx(curNode, mLedger, newMod); + } } if (nType == TMNModifiedNode) diff --git a/src/LedgerEntrySet.h b/src/LedgerEntrySet.h index 92d96294e..150a5ae89 100644 --- a/src/LedgerEntrySet.h +++ b/src/LedgerEntrySet.h @@ -42,14 +42,12 @@ protected: SLE::pointer getForMod(const uint256& node, Ledger::ref ledger, boost::unordered_map& newMods); - bool threadTx(TransactionMetaNode& metaNode, const NewcoinAddress& threadTo, Ledger::ref ledger, + bool threadTx(const NewcoinAddress& threadTo, Ledger::ref ledger, boost::unordered_map& newMods); - bool threadTx(TransactionMetaNode& metaNode, SLE::ref threadTo, Ledger::ref ledger, - boost::unordered_map& newMods); + bool threadTx(SLE::ref threadTo, Ledger::ref ledger, boost::unordered_map& newMods); - bool threadOwners(TransactionMetaNode& metaNode, SLE::ref node, Ledger::ref ledger, - boost::unordered_map& newMods); + bool threadOwners(SLE::ref node, Ledger::ref ledger, boost::unordered_map& newMods); public: diff --git a/src/SerializedLedger.cpp b/src/SerializedLedger.cpp index 41c4bc7fb..0353df8b6 100644 --- a/src/SerializedLedger.cpp +++ b/src/SerializedLedger.cpp @@ -3,6 +3,7 @@ #include #include "Ledger.h" +#include "Log.h" SerializedLedgerEntry::SerializedLedgerEntry(SerializerIterator& sit, const uint256& index) : SerializedType("LedgerEntry"), mIndex(index) @@ -99,6 +100,7 @@ uint32 SerializedLedgerEntry::getThreadedLedger() bool SerializedLedgerEntry::thread(const uint256& txID, uint32 ledgerSeq, uint256& prevTxID, uint32& prevLedgerID) { uint256 oldPrevTxID = getIFieldH256(sfLastTxnID); + Log(lsTRACE) << "Thread Tx:" << txID << " prev:" << oldPrevTxID; if (oldPrevTxID == txID) return false; prevTxID = oldPrevTxID; diff --git a/src/TransactionMeta.cpp b/src/TransactionMeta.cpp index d43e55e34..4c179f0b7 100644 --- a/src/TransactionMeta.cpp +++ b/src/TransactionMeta.cpp @@ -294,11 +294,15 @@ bool TransactionMetaSet::isNodeAffected(const uint256& node) const return mNodes.find(node) != mNodes.end(); } -TransactionMetaNode& TransactionMetaSet::getAffectedNode(const uint256& node, int type) +TransactionMetaNode& TransactionMetaSet::getAffectedNode(const uint256& node, int type, bool overrideType) { std::map::iterator it = mNodes.find(node); if (it != mNodes.end()) + { + if (overrideType) + it->second.setType(type); return it->second; + } return mNodes.insert(std::make_pair(node, TransactionMetaNode(node, type))).first->second; } diff --git a/src/TransactionMeta.h b/src/TransactionMeta.h index 10423aeda..e3ac3b6cd 100644 --- a/src/TransactionMeta.h +++ b/src/TransactionMeta.h @@ -158,6 +158,7 @@ public: TransactionMetaNode(int type, const uint256& node, SerializerIterator&); void addRaw(Serializer&); + void setType(int t) { mType = t; } Json::Value getJson(int) const; bool addAmount(int nodeType, const STAmount& amount); @@ -189,7 +190,7 @@ public: uint32 getLgrSeq() { return mLedger; } bool isNodeAffected(const uint256&) const; - TransactionMetaNode& getAffectedNode(const uint256&, int type); + TransactionMetaNode& getAffectedNode(const uint256&, int type, bool overrideType); const TransactionMetaNode& peekAffectedNode(const uint256&) const; Json::Value getJson(int) const;