From 2864dda4eb652019c6a032e5b248f21a3551c9cc Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 30 Nov 2012 00:30:19 -0800 Subject: [PATCH] Make directory nodes self-descriptive. Callers pass in a "describer" function that stamps new directory entries. --- src/cpp/ripple/Ledger.cpp | 18 ++++++++++++++++++ src/cpp/ripple/Ledger.h | 5 +++++ src/cpp/ripple/LedgerEntrySet.cpp | 10 +++++++--- src/cpp/ripple/LedgerEntrySet.h | 8 +++++--- src/cpp/ripple/LedgerFormats.cpp | 2 +- src/cpp/ripple/OfferCreateTransactor.cpp | 10 ++++++++-- src/cpp/ripple/TrustSetTransactor.cpp | 14 ++++++++++++-- 7 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/cpp/ripple/Ledger.cpp b/src/cpp/ripple/Ledger.cpp index c91662aa03..efd3e7cd9d 100644 --- a/src/cpp/ripple/Ledger.cpp +++ b/src/cpp/ripple/Ledger.cpp @@ -1180,4 +1180,22 @@ void Ledger::decPendingSaves() --sPendingSaves; } +void Ledger::ownerDirDescriber(SLE::ref sle, const uint160& owner) +{ + sle->setFieldH160(sfOwner, owner); +} + +void Ledger::qualityDirDescriber(SLE::ref sle, + const uint160& uTakerPaysCurrency, const uint160& uTakerPaysIssuer, + const uint160& uTakerGetsCurrency, const uint160& uTakerGetsIssuer, + const uint64& uRate) +{ + sle->setFieldH160(sfTakerPaysCurrency, uTakerPaysCurrency); + sle->setFieldH160(sfTakerPaysIssuer, uTakerPaysIssuer); + sle->setFieldH160(sfTakerGetsCurrency, uTakerGetsCurrency); + sle->setFieldH160(sfTakerGetsIssuer, uTakerGetsIssuer); + sle->setFieldU64(sfExchangeRate, uRate); +} + + // vim:ts=4 diff --git a/src/cpp/ripple/Ledger.h b/src/cpp/ripple/Ledger.h index 6e9226634a..23292254b3 100644 --- a/src/cpp/ripple/Ledger.h +++ b/src/cpp/ripple/Ledger.h @@ -263,6 +263,7 @@ public: // Given a directory root and and index compute the index of a node. static uint256 getDirNodeIndex(const uint256& uDirRoot, const uint64 uNodeIndex = 0); + static void ownerDirDescriber(SLE::ref, const uint160& owner); // Return a node: root or normal SLE::pointer getDirNode(LedgerStateParms& parms, const uint256& uNodeIndex); @@ -274,6 +275,10 @@ public: static uint256 getQualityIndex(const uint256& uBase, const uint64 uNodeDir = 0); static uint256 getQualityNext(const uint256& uBase); static uint64 getQuality(const uint256& uBase); + static void qualityDirDescriber(SLE::ref, + const uint160& uTakerPaysCurrency, const uint160& uTakerPaysIssuer, + const uint160& uTakerGetsCurrency, const uint160& uTakerGetsIssuer, + const uint64& uRate); // // Ripple functions : credit lines diff --git a/src/cpp/ripple/LedgerEntrySet.cpp b/src/cpp/ripple/LedgerEntrySet.cpp index b2cca2b713..5edd8944b5 100644 --- a/src/cpp/ripple/LedgerEntrySet.cpp +++ b/src/cpp/ripple/LedgerEntrySet.cpp @@ -492,9 +492,10 @@ void LedgerEntrySet::calcRawMeta(Serializer& s, TER result, uint32 index) // We only append. This allow for things that watch append only structure to just monitor from the last node on ward. // Within a node with no deletions order of elements is sequential. Otherwise, order of elements is random. TER LedgerEntrySet::dirAdd( - uint64& uNodeDir, - const uint256& uRootIndex, - const uint256& uLedgerIndex) + uint64& uNodeDir, + const uint256& uRootIndex, + const uint256& uLedgerIndex, + boost::function fDescriber) { SLE::pointer sleNode; STVector256 svIndexes; @@ -505,6 +506,7 @@ TER LedgerEntrySet::dirAdd( // No root, make it. sleRoot = entryCreate(ltDIR_NODE, uRootIndex); sleRoot->setFieldH256(sfRootIndex, uRootIndex); + fDescriber(sleRoot); sleNode = sleRoot; uNodeDir = 0; @@ -566,6 +568,8 @@ TER LedgerEntrySet::dirAdd( // Create the new node. sleNode = entryCreate(ltDIR_NODE, Ledger::getDirNodeIndex(uRootIndex, uNodeDir)); sleNode->setFieldH256(sfRootIndex, uRootIndex); + fDescriber(sleNode); + svIndexes = STVector256(); } } diff --git a/src/cpp/ripple/LedgerEntrySet.h b/src/cpp/ripple/LedgerEntrySet.h index 754b31a586..ea91ff9fbb 100644 --- a/src/cpp/ripple/LedgerEntrySet.h +++ b/src/cpp/ripple/LedgerEntrySet.h @@ -2,6 +2,7 @@ #define __LEDGERENTRYSET__ #include +#include #include "SerializedLedger.h" #include "TransactionMeta.h" @@ -86,9 +87,10 @@ public: // Directory functions. TER dirAdd( - uint64& uNodeDir, // Node of entry. - const uint256& uRootIndex, - const uint256& uLedgerIndex); + uint64& uNodeDir, // Node of entry. + const uint256& uRootIndex, + const uint256& uLedgerIndex, + boost::function fDescriber); TER dirDelete( const bool bKeepRoot, diff --git a/src/cpp/ripple/LedgerFormats.cpp b/src/cpp/ripple/LedgerFormats.cpp index cbc45dba9c..98c70857a7 100644 --- a/src/cpp/ripple/LedgerFormats.cpp +++ b/src/cpp/ripple/LedgerFormats.cpp @@ -51,7 +51,7 @@ static bool LEFInit() << SOElement(sfTakerPaysIssuer, SOE_OPTIONAL) // for order book directories << SOElement(sfTakerGetsCurrency, SOE_OPTIONAL) // for order book directories << SOElement(sfTakerGetsIssuer, SOE_OPTIONAL) // for order book directories - << SOElement(sfExhangeRate, SOE_OPTIONAL) // for order book directories + << SOElement(sfExchangeRate, SOE_OPTIONAL) // for order book directories << SOElement(sfIndexes, SOE_REQUIRED) << SOElement(sfRootIndex, SOE_REQUIRED) << SOElement(sfIndexNext, SOE_OPTIONAL) diff --git a/src/cpp/ripple/OfferCreateTransactor.cpp b/src/cpp/ripple/OfferCreateTransactor.cpp index 27136b476c..db0ce70be5 100644 --- a/src/cpp/ripple/OfferCreateTransactor.cpp +++ b/src/cpp/ripple/OfferCreateTransactor.cpp @@ -1,5 +1,7 @@ #include "OfferCreateTransactor.h" + #include +#include // Take as much as possible. Adjusts account balances. Charges fees on top to taker. // --> uBookBase: The order book to take against. @@ -387,7 +389,9 @@ TER OfferCreateTransactor::doApply() % saTakerGets.getFullText()); // Add offer to owner's directory. - terResult = mEngine->getNodes().dirAdd(uOwnerNode, Ledger::getOwnerDirIndex(mTxnAccountID), uLedgerIndex); + terResult = mEngine->getNodes().dirAdd(uOwnerNode, Ledger::getOwnerDirIndex(mTxnAccountID), uLedgerIndex, + boost::bind(&Ledger::qualityDirDescriber, _1, saTakerPays.getCurrency(), uPaysIssuerID, + saTakerGets.getCurrency(), uGetsIssuerID, uRate)); if (tesSUCCESS == terResult) { @@ -403,7 +407,9 @@ TER OfferCreateTransactor::doApply() uDirectory = Ledger::getQualityIndex(uBookBase, uRate); // Use original rate. // Add offer to order book. - terResult = mEngine->getNodes().dirAdd(uBookNode, uDirectory, uLedgerIndex); + terResult = mEngine->getNodes().dirAdd(uBookNode, uDirectory, uLedgerIndex, + boost::bind(&Ledger::qualityDirDescriber, _1, saTakerPays.getCurrency(), uPaysIssuerID, + saTakerGets.getCurrency(), uGetsIssuerID, uRate)); } if (tesSUCCESS == terResult) diff --git a/src/cpp/ripple/TrustSetTransactor.cpp b/src/cpp/ripple/TrustSetTransactor.cpp index 1d287fda97..3403c40389 100644 --- a/src/cpp/ripple/TrustSetTransactor.cpp +++ b/src/cpp/ripple/TrustSetTransactor.cpp @@ -1,5 +1,7 @@ #include "TrustSetTransactor.h" +#include + TER TrustSetTransactor::doApply() { TER terResult = tesSUCCESS; @@ -135,10 +137,18 @@ TER TrustSetTransactor::doApply() uint64 uSrcRef; // Ignored, dirs never delete. - terResult = mEngine->getNodes().dirAdd(uSrcRef, Ledger::getOwnerDirIndex(mTxnAccountID), sleRippleState->getIndex()); + terResult = mEngine->getNodes().dirAdd( + uSrcRef, + Ledger::getOwnerDirIndex(mTxnAccountID), + sleRippleState->getIndex(), + boost::bind(&Ledger::ownerDirDescriber, _1, mTxnAccountID)); if (tesSUCCESS == terResult) - terResult = mEngine->getNodes().dirAdd(uSrcRef, Ledger::getOwnerDirIndex(uDstAccountID), sleRippleState->getIndex()); + terResult = mEngine->getNodes().dirAdd( + uSrcRef, + Ledger::getOwnerDirIndex(uDstAccountID), + sleRippleState->getIndex(), + boost::bind(&Ledger::ownerDirDescriber, _1, uDstAccountID)); } Log(lsINFO) << "doTrustSet<";