From e8abe71ea8429a73a94715bc408e5c59d25a7d69 Mon Sep 17 00:00:00 2001 From: Stefan Thomas Date: Thu, 29 Nov 2012 22:01:24 -0800 Subject: [PATCH 1/6] Add the ledger time to the JSON account transaction event. --- src/cpp/ripple/NetworkOPs.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index d36d00453..9db94bcee 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -1079,6 +1079,7 @@ Json::Value NetworkOPs::transJson(const SerializedTransaction& stTxn, TER terRes if (bAccepted) { jvObj["ledger_index"] = lpCurrent->getLedgerSeq(); jvObj["ledger_hash"] = lpCurrent->getHash().ToString(); + jvObj["transaction"]["date"] = lpCurrent->getCloseTimeNC(); } else { From 1d3a17b59d90e243e713618536df2b26231d0f72 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 30 Nov 2012 00:12:25 -0800 Subject: [PATCH 2/6] Structures for self-descriptive directory nodes. --- src/cpp/ripple/Ledger.h | 4 ++-- src/cpp/ripple/LedgerFormats.cpp | 6 ++++++ src/cpp/ripple/SerializeProto.h | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/cpp/ripple/Ledger.h b/src/cpp/ripple/Ledger.h index d9ddc14cb..6e9226634 100644 --- a/src/cpp/ripple/Ledger.h +++ b/src/cpp/ripple/Ledger.h @@ -262,7 +262,7 @@ public: // Directories are doubly linked lists of nodes. // Given a directory root and and index compute the index of a node. - static uint256 getDirNodeIndex(const uint256& uDirRoot, const uint64 uNodeIndex=0); + static uint256 getDirNodeIndex(const uint256& uDirRoot, const uint64 uNodeIndex = 0); // Return a node: root or normal SLE::pointer getDirNode(LedgerStateParms& parms, const uint256& uNodeIndex); @@ -271,7 +271,7 @@ public: // Quality // - static uint256 getQualityIndex(const uint256& uBase, const uint64 uNodeDir=0); + static uint256 getQualityIndex(const uint256& uBase, const uint64 uNodeDir = 0); static uint256 getQualityNext(const uint256& uBase); static uint64 getQuality(const uint256& uBase); diff --git a/src/cpp/ripple/LedgerFormats.cpp b/src/cpp/ripple/LedgerFormats.cpp index 5605cd041..cbc45dba9 100644 --- a/src/cpp/ripple/LedgerFormats.cpp +++ b/src/cpp/ripple/LedgerFormats.cpp @@ -46,6 +46,12 @@ static bool LEFInit() ; DECLARE_LEF(DirectoryNode, ltDIR_NODE) + << SOElement(sfOwner, SOE_OPTIONAL) // for owner directories + << SOElement(sfTakerPaysCurrency, SOE_OPTIONAL) // for order book directories + << 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(sfIndexes, SOE_REQUIRED) << SOElement(sfRootIndex, SOE_REQUIRED) << SOElement(sfIndexNext, SOE_OPTIONAL) diff --git a/src/cpp/ripple/SerializeProto.h b/src/cpp/ripple/SerializeProto.h index 006abd028..a10ab314b 100644 --- a/src/cpp/ripple/SerializeProto.h +++ b/src/cpp/ripple/SerializeProto.h @@ -65,6 +65,7 @@ FIELD(BookNode, UINT64, 3) FIELD(OwnerNode, UINT64, 4) FIELD(BaseFee, UINT64, 5) + FIELD(ExchangeRate, UINT64, 6) // 128-bit FIELD(EmailHash, HASH128, 1) @@ -84,6 +85,12 @@ FIELD(InvoiceID, HASH256, 17) FIELD(Nickname, HASH256, 18) + // 160-bit (common) + FIELD(TakerPaysCurrency, HASH160, 1) + FIELD(TakerPaysIssuer, HASH160, 2) + FIELD(TakerGetsCurrency, HASH160, 3) + FIELD(TakerGetsIssuer, HASH160, 4) + // currency amount (common) FIELD(Amount, AMOUNT, 1) FIELD(Balance, AMOUNT, 2) From 2864dda4eb652019c6a032e5b248f21a3551c9cc Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 30 Nov 2012 00:30:19 -0800 Subject: [PATCH 3/6] 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 c91662aa0..efd3e7cd9 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 6e9226634..23292254b 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 b2cca2b71..5edd8944b 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 754b31a58..ea91ff9fb 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 cbc45dba9..98c70857a 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 27136b476..db0ce70be 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 1d287fda9..3403c4038 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<"; From e5e96f9dd7fafdc9abb0e2937a529c0bbdc235a8 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 30 Nov 2012 03:17:16 -0800 Subject: [PATCH 4/6] Bugfix. --- src/cpp/ripple/Ledger.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/ripple/Ledger.cpp b/src/cpp/ripple/Ledger.cpp index efd3e7cd9..a498fee1c 100644 --- a/src/cpp/ripple/Ledger.cpp +++ b/src/cpp/ripple/Ledger.cpp @@ -1182,7 +1182,7 @@ void Ledger::decPendingSaves() void Ledger::ownerDirDescriber(SLE::ref sle, const uint160& owner) { - sle->setFieldH160(sfOwner, owner); + sle->setFieldAccount(sfOwner, owner); } void Ledger::qualityDirDescriber(SLE::ref sle, From 41fe8f4443f52f524c80d42d0acf59962bc28386 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 30 Nov 2012 03:48:49 -0800 Subject: [PATCH 5/6] Count InfoSub's. --- src/cpp/ripple/NetworkOPs.cpp | 1 + src/cpp/ripple/NetworkOPs.h | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index 9db94bcee..9a39d3126 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -24,6 +24,7 @@ // there's a functional network. SETUP_LOG(); +DECLARE_INSTANCE(InfoSub); NetworkOPs::NetworkOPs(boost::asio::io_service& io_service, LedgerMaster* pLedgerMaster) : mMode(omDISCONNECTED), mNeedNetworkLedger(false), mNetTimer(io_service), mLedgerMaster(pLedgerMaster), diff --git a/src/cpp/ripple/NetworkOPs.h b/src/cpp/ripple/NetworkOPs.h index 8e5730df5..4f8accb56 100644 --- a/src/cpp/ripple/NetworkOPs.h +++ b/src/cpp/ripple/NetworkOPs.h @@ -20,7 +20,9 @@ class Peer; class LedgerConsensus; -class InfoSub +DEFINE_INSTANCE(InfoSub); + +class InfoSub : public IS_INSTANCE(InfoSub) { public: From 5957a79584579a569b65cfac5f45741f93236fb8 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 30 Nov 2012 15:26:18 -0800 Subject: [PATCH 6/6] Make only one version of each ledger history option. --- rippled-example.cfg | 6 ++++++ src/cpp/ripple/Config.cpp | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/rippled-example.cfg b/rippled-example.cfg index 0bbd0f5dd..7234df1a1 100644 --- a/rippled-example.cfg +++ b/rippled-example.cfg @@ -109,6 +109,12 @@ # Examples: RASH BUSH MILK LOOK BAD BRIM AVID GAFF BAIT ROT POD LOVE # shfArahZT9Q9ckTf3s1psJ7C7qzVN # +# [ledger_history]: +# To serve clients, servers need historical ledger data. This sets the number of +# past ledgers to acquire on server startup and the minimum to maintain while +# running. Servers that don't need to serve clients can set this to "none". +# Servers that want complete history can set this to "full". +# The default is 256 ledgers [peer_ip] 0.0.0.0 diff --git a/src/cpp/ripple/Config.cpp b/src/cpp/ripple/Config.cpp index 0304de7b4..4701634fb 100644 --- a/src/cpp/ripple/Config.cpp +++ b/src/cpp/ripple/Config.cpp @@ -296,9 +296,9 @@ void Config::load() if (sectionSingleB(secConfig, SECTION_LEDGER_HISTORY, strTemp)) { boost::to_lower(strTemp); - if ((strTemp == "no") || (strTemp == "none") || (strTemp == "off") || (strTemp == "false")) + if (strTemp == "none") LEDGER_HISTORY = 0; - else if ((strTemp == "yes") || (strTemp == "full") || (strTemp == "on") || (strTemp == "-1")) + else if (strTemp == "full") LEDGER_HISTORY = 1000000000u; else LEDGER_HISTORY = boost::lexical_cast(strTemp);