mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Refactor View classes:
The View hierarchy of classes is reorganized to include new classes with member functions moved and renamed, to solve defects in the original design: OpenView accumulates raw state and tx changes and can be applied to the base. ApplyView accumulates changes for a single transaction, including metadata, and can be applied to an OpenView. The Sandbox allows changes with the option to apply or throw them out. The PaymentSandbox provides a sandbox with account credit deferral. Call sites are changed to use the class appropriate for the task.
This commit is contained in:
@@ -25,13 +25,13 @@
|
||||
#include <ripple/test/jtx/JTx.h>
|
||||
#include <ripple/test/jtx/require.h>
|
||||
#include <ripple/test/jtx/tags.h>
|
||||
|
||||
#include <ripple/app/ledger/Ledger.h>
|
||||
#include <ripple/app/ledger/OpenLedger.h>
|
||||
#include <ripple/basics/chrono.h>
|
||||
#include <ripple/core/Config.h>
|
||||
#include <ripple/json/json_value.h>
|
||||
#include <ripple/json/to_string.h>
|
||||
#include <ripple/ledger/CachedSLEs.h>
|
||||
#include <ripple/protocol/Indexes.h>
|
||||
#include <ripple/protocol/Issue.h>
|
||||
#include <ripple/protocol/RippleAddress.h>
|
||||
@@ -134,7 +134,8 @@ public:
|
||||
Account const master;
|
||||
|
||||
private:
|
||||
std::shared_ptr<Ledger> closed_;
|
||||
std::shared_ptr<Ledger const> closed_;
|
||||
CachedSLEs cachedSLEs_;
|
||||
public:
|
||||
|
||||
// Careful with this
|
||||
@@ -153,7 +154,7 @@ public:
|
||||
as a public member for interested callers.
|
||||
*/
|
||||
static
|
||||
std::shared_ptr<Ledger>
|
||||
std::shared_ptr<Ledger const>
|
||||
genesis();
|
||||
|
||||
/** Returns the open ledger.
|
||||
@@ -164,7 +165,7 @@ public:
|
||||
will not be visible.
|
||||
|
||||
*/
|
||||
std::shared_ptr<BasicView const>
|
||||
std::shared_ptr<ReadView const>
|
||||
open() const;
|
||||
|
||||
/** Returns the last closed ledger.
|
||||
@@ -174,7 +175,7 @@ public:
|
||||
is closed, it becomes the new closed ledger
|
||||
and a new open ledger takes its place.
|
||||
*/
|
||||
std::shared_ptr<BasicView const>
|
||||
std::shared_ptr<ReadView const>
|
||||
closed() const;
|
||||
|
||||
/** Close and advance the ledger.
|
||||
@@ -463,6 +464,9 @@ protected:
|
||||
std::shared_ptr<STTx>
|
||||
st (JTx const& jt);
|
||||
|
||||
ApplyFlags
|
||||
applyFlags() const;
|
||||
|
||||
inline
|
||||
void
|
||||
invoke (STTx& stx)
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace test {
|
||||
|
||||
namespace jtx {
|
||||
|
||||
std::shared_ptr<Ledger>
|
||||
std::shared_ptr<Ledger const>
|
||||
Env::genesis()
|
||||
{
|
||||
Account master("master", generateKeysFromSeed(
|
||||
@@ -71,19 +71,20 @@ Env::Env (beast::unit_test::suite& test_)
|
||||
KeyType::secp256k1, RippleAddress::createSeedGeneric(
|
||||
"masterpassphrase")))
|
||||
, closed_ (genesis())
|
||||
, openLedger (closed_, config, clock, journal)
|
||||
, cachedSLEs_ (std::chrono::seconds(5), clock)
|
||||
, openLedger (closed_, config, cachedSLEs_, journal)
|
||||
{
|
||||
memoize(master);
|
||||
initializePathfinding();
|
||||
}
|
||||
|
||||
std::shared_ptr<BasicView const>
|
||||
std::shared_ptr<ReadView const>
|
||||
Env::open() const
|
||||
{
|
||||
return openLedger.current();
|
||||
}
|
||||
|
||||
std::shared_ptr<BasicView const>
|
||||
std::shared_ptr<ReadView const>
|
||||
Env::closed() const
|
||||
{
|
||||
return closed_;
|
||||
@@ -94,8 +95,9 @@ Env::close(
|
||||
TestClock::time_point const& closeTime)
|
||||
{
|
||||
clock.set(closeTime);
|
||||
// VFALCO TODO Fix the Ledger constructor
|
||||
auto next = std::make_shared<Ledger>(
|
||||
false, *closed_);
|
||||
false, const_cast<Ledger&>(*closed_));
|
||||
next->setClosed();
|
||||
#if 0
|
||||
// Build a SHAMap, put all the transactions
|
||||
@@ -116,10 +118,10 @@ Env::close(
|
||||
IHashRouter::New(60));
|
||||
OrderedTxs retries(uint256{});
|
||||
{
|
||||
MetaView accum(*next, tapNONE);
|
||||
OpenView accum(&*next);
|
||||
OpenLedger::apply(accum, *closed_,
|
||||
txs, retries, *router, config,
|
||||
journal);
|
||||
txs, retries, applyFlags(), *router,
|
||||
config, journal);
|
||||
accum.apply(*next);
|
||||
}
|
||||
next->setAccepted(
|
||||
@@ -128,8 +130,9 @@ Env::close(
|
||||
true);
|
||||
OrderedTxs locals({});
|
||||
openLedger.accept(next, locals,
|
||||
false, retries, *router);
|
||||
false, retries, applyFlags(), *router);
|
||||
closed_ = next;
|
||||
cachedSLEs_.expire();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -268,12 +271,10 @@ Env::submit (JTx const& jt)
|
||||
if (stx)
|
||||
{
|
||||
openLedger.modify(
|
||||
[&](View& view, beast::Journal j)
|
||||
[&](OpenView& view, beast::Journal j)
|
||||
{
|
||||
ViewFlags flags = tapNONE;
|
||||
flags = flags | tapENABLE_TESTING;
|
||||
std::tie(ter, didApply) = ripple::apply(
|
||||
view, *stx, flags, config,
|
||||
view, *stx, applyFlags(), config,
|
||||
beast::Journal{});
|
||||
return didApply;
|
||||
});
|
||||
@@ -377,6 +378,12 @@ Env::st (JTx const& jt)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ApplyFlags
|
||||
Env::applyFlags() const
|
||||
{
|
||||
return tapENABLE_TESTING;
|
||||
}
|
||||
|
||||
} // jtx
|
||||
|
||||
} // test
|
||||
|
||||
@@ -563,8 +563,6 @@ public:
|
||||
env.close();
|
||||
env.close();
|
||||
env.fund(XRP(100000), "alice", "bob");
|
||||
auto const epoch =
|
||||
Env::clock_type::time_point{};
|
||||
env.close();
|
||||
env(pay("alice", "bob", XRP(100)));
|
||||
env.close();
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace jtx {
|
||||
namespace detail {
|
||||
|
||||
std::uint32_t
|
||||
owned_count_of(BasicView const& view,
|
||||
owned_count_of(ReadView const& view,
|
||||
AccountID const& id,
|
||||
LedgerEntryType type)
|
||||
{
|
||||
|
||||
@@ -58,7 +58,7 @@ sign (Json::Value& jv,
|
||||
|
||||
void
|
||||
fill_fee (Json::Value& jv,
|
||||
BasicView const& view)
|
||||
ReadView const& view)
|
||||
{
|
||||
if (jv.isMember(jss::Fee))
|
||||
return;
|
||||
@@ -68,7 +68,7 @@ fill_fee (Json::Value& jv,
|
||||
|
||||
void
|
||||
fill_seq (Json::Value& jv,
|
||||
BasicView const& view)
|
||||
ReadView const& view)
|
||||
{
|
||||
if (jv.isMember(jss::Sequence))
|
||||
return;
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace jtx {
|
||||
namespace detail {
|
||||
|
||||
std::uint32_t
|
||||
owned_count_of (BasicView const& view,
|
||||
owned_count_of (ReadView const& view,
|
||||
AccountID const& id,
|
||||
LedgerEntryType type);
|
||||
|
||||
|
||||
@@ -59,12 +59,12 @@ sign (Json::Value& jv,
|
||||
/** Set the fee automatically. */
|
||||
void
|
||||
fill_fee (Json::Value& jv,
|
||||
BasicView const& view);
|
||||
ReadView const& view);
|
||||
|
||||
/** Set the sequence number automatically. */
|
||||
void
|
||||
fill_seq (Json::Value& jv,
|
||||
BasicView const& view);
|
||||
ReadView const& view);
|
||||
|
||||
} // jtx
|
||||
} // test
|
||||
|
||||
Reference in New Issue
Block a user