From 326ff5a205afbb215306d5128ddcca71421d3802 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sun, 16 Jun 2013 08:30:07 -0700 Subject: [PATCH] Tidy up LedgerEntrySet --- RefactoringNotes.txt | 4 ++ modules/ripple_client/ripple_client.cpp | 2 +- .../ripple_data/protocol/ripple_HashPrefix.h | 4 ++ .../protocol/ripple_LedgerFormat.h | 39 +++++++++++++++++++ modules/ripple_main/ripple_main.cpp | 4 +- newcoin.vcxproj | 4 +- newcoin.vcxproj.filters | 12 +++--- src/cpp/ripple/Ledger.h | 3 ++ ...EntrySet.cpp => ripple_LedgerEntrySet.cpp} | 3 ++ ...dgerEntrySet.h => ripple_LedgerEntrySet.h} | 23 ++++++++--- 10 files changed, 81 insertions(+), 17 deletions(-) rename src/cpp/ripple/{LedgerEntrySet.cpp => ripple_LedgerEntrySet.cpp} (99%) rename src/cpp/ripple/{LedgerEntrySet.h => ripple_LedgerEntrySet.h} (98%) diff --git a/RefactoringNotes.txt b/RefactoringNotes.txt index c0239bd81c..b32823234f 100644 --- a/RefactoringNotes.txt +++ b/RefactoringNotes.txt @@ -49,6 +49,10 @@ Ledger "Skip List" Is not really a skip list data structure +Duplicate Code + + LedgerEntryFormat and TxFormat + -------------------------------------------------------------------------------- Interfaces diff --git a/modules/ripple_client/ripple_client.cpp b/modules/ripple_client/ripple_client.cpp index fa3650fbf2..331a0aca1f 100644 --- a/modules/ripple_client/ripple_client.cpp +++ b/modules/ripple_client/ripple_client.cpp @@ -41,7 +41,7 @@ #include "src/cpp/ripple/ripple_AccountState.h" #include "src/cpp/ripple/ripple_NicknameState.h" #include "src/cpp/ripple/Ledger.h" -#include "src/cpp/ripple/LedgerEntrySet.h" +#include "src/cpp/ripple/ripple_LedgerEntrySet.h" #include "src/cpp/ripple/TransactionEngine.h" #include "src/cpp/ripple/ripple_LoadManager.h" #include "src/cpp/ripple/ripple_Peer.h" diff --git a/modules/ripple_data/protocol/ripple_HashPrefix.h b/modules/ripple_data/protocol/ripple_HashPrefix.h index fe7d575a79..6052b79ae1 100644 --- a/modules/ripple_data/protocol/ripple_HashPrefix.h +++ b/modules/ripple_data/protocol/ripple_HashPrefix.h @@ -22,6 +22,10 @@ @ingroup protocol */ +// VFALCO NOTE there are ledger entry prefixes too but they are only +// 1 byte, find out why they are different. Maybe we should +// group them all together? +// struct HashPrefix { // VFALCO TODO Make these Doxygen comments and expand the diff --git a/modules/ripple_data/protocol/ripple_LedgerFormat.h b/modules/ripple_data/protocol/ripple_LedgerFormat.h index 3cc08692ff..f6cf7e07f1 100644 --- a/modules/ripple_data/protocol/ripple_LedgerFormat.h +++ b/modules/ripple_data/protocol/ripple_LedgerFormat.h @@ -7,23 +7,57 @@ #ifndef RIPPLE_LEDGERFORMAT_H #define RIPPLE_LEDGERFORMAT_H +/** + + These are stored in serialized data. + + @ingroup protocol +*/ // Used as the type of a transaction or the type of a ledger entry. enum LedgerEntryType { ltINVALID = -1, + ltACCOUNT_ROOT = 'a', + + /** Directory node. + + A directory is a vector 256-bit values. Usually they represent + hashes of other objects in the ledger. + + Used in an append-only fashion. + + (There's a little more information than this, see the template) + */ ltDIR_NODE = 'd', + ltGENERATOR_MAP = 'g', + + /** Describes a trust line. + */ + // VFALCO TODO Rename to TrustLine or something similar. ltRIPPLE_STATE = 'r', + + /** Deprecated. + */ ltNICKNAME = 'n', + ltOFFER = 'o', + ltCONTRACT = 'c', + ltLEDGER_HASHES = 'h', + ltFEATURES = 'f', + ltFEE_SETTINGS = 's', }; +/** + @ingroup protocol +*/ // Used as a prefix for computing ledger indexes (keys). +// VFALCO TODO Why are there a separate set of prefixes? i.e. class HashPrefix enum LedgerNameSpace { spaceAccount = 'a', @@ -40,6 +74,9 @@ enum LedgerNameSpace spaceFee = 'e', }; +/** + @ingroup protocol +*/ enum LedgerSpecificFlags { // ltACCOUNT_ROOT @@ -59,6 +96,8 @@ enum LedgerSpecificFlags lsfHighAuth = 0x00080000, }; +// VFALCO TODO See if we can merge LedgerEntryFormat with TxFormat +// class LedgerEntryFormat { public: diff --git a/modules/ripple_main/ripple_main.cpp b/modules/ripple_main/ripple_main.cpp index 5ff5ff1099..01aef6e28e 100644 --- a/modules/ripple_main/ripple_main.cpp +++ b/modules/ripple_main/ripple_main.cpp @@ -179,7 +179,7 @@ #include "src/cpp/ripple/ripple_AccountItems.h" #include "src/cpp/ripple/ripple_AcceptedLedgerTx.h" #include "src/cpp/ripple/ripple_AcceptedLedger.h" -#include "src/cpp/ripple/LedgerEntrySet.h" +#include "src/cpp/ripple/ripple_LedgerEntrySet.h" #include "src/cpp/ripple/TransactionEngine.h" #include "src/cpp/ripple/ripple_CanonicalTXSet.h" @@ -277,7 +277,7 @@ static const uint64 tenTo17m1 = tenTo17 - 1; #include "src/cpp/ripple/HttpsClient.cpp" #include "src/cpp/ripple/Interpreter.cpp" // no log #include "src/cpp/ripple/Ledger.cpp" -#include "src/cpp/ripple/LedgerEntrySet.cpp" +#include "src/cpp/ripple/ripple_LedgerEntrySet.cpp" #include "src/cpp/ripple/LedgerMaster.cpp" #include "src/cpp/ripple/LedgerProposal.cpp" // no log #include "src/cpp/ripple/LedgerTiming.cpp" diff --git a/newcoin.vcxproj b/newcoin.vcxproj index 02a4c2a656..7bab345c59 100644 --- a/newcoin.vcxproj +++ b/newcoin.vcxproj @@ -891,7 +891,7 @@ true true - + true true true @@ -1772,7 +1772,7 @@ - + diff --git a/newcoin.vcxproj.filters b/newcoin.vcxproj.filters index 37820f491e..5001683f1f 100644 --- a/newcoin.vcxproj.filters +++ b/newcoin.vcxproj.filters @@ -633,9 +633,6 @@ 1. Modules\ripple_main\_unfactored\ledger - - 1. Modules\ripple_main\_unfactored\ledger - 1. Modules\ripple_main\_unfactored\ledger @@ -885,6 +882,9 @@ 1. Modules\ripple_main\refactored + + 1. Modules\ripple_main\_unfactored\ledger + @@ -1397,9 +1397,6 @@ 1. Modules\ripple_main\_unfactored\ledger - - 1. Modules\ripple_main\_unfactored\ledger - 1. Modules\ripple_main\_unfactored\ledger @@ -1649,6 +1646,9 @@ 1. Modules\ripple_main\refactored + + 1. Modules\ripple_main\_unfactored\ledger + diff --git a/src/cpp/ripple/Ledger.h b/src/cpp/ripple/Ledger.h index 6aaca879df..5ab50867b2 100644 --- a/src/cpp/ripple/Ledger.h +++ b/src/cpp/ripple/Ledger.h @@ -358,6 +358,9 @@ public: // // Index of node which is the ripple state between two accounts for a currency. + // VFALCO NOTE Rename these to make it clear they are simple functions that + // don't access global variables. e.g. "calculateKeyFromRippleStateAndAddress" + // static uint256 getRippleStateIndex (const RippleAddress & naA, const RippleAddress & naB, const uint160 & uCurrency); static uint256 getRippleStateIndex (const uint160 & uiA, const uint160 & uiB, const uint160 & uCurrency) { diff --git a/src/cpp/ripple/LedgerEntrySet.cpp b/src/cpp/ripple/ripple_LedgerEntrySet.cpp similarity index 99% rename from src/cpp/ripple/LedgerEntrySet.cpp rename to src/cpp/ripple/ripple_LedgerEntrySet.cpp index ed652a0937..94040b6788 100644 --- a/src/cpp/ripple/LedgerEntrySet.cpp +++ b/src/cpp/ripple/ripple_LedgerEntrySet.cpp @@ -11,6 +11,9 @@ DECLARE_INSTANCE (LedgerEntrySet) // #define META_DEBUG +// VFALCO TODO Replace this macro with a documented language constant +// NOTE Is this part of the protocol? +// #define DIR_NODE_MAX 32 void LedgerEntrySet::init (Ledger::ref ledger, uint256 const& transactionID, diff --git a/src/cpp/ripple/LedgerEntrySet.h b/src/cpp/ripple/ripple_LedgerEntrySet.h similarity index 98% rename from src/cpp/ripple/LedgerEntrySet.h rename to src/cpp/ripple/ripple_LedgerEntrySet.h index 261ead9441..1aa7ff2132 100644 --- a/src/cpp/ripple/LedgerEntrySet.h +++ b/src/cpp/ripple/ripple_LedgerEntrySet.h @@ -4,8 +4,8 @@ */ //============================================================================== -#ifndef __LEDGERENTRYSET__ -#define __LEDGERENTRYSET__ +#ifndef RIPPLE_LEDGERENTRYSET_H +#define RIPPLE_LEDGERENTRYSET_H DEFINE_INSTANCE (LedgerEntrySetEntry); DEFINE_INSTANCE (LedgerEntrySet); @@ -42,9 +42,11 @@ public: LedgerEntryAction mAction; int mSeq; - LedgerEntrySetEntry (SLE::ref e, LedgerEntryAction a, int s) : mEntry (e), mAction (a), mSeq (s) + LedgerEntrySetEntry (SLE::ref e, LedgerEntryAction a, int s) + : mEntry (e) + , mAction (a) + , mSeq (s) { - ; } }; @@ -62,12 +64,10 @@ public: LedgerEntrySet (Ledger::ref ledger, TransactionEngineParams tep, bool immutable = false) : mLedger (ledger), mParams (tep), mSeq (0), mImmutable (immutable) { - ; } LedgerEntrySet () : mParams (tapNONE), mSeq (0), mImmutable (false) { - ; } // set functions @@ -75,17 +75,23 @@ public: { mImmutable = true; } + bool isImmutable () const { return mImmutable; } + LedgerEntrySet duplicate () const; // Make a duplicate of this set + void setTo (const LedgerEntrySet&); // Set this set to have the same contents as another + void swapWith (LedgerEntrySet&); // Swap the contents of two sets + void invalidate () { mLedger.reset (); } + bool isValid () const { return !!mLedger; @@ -95,21 +101,26 @@ public: { return mSeq; } + TransactionEngineParams getParams () const { return mParams; } + void bumpSeq () { ++mSeq; } + void init (Ledger::ref ledger, uint256 const & transactionID, uint32 ledgerID, TransactionEngineParams params); + void clear (); Ledger::pointer& getLedger () { return mLedger; } + Ledger::ref getLedgerRef () const { return mLedger;