Refactor Ledger:

* Consolidate constructors
* Use pointer/size instead of Serializer
* Factor out PendingSaves
* Make some members free functions
* Reduce size of constructor initializer lists
This commit is contained in:
Vinnie Falco
2015-05-18 17:17:53 -07:00
parent 36ac3bc672
commit 860ab3523c
17 changed files with 304 additions and 175 deletions

View File

@@ -1468,6 +1468,12 @@
</ClCompile>
<ClInclude Include="..\..\src\ripple\app\ledger\DirectoryEntryIterator.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\ledger\impl\LedgerFees.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='debug.classic|x64'">..\..\src\soci\src\core;..\..\src\sqlite;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='release.classic|x64'">..\..\src\soci\src\core;..\..\src\sqlite;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<ClCompile Include="..\..\src\ripple\app\ledger\InboundLedger.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
@@ -1508,6 +1514,8 @@
</ClCompile>
<ClInclude Include="..\..\src\ripple\app\ledger\LedgerEntrySet.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\ledger\LedgerFees.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\ledger\LedgerHistory.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
@@ -1560,6 +1568,8 @@
</ClCompile>
<ClInclude Include="..\..\src\ripple\app\ledger\OrderBookIterator.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\ledger\PendingSaves.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\ledger\tests\DeferredCredits.test.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>

View File

@@ -262,6 +262,9 @@
<Filter Include="ripple\app\ledger">
<UniqueIdentifier>{CE126498-A44D-30A2-345B-0F672BCDF947}</UniqueIdentifier>
</Filter>
<Filter Include="ripple\app\ledger\impl">
<UniqueIdentifier>{0EF1A571-94CC-4D70-E004-48579DF8AF2B}</UniqueIdentifier>
</Filter>
<Filter Include="ripple\app\ledger\tests">
<UniqueIdentifier>{55A76B5B-A18E-E655-1A07-9492C6F8F356}</UniqueIdentifier>
</Filter>
@@ -2169,6 +2172,9 @@
<ClInclude Include="..\..\src\ripple\app\ledger\DirectoryEntryIterator.h">
<Filter>ripple\app\ledger</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\ledger\impl\LedgerFees.cpp">
<Filter>ripple\app\ledger\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\app\ledger\InboundLedger.cpp">
<Filter>ripple\app\ledger</Filter>
</ClCompile>
@@ -2199,6 +2205,9 @@
<ClInclude Include="..\..\src\ripple\app\ledger\LedgerEntrySet.h">
<Filter>ripple\app\ledger</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\ledger\LedgerFees.h">
<Filter>ripple\app\ledger</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\ledger\LedgerHistory.cpp">
<Filter>ripple\app\ledger</Filter>
</ClCompile>
@@ -2241,6 +2250,9 @@
<ClInclude Include="..\..\src\ripple\app\ledger\OrderBookIterator.h">
<Filter>ripple\app\ledger</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\ledger\PendingSaves.h">
<Filter>ripple\app\ledger</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\ledger\tests\DeferredCredits.test.cpp">
<Filter>ripple\app\ledger\tests</Filter>
</ClCompile>

View File

