mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Inject Application (cont.)
This commit is contained in:
committed by
Edward Hennis
parent
eed1a891a7
commit
ffbcb96eff
@@ -24,13 +24,15 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
AcceptedLedger::AcceptedLedger (std::shared_ptr<ReadView const> const& ledger)
|
||||
AcceptedLedger::AcceptedLedger (
|
||||
std::shared_ptr<ReadView const> const& ledger,
|
||||
AccountIDCache const& accountCache)
|
||||
: mLedger (ledger)
|
||||
{
|
||||
for (auto const& item : ledger->txs)
|
||||
{
|
||||
insert (std::make_shared<AcceptedLedgerTx>(
|
||||
ledger, item.first, item.second));
|
||||
ledger, item.first, item.second, accountCache));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#define RIPPLE_APP_LEDGER_ACCEPTEDLEDGER_H_INCLUDED
|
||||
|
||||
#include <ripple/app/ledger/AcceptedLedgerTx.h>
|
||||
#include <ripple/protocol/AccountID.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -67,11 +68,11 @@ public:
|
||||
|
||||
AcceptedLedgerTx::pointer getTxn (int) const;
|
||||
|
||||
explicit AcceptedLedger (std::shared_ptr<ReadView const> const& ledger);
|
||||
|
||||
AcceptedLedger (
|
||||
std::shared_ptr<ReadView const> const& ledger,
|
||||
AccountIDCache const& accountCache);
|
||||
|
||||
private:
|
||||
|
||||
void insert (AcceptedLedgerTx::ref);
|
||||
|
||||
std::shared_ptr<ReadView const> mLedger;
|
||||
|
||||
@@ -29,12 +29,14 @@ namespace ripple {
|
||||
AcceptedLedgerTx::AcceptedLedgerTx (
|
||||
std::shared_ptr<ReadView const> const& ledger,
|
||||
std::shared_ptr<STTx const> const& txn,
|
||||
std::shared_ptr<STObject const> const& met)
|
||||
std::shared_ptr<STObject const> const& met,
|
||||
AccountIDCache const& accountCache)
|
||||
: mLedger (ledger)
|
||||
, mTxn (txn)
|
||||
, mMeta (std::make_shared<TxMeta> (
|
||||
txn->getTransactionID(), ledger->seq(), *met))
|
||||
, mAffected (mMeta->getAffectedAccounts ())
|
||||
, accountCache_ (accountCache)
|
||||
{
|
||||
assert (! ledger->info().open);
|
||||
|
||||
@@ -49,11 +51,14 @@ AcceptedLedgerTx::AcceptedLedgerTx (
|
||||
|
||||
AcceptedLedgerTx::AcceptedLedgerTx (
|
||||
std::shared_ptr<ReadView const> const& ledger,
|
||||
STTx::ref txn, TER result)
|
||||
STTx::ref txn,
|
||||
TER result,
|
||||
AccountIDCache const& accountCache)
|
||||
: mLedger (ledger)
|
||||
, mTxn (txn)
|
||||
, mResult (result)
|
||||
, mAffected (txn->getMentionedAccounts ())
|
||||
, accountCache_ (accountCache)
|
||||
{
|
||||
assert (ledger->info().open);
|
||||
buildJson ();
|
||||
@@ -82,7 +87,7 @@ void AcceptedLedgerTx::buildJson ()
|
||||
{
|
||||
Json::Value& affected = (mJson[jss::affected] = Json::arrayValue);
|
||||
for (auto const& account: mAffected)
|
||||
affected.append (getApp().accountIDCache().toBase58(account));
|
||||
affected.append (accountCache_.toBase58(account));
|
||||
}
|
||||
|
||||
if (mTxn->getTxnType () == ttOFFER_CREATE)
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#define RIPPLE_APP_LEDGER_ACCEPTEDLEDGERTX_H_INCLUDED
|
||||
|
||||
#include <ripple/app/ledger/Ledger.h>
|
||||
#include <ripple/protocol/AccountID.h>
|
||||
#include <boost/container/flat_set.hpp>
|
||||
|
||||
namespace ripple {
|
||||
@@ -54,8 +55,13 @@ public:
|
||||
AcceptedLedgerTx (
|
||||
std::shared_ptr<ReadView const> const& ledger,
|
||||
std::shared_ptr<STTx const> const&,
|
||||
std::shared_ptr<STObject const> const&);
|
||||
AcceptedLedgerTx (std::shared_ptr<ReadView const> const&, STTx::ref, TER);
|
||||
std::shared_ptr<STObject const> const&,
|
||||
AccountIDCache const&);
|
||||
AcceptedLedgerTx (
|
||||
std::shared_ptr<ReadView const> const&,
|
||||
STTx::ref,
|
||||
TER,
|
||||
AccountIDCache const&);
|
||||
|
||||
std::shared_ptr <STTx const> const& getTxn () const
|
||||
{
|
||||
@@ -111,6 +117,7 @@ private:
|
||||
boost::container::flat_set<AccountID> mAffected;
|
||||
Blob mRawMeta;
|
||||
Json::Value mJson;
|
||||
AccountIDCache const& accountCache_;
|
||||
|
||||
void buildJson ();
|
||||
};
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
#include <ripple/core/LoadFeeTrack.h>
|
||||
#include <ripple/core/JobQueue.h>
|
||||
#include <ripple/core/SociDB.h>
|
||||
#include <ripple/core/TimeKeeper.h>
|
||||
#include <ripple/json/to_string.h>
|
||||
#include <ripple/nodestore/Database.h>
|
||||
#include <ripple/protocol/digest.h>
|
||||
@@ -170,12 +169,12 @@ public:
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
Ledger::Ledger (create_genesis_t, Config const& config)
|
||||
Ledger::Ledger (create_genesis_t, Config const& config, Family& family)
|
||||
: mImmutable (false)
|
||||
, txMap_ (std::make_shared <SHAMap> (SHAMapType::TRANSACTION,
|
||||
getApp().family(), deprecatedLogs().journal("SHAMap")))
|
||||
family, deprecatedLogs().journal("SHAMap")))
|
||||
, stateMap_ (std::make_shared <SHAMap> (SHAMapType::STATE,
|
||||
getApp().family(), deprecatedLogs().journal("SHAMap")))
|
||||
family, deprecatedLogs().journal("SHAMap")))
|
||||
{
|
||||
info_.seq = 1;
|
||||
info_.drops = SYSTEM_CURRENCY_START;
|
||||
@@ -205,13 +204,14 @@ Ledger::Ledger (uint256 const& parentHash,
|
||||
int closeResolution,
|
||||
std::uint32_t ledgerSeq,
|
||||
bool& loaded,
|
||||
Config const& config)
|
||||
Config const& config,
|
||||
Family& family)
|
||||
: mImmutable (true)
|
||||
, txMap_ (std::make_shared <SHAMap> (
|
||||
SHAMapType::TRANSACTION, transHash, getApp().family(),
|
||||
SHAMapType::TRANSACTION, transHash, family,
|
||||
deprecatedLogs().journal("SHAMap")))
|
||||
, stateMap_ (std::make_shared <SHAMap> (SHAMapType::STATE, accountHash,
|
||||
getApp().family(), deprecatedLogs().journal("SHAMap")))
|
||||
family, deprecatedLogs().journal("SHAMap")))
|
||||
{
|
||||
info_.seq = ledgerSeq;
|
||||
info_.parentCloseTime = parentCloseTime;
|
||||
@@ -256,10 +256,11 @@ Ledger::Ledger (Ledger const& ledger,
|
||||
}
|
||||
|
||||
// Create a new open ledger that follows this one
|
||||
Ledger::Ledger (open_ledger_t, Ledger const& prevLedger)
|
||||
Ledger::Ledger (open_ledger_t, Ledger const& prevLedger,
|
||||
NetClock::time_point closeTime)
|
||||
: mImmutable (false)
|
||||
, txMap_ (std::make_shared <SHAMap> (SHAMapType::TRANSACTION,
|
||||
getApp().family(), deprecatedLogs().journal("SHAMap")))
|
||||
prevLedger.stateMap_->family(), deprecatedLogs().journal("SHAMap")))
|
||||
, stateMap_ (prevLedger.stateMap_->snapShot (true))
|
||||
, fees_(prevLedger.fees_)
|
||||
{
|
||||
@@ -274,11 +275,10 @@ Ledger::Ledger (open_ledger_t, Ledger const& prevLedger)
|
||||
info_.closeTimeResolution = getNextLedgerTimeResolution (
|
||||
prevLedger.info_.closeTimeResolution,
|
||||
getCloseAgree(prevLedger.info()), info_.seq);
|
||||
// VFALCO Remove this call to getApp
|
||||
if (prevLedger.info_.closeTime == 0)
|
||||
{
|
||||
info_.closeTime = roundCloseTime (
|
||||
getApp().timeKeeper().closeTime().time_since_epoch().count(),
|
||||
closeTime.time_since_epoch().count(),
|
||||
info_.closeTimeResolution);
|
||||
}
|
||||
else
|
||||
@@ -290,28 +290,29 @@ Ledger::Ledger (open_ledger_t, Ledger const& prevLedger)
|
||||
|
||||
Ledger::Ledger (void const* data,
|
||||
std::size_t size, bool hasPrefix,
|
||||
Config const& config)
|
||||
Config const& config, Family& family)
|
||||
: mImmutable (true)
|
||||
, txMap_ (std::make_shared <SHAMap> (
|
||||
SHAMapType::TRANSACTION, getApp().family(),
|
||||
SHAMapType::TRANSACTION, family,
|
||||
deprecatedLogs().journal("SHAMap")))
|
||||
, stateMap_ (std::make_shared <SHAMap> (
|
||||
SHAMapType::STATE, getApp().family(),
|
||||
SHAMapType::STATE, family,
|
||||
deprecatedLogs().journal("SHAMap")))
|
||||
{
|
||||
SerialIter sit (data, size);
|
||||
setRaw (sit, hasPrefix);
|
||||
setRaw (sit, hasPrefix, family);
|
||||
// Can't set up until the stateMap is filled in
|
||||
}
|
||||
|
||||
Ledger::Ledger (std::uint32_t ledgerSeq,
|
||||
std::uint32_t closeTime, Config const& config)
|
||||
std::uint32_t closeTime, Config const& config,
|
||||
Family& family)
|
||||
: mImmutable (false)
|
||||
, txMap_ (std::make_shared <SHAMap> (
|
||||
SHAMapType::TRANSACTION, getApp().family(),
|
||||
SHAMapType::TRANSACTION, family,
|
||||
deprecatedLogs().journal("SHAMap")))
|
||||
, stateMap_ (std::make_shared <SHAMap> (
|
||||
SHAMapType::STATE, getApp().family(),
|
||||
SHAMapType::STATE, family,
|
||||
deprecatedLogs().journal("SHAMap")))
|
||||
{
|
||||
info_.seq = ledgerSeq;
|
||||
@@ -370,7 +371,7 @@ void Ledger::updateHash()
|
||||
mValidHash = true;
|
||||
}
|
||||
|
||||
void Ledger::setRaw (SerialIter& sit, bool hasPrefix)
|
||||
void Ledger::setRaw (SerialIter& sit, bool hasPrefix, Family& family)
|
||||
{
|
||||
if (hasPrefix)
|
||||
sit.get32 ();
|
||||
@@ -386,9 +387,9 @@ void Ledger::setRaw (SerialIter& sit, bool hasPrefix)
|
||||
info_.closeFlags = sit.get8 ();
|
||||
updateHash ();
|
||||
txMap_ = std::make_shared<SHAMap> (SHAMapType::TRANSACTION, info_.txHash,
|
||||
getApp().family(), deprecatedLogs().journal("SHAMap"));
|
||||
family, deprecatedLogs().journal("SHAMap"));
|
||||
stateMap_ = std::make_shared<SHAMap> (SHAMapType::STATE, info_.accountHash,
|
||||
getApp().family(), deprecatedLogs().journal("SHAMap"));
|
||||
family, deprecatedLogs().journal("SHAMap"));
|
||||
}
|
||||
|
||||
void Ledger::addRaw (Serializer& s) const
|
||||
@@ -448,227 +449,6 @@ deserializeTxPlusMeta (SHAMapItem const& item)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Load a ledger from the database.
|
||||
*
|
||||
* @param sqlSuffix: Additional string to append to the sql query.
|
||||
* (typically a where clause).
|
||||
* @return The ledger, ledger sequence, and ledger hash.
|
||||
*/
|
||||
std::tuple<Ledger::pointer, std::uint32_t, uint256>
|
||||
loadLedgerHelper(std::string const& sqlSuffix)
|
||||
{
|
||||
Ledger::pointer ledger;
|
||||
uint256 ledgerHash{};
|
||||
std::uint32_t ledgerSeq{0};
|
||||
|
||||
auto db = getApp ().getLedgerDB ().checkoutDb ();
|
||||
|
||||
boost::optional<std::string> sLedgerHash, sPrevHash, sAccountHash,
|
||||
sTransHash;
|
||||
boost::optional<std::uint64_t> totDrops, closingTime, prevClosingTime,
|
||||
closeResolution, closeFlags, ledgerSeq64;
|
||||
|
||||
std::string const sql =
|
||||
"SELECT "
|
||||
"LedgerHash, PrevHash, AccountSetHash, TransSetHash, "
|
||||
"TotalCoins,"
|
||||
"ClosingTime, PrevClosingTime, CloseTimeRes, CloseFlags,"
|
||||
"LedgerSeq from Ledgers " +
|
||||
sqlSuffix + ";";
|
||||
|
||||
*db << sql,
|
||||
soci::into(sLedgerHash),
|
||||
soci::into(sPrevHash),
|
||||
soci::into(sAccountHash),
|
||||
soci::into(sTransHash),
|
||||
soci::into(totDrops),
|
||||
soci::into(closingTime),
|
||||
soci::into(prevClosingTime),
|
||||
soci::into(closeResolution),
|
||||
soci::into(closeFlags),
|
||||
soci::into(ledgerSeq64);
|
||||
|
||||
if (!db->got_data ())
|
||||
{
|
||||
WriteLog (lsDEBUG, Ledger) << "Ledger not found: " << sqlSuffix;
|
||||
return std::make_tuple (Ledger::pointer (), ledgerSeq, ledgerHash);
|
||||
}
|
||||
|
||||
ledgerSeq =
|
||||
rangeCheckedCast<std::uint32_t>(ledgerSeq64.value_or (0));
|
||||
|
||||
uint256 prevHash{}, accountHash{}, transHash{};
|
||||
if (sLedgerHash)
|
||||
ledgerHash.SetHexExact (*sLedgerHash);
|
||||
if (sPrevHash)
|
||||
prevHash.SetHexExact (*sPrevHash);
|
||||
if (sAccountHash)
|
||||
accountHash.SetHexExact (*sAccountHash);
|
||||
if (sTransHash)
|
||||
transHash.SetHexExact (*sTransHash);
|
||||
|
||||
bool loaded = false;
|
||||
ledger = std::make_shared<Ledger>(prevHash,
|
||||
transHash,
|
||||
accountHash,
|
||||
totDrops.value_or(0),
|
||||
closingTime.value_or(0),
|
||||
prevClosingTime.value_or(0),
|
||||
closeFlags.value_or(0),
|
||||
closeResolution.value_or(0),
|
||||
ledgerSeq,
|
||||
loaded,
|
||||
getConfig());
|
||||
|
||||
if (!loaded)
|
||||
return std::make_tuple (Ledger::pointer (), ledgerSeq, ledgerHash);
|
||||
|
||||
return std::make_tuple (ledger, ledgerSeq, ledgerHash);
|
||||
}
|
||||
|
||||
void finishLoadByIndexOrHash(Ledger::pointer& ledger)
|
||||
{
|
||||
if (!ledger)
|
||||
return;
|
||||
|
||||
ledger->setClosed ();
|
||||
ledger->setImmutable ();
|
||||
|
||||
WriteLog (lsTRACE, Ledger)
|
||||
<< "Loaded ledger: " << to_string (ledger->getHash ());
|
||||
|
||||
ledger->setFull ();
|
||||
}
|
||||
|
||||
Ledger::pointer Ledger::loadByIndex (std::uint32_t ledgerIndex)
|
||||
{
|
||||
Ledger::pointer ledger;
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "WHERE LedgerSeq = " << ledgerIndex;
|
||||
std::tie (ledger, std::ignore, std::ignore) =
|
||||
loadLedgerHelper (s.str ());
|
||||
}
|
||||
|
||||
finishLoadByIndexOrHash (ledger);
|
||||
return ledger;
|
||||
}
|
||||
|
||||
Ledger::pointer Ledger::loadByHash (uint256 const& ledgerHash)
|
||||
{
|
||||
Ledger::pointer ledger;
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "WHERE LedgerHash = '" << ledgerHash << "'";
|
||||
std::tie (ledger, std::ignore, std::ignore) =
|
||||
loadLedgerHelper (s.str ());
|
||||
}
|
||||
|
||||
finishLoadByIndexOrHash (ledger);
|
||||
|
||||
assert (!ledger || ledger->getHash () == ledgerHash);
|
||||
|
||||
return ledger;
|
||||
}
|
||||
|
||||
uint256 Ledger::getHashByIndex (std::uint32_t ledgerIndex)
|
||||
{
|
||||
uint256 ret;
|
||||
|
||||
std::string sql =
|
||||
"SELECT LedgerHash FROM Ledgers INDEXED BY SeqLedger WHERE LedgerSeq='";
|
||||
sql.append (beast::lexicalCastThrow <std::string> (ledgerIndex));
|
||||
sql.append ("';");
|
||||
|
||||
std::string hash;
|
||||
{
|
||||
auto db = getApp().getLedgerDB ().checkoutDb ();
|
||||
|
||||
boost::optional<std::string> lh;
|
||||
*db << sql,
|
||||
soci::into (lh);
|
||||
|
||||
if (!db->got_data () || !lh)
|
||||
return ret;
|
||||
|
||||
hash = *lh;
|
||||
if (hash.empty ())
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret.SetHexExact (hash);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Ledger::getHashesByIndex (
|
||||
std::uint32_t ledgerIndex, uint256& ledgerHash, uint256& parentHash)
|
||||
{
|
||||
auto db = getApp().getLedgerDB ().checkoutDb ();
|
||||
|
||||
boost::optional <std::string> lhO, phO;
|
||||
|
||||
*db << "SELECT LedgerHash,PrevHash FROM Ledgers "
|
||||
"INDEXED BY SeqLedger Where LedgerSeq = :ls;",
|
||||
soci::into (lhO),
|
||||
soci::into (phO),
|
||||
soci::use (ledgerIndex);
|
||||
|
||||
if (!lhO || !phO)
|
||||
{
|
||||
WriteLog (lsTRACE, Ledger) << "Don't have ledger " << ledgerIndex;
|
||||
return false;
|
||||
}
|
||||
|
||||
ledgerHash.SetHexExact (*lhO);
|
||||
parentHash.SetHexExact (*phO);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::map< std::uint32_t, std::pair<uint256, uint256> >
|
||||
Ledger::getHashesByIndex (std::uint32_t minSeq, std::uint32_t maxSeq)
|
||||
{
|
||||
std::map< std::uint32_t, std::pair<uint256, uint256> > ret;
|
||||
|
||||
std::string sql =
|
||||
"SELECT LedgerSeq,LedgerHash,PrevHash FROM Ledgers WHERE LedgerSeq >= ";
|
||||
sql.append (beast::lexicalCastThrow <std::string> (minSeq));
|
||||
sql.append (" AND LedgerSeq <= ");
|
||||
sql.append (beast::lexicalCastThrow <std::string> (maxSeq));
|
||||
sql.append (";");
|
||||
|
||||
auto db = getApp().getLedgerDB ().checkoutDb ();
|
||||
|
||||
std::uint64_t ls;
|
||||
std::string lh;
|
||||
boost::optional<std::string> ph;
|
||||
soci::statement st =
|
||||
(db->prepare << sql,
|
||||
soci::into (ls),
|
||||
soci::into (lh),
|
||||
soci::into (ph));
|
||||
|
||||
st.execute ();
|
||||
while (st.fetch ())
|
||||
{
|
||||
std::pair<uint256, uint256>& hashes =
|
||||
ret[rangeCheckedCast<std::uint32_t>(ls)];
|
||||
hashes.first.SetHexExact (lh);
|
||||
if (ph)
|
||||
hashes.second.SetHexExact (*ph);
|
||||
else
|
||||
hashes.second.zero ();
|
||||
if (!ph)
|
||||
{
|
||||
WriteLog (lsWARNING, Ledger)
|
||||
<< "Null prev hash for ledger seq: " << ls;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Ledger::setAcquiring (void)
|
||||
{
|
||||
if (!txMap_ || !stateMap_)
|
||||
@@ -961,11 +741,7 @@ void Ledger::visitStateItems (std::function<void (SLE::ref)> callback) const
|
||||
}
|
||||
catch (SHAMapMissingNode&)
|
||||
{
|
||||
if (info_.hash.isNonZero ())
|
||||
{
|
||||
getApp().getInboundLedgers().acquire(
|
||||
info_.hash, info_.seq, InboundLedger::fcGENERIC);
|
||||
}
|
||||
stateMap_->family().missing_node (info_.hash);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -1169,7 +945,7 @@ static bool saveValidatedLedger (
|
||||
aLedger = app.getAcceptedLedgerCache().fetch (ledger->info().hash);
|
||||
if (! aLedger)
|
||||
{
|
||||
aLedger = std::make_shared<AcceptedLedger>(ledger);
|
||||
aLedger = std::make_shared<AcceptedLedger>(ledger, app.accountIDCache());
|
||||
app.getAcceptedLedgerCache().canonicalize(ledger->info().hash, aLedger);
|
||||
}
|
||||
}
|
||||
@@ -1338,7 +1114,8 @@ qualityDirDescriber (
|
||||
SLE::ref sle, bool isNew,
|
||||
Currency const& uTakerPaysCurrency, AccountID const& uTakerPaysIssuer,
|
||||
Currency const& uTakerGetsCurrency, AccountID const& uTakerGetsIssuer,
|
||||
const std::uint64_t& uRate)
|
||||
const std::uint64_t& uRate,
|
||||
Application& app)
|
||||
{
|
||||
sle->setFieldH160 (sfTakerPaysCurrency, uTakerPaysCurrency);
|
||||
sle->setFieldH160 (sfTakerPaysIssuer, uTakerPaysIssuer);
|
||||
@@ -1348,7 +1125,7 @@ qualityDirDescriber (
|
||||
if (isNew)
|
||||
{
|
||||
// VFALCO NO! This shouldn't be done here!
|
||||
getApp().getOrderBookDB().addOrderBook(
|
||||
app.getOrderBookDB().addOrderBook(
|
||||
{{uTakerPaysCurrency, uTakerPaysIssuer},
|
||||
{uTakerGetsCurrency, uTakerGetsIssuer}});
|
||||
}
|
||||
@@ -1428,4 +1205,234 @@ Ledger::getNeededAccountStateHashes (
|
||||
return ret;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Load a ledger from the database.
|
||||
*
|
||||
* @param sqlSuffix: Additional string to append to the sql query.
|
||||
* (typically a where clause).
|
||||
* @return The ledger, ledger sequence, and ledger hash.
|
||||
*/
|
||||
std::tuple<Ledger::pointer, std::uint32_t, uint256>
|
||||
loadLedgerHelper(std::string const& sqlSuffix, Application& app)
|
||||
{
|
||||
Ledger::pointer ledger;
|
||||
uint256 ledgerHash{};
|
||||
std::uint32_t ledgerSeq{0};
|
||||
|
||||
auto db = app.getLedgerDB ().checkoutDb ();
|
||||
|
||||
boost::optional<std::string> sLedgerHash, sPrevHash, sAccountHash,
|
||||
sTransHash;
|
||||
boost::optional<std::uint64_t> totDrops, closingTime, prevClosingTime,
|
||||
closeResolution, closeFlags, ledgerSeq64;
|
||||
|
||||
std::string const sql =
|
||||
"SELECT "
|
||||
"LedgerHash, PrevHash, AccountSetHash, TransSetHash, "
|
||||
"TotalCoins,"
|
||||
"ClosingTime, PrevClosingTime, CloseTimeRes, CloseFlags,"
|
||||
"LedgerSeq from Ledgers " +
|
||||
sqlSuffix + ";";
|
||||
|
||||
*db << sql,
|
||||
soci::into(sLedgerHash),
|
||||
soci::into(sPrevHash),
|
||||
soci::into(sAccountHash),
|
||||
soci::into(sTransHash),
|
||||
soci::into(totDrops),
|
||||
soci::into(closingTime),
|
||||
soci::into(prevClosingTime),
|
||||
soci::into(closeResolution),
|
||||
soci::into(closeFlags),
|
||||
soci::into(ledgerSeq64);
|
||||
|
||||
if (!db->got_data ())
|
||||
{
|
||||
WriteLog (lsDEBUG, Ledger) << "Ledger not found: " << sqlSuffix;
|
||||
return std::make_tuple (Ledger::pointer (), ledgerSeq, ledgerHash);
|
||||
}
|
||||
|
||||
ledgerSeq =
|
||||
rangeCheckedCast<std::uint32_t>(ledgerSeq64.value_or (0));
|
||||
|
||||
uint256 prevHash{}, accountHash{}, transHash{};
|
||||
if (sLedgerHash)
|
||||
ledgerHash.SetHexExact (*sLedgerHash);
|
||||
if (sPrevHash)
|
||||
prevHash.SetHexExact (*sPrevHash);
|
||||
if (sAccountHash)
|
||||
accountHash.SetHexExact (*sAccountHash);
|
||||
if (sTransHash)
|
||||
transHash.SetHexExact (*sTransHash);
|
||||
|
||||
bool loaded = false;
|
||||
ledger = std::make_shared<Ledger>(prevHash,
|
||||
transHash,
|
||||
accountHash,
|
||||
totDrops.value_or(0),
|
||||
closingTime.value_or(0),
|
||||
prevClosingTime.value_or(0),
|
||||
closeFlags.value_or(0),
|
||||
closeResolution.value_or(0),
|
||||
ledgerSeq,
|
||||
loaded,
|
||||
getConfig(),
|
||||
app.family());
|
||||
|
||||
if (!loaded)
|
||||
return std::make_tuple (Ledger::pointer (), ledgerSeq, ledgerHash);
|
||||
|
||||
return std::make_tuple (ledger, ledgerSeq, ledgerHash);
|
||||
}
|
||||
|
||||
void finishLoadByIndexOrHash(Ledger::pointer& ledger)
|
||||
{
|
||||
if (!ledger)
|
||||
return;
|
||||
|
||||
ledger->setClosed ();
|
||||
ledger->setImmutable ();
|
||||
|
||||
WriteLog (lsTRACE, Ledger)
|
||||
<< "Loaded ledger: " << to_string (ledger->getHash ());
|
||||
|
||||
ledger->setFull ();
|
||||
}
|
||||
|
||||
Ledger::pointer
|
||||
loadByIndex (std::uint32_t ledgerIndex, Application& app)
|
||||
{
|
||||
Ledger::pointer ledger;
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "WHERE LedgerSeq = " << ledgerIndex;
|
||||
std::tie (ledger, std::ignore, std::ignore) =
|
||||
loadLedgerHelper (s.str (), app);
|
||||
}
|
||||
|
||||
finishLoadByIndexOrHash (ledger);
|
||||
return ledger;
|
||||
}
|
||||
|
||||
Ledger::pointer
|
||||
loadByHash (uint256 const& ledgerHash, Application& app)
|
||||
{
|
||||
Ledger::pointer ledger;
|
||||
{
|
||||
std::ostringstream s;
|
||||
s << "WHERE LedgerHash = '" << ledgerHash << "'";
|
||||
std::tie (ledger, std::ignore, std::ignore) =
|
||||
loadLedgerHelper (s.str (), app);
|
||||
}
|
||||
|
||||
finishLoadByIndexOrHash (ledger);
|
||||
|
||||
assert (!ledger || ledger->getHash () == ledgerHash);
|
||||
|
||||
return ledger;
|
||||
}
|
||||
|
||||
uint256
|
||||
getHashByIndex (std::uint32_t ledgerIndex, Application& app)
|
||||
{
|
||||
uint256 ret;
|
||||
|
||||
std::string sql =
|
||||
"SELECT LedgerHash FROM Ledgers INDEXED BY SeqLedger WHERE LedgerSeq='";
|
||||
sql.append (beast::lexicalCastThrow <std::string> (ledgerIndex));
|
||||
sql.append ("';");
|
||||
|
||||
std::string hash;
|
||||
{
|
||||
auto db = app.getLedgerDB ().checkoutDb ();
|
||||
|
||||
boost::optional<std::string> lh;
|
||||
*db << sql,
|
||||
soci::into (lh);
|
||||
|
||||
if (!db->got_data () || !lh)
|
||||
return ret;
|
||||
|
||||
hash = *lh;
|
||||
if (hash.empty ())
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret.SetHexExact (hash);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
getHashesByIndex(std::uint32_t ledgerIndex,
|
||||
uint256& ledgerHash, uint256& parentHash,
|
||||
Application& app)
|
||||
{
|
||||
auto db = app.getLedgerDB ().checkoutDb ();
|
||||
|
||||
boost::optional <std::string> lhO, phO;
|
||||
|
||||
*db << "SELECT LedgerHash,PrevHash FROM Ledgers "
|
||||
"INDEXED BY SeqLedger Where LedgerSeq = :ls;",
|
||||
soci::into (lhO),
|
||||
soci::into (phO),
|
||||
soci::use (ledgerIndex);
|
||||
|
||||
if (!lhO || !phO)
|
||||
{
|
||||
WriteLog (lsTRACE, Ledger) << "Don't have ledger " << ledgerIndex;
|
||||
return false;
|
||||
}
|
||||
|
||||
ledgerHash.SetHexExact (*lhO);
|
||||
parentHash.SetHexExact (*phO);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::map< std::uint32_t, std::pair<uint256, uint256> >
|
||||
getHashesByIndex (std::uint32_t minSeq, std::uint32_t maxSeq,
|
||||
Application& app)
|
||||
{
|
||||
std::map< std::uint32_t, std::pair<uint256, uint256> > ret;
|
||||
|
||||
std::string sql =
|
||||
"SELECT LedgerSeq,LedgerHash,PrevHash FROM Ledgers WHERE LedgerSeq >= ";
|
||||
sql.append (beast::lexicalCastThrow <std::string> (minSeq));
|
||||
sql.append (" AND LedgerSeq <= ");
|
||||
sql.append (beast::lexicalCastThrow <std::string> (maxSeq));
|
||||
sql.append (";");
|
||||
|
||||
auto db = app.getLedgerDB ().checkoutDb ();
|
||||
|
||||
std::uint64_t ls;
|
||||
std::string lh;
|
||||
boost::optional<std::string> ph;
|
||||
soci::statement st =
|
||||
(db->prepare << sql,
|
||||
soci::into (ls),
|
||||
soci::into (lh),
|
||||
soci::into (ph));
|
||||
|
||||
st.execute ();
|
||||
while (st.fetch ())
|
||||
{
|
||||
std::pair<uint256, uint256>& hashes =
|
||||
ret[rangeCheckedCast<std::uint32_t>(ls)];
|
||||
hashes.first.SetHexExact (lh);
|
||||
if (ph)
|
||||
hashes.second.SetHexExact (*ph);
|
||||
else
|
||||
hashes.second.zero ();
|
||||
if (!ph)
|
||||
{
|
||||
WriteLog (lsWARNING, Ledger)
|
||||
<< "Null prev hash for ledger seq: " << ls;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <ripple/ledger/CachedView.h>
|
||||
#include <ripple/app/tx/Transaction.h>
|
||||
#include <ripple/basics/CountedObject.h>
|
||||
#include <ripple/core/TimeKeeper.h>
|
||||
#include <ripple/protocol/Indexes.h>
|
||||
#include <ripple/protocol/STLedgerEntry.h>
|
||||
#include <ripple/protocol/Serializer.h>
|
||||
@@ -98,14 +99,15 @@ public:
|
||||
starts in this account can ever exist, with amounts
|
||||
used to pay fees being destroyed.
|
||||
*/
|
||||
Ledger (create_genesis_t, Config const& config);
|
||||
Ledger (create_genesis_t, Config const& config, Family& family);
|
||||
|
||||
// Used for ledgers loaded from JSON files
|
||||
Ledger (uint256 const& parentHash, uint256 const& transHash,
|
||||
uint256 const& accountHash,
|
||||
std::uint64_t totDrops, std::uint32_t closeTime,
|
||||
std::uint32_t parentCloseTime, int closeFlags, int closeResolution,
|
||||
std::uint32_t ledgerSeq, bool & loaded, Config const& config);
|
||||
std::uint32_t ledgerSeq, bool & loaded, Config const& config,
|
||||
Family& family);
|
||||
|
||||
// Create a new ledger that's a snapshot of this one
|
||||
Ledger (Ledger const& target, bool isMutable);
|
||||
@@ -116,15 +118,17 @@ public:
|
||||
follows previous, and have
|
||||
parentCloseTime == previous.closeTime.
|
||||
*/
|
||||
Ledger (open_ledger_t, Ledger const& previous);
|
||||
Ledger (open_ledger_t, Ledger const& previous,
|
||||
NetClock::time_point closeTime);
|
||||
|
||||
Ledger (void const* data,
|
||||
std::size_t size, bool hasPrefix,
|
||||
Config const& config);
|
||||
Config const& config, Family& family);
|
||||
|
||||
// used for database ledgers
|
||||
Ledger (std::uint32_t ledgerSeq,
|
||||
std::uint32_t closeTime, Config const& config);
|
||||
std::uint32_t closeTime, Config const& config,
|
||||
Family& family);
|
||||
|
||||
~Ledger();
|
||||
|
||||
@@ -250,7 +254,7 @@ public:
|
||||
|
||||
// ledger signature operations
|
||||
void addRaw (Serializer& s) const;
|
||||
void setRaw (SerialIter& sit, bool hasPrefix);
|
||||
void setRaw (SerialIter& sit, bool hasPrefix, Family& family);
|
||||
|
||||
// DEPRECATED
|
||||
// Remove contract.h include
|
||||
@@ -356,19 +360,6 @@ public:
|
||||
|
||||
bool assertSane ();
|
||||
|
||||
// database functions (low-level)
|
||||
static Ledger::pointer loadByIndex (std::uint32_t ledgerIndex);
|
||||
|
||||
static Ledger::pointer loadByHash (uint256 const& ledgerHash);
|
||||
|
||||
static uint256 getHashByIndex (std::uint32_t index);
|
||||
|
||||
static bool getHashesByIndex (
|
||||
std::uint32_t index, uint256 & ledgerHash, uint256 & parentHash);
|
||||
|
||||
static std::map< std::uint32_t, std::pair<uint256, uint256> >
|
||||
getHashesByIndex (std::uint32_t minSeq, std::uint32_t maxSeq);
|
||||
|
||||
private:
|
||||
class sles_iter_impl;
|
||||
class txs_iter_impl;
|
||||
@@ -416,12 +407,6 @@ private:
|
||||
std::uint32_t mutable mReserveIncrement = 0;
|
||||
};
|
||||
|
||||
bool pendSaveValidated (
|
||||
Application& app,
|
||||
std::shared_ptr<Ledger> const& ledger,
|
||||
bool isSynchronous,
|
||||
bool isCurrent);
|
||||
|
||||
/** A ledger wrapped in a CachedView. */
|
||||
using CachedLedger = CachedView<Ledger>;
|
||||
|
||||
@@ -431,6 +416,43 @@ using CachedLedger = CachedView<Ledger>;
|
||||
//
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
extern
|
||||
bool
|
||||
pendSaveValidated(
|
||||
Application& app,
|
||||
std::shared_ptr<Ledger> const& ledger,
|
||||
bool isSynchronous,
|
||||
bool isCurrent);
|
||||
|
||||
extern
|
||||
Ledger::pointer
|
||||
loadByIndex (std::uint32_t ledgerIndex,
|
||||
Application& app);
|
||||
|
||||
extern
|
||||
std::tuple<Ledger::pointer, std::uint32_t, uint256>
|
||||
loadLedgerHelper(std::string const& sqlSuffix,
|
||||
Application& app);
|
||||
|
||||
extern
|
||||
Ledger::pointer
|
||||
loadByHash (uint256 const& ledgerHash, Application& app);
|
||||
|
||||
extern
|
||||
uint256
|
||||
getHashByIndex(std::uint32_t index, Application& app);
|
||||
|
||||
extern
|
||||
bool
|
||||
getHashesByIndex(std::uint32_t index,
|
||||
uint256 &ledgerHash, uint256& parentHash,
|
||||
Application& app);
|
||||
|
||||
extern
|
||||
std::map< std::uint32_t, std::pair<uint256, uint256>>
|
||||
getHashesByIndex (std::uint32_t minSeq, std::uint32_t maxSeq,
|
||||
Application& app);
|
||||
|
||||
/** Deserialize a SHAMapItem containing a single STTx
|
||||
|
||||
Throw:
|
||||
@@ -454,9 +476,6 @@ std::pair<std::shared_ptr<
|
||||
STObject const>>
|
||||
deserializeTxPlusMeta (SHAMapItem const& item);
|
||||
|
||||
std::tuple<Ledger::pointer, std::uint32_t, uint256>
|
||||
loadLedgerHelper(std::string const& sqlSuffix);
|
||||
|
||||
// DEPRECATED
|
||||
inline
|
||||
std::shared_ptr<SLE const>
|
||||
@@ -479,7 +498,7 @@ qualityDirDescriber (
|
||||
SLE::ref, bool,
|
||||
Currency const& uTakerPaysCurrency, AccountID const& uTakerPaysIssuer,
|
||||
Currency const& uTakerGetsCurrency, AccountID const& uTakerGetsIssuer,
|
||||
const std::uint64_t & uRate);
|
||||
const std::uint64_t & uRate, Application& app);
|
||||
|
||||
} // ripple
|
||||
|
||||
|
||||
@@ -39,8 +39,10 @@ namespace ripple {
|
||||
// FIXME: Need to clean up ledgers by index at some point
|
||||
|
||||
LedgerHistory::LedgerHistory (
|
||||
beast::insight::Collector::ptr const& collector)
|
||||
: collector_ (collector)
|
||||
beast::insight::Collector::ptr const& collector,
|
||||
Application& app)
|
||||
: app_ (app)
|
||||
, collector_ (collector)
|
||||
, mismatch_counter_ (collector->make_counter ("ledger.history", "mismatch"))
|
||||
, m_ledgers_by_hash ("LedgerCache", CACHED_LEDGER_NUM, CACHED_LEDGER_AGE,
|
||||
stopwatch(), deprecatedLogs().journal("TaggedCache"))
|
||||
@@ -89,7 +91,7 @@ Ledger::pointer LedgerHistory::getLedgerBySeq (LedgerIndex index)
|
||||
}
|
||||
}
|
||||
|
||||
Ledger::pointer ret (Ledger::loadByIndex (index));
|
||||
Ledger::pointer ret = loadByIndex (index, app_);
|
||||
|
||||
if (!ret)
|
||||
return ret;
|
||||
@@ -118,7 +120,7 @@ Ledger::pointer LedgerHistory::getLedgerByHash (LedgerHash const& hash)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = Ledger::loadByHash (hash);
|
||||
ret = loadByHash (hash, app_);
|
||||
|
||||
if (!ret)
|
||||
return ret;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#define RIPPLE_APP_LEDGER_LEDGERHISTORY_H_INCLUDED
|
||||
|
||||
#include <ripple/app/ledger/Ledger.h>
|
||||
#include <ripple/app/main/Application.h>
|
||||
#include <ripple/protocol/RippleLedgerHash.h>
|
||||
#include <beast/insight/Collector.h>
|
||||
#include <beast/insight/Event.h>
|
||||
@@ -33,8 +34,8 @@ namespace ripple {
|
||||
class LedgerHistory
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
LedgerHistory (beast::insight::Collector::ptr const& collector);
|
||||
LedgerHistory (beast::insight::Collector::ptr const& collector,
|
||||
Application& app);
|
||||
|
||||
/** Track a ledger
|
||||
@return `true` if the ledger was already tracked
|
||||
@@ -106,6 +107,7 @@ private:
|
||||
*/
|
||||
void handleMismatch (LedgerHash const& built, LedgerHash const& valid);
|
||||
|
||||
Application& app_;
|
||||
beast::insight::Collector::ptr collector_;
|
||||
beast::insight::Counter mismatch_counter_;
|
||||
|
||||
|
||||
@@ -166,7 +166,7 @@ bool InboundLedger::tryLocal ()
|
||||
if (m_journal.trace) m_journal.trace <<
|
||||
"Ledger header found in fetch pack";
|
||||
mLedger = std::make_shared<Ledger> (
|
||||
data.data(), data.size(), true, getConfig());
|
||||
data.data(), data.size(), true, getConfig(), app_.family());
|
||||
app_.getNodeStore ().store (
|
||||
hotLEDGER, std::move (data), mHash);
|
||||
}
|
||||
@@ -174,7 +174,7 @@ bool InboundLedger::tryLocal ()
|
||||
{
|
||||
mLedger = std::make_shared<Ledger>(
|
||||
node->getData().data(), node->getData().size(),
|
||||
true, getConfig());
|
||||
true, getConfig(), app_.family());
|
||||
}
|
||||
|
||||
if (mLedger->getHash () != mHash)
|
||||
@@ -769,7 +769,7 @@ bool InboundLedger::takeHeader (std::string const& data)
|
||||
return true;
|
||||
|
||||
mLedger = std::make_shared<Ledger>(
|
||||
data.data(), data.size(), false, getConfig());
|
||||
data.data(), data.size(), false, getConfig(), app_.family());
|
||||
|
||||
if (mLedger->getHash () != mHash)
|
||||
{
|
||||
|
||||
@@ -301,7 +301,7 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
Ledger::pointer dbLedger = Ledger::loadByIndex(ledgerIndex);
|
||||
Ledger::pointer dbLedger = loadByIndex(ledgerIndex, app_);
|
||||
if (! dbLedger ||
|
||||
(dbLedger->getHash() != ledgerHash) ||
|
||||
(dbLedger->info().parentHash != nodeLedger->info().parentHash))
|
||||
|
||||
@@ -1006,7 +1006,8 @@ void LedgerConsensusImp::accept (std::shared_ptr<SHAMap> set)
|
||||
|
||||
// Build the new last closed ledger
|
||||
auto newLCL = std::make_shared<Ledger>(
|
||||
open_ledger, *mPreviousLedger);
|
||||
open_ledger, *mPreviousLedger,
|
||||
app_.timeKeeper().closeTime());
|
||||
newLCL->setClosed (); // so applyTransactions sees a closed ledger
|
||||
|
||||
// Set up to write SHAMap changes to our database,
|
||||
@@ -1113,7 +1114,7 @@ void LedgerConsensusImp::accept (std::shared_ptr<SHAMap> set)
|
||||
|
||||
// Build new open ledger
|
||||
auto newOL = std::make_shared<Ledger>(
|
||||
open_ledger, *newLCL);
|
||||
open_ledger, *newLCL, app_.timeKeeper().closeTime());
|
||||
OpenView accum(&*newOL);
|
||||
assert(accum.open());
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ public:
|
||||
, app_ (app)
|
||||
, m_journal (journal)
|
||||
, mLastValidLedger (std::make_pair (uint256(), 0))
|
||||
, mLedgerHistory (collector)
|
||||
, mLedgerHistory (collector, app)
|
||||
, mHeldTransactions (uint256 ())
|
||||
, mLedgerCleaner (make_LedgerCleaner (
|
||||
app, *this, deprecatedLogs().journal("LedgerCleaner")))
|
||||
@@ -617,9 +617,9 @@ public:
|
||||
mCompleteLedgers.setRange (minHas, maxHas);
|
||||
}
|
||||
maxHas = minHas;
|
||||
ledgerHashes = Ledger::getHashesByIndex ((seq < 500)
|
||||
ledgerHashes = getHashesByIndex ((seq < 500)
|
||||
? 0
|
||||
: (seq - 499), seq);
|
||||
: (seq - 499), seq, app_);
|
||||
it = ledgerHashes.find (seq);
|
||||
|
||||
if (it == ledgerHashes.end ())
|
||||
@@ -755,7 +755,7 @@ public:
|
||||
{
|
||||
// Check the SQL database's entry for the sequence before this
|
||||
// ledger, if it's not this ledger's parent, invalidate it
|
||||
uint256 prevHash = Ledger::getHashByIndex (ledger->info().seq - 1);
|
||||
uint256 prevHash = getHashByIndex (ledger->info().seq - 1, app_);
|
||||
if (prevHash.isNonZero () && prevHash != ledger->info().parentHash)
|
||||
clearLedger (ledger->info().seq - 1);
|
||||
}
|
||||
@@ -1451,7 +1451,7 @@ public:
|
||||
if (hash.isNonZero ())
|
||||
return hash;
|
||||
|
||||
return Ledger::getHashByIndex (index);
|
||||
return getHashByIndex (index, app_);
|
||||
}
|
||||
|
||||
// VFALCO NOTE This should return boost::optional<uint256>
|
||||
@@ -1747,7 +1747,7 @@ void LedgerMasterImp::doAdvance ()
|
||||
mHistLedger = ledger;
|
||||
auto& parent = ledger->info().parentHash;
|
||||
if (mFillInProgress == 0 &&
|
||||
Ledger::getHashByIndex(seq - 1) == parent)
|
||||
getHashByIndex(seq - 1, app_) == parent)
|
||||
{
|
||||
// Previous ledger is in DB
|
||||
ScopedLockType lock (m_mutex);
|
||||
|
||||
@@ -110,7 +110,7 @@ Application* ApplicationImpBase::s_instance;
|
||||
|
||||
namespace detail {
|
||||
|
||||
class AppFamily : public shamap::Family
|
||||
class AppFamily : public Family
|
||||
{
|
||||
private:
|
||||
Application& app_;
|
||||
@@ -178,6 +178,17 @@ public:
|
||||
app_.getInboundLedgers ().acquire (
|
||||
hash, seq, InboundLedger::fcGENERIC);
|
||||
}
|
||||
|
||||
virtual
|
||||
void
|
||||
missing_node (uint256 const& hash) override
|
||||
{
|
||||
if (hash.isNonZero())
|
||||
{
|
||||
app_.getInboundLedgers ().acquire (
|
||||
hash, 0, InboundLedger::fcGENERIC);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // detail
|
||||
@@ -341,6 +352,8 @@ public:
|
||||
, timeKeeper_ (make_TimeKeeper(
|
||||
deprecatedLogs().journal("TimeKeeper")))
|
||||
|
||||
, m_txMaster (*this)
|
||||
|
||||
, m_nodeStoreScheduler (*this)
|
||||
|
||||
, m_shaMapStore (make_SHAMapStore (*this, setup_SHAMapStore (
|
||||
@@ -471,7 +484,7 @@ public:
|
||||
return *m_collectorManager;
|
||||
}
|
||||
|
||||
shamap::Family&
|
||||
Family&
|
||||
family()
|
||||
{
|
||||
return family_;
|
||||
@@ -1064,16 +1077,17 @@ void ApplicationImp::startGenesisLedger ()
|
||||
{
|
||||
std::shared_ptr<Ledger const> const genesis =
|
||||
std::make_shared<Ledger>(
|
||||
create_genesis, config_);
|
||||
create_genesis, config_, family());
|
||||
auto const next = std::make_shared<Ledger>(
|
||||
open_ledger, *genesis);
|
||||
open_ledger, *genesis, timeKeeper().closeTime());
|
||||
next->setClosed ();
|
||||
next->setImmutable ();
|
||||
m_networkOPs->setLastCloseTime (next->info().closeTime);
|
||||
openLedger_.emplace(next, config_,
|
||||
cachedSLEs_, deprecatedLogs().journal("OpenLedger"));
|
||||
m_ledgerMaster->pushLedger (next,
|
||||
std::make_shared<Ledger>(open_ledger, *next));
|
||||
std::make_shared<Ledger>(open_ledger, *next,
|
||||
timeKeeper().closeTime()));
|
||||
}
|
||||
|
||||
Ledger::pointer
|
||||
@@ -1085,7 +1099,7 @@ ApplicationImp::getLastFullLedger()
|
||||
std::uint32_t ledgerSeq;
|
||||
uint256 ledgerHash;
|
||||
std::tie (ledger, ledgerSeq, ledgerHash) =
|
||||
loadLedgerHelper ("order by LedgerSeq desc limit 1");
|
||||
loadLedgerHelper ("order by LedgerSeq desc limit 1", *this);
|
||||
|
||||
if (!ledger)
|
||||
return ledger;
|
||||
@@ -1192,7 +1206,7 @@ bool ApplicationImp::loadOldLedger (
|
||||
}
|
||||
else
|
||||
{
|
||||
loadLedger = std::make_shared<Ledger> (seq, closeTime, config_);
|
||||
loadLedger = std::make_shared<Ledger> (seq, closeTime, config_, family());
|
||||
loadLedger->setTotalDrops(totalDrops);
|
||||
|
||||
for (Json::UInt index = 0; index < ledger.get().size(); ++index)
|
||||
@@ -1237,7 +1251,7 @@ bool ApplicationImp::loadOldLedger (
|
||||
// by hash
|
||||
uint256 hash;
|
||||
hash.SetHex (ledgerID);
|
||||
loadLedger = Ledger::loadByHash (hash);
|
||||
loadLedger = loadByHash (hash, *this);
|
||||
|
||||
if (!loadLedger)
|
||||
{
|
||||
@@ -1250,8 +1264,8 @@ bool ApplicationImp::loadOldLedger (
|
||||
|
||||
}
|
||||
else // assume by sequence
|
||||
loadLedger = Ledger::loadByIndex (
|
||||
beast::lexicalCastThrow <std::uint32_t> (ledgerID));
|
||||
loadLedger = loadByIndex (
|
||||
beast::lexicalCastThrow <std::uint32_t> (ledgerID), *this);
|
||||
|
||||
if (!loadLedger)
|
||||
{
|
||||
@@ -1269,7 +1283,7 @@ bool ApplicationImp::loadOldLedger (
|
||||
|
||||
m_journal.info << "Loading parent ledger";
|
||||
|
||||
loadLedger = Ledger::loadByHash (replayLedger->info().parentHash);
|
||||
loadLedger = loadByHash (replayLedger->info().parentHash, *this);
|
||||
if (!loadLedger)
|
||||
{
|
||||
m_journal.info << "Loading parent ledger from node store";
|
||||
@@ -1318,7 +1332,8 @@ bool ApplicationImp::loadOldLedger (
|
||||
m_ledgerMaster->setLedgerRangePresent (loadLedger->info().seq, loadLedger->info().seq);
|
||||
|
||||
auto const openLedger =
|
||||
std::make_shared<Ledger>(open_ledger, *loadLedger);
|
||||
std::make_shared<Ledger>(open_ledger, *loadLedger,
|
||||
timeKeeper().closeTime());
|
||||
m_ledgerMaster->switchLedgers (loadLedger, openLedger);
|
||||
m_ledgerMaster->forceValid(loadLedger);
|
||||
m_networkOPs->setLastCloseTime (loadLedger->info().closeTime);
|
||||
|
||||
@@ -40,9 +40,7 @@ namespace NodeStore { class Database; }
|
||||
class AmendmentTable;
|
||||
class CachedSLEs;
|
||||
class CollectorManager;
|
||||
namespace shamap {
|
||||
class Family;
|
||||
} // shamap
|
||||
class HashRouter;
|
||||
class Logs;
|
||||
class LoadFeeTrack;
|
||||
@@ -95,7 +93,7 @@ public:
|
||||
virtual Config const& config() const = 0;
|
||||
virtual boost::asio::io_service& getIOService () = 0;
|
||||
virtual CollectorManager& getCollectorManager () = 0;
|
||||
virtual shamap::Family& family() = 0;
|
||||
virtual Family& family() = 0;
|
||||
virtual TimeKeeper& timeKeeper() = 0;
|
||||
virtual JobQueue& getJobQueue () = 0;
|
||||
virtual NodeCache& getTempNodeCache () = 0;
|
||||
|
||||
@@ -94,7 +94,7 @@ void startServer (Application& app)
|
||||
Resource::Charge loadType = Resource::feeReferenceRPC;
|
||||
RPC::Context context {
|
||||
jvCommand, app, loadType, app.getOPs (),
|
||||
app.getLedgerMaster(), Role::ADMIN};
|
||||
app.getLedgerMaster(), Role::ADMIN, app};
|
||||
|
||||
Json::Value jvResult;
|
||||
RPC::doCommand (context, jvResult);
|
||||
|
||||
@@ -699,7 +699,7 @@ void NetworkOPsImp::submitTransaction (STTx::pointer iTrans)
|
||||
}
|
||||
|
||||
auto tx = std::make_shared<Transaction> (
|
||||
trans, Validate::NO, directSigVerify, reason);
|
||||
trans, Validate::NO, directSigVerify, reason, app_);
|
||||
|
||||
m_job_queue.addJob (jtTRANSACTION, "submitTxn", [this, tx] (Job&) {
|
||||
auto t = tx;
|
||||
@@ -1316,7 +1316,8 @@ void NetworkOPsImp::switchLastClosedLedger (
|
||||
clearNeedNetworkLedger ();
|
||||
newLCL->setClosed ();
|
||||
auto const newOL = std::make_shared<
|
||||
Ledger>(open_ledger, std::ref (*newLCL));
|
||||
Ledger>(open_ledger, std::ref (*newLCL),
|
||||
app_.timeKeeper().closeTime());
|
||||
// Caller must own master lock
|
||||
{
|
||||
auto const oldOL =
|
||||
@@ -1746,7 +1747,7 @@ NetworkOPs::AccountTxs NetworkOPsImp::getAccountTxs (
|
||||
txnMeta.clear ();
|
||||
|
||||
auto txn = Transaction::transactionFromSQL (
|
||||
ledgerSeq, status, rawTxn, Validate::NO);
|
||||
ledgerSeq, status, rawTxn, Validate::NO, app_);
|
||||
|
||||
if (txnMeta.empty ())
|
||||
{ // Work around a bug that could leave the metadata missing
|
||||
@@ -1824,15 +1825,17 @@ NetworkOPsImp::getTxsAccount (
|
||||
{
|
||||
static std::uint32_t const page_length (200);
|
||||
|
||||
Application& app = app_;
|
||||
NetworkOPsImp::AccountTxs ret;
|
||||
|
||||
auto bound = [&ret](
|
||||
auto bound = [&ret, &app](
|
||||
std::uint32_t ledger_index,
|
||||
std::string const& status,
|
||||
Blob const& rawTxn,
|
||||
Blob const& rawMeta)
|
||||
{
|
||||
convertBlobsToTxResult (ret, ledger_index, status, rawTxn, rawMeta);
|
||||
convertBlobsToTxResult (
|
||||
ret, ledger_index, status, rawTxn, rawMeta, app);
|
||||
};
|
||||
|
||||
accountTxPage(app_.getTxnDB (), app_.accountIDCache(),
|
||||
@@ -2099,7 +2102,8 @@ void NetworkOPsImp::pubProposedTransaction (
|
||||
}
|
||||
}
|
||||
}
|
||||
AcceptedLedgerTx alt (lpCurrent, stTxn, terResult);
|
||||
AcceptedLedgerTx alt (lpCurrent, stTxn, terResult,
|
||||
app_.accountIDCache());
|
||||
m_journal.trace << "pubProposed: " << alt.getJson ();
|
||||
pubAccountTransaction (lpCurrent, alt, false);
|
||||
}
|
||||
@@ -2113,7 +2117,8 @@ void NetworkOPsImp::pubLedger (Ledger::ref lpAccepted)
|
||||
app_.getAcceptedLedgerCache().fetch (lpAccepted->info().hash);
|
||||
if (! alpAccepted)
|
||||
{
|
||||
alpAccepted = std::make_shared<AcceptedLedger> (lpAccepted);
|
||||
alpAccepted = std::make_shared<AcceptedLedger> (
|
||||
lpAccepted, app_.accountIDCache());
|
||||
app_.getAcceptedLedgerCache().canonicalize (
|
||||
lpAccepted->info().hash, alpAccepted);
|
||||
}
|
||||
|
||||
@@ -36,14 +36,15 @@ convertBlobsToTxResult (
|
||||
std::uint32_t ledger_index,
|
||||
std::string const& status,
|
||||
Blob const& rawTxn,
|
||||
Blob const& rawMeta)
|
||||
Blob const& rawMeta,
|
||||
Application& app)
|
||||
{
|
||||
SerialIter it (makeSlice(rawTxn));
|
||||
STTx::pointer txn = std::make_shared<STTx> (it);
|
||||
std::string reason;
|
||||
|
||||
auto tr = std::make_shared<Transaction> (txn, Validate::NO,
|
||||
directSigVerify, reason);
|
||||
directSigVerify, reason, app);
|
||||
|
||||
tr->setStatus (Transaction::sqlTransactionStatus(status));
|
||||
tr->setLedger (ledger_index);
|
||||
|
||||
@@ -37,7 +37,8 @@ convertBlobsToTxResult (
|
||||
std::uint32_t ledger_index,
|
||||
std::string const& status,
|
||||
Blob const& rawTxn,
|
||||
Blob const& rawMeta);
|
||||
Blob const& rawMeta,
|
||||
Application& app);
|
||||
|
||||
void
|
||||
saveLedgerAsync (Application& app, std::uint32_t seq);
|
||||
|
||||
@@ -47,9 +47,10 @@ public:
|
||||
findPathsForIssue (
|
||||
Issue const& issue,
|
||||
STPathSet const& paths,
|
||||
STPath& fullLiquidityPath)
|
||||
STPath& fullLiquidityPath,
|
||||
Application& app)
|
||||
{
|
||||
if (auto& pathfinder = getPathFinder (issue.currency))
|
||||
if (auto& pathfinder = getPathFinder (issue.currency, app))
|
||||
{
|
||||
return pathfinder->getBestPaths (maxPaths_,
|
||||
fullLiquidityPath, paths, issue.account);
|
||||
@@ -69,14 +70,15 @@ private:
|
||||
int const searchLevel_;
|
||||
unsigned int const maxPaths_;
|
||||
|
||||
std::unique_ptr<Pathfinder> const& getPathFinder (Currency const& currency)
|
||||
std::unique_ptr<Pathfinder> const&
|
||||
getPathFinder (Currency const& currency, Application& app)
|
||||
{
|
||||
auto i = currencyMap_.find (currency);
|
||||
if (i != currencyMap_.end ())
|
||||
return i->second;
|
||||
auto pathfinder = std::make_unique<Pathfinder> (
|
||||
cache_, srcAccount_, dstAccount_, currency,
|
||||
boost::none, dstAmount_, srcAmount_);
|
||||
boost::none, dstAmount_, srcAmount_, app);
|
||||
if (pathfinder->findPaths (searchLevel_))
|
||||
pathfinder->computePathRanks (maxPaths_);
|
||||
else
|
||||
@@ -108,9 +110,10 @@ boost::optional<STPathSet>
|
||||
FindPaths::findPathsForIssue (
|
||||
Issue const& issue,
|
||||
STPathSet const& paths,
|
||||
STPath& fullLiquidityPath)
|
||||
STPath& fullLiquidityPath,
|
||||
Application& app)
|
||||
{
|
||||
return impl_->findPathsForIssue (issue, paths, fullLiquidityPath);
|
||||
return impl_->findPathsForIssue (issue, paths, fullLiquidityPath, app);
|
||||
}
|
||||
|
||||
boost::optional<STPathSet>
|
||||
@@ -123,7 +126,8 @@ findPathsForOneIssuer (
|
||||
int searchLevel,
|
||||
unsigned int const maxPaths,
|
||||
STPathSet const& paths,
|
||||
STPath& fullLiquidityPath)
|
||||
STPath& fullLiquidityPath,
|
||||
Application& app)
|
||||
{
|
||||
Pathfinder pf (
|
||||
cache,
|
||||
@@ -132,7 +136,8 @@ findPathsForOneIssuer (
|
||||
srcIssue.currency,
|
||||
srcIssue.account,
|
||||
dstAmount,
|
||||
boost::none);
|
||||
boost::none,
|
||||
app);
|
||||
|
||||
if (! pf.findPaths(searchLevel))
|
||||
return boost::none;
|
||||
|
||||
@@ -55,7 +55,9 @@ public:
|
||||
|
||||
On output, if fullLiquidityPath is non-empty, it contains one extra
|
||||
path that can move the entire liquidity requested. */
|
||||
STPath& fullLiquidityPath);
|
||||
STPath& fullLiquidityPath,
|
||||
|
||||
Application& app);
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
@@ -88,7 +90,9 @@ findPathsForOneIssuer (
|
||||
|
||||
On output, if fullLiquidityPath is non-empty, it contains one extra path
|
||||
that can move the entire liquidity requested. */
|
||||
STPath& fullLiquidityPath);
|
||||
STPath& fullLiquidityPath,
|
||||
|
||||
Application& app);
|
||||
|
||||
void initializePathfinding ();
|
||||
|
||||
|
||||
@@ -454,7 +454,7 @@ PathRequest::findPaths (
|
||||
{
|
||||
STPath fullLiquidityPath;
|
||||
auto result = fp.findPathsForIssue(issue,
|
||||
mContext[issue], fullLiquidityPath);
|
||||
mContext[issue], fullLiquidityPath, app_);
|
||||
if (! result)
|
||||
{
|
||||
m_journal.debug << iIdentifier << " No paths found";
|
||||
|
||||
@@ -148,7 +148,8 @@ Pathfinder::Pathfinder (
|
||||
Currency const& uSrcCurrency,
|
||||
boost::optional<AccountID> const& uSrcIssuer,
|
||||
STAmount const& saDstAmount,
|
||||
boost::optional<STAmount> const& srcAmount)
|
||||
boost::optional<STAmount> const& srcAmount,
|
||||
Application& app)
|
||||
: mSrcAccount (uSrcAccount),
|
||||
mDstAccount (uDstAccount),
|
||||
mEffectiveDst (isXRP(saDstAmount.getIssuer ()) ?
|
||||
@@ -162,7 +163,8 @@ Pathfinder::Pathfinder (
|
||||
convert_all_ (mDstAmount ==
|
||||
STAmount(mDstAmount.issue(), STAmount::cMaxValue, STAmount::cMaxOffset)),
|
||||
mLedger (cache->getLedger ()),
|
||||
mRLCache (cache)
|
||||
mRLCache (cache),
|
||||
app_ (app)
|
||||
{
|
||||
assert (! uSrcIssuer || isXRP(uSrcCurrency) == isXRP(uSrcIssuer.get()));
|
||||
}
|
||||
@@ -201,7 +203,7 @@ bool Pathfinder::findPaths (int searchLevel)
|
||||
return true;
|
||||
}
|
||||
|
||||
m_loadEvent = getApp ().getJobQueue ().getLoadEvent (
|
||||
m_loadEvent = app_.getJobQueue ().getLoadEvent (
|
||||
jtPATH_FIND, "FindPath");
|
||||
auto currencyIsXRP = isXRP (mSrcCurrency);
|
||||
|
||||
@@ -715,7 +717,7 @@ int Pathfinder::getPathsOut (
|
||||
|
||||
if (!bFrozen)
|
||||
{
|
||||
count = getApp ().getOrderBookDB ().getBookSize (issue);
|
||||
count = app_.getOrderBookDB ().getBookSize (issue);
|
||||
|
||||
for (auto const& item : mRLCache->getRippleLines (account))
|
||||
{
|
||||
@@ -1057,7 +1059,7 @@ void Pathfinder::addLink (
|
||||
if (addFlags & afOB_XRP)
|
||||
{
|
||||
// to XRP only
|
||||
if (!bOnXRP && getApp ().getOrderBookDB ().isBookToXRP (
|
||||
if (!bOnXRP && app_.getOrderBookDB ().isBookToXRP (
|
||||
{uEndCurrency, uEndIssuer}))
|
||||
{
|
||||
STPathElement pathElement(
|
||||
@@ -1071,7 +1073,7 @@ void Pathfinder::addLink (
|
||||
else
|
||||
{
|
||||
bool bDestOnly = (addFlags & afOB_LAST) != 0;
|
||||
auto books = getApp ().getOrderBookDB ().getBooksByTakerPays(
|
||||
auto books = app_.getOrderBookDB ().getBooksByTakerPays(
|
||||
{uEndCurrency, uEndIssuer});
|
||||
WriteLog (lsTRACE, Pathfinder)
|
||||
<< books.size () << " books found from this currency/issuer";
|
||||
|
||||
@@ -45,7 +45,8 @@ public:
|
||||
Currency const& uSrcCurrency,
|
||||
boost::optional<AccountID> const& uSrcIssuer,
|
||||
STAmount const& dstAmount,
|
||||
boost::optional<STAmount> const& srcAmount);
|
||||
boost::optional<STAmount> const& srcAmount,
|
||||
Application& app);
|
||||
~Pathfinder();
|
||||
|
||||
static void initPathTable ();
|
||||
@@ -190,6 +191,8 @@ private:
|
||||
|
||||
hash_map<Issue, int> mPathsOutCountMap;
|
||||
|
||||
Application& app_;
|
||||
|
||||
// Add ripple paths
|
||||
static std::uint32_t const afADD_ACCOUNTS = 0x001;
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <ripple/core/DatabaseCon.h>
|
||||
#include <ripple/app/misc/impl/AccountTxPaging.h>
|
||||
#include <ripple/protocol/types.h>
|
||||
#include <ripple/test/jtx.h>
|
||||
#include <beast/cxx14/memory.h> // <memory>
|
||||
#include <beast/unit_test/suite.h>
|
||||
#include <cstdlib>
|
||||
@@ -90,15 +91,18 @@ struct AccountTxPaging_test : beast::unit_test::suite
|
||||
std::int32_t const page_length = 200;
|
||||
bool const admin = true;
|
||||
|
||||
test::jtx::Env env(*this);
|
||||
Application& app = env.app();
|
||||
auto& txs = txs_;
|
||||
|
||||
auto bound = [&txs](
|
||||
auto bound = [&txs, &app](
|
||||
std::uint32_t ledger_index,
|
||||
std::string const& status,
|
||||
Blob const& rawTxn,
|
||||
Blob const& rawMeta)
|
||||
{
|
||||
convertBlobsToTxResult (txs, ledger_index, status, rawTxn, rawMeta);
|
||||
convertBlobsToTxResult (
|
||||
txs, ledger_index, status, rawTxn, rawMeta, app);
|
||||
};
|
||||
|
||||
accountTxPage(*db_, *idCache_, [](std::uint32_t){}, bound, account_, minLedger,
|
||||
|
||||
@@ -135,12 +135,13 @@ equal(STAmount const& sa1, STAmount const& sa2)
|
||||
}
|
||||
|
||||
std::tuple <STPathSet, STAmount, STAmount>
|
||||
find_paths(std::shared_ptr<ReadView const> const& view,
|
||||
find_paths(jtx::Env& env,
|
||||
jtx::Account const& src, jtx::Account const& dst,
|
||||
STAmount const& saDstAmount,
|
||||
boost::optional<STAmount> const& saSendMax = boost::none)
|
||||
{
|
||||
static int const level = 8;
|
||||
auto const& view = env.open ();
|
||||
auto cache = std::make_shared<RippleLineCache>(view);
|
||||
auto currencies = accountSourceCurrencies(src, cache, true);
|
||||
auto jvSrcCurrencies = Json::Value(Json::arrayValue);
|
||||
@@ -153,7 +154,7 @@ find_paths(std::shared_ptr<ReadView const> const& view,
|
||||
|
||||
auto result = ripplePathFind(cache, src.id(), dst.id(),
|
||||
saDstAmount, jvSrcCurrencies, boost::none, level, saSendMax,
|
||||
saDstAmount == STAmount(saDstAmount.issue(), 1u, 0, true));
|
||||
saDstAmount == STAmount(saDstAmount.issue(), 1u, 0, true), env.app ());
|
||||
if (! result.first)
|
||||
{
|
||||
throw std::runtime_error(
|
||||
@@ -191,7 +192,7 @@ public:
|
||||
Env env(*this);
|
||||
env.fund(XRP(10000), "alice", "bob");
|
||||
|
||||
auto const result = find_paths(env.open(),
|
||||
auto const result = find_paths(env,
|
||||
"alice", "bob", Account("bob")["USD"](5));
|
||||
expect(std::get<0>(result).empty());
|
||||
}
|
||||
@@ -207,7 +208,7 @@ public:
|
||||
|
||||
STPathSet st;
|
||||
STAmount sa;
|
||||
std::tie(st, sa, std::ignore) = find_paths(env.open(),
|
||||
std::tie(st, sa, std::ignore) = find_paths(env,
|
||||
"alice", "bob", Account("bob")["USD"](5));
|
||||
expect(st.empty());
|
||||
expect(equal(sa, Account("alice")["USD"](5)));
|
||||
@@ -248,7 +249,7 @@ public:
|
||||
|
||||
STPathSet st;
|
||||
STAmount sa;
|
||||
std::tie(st, sa, std::ignore) = find_paths(env.open(),
|
||||
std::tie(st, sa, std::ignore) = find_paths(env,
|
||||
"alice", "bob", Account("bob")["USD"](5));
|
||||
expect(same(st, stpath("gateway")));
|
||||
expect(equal(sa, Account("alice")["USD"](5)));
|
||||
@@ -273,7 +274,7 @@ public:
|
||||
STPathSet st;
|
||||
STAmount sa;
|
||||
STAmount da;
|
||||
std::tie(st, sa, da) = find_paths(env.open(),
|
||||
std::tie(st, sa, da) = find_paths(env,
|
||||
"alice", "edward", Account("edward")["USD"](-1));
|
||||
expect(same(st, stpath("dan"), stpath("bob", "carol")));
|
||||
expect(equal(sa, Account("alice")["USD"](110)));
|
||||
@@ -292,11 +293,11 @@ public:
|
||||
STPathSet st;
|
||||
STAmount sa;
|
||||
STAmount da;
|
||||
std::tie(st, sa, da) = find_paths(env.open(),
|
||||
std::tie(st, sa, da) = find_paths(env,
|
||||
"alice", "bob", Account("bob")["AUD"](-1),
|
||||
boost::optional<STAmount>(XRP(100000000)));
|
||||
expect(st.empty());
|
||||
std::tie(st, sa, da) = find_paths(env.open(),
|
||||
std::tie(st, sa, da) = find_paths(env,
|
||||
"alice", "bob", Account("bob")["USD"](-1),
|
||||
boost::optional<STAmount>(XRP(100000000)));
|
||||
expect(sa == XRP(100));
|
||||
@@ -417,7 +418,7 @@ public:
|
||||
|
||||
STPathSet st;
|
||||
STAmount sa;
|
||||
std::tie(st, sa, std::ignore) = find_paths(env.open(),
|
||||
std::tie(st, sa, std::ignore) = find_paths(env,
|
||||
"alice", "bob", Account("bob")["USD"](5));
|
||||
expect(same(st, stpath("gateway"), stpath("gateway2"),
|
||||
stpath("dan"), stpath("carol")));
|
||||
@@ -438,14 +439,14 @@ public:
|
||||
env.require(balance("bob", Account("carol")["USD"](-75)));
|
||||
env.require(balance("carol", Account("bob")["USD"](75)));
|
||||
|
||||
auto result = find_paths(env.open(),
|
||||
auto result = find_paths(env,
|
||||
"alice", "bob", Account("bob")["USD"](25));
|
||||
expect(std::get<0>(result).empty());
|
||||
|
||||
env(pay("alice", "bob", Account("alice")["USD"](25)),
|
||||
ter(tecPATH_DRY));
|
||||
|
||||
result = find_paths(env.open(),
|
||||
result = find_paths(env,
|
||||
"alice", "bob", Account("alice")["USD"](25));
|
||||
expect(std::get<0>(result).empty());
|
||||
|
||||
@@ -527,7 +528,7 @@ public:
|
||||
env.require(balance("bob", AUD(10)));
|
||||
env.require(balance("carol", AUD(39)));
|
||||
|
||||
auto const result = find_paths(env.open(),
|
||||
auto const result = find_paths(env,
|
||||
"alice", "bob", Account("bob")["USD"](25));
|
||||
expect(std::get<0>(result).empty());
|
||||
}
|
||||
@@ -544,7 +545,7 @@ public:
|
||||
|
||||
STPathSet st;
|
||||
STAmount sa;
|
||||
std::tie(st, sa, std::ignore) = find_paths(env.open(),
|
||||
std::tie(st, sa, std::ignore) = find_paths(env,
|
||||
"alice", "carol", Account("carol")["USD"](5));
|
||||
expect(same(st, stpath("bob")));
|
||||
expect(equal(sa, Account("alice")["USD"](5)));
|
||||
|
||||
@@ -49,7 +49,7 @@ struct Regression_test : public beast::unit_test::suite
|
||||
// be reproduced against an open ledger. Make a local
|
||||
// closed ledger and work with it directly.
|
||||
auto closed = std::make_shared<Ledger>(
|
||||
create_genesis, env.config);
|
||||
create_genesis, env.config, env.app().family());
|
||||
auto expectedDrops = SYSTEM_CURRENCY_START;
|
||||
expect(closed->info().drops == expectedDrops);
|
||||
|
||||
@@ -57,7 +57,8 @@ struct Regression_test : public beast::unit_test::suite
|
||||
auto const aliceAmount = XRP(aliceXRP);
|
||||
|
||||
auto next = std::make_shared<Ledger>(
|
||||
open_ledger, *closed);
|
||||
open_ledger, *closed,
|
||||
env.app().timeKeeper().closeTime());
|
||||
next->setClosed();
|
||||
{
|
||||
// Fund alice
|
||||
@@ -89,7 +90,7 @@ struct Regression_test : public beast::unit_test::suite
|
||||
// doesn't know about this account.
|
||||
auto const jt = env.jt(noop("alice"), fee(expectedDrops),
|
||||
seq(1));
|
||||
|
||||
|
||||
OpenView accum(&*next);
|
||||
|
||||
auto const result = ripple::apply(env.app(),
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace ripple {
|
||||
// obtain a binary version.
|
||||
//
|
||||
|
||||
class Application;
|
||||
class Database;
|
||||
|
||||
enum TransStatus
|
||||
@@ -62,11 +63,12 @@ public:
|
||||
using ref = const pointer&;
|
||||
|
||||
public:
|
||||
Transaction (STTx::ref, Validate, SigVerify, std::string&) noexcept;
|
||||
Transaction (
|
||||
STTx::ref, Validate, SigVerify, std::string&, Application&) noexcept;
|
||||
|
||||
static
|
||||
Transaction::pointer
|
||||
sharedTransaction (Blob const&, Validate);
|
||||
sharedTransaction (Blob const&, Validate, Application& app);
|
||||
|
||||
static
|
||||
Transaction::pointer
|
||||
@@ -74,7 +76,8 @@ public:
|
||||
boost::optional<std::uint64_t> const& ledgerSeq,
|
||||
boost::optional<std::string> const& status,
|
||||
Blob const& rawTxn,
|
||||
Validate validate);
|
||||
Validate validate,
|
||||
Application& app);
|
||||
|
||||
static
|
||||
TransStatus
|
||||
@@ -152,12 +155,10 @@ public:
|
||||
|
||||
Json::Value getJson (int options, bool binary = false) const;
|
||||
|
||||
static Transaction::pointer load (uint256 const& id);
|
||||
static Transaction::pointer load (uint256 const& id, Application& app);
|
||||
|
||||
private:
|
||||
uint256 mTransactionID;
|
||||
// VFALCO NOTE This member appears unused
|
||||
AccountID mAccountFrom;
|
||||
RippleAddress mFromPubKey; // Sign transaction with this. mSignPubKey
|
||||
RippleAddress mSourcePrivate; // Sign transaction with this.
|
||||
|
||||
@@ -166,7 +167,8 @@ private:
|
||||
TER mResult = temUNCERTAIN;
|
||||
bool mApplying = false;
|
||||
|
||||
STTx::pointer mTransaction;
|
||||
STTx::pointer mTransaction;
|
||||
Application& mApp;
|
||||
};
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -26,12 +26,16 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
class Application;
|
||||
|
||||
// Tracks all transactions in memory
|
||||
|
||||
class TransactionMaster
|
||||
{
|
||||
public:
|
||||
TransactionMaster ();
|
||||
TransactionMaster (Application& app);
|
||||
TransactionMaster (TransactionMaster const&) = delete;
|
||||
TransactionMaster& operator= (TransactionMaster const&) = delete;
|
||||
|
||||
Transaction::pointer fetch (uint256 const& , bool checkDisk);
|
||||
STTx::pointer fetch (std::shared_ptr<SHAMapItem> const& item, SHAMapTreeNode:: TNType type,
|
||||
@@ -44,6 +48,7 @@ public:
|
||||
TaggedCache <uint256, Transaction>& getCache();
|
||||
|
||||
private:
|
||||
Application& mApp;
|
||||
TaggedCache <uint256, Transaction> mCache;
|
||||
};
|
||||
|
||||
|
||||
@@ -835,7 +835,7 @@ CreateOffer::applyGuts (ApplyView& view, ApplyView& view_cancel)
|
||||
&qualityDirDescriber, std::placeholders::_1,
|
||||
std::placeholders::_2, saTakerPays.getCurrency (),
|
||||
uPaysIssuerID, saTakerGets.getCurrency (),
|
||||
uGetsIssuerID, uRate));
|
||||
uGetsIssuerID, uRate, std::ref(ctx_.app)));
|
||||
}
|
||||
|
||||
if (result == tesSUCCESS)
|
||||
|
||||
@@ -31,15 +31,15 @@
|
||||
namespace ripple {
|
||||
|
||||
Transaction::Transaction (STTx::ref stx, Validate validate,
|
||||
SigVerify sigVerify, std::string& reason)
|
||||
SigVerify sigVerify, std::string& reason, Application& app)
|
||||
noexcept
|
||||
: mTransaction (stx)
|
||||
, mApp (app)
|
||||
{
|
||||
try
|
||||
{
|
||||
mFromPubKey.setAccountPublic (mTransaction->getSigningPubKey ());
|
||||
mTransactionID = mTransaction->getTransactionID ();
|
||||
mAccountFrom = mTransaction->getAccountID(sfAccount);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
@@ -61,7 +61,7 @@ Transaction::Transaction (STTx::ref stx, Validate validate,
|
||||
}
|
||||
|
||||
Transaction::pointer Transaction::sharedTransaction (
|
||||
Blob const& vucTransaction, Validate validate)
|
||||
Blob const& vucTransaction, Validate validate, Application& app)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -69,7 +69,7 @@ Transaction::pointer Transaction::sharedTransaction (
|
||||
std::string reason;
|
||||
|
||||
return std::make_shared<Transaction> (std::make_shared<STTx> (sit),
|
||||
validate, getApp().getHashRouter().sigVerify(), reason);
|
||||
validate, app.getHashRouter().sigVerify(), reason, app);
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
@@ -90,7 +90,7 @@ Transaction::pointer Transaction::sharedTransaction (
|
||||
|
||||
bool Transaction::checkSign (std::string& reason, SigVerify sigVerify) const
|
||||
{
|
||||
bool const allowMultiSign = getApp().getLedgerMaster().
|
||||
bool const allowMultiSign = mApp.getLedgerMaster().
|
||||
getValidatedRules().enabled (featureMultiSign, getConfig().features);
|
||||
|
||||
if (! mFromPubKey.isValid ())
|
||||
@@ -135,7 +135,8 @@ Transaction::pointer Transaction::transactionFromSQL (
|
||||
boost::optional<std::uint64_t> const& ledgerSeq,
|
||||
boost::optional<std::string> const& status,
|
||||
Blob const& rawTxn,
|
||||
Validate validate)
|
||||
Validate validate,
|
||||
Application& app)
|
||||
{
|
||||
std::uint32_t const inLedger =
|
||||
rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or (0));
|
||||
@@ -144,14 +145,14 @@ Transaction::pointer Transaction::transactionFromSQL (
|
||||
auto txn = std::make_shared<STTx> (it);
|
||||
std::string reason;
|
||||
auto tr = std::make_shared<Transaction> (txn, validate,
|
||||
getApp().getHashRouter().sigVerify(), reason);
|
||||
app.getHashRouter().sigVerify(), reason, app);
|
||||
|
||||
tr->setStatus (sqlTransactionStatus (status));
|
||||
tr->setLedger (inLedger);
|
||||
return tr;
|
||||
}
|
||||
|
||||
Transaction::pointer Transaction::load (uint256 const& id)
|
||||
Transaction::pointer Transaction::load (uint256 const& id, Application& app)
|
||||
{
|
||||
std::string sql = "SELECT LedgerSeq,Status,RawTxn "
|
||||
"FROM Transactions WHERE TransID='";
|
||||
@@ -162,7 +163,7 @@ Transaction::pointer Transaction::load (uint256 const& id)
|
||||
boost::optional<std::string> status;
|
||||
Blob rawTxn;
|
||||
{
|
||||
auto db = getApp().getTxnDB ().checkoutDb ();
|
||||
auto db = app.getTxnDB ().checkoutDb ();
|
||||
soci::blob sociRawTxnBlob (*db);
|
||||
soci::indicator rti;
|
||||
|
||||
@@ -175,7 +176,7 @@ Transaction::pointer Transaction::load (uint256 const& id)
|
||||
}
|
||||
|
||||
return Transaction::transactionFromSQL (
|
||||
ledgerSeq, status, rawTxn, Validate::YES);
|
||||
ledgerSeq, status, rawTxn, Validate::YES, app);
|
||||
}
|
||||
|
||||
// options 1 to include the date of the transaction
|
||||
@@ -190,7 +191,7 @@ Json::Value Transaction::getJson (int options, bool binary) const
|
||||
|
||||
if (options == 1)
|
||||
{
|
||||
auto ledger = getApp().getLedgerMaster ().
|
||||
auto ledger = mApp.getLedgerMaster ().
|
||||
getLedgerBySeq (mInLedger);
|
||||
if (ledger)
|
||||
ret[jss::date] = ledger->info().closeTime;
|
||||
|
||||
@@ -25,8 +25,9 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
TransactionMaster::TransactionMaster ()
|
||||
: mCache ("TransactionCache", 65536, 1800, stopwatch(),
|
||||
TransactionMaster::TransactionMaster (Application& app)
|
||||
: mApp (app)
|
||||
, mCache ("TransactionCache", 65536, 1800, stopwatch(),
|
||||
deprecatedLogs().journal("TaggedCache"))
|
||||
{
|
||||
}
|
||||
@@ -49,7 +50,7 @@ Transaction::pointer TransactionMaster::fetch (uint256 const& txnID, bool checkD
|
||||
if (!checkDisk || txn)
|
||||
return txn;
|
||||
|
||||
txn = Transaction::load (txnID);
|
||||
txn = Transaction::load (txnID, mApp);
|
||||
|
||||
if (!txn)
|
||||
return txn;
|
||||
@@ -64,7 +65,7 @@ STTx::pointer TransactionMaster::fetch (std::shared_ptr<SHAMapItem> const& item,
|
||||
bool checkDisk, std::uint32_t uCommitLedger)
|
||||
{
|
||||
STTx::pointer txn;
|
||||
auto iTx = getApp().getMasterTransaction ().fetch (item->key(), false);
|
||||
auto iTx = fetch (item->key(), false);
|
||||
|
||||
if (!iTx)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user