@@ -161,14 +161,15 @@ bool InboundLedger::tryLocal ()
if (m_journal.trace) m_journal.trace <<
"Ledger header found in fetch pack";
mLedger = std::make_shared<Ledger> (data, true);
mLedger = std::make_shared<Ledger> (
data.data(), data.size(), true);
getApp().getNodeStore ().store (
hotLEDGER, std::move (data), mHash);
}
else
{
mLedger = std::make_shared<Ledger> (
strCopy (node->getData ()), true);
mLedger = std::make_shared<Ledger>(
node->getData().data(), node->getData().size(), true);
}
if (mLedger->getHash () != mHash)
@@ -761,7 +762,8 @@ bool InboundLedger::takeHeader (std::string const& data)
if (mComplete || mFailed || mHaveHeader)
return true;
mLedger = std::make_shared<Ledger> (data, false);
mLedger = std::make_shared<Ledger>(
data.data(), data.size(), false);
if (mLedger->getHash () != mHash)
{

View File

@@ -25,6 +25,7 @@
#include <ripple/app/ledger/LedgerTiming.h>
#include <ripple/app/ledger/LedgerToJson.h>
#include <ripple/app/ledger/OrderBookDB.h>
#include <ripple/app/ledger/PendingSaves.h>
#include <ripple/app/data/DatabaseCon.h>
#include <ripple/app/data/SociDB.h>
#include <ripple/app/main/Application.h>
@@ -55,10 +56,6 @@ Ledger::Ledger (RippleAddress const& masterID, std::uint64_t startAmount)
, mParentCloseTime (0)
, mCloseResolution (ledgerDefaultTimeResolution)
, mCloseFlags (0)
, mClosed (false)
, mValidated (false)
, mValidHash (false)
, mAccepted (false)
, mImmutable (false)
, mTransactionMap (std::make_shared <SHAMap> (SHAMapType::TRANSACTION,
getApp().family(), deprecatedLogs().journal("SHAMap")))
@@ -77,8 +74,6 @@ Ledger::Ledger (RippleAddress const& masterID, std::uint64_t startAmount)
writeBack (lepCREATE, startAccount->getSLE ());
mAccountStateMap->flushDirty (hotACCOUNT_NODE, mLedgerSeq);
initializeFees ();
}
Ledger::Ledger (uint256 const& parentHash,
@@ -100,10 +95,6 @@ Ledger::Ledger (uint256 const& parentHash,
, mParentCloseTime (parentCloseTime)
, mCloseResolution (closeResolution)
, mCloseFlags (closeFlags)
, mClosed (false)
, mValidated (false)
, mValidHash (false)
, mAccepted (false)
, mImmutable (true)
, mTransactionMap (std::make_shared <SHAMap> (
SHAMapType::TRANSACTION, transHash, getApp().family(),
@@ -130,8 +121,6 @@ Ledger::Ledger (uint256 const& parentHash,
mTransactionMap->setImmutable ();
mAccountStateMap->setImmutable ();
initializeFees ();
}
// Create a new ledger that's a snapshot of this one
@@ -146,14 +135,12 @@ Ledger::Ledger (Ledger& ledger,
, mCloseFlags (ledger.mCloseFlags)
, mClosed (ledger.mClosed)
, mValidated (ledger.mValidated)
, mValidHash (false)
, mAccepted (ledger.mAccepted)
, mImmutable (!isMutable)
, mTransactionMap (ledger.mTransactionMap->snapShot (isMutable))
, mAccountStateMap (ledger.mAccountStateMap->snapShot (isMutable))
{
updateHash ();
initializeFees ();
}
// Create a new ledger that follows this one
@@ -164,10 +151,6 @@ Ledger::Ledger (bool /* dummy */,
, mParentCloseTime (prevLedger.mCloseTime)
, mCloseResolution (prevLedger.mCloseResolution)
, mCloseFlags (0)
, mClosed (false)
, mValidated (false)
, mValidHash (false)
, mAccepted (false)
, mImmutable (false)
, mTransactionMap (std::make_shared <SHAMap> (SHAMapType::TRANSACTION,
getApp().family(), deprecatedLogs().journal("SHAMap")))
@@ -191,60 +174,34 @@ Ledger::Ledger (bool /* dummy */,
{
mCloseTime = prevLedger.mCloseTime + mCloseResolution;
}
initializeFees ();
}
Ledger::Ledger (Blob const& rawLedger,
bool hasPrefix)
: mClosed (false)
, mValidated (false)
, mValidHash (false)
, mAccepted (false)
, mImmutable (true)
Ledger::Ledger (void const* data,
std::size_t size, bool hasPrefix)
: mImmutable (true)
{
Serializer s (rawLedger);
setRaw (s, hasPrefix);
initializeFees ();
SerialIter sit (data, size);
setRaw (sit, hasPrefix);
}
Ledger::Ledger (std::string const& rawLedger, bool hasPrefix)
: mClosed (false)
, mValidated (false)
, mValidHash (false)
, mAccepted (false)
, mImmutable (true)
{
Serializer s (rawLedger);
setRaw (s, hasPrefix);
initializeFees ();
}
/** Used for ledgers loaded from JSON files */
Ledger::Ledger (std::uint32_t ledgerSeq, std::uint32_t closeTime)
: mTotCoins (0),
mLedgerSeq (ledgerSeq),
mCloseTime (closeTime),
mParentCloseTime (0),
mCloseResolution (ledgerDefaultTimeResolution),
mCloseFlags (0),
mClosed (false),
mValidated (false),
mValidHash (false),
mAccepted (false),
mImmutable (false),
mTransactionMap (std::make_shared <SHAMap> (
: mTotCoins (0)
, mLedgerSeq (ledgerSeq)
, mCloseTime (closeTime)
, mParentCloseTime (0)
, mCloseResolution (ledgerDefaultTimeResolution)
, mCloseFlags (0)
, mImmutable (false)
, mTransactionMap (std::make_shared <SHAMap> (
SHAMapType::TRANSACTION, getApp().family(),
deprecatedLogs().journal("SHAMap"))),
mAccountStateMap (std::make_shared <SHAMap> (
deprecatedLogs().journal("SHAMap")))
, mAccountStateMap (std::make_shared <SHAMap> (
SHAMapType::STATE, getApp().family(),
deprecatedLogs().journal("SHAMap")))
{
initializeFees ();
}
//------------------------------------------------------------------------------
Ledger::~Ledger ()
{
@@ -296,10 +253,8 @@ void Ledger::updateHash ()
mValidHash = true;
}
void Ledger::setRaw (Serializer& s, bool hasPrefix)
void Ledger::setRaw (SerialIter& sit, bool hasPrefix)
{
SerialIter sit (s);
if (hasPrefix)
sit.get32 ();
@@ -660,12 +615,9 @@ bool Ledger::saveValidatedLedger (bool current)
{
WriteLog (lsWARNING, Ledger) << "An accepted ledger was missing nodes";
getApp().getLedgerMaster().failedSave(mLedgerSeq, mHash);
{
// Clients can now trust the database for information about this
// ledger sequence.
StaticScopedLockType sl (sPendingSaveLock);
sPendingSaves.erase(getLedgerSeq());
}
// Clients can now trust the database for information about this
// ledger sequence.
getApp().pendingSaves().erase(getLedgerSeq());
return false;
}
@@ -760,12 +712,9 @@ bool Ledger::saveValidatedLedger (bool current)
to_string (mAccountHash) % to_string (mTransHash));
}
{
// Clients can now trust the database for information about this ledger
// sequence.
StaticScopedLockType sl (sPendingSaveLock);
sPendingSaves.erase(getLedgerSeq());
}
// Clients can now trust the database for
// information about this ledger sequence.
getApp().pendingSaves().erase(getLedgerSeq());
return true;
}
@@ -1666,14 +1615,11 @@ bool Ledger::pendSaveValidated (bool isSynchronous, bool isCurrent)
assert (isImmutable ());
if (!getApp().pendingSaves().insert(getLedgerSeq()))
{
StaticScopedLockType sl (sPendingSaveLock);
if (!sPendingSaves.insert(getLedgerSeq()).second)
{
WriteLog (lsDEBUG, Ledger)
<< "Pend save with seq in pending saves " << getLedgerSeq();
return true;
}
WriteLog (lsDEBUG, Ledger)
<< "Pend save with seq in pending saves " << getLedgerSeq();
return true;
}
if (isSynchronous)
@@ -1696,12 +1642,6 @@ bool Ledger::pendSaveValidated (bool isSynchronous, bool isCurrent)
return true;
}
std::set<std::uint32_t> Ledger::getPendingSaves()
{
StaticScopedLockType sl (sPendingSaveLock);
return sPendingSaves;
}
void Ledger::ownerDirDescriber (SLE::ref sle, bool, Account const& owner)
{
sle->setFieldAccount (sfOwner, owner);
@@ -1726,15 +1666,7 @@ void Ledger::qualityDirDescriber (
}
}
void Ledger::initializeFees ()
{
mBaseFee = 0;
mReferenceFeeUnits = 0;
mReserveBase = 0;
mReserveIncrement = 0;
}
void Ledger::updateFees ()
void Ledger::deprecatedUpdateCachedFees() const
{
if (mBaseFee)
return;
@@ -1762,7 +1694,9 @@ void Ledger::updateFees ()
}
{
StaticScopedLockType sl (sPendingSaveLock);
// VFALCO Why not do this before calling getASNode?
std::lock_guard<
std::mutex> lock(mutex_);
if (mBaseFee == 0)
{
mBaseFee = baseFee;
@@ -1773,21 +1707,6 @@ void Ledger::updateFees ()
}
}
std::uint64_t Ledger::scaleFeeBase (std::uint64_t fee)
{
// Converts a fee in fee units to a fee in drops
updateFees ();
return getApp().getFeeTrack ().scaleFeeBase (
fee, mBaseFee, mReferenceFeeUnits);
}
std::uint64_t Ledger::scaleFeeLoad (std::uint64_t fee, bool bAdmin)
{
updateFees ();
return getApp().getFeeTrack ().scaleFeeLoad (
fee, mBaseFee, mReferenceFeeUnits, bAdmin);
}
std::vector<uint256> Ledger::getNeededTransactionHashes (
int max, SHAMapSyncFilter* filter) const
{
@@ -1820,7 +1739,4 @@ std::vector<uint256> Ledger::getNeededAccountStateHashes (
return ret;
}
Ledger::StaticLockType Ledger::sPendingSaveLock;
std::set<std::uint32_t> Ledger::sPendingSaves;
} // ripple

View File

@@ -28,7 +28,7 @@
#include <ripple/basics/CountedObject.h>
#include <ripple/protocol/Serializer.h>
#include <ripple/protocol/Book.h>
#include <set>
#include <mutex>
namespace ripple {
@@ -119,6 +119,7 @@ public:
// used for the starting bootstrap ledger
Ledger (const RippleAddress & masterID, std::uint64_t startAmount);
// Used for ledgers loaded from JSON files
Ledger (uint256 const& parentHash, uint256 const& transHash,
uint256 const& accountHash,
std::uint64_t totCoins, std::uint32_t closeTime,
@@ -127,8 +128,8 @@ public:
// used for database ledgers
Ledger (std::uint32_t ledgerSeq, std::uint32_t closeTime);
Ledger (Blob const & rawLedger, bool hasPrefix);
Ledger (std::string const& rawLedger, bool hasPrefix);
Ledger (void const* data,
std::size_t size, bool hasPrefix);
Ledger (bool dummy, Ledger & previous); // ledger after this one
Ledger (Ledger & target, bool isMutable); // snapshot
@@ -182,8 +183,8 @@ public:
}
// ledger signature operations
void addRaw (Serializer & s) const;
void setRaw (Serializer & s, bool hasPrefix);
void addRaw (Serializer& s) const;
void setRaw (SerialIter& sit, bool hasPrefix);
uint256 const& getHash ();
uint256 const& getParentHash () const
@@ -380,39 +381,34 @@ public:
getRippleState (
Account const& a, Account const& b, Currency const& currency) const;
std::uint32_t getReferenceFeeUnits ()
std::uint32_t getReferenceFeeUnits() const
{
// Returns the cost of the reference transaction in fee units
updateFees ();
deprecatedUpdateCachedFees ();
return mReferenceFeeUnits;
}
std::uint64_t getBaseFee ()
std::uint64_t getBaseFee() const
{
// Returns the cost of the reference transaction in drops
updateFees ();
deprecatedUpdateCachedFees ();
return mBaseFee;
}
std::uint64_t getReserve (int increments)
std::uint64_t getReserve (int increments) const
{
// Returns the required reserve in drops
updateFees ();
deprecatedUpdateCachedFees ();
return static_cast<std::uint64_t> (increments) * mReserveIncrement
+ mReserveBase;
}
std::uint64_t getReserveInc ()
std::uint64_t getReserveInc () const
{
updateFees ();
deprecatedUpdateCachedFees ();
return mReserveIncrement;
}
std::uint64_t scaleFeeBase (std::uint64_t fee);
std::uint64_t scaleFeeLoad (std::uint64_t fee, bool bAdmin);
static std::set<std::uint32_t> getPendingSaves();
/** Const version of getHash() which gets the current value without calling
updateHash(). */
uint256 const& getRawHash () const
@@ -437,11 +433,15 @@ protected:
bool saveValidatedLedger (bool current);
private:
void initializeFees ();
void updateFees ();
// Updates the fees cached in the ledger.
// Safe to call concurrently. We shouldn't be storing
// fees in the Ledger object, they should be a local side-structure
// associated with a particular module (rpc, tx processing, consensus)
//
void deprecatedUpdateCachedFees() const;
// The basic Ledger structure, can be opened, closed, or synching
uint256 mHash;
uint256 mHash; // VFALCO This could be boost::optional<uint256>
uint256 mParentHash;
uint256 mTransHash;
uint256 mAccountHash;
@@ -459,28 +459,28 @@ private:
// flags indicating how this ledger close took place
std::uint32_t mCloseFlags;
bool mClosed, mValidated, mValidHash, mAccepted, mImmutable;
// Fee units for the reference transaction
std::uint32_t mReferenceFeeUnits;
// Reserve basse and increment in fee units
std::uint32_t mReserveBase, mReserveIncrement;
// Ripple cost of the reference transaction
std::uint64_t mBaseFee;
bool mClosed = false;
bool mValidated = false;
bool mValidHash = false;
bool mAccepted = false;
bool mImmutable;
std::shared_ptr<SHAMap> mTransactionMap;
std::shared_ptr<SHAMap> mAccountStateMap;
typedef RippleMutex StaticLockType;
typedef std::lock_guard <StaticLockType> StaticScopedLockType;
// Protects fee variables
std::mutex mutable mutex_;
// Ledgers not fully saved, validated ledger present but DB may not be
// correct yet.
static StaticLockType sPendingSaveLock;
// Ripple cost of the reference transaction
std::uint64_t mutable mBaseFee = 0;
static std::set<std::uint32_t> sPendingSaves;
// Fee units for the reference transaction
std::uint32_t mutable mReferenceFeeUnits = 0;
// Reserve base in fee units
std::uint32_t mutable mReserveBase = 0;
// Reserve increment in fee units
std::uint32_t mutable mReserveIncrement = 0;
};
inline LedgerStateParms operator| (

View File

@@ -0,0 +1,40 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_APP_FEES_H_INCLUDED
#define RIPPLE_APP_FEES_H_INCLUDED
#include <ripple/app/ledger/Ledger.h>
#include <ripple/core/LoadFeeTrack.h>
namespace ripple {
// VFALCO Replace std::uint64_t with a real type, maybe Amount?
// Converts a fee in fee units to a fee in drops
std::uint64_t
scaleFeeBase (LoadFeeTrack& track,
Ledger const& ledger, std::uint64_t fee);
std::uint64_t
scaleFeeLoad (LoadFeeTrack& track,
Ledger const& ledger, std::uint64_t fee, bool admin);
}
#endif

View File

@@ -24,6 +24,7 @@
#include <ripple/app/ledger/LedgerHistory.h>
#include <ripple/app/ledger/LedgerHolder.h>
#include <ripple/app/ledger/OrderBookDB.h>
#include <ripple/app/ledger/PendingSaves.h>
#include <ripple/app/main/Application.h>
#include <ripple/app/misc/IHashRouter.h>
#include <ripple/app/misc/NetworkOPs.h>
@@ -480,20 +481,21 @@ public:
// Remove from the validated range any ledger sequences that may not be
// fully updated in the database yet
std::set<std::uint32_t> sPendingSaves = Ledger::getPendingSaves();
auto const pendingSaves =
getApp().pendingSaves().getSnapshot();
if (!sPendingSaves.empty() && ((minVal != 0) || (maxVal != 0)))
if (!pendingSaves.empty() && ((minVal != 0) || (maxVal != 0)))
{
// Ensure we shrink the tips as much as possible
// If we have 7-9 and 8,9 are invalid, we don't want to see the 8 and shrink to just 9
// because then we'll have nothing when we could have 7.
while (sPendingSaves.count(maxVal) > 0)
while (pendingSaves.count(maxVal) > 0)
--maxVal;
while (sPendingSaves.count(minVal) > 0)
while (pendingSaves.count(minVal) > 0)
++minVal;
// Best effort for remaining exclusions
for(auto v : sPendingSaves)
for(auto v : pendingSaves)
{
if ((v >= minVal) && (v <= maxVal))
{

View File

@@ -0,0 +1,86 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2015 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_APP_PENDINGSAVES_H_INCLUDED
#define RIPPLE_APP_PENDINGSAVES_H_INCLUDED
#include <ripple/protocol/Protocol.h>
#include <boost/container/flat_set.hpp>
#include <mutex>
namespace ripple {
/** Keeps track of which ledgers haven't been fully saved.
During the ledger building process this collection will keep
track of those ledgers that are being built but have not yet
been completely written.
*/
class PendingSaves
{
private:
std::mutex mutable mutex_;
boost::container::flat_set<LedgerIndex> set_;
public:
/** Add a ledger to the list.
This is called when the ledger is built but before
we have updated the SQLite indexes. Clients querying
the indexes will not see results from this ledger.
@return `true` If the ledger indexes was not
already in the list.
*/
bool
insert (LedgerIndex seq)
{
std::lock_guard<
std::mutex> lock(mutex_);
return set_.insert(seq).second;
}
/** Remove a ledger from the list.
This is called after the ledger has been fully saved,
indicating that the SQLite indexes will produce correct
results in response to client requests.
*/
void
erase (LedgerIndex seq)
{
std::lock_guard<
std::mutex> lock(mutex_);
set_.erase(seq);
}
/** Returns a copy of the current set. */
auto
getSnapshot() const ->
decltype(set_)
{
std::lock_guard<
std::mutex> lock(mutex_);
return set_;
}
};
}
#endif

View File

@@ -0,0 +1,42 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <BeastConfig.h>
#include <ripple/app/ledger/LedgerFees.h>
namespace ripple {
std::uint64_t
scaleFeeBase (LoadFeeTrack& track,
Ledger const& ledger, std::uint64_t fee)
{
return track.scaleFeeBase (fee,
ledger.getBaseFee(), ledger.getReferenceFeeUnits());
}
std::uint64_t
scaleFeeLoad (LoadFeeTrack& track,
Ledger const& ledger, std::uint64_t fee, bool admin)
{
return track.scaleFeeLoad (fee,
ledger.getBaseFee(), ledger.getReferenceFeeUnits(),
admin);
}
} // ripple

View File

@@ -27,6 +27,7 @@
#include <ripple/app/ledger/InboundLedgers.h>
#include <ripple/app/ledger/LedgerMaster.h>
#include <ripple/app/ledger/OrderBookDB.h>
#include <ripple/app/ledger/PendingSaves.h>
#include <ripple/app/main/CollectorManager.h>
#include <ripple/app/main/LoadManager.h>
#include <ripple/app/main/LocalCredentials.h>
@@ -257,6 +258,7 @@ public:
NodeStoreScheduler m_nodeStoreScheduler;
std::unique_ptr <SHAMapStore> m_shaMapStore;
std::unique_ptr <NodeStore::Database> m_nodeStore;
PendingSaves pendingSaves_;
// These are not Stoppable-derived
NodeCache m_tempNodeCache;
@@ -591,6 +593,11 @@ public:
return *m_shaMapStore;
}
PendingSaves& pendingSaves() override
{
return pendingSaves_;
}
Overlay& overlay ()
{
return *m_overlay;

View File

@@ -56,6 +56,7 @@ class NetworkOPs;
class OrderBookDB;
class Overlay;
class PathRequests;
class PendingSaves;
class STLedgerEntry;
class TransactionMaster;
class Validations;
@@ -114,7 +115,7 @@ public:
virtual Resource::Manager& getResourceManager () = 0;
virtual PathRequests& getPathRequests () = 0;
virtual SHAMapStore& getSHAMapStore () = 0;
virtual PendingSaves& pendingSaves() = 0;
virtual DatabaseCon& getTxnDB () = 0;
virtual DatabaseCon& getLedgerDB () = 0;

View File

@@ -23,6 +23,8 @@
#include <ripple/app/paths/RippleLineCache.h>
#include <ripple/json/json_value.h>
#include <ripple/net/InfoSub.h>
#include <map>
#include <set>
namespace ripple {

View File

@@ -18,6 +18,8 @@
//==============================================================================
#include <BeastConfig.h>
#include <ripple/app/ledger/LedgerFees.h>
#include <ripple/app/main/Application.h>
#include <ripple/app/tx/impl/Transactor.h>
#include <ripple/app/tx/impl/SignerEntries.h>
#include <ripple/core/Config.h>
@@ -100,8 +102,8 @@ Transactor::Transactor (
void Transactor::calculateFee ()
{
mFeeDue = STAmount (mEngine->getLedger ()->scaleFeeLoad (
calculateBaseFee (), mParams & tapADMIN));
mFeeDue = STAmount (scaleFeeLoad (getApp().getFeeTrack(),
*mEngine->getLedger(), calculateBaseFee (), mParams & tapADMIN));
}
std::uint64_t Transactor::calculateBaseFee ()

View File

@@ -59,18 +59,18 @@ public:
/** A ledger index. */
// VFALCO TODO pick one. I like Index since its not an abbreviation
typedef std::uint32_t LedgerIndex;
using LedgerIndex = std::uint32_t;
// VFALCO NOTE "LedgerSeq" appears in some SQL statement text
typedef std::uint32_t LedgerSeq;
using LedgerSeq = std::uint32_t;
/** A transaction identifier.
The value is computed as the hash of the
canonicalized, serialized transaction object.
*/
// VFALCO TODO maybe rename to TxHash
typedef uint256 TxID;
using TxID = uint256;
/** A transaction index.
*/
typedef std::uint32_t TxSeq; // VFALCO NOTE Should read TxIndex or TxNum
/** A transaction index. */
using TxSeq = std::uint32_t;
} // ripple

View File

@@ -19,6 +19,7 @@
#include <BeastConfig.h>
#include <ripple/rpc/impl/Tuning.h>
#include <ripple/app/ledger/LedgerFees.h>
#include <ripple/app/paths/RippleState.h>
#include <ripple/protocol/TxFlags.h>
@@ -32,7 +33,8 @@ static void fillTransaction (
{
txArray["Sequence"] = Json::UInt (sequence++);
txArray["Account"] = account.humanAccountID ();
txArray["Fee"] = Json::UInt (ledger->scaleFeeLoad (10, false));
txArray["Fee"] = Json::UInt (scaleFeeLoad (
getApp().getFeeTrack(), *ledger, 10, false));
}
// {

View File

@@ -18,6 +18,7 @@
//==============================================================================
#include <BeastConfig.h>
#include <ripple/app/ledger/LedgerFees.h>
#include <ripple/rpc/impl/TransactionSign.h>
#include <ripple/rpc/impl/KeypairForSignature.h>
#include <ripple/app/paths/FindPaths.h>
@@ -172,7 +173,8 @@ std::uint64_t TxnSignApiFacade::scaleFeeBase (std::uint64_t fee) const
if (!ledger_) // Unit testing.
return fee;
return ledger_->scaleFeeBase (fee);
return ripple::scaleFeeBase(
getApp().getFeeTrack(), *ledger_, fee);
}
std::uint64_t
@@ -181,7 +183,9 @@ TxnSignApiFacade::scaleFeeLoad (std::uint64_t fee, bool bAdmin) const
if (!ledger_) // Unit testing.
return fee;
return ledger_->scaleFeeLoad (fee, bAdmin);
return ripple::scaleFeeLoad (
getApp().getFeeTrack(),
*ledger_, fee, bAdmin);
}
bool TxnSignApiFacade::hasAccountRoot () const

View File

@@ -20,6 +20,7 @@
#include <BeastConfig.h>
#include <ripple/app/ledger/Ledger.cpp>
#include <ripple/app/ledger/impl/LedgerFees.cpp>
#include <ripple/app/misc/AccountState.cpp>
#include <ripple/app/tests/common_ledger.cpp>