mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Add modify function to OpenLedger::accept
This commit is contained in:
committed by
Edward Hennis
parent
6700e44793
commit
656a6c5eb5
@@ -57,6 +57,20 @@ private:
|
||||
std::shared_ptr<OpenView const> current_;
|
||||
|
||||
public:
|
||||
/** Signature for modification functions.
|
||||
|
||||
The modification function is called during
|
||||
apply and modify with an OpenView to accumulate
|
||||
changes and the Journal to use for logging.
|
||||
|
||||
A return value of `true` informs OpenLedger
|
||||
that changes were made. Always returning
|
||||
`true` won't cause harm, but it may be
|
||||
sub-optimal.
|
||||
*/
|
||||
using modify_type = std::function<
|
||||
bool(OpenView&, beast::Journal)>;
|
||||
|
||||
OpenLedger() = delete;
|
||||
OpenLedger (OpenLedger const&) = delete;
|
||||
OpenLedger& operator= (OpenLedger const&) = delete;
|
||||
@@ -105,17 +119,13 @@ public:
|
||||
Thread safety:
|
||||
Can be called concurrently from any thread.
|
||||
|
||||
`f` will be called as
|
||||
bool(ReadView&)
|
||||
|
||||
If `f` returns `true`, the changes made in the
|
||||
OpenView will be published to the open ledger.
|
||||
|
||||
@return `true` if the open view was changed
|
||||
*/
|
||||
bool
|
||||
modify (std::function<
|
||||
bool(OpenView&, beast::Journal)> const& f);
|
||||
modify (modify_type const& f);
|
||||
|
||||
/** Accept a new ledger.
|
||||
|
||||
@@ -135,6 +145,12 @@ public:
|
||||
The list of local transactions are applied
|
||||
to the new open view.
|
||||
|
||||
The optional modify function f is called
|
||||
to perform further modifications to the
|
||||
open view, atomically. Changes made in
|
||||
the modify function are not visible to
|
||||
callers until accept() returns.
|
||||
|
||||
Any failed, retriable transactions are left
|
||||
in `retries` for the caller.
|
||||
|
||||
@@ -150,7 +166,8 @@ public:
|
||||
OrderedTxs const& locals, bool retriesFirst,
|
||||
OrderedTxs& retries, ApplyFlags flags,
|
||||
HashRouter& router,
|
||||
std::string const& suffix = "");
|
||||
std::string const& suffix = "",
|
||||
modify_type const& f = {});
|
||||
|
||||
/** Algorithm for applying transactions.
|
||||
|
||||
|
||||
@@ -54,8 +54,7 @@ OpenLedger::current() const
|
||||
}
|
||||
|
||||
bool
|
||||
OpenLedger::modify (std::function<
|
||||
bool(OpenView&, beast::Journal)> const& f)
|
||||
OpenLedger::modify (modify_type const& f)
|
||||
{
|
||||
std::lock_guard<
|
||||
std::mutex> lock1(modify_mutex_);
|
||||
@@ -77,7 +76,8 @@ OpenLedger::accept(Application& app, Rules const& rules,
|
||||
std::shared_ptr<Ledger const> const& ledger,
|
||||
OrderedTxs const& locals, bool retriesFirst,
|
||||
OrderedTxs& retries, ApplyFlags flags,
|
||||
HashRouter& router, std::string const& suffix)
|
||||
HashRouter& router, std::string const& suffix,
|
||||
modify_type const& f)
|
||||
{
|
||||
JLOG(j_.trace) <<
|
||||
"accept ledger " << ledger->seq() << " " << suffix;
|
||||
@@ -112,6 +112,9 @@ OpenLedger::accept(Application& app, Rules const& rules,
|
||||
for (auto const& item : locals)
|
||||
ripple::apply(app, *next,
|
||||
*item.second, flags, j_);
|
||||
// Call the modifier
|
||||
if (f)
|
||||
f(*next, j_);
|
||||
// Switch to the new open view
|
||||
std::lock_guard<
|
||||
std::mutex> lock2(current_mutex_);
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
|
||||
// ledger close times have a dynamic resolution depending on network
|
||||
// conditions it appears the resolution in test is 10 seconds
|
||||
env.close (tp);
|
||||
env.close (tp, {});
|
||||
|
||||
NetClock::time_point const pct (
|
||||
std::chrono::seconds (env.open ()->info ().parentCloseTime));
|
||||
|
||||
@@ -195,7 +195,8 @@ public:
|
||||
The Env clock is set to the new time.
|
||||
*/
|
||||
void
|
||||
close (NetClock::time_point const& closeTime);
|
||||
close (NetClock::time_point const& closeTime,
|
||||
OpenLedger::modify_type const& f = {});
|
||||
|
||||
/** Close and advance the ledger.
|
||||
|
||||
@@ -205,10 +206,11 @@ public:
|
||||
template <class Rep, class Period>
|
||||
void
|
||||
close (std::chrono::duration<
|
||||
Rep, Period> const& elapsed)
|
||||
Rep, Period> const& elapsed,
|
||||
OpenLedger::modify_type const& f = {})
|
||||
{
|
||||
stopwatch_.advance(elapsed);
|
||||
close (clock.now() + elapsed);
|
||||
close (clock.now() + elapsed, f);
|
||||
}
|
||||
|
||||
/** Close and advance the ledger.
|
||||
@@ -217,9 +219,9 @@ public:
|
||||
the previous ledger closing time.
|
||||
*/
|
||||
void
|
||||
close()
|
||||
close(OpenLedger::modify_type const& f = {})
|
||||
{
|
||||
close (std::chrono::seconds(5));
|
||||
close (std::chrono::seconds(5), f);
|
||||
}
|
||||
|
||||
/** Turn on JSON tracing.
|
||||
|
||||
@@ -104,7 +104,8 @@ Env::closed() const
|
||||
}
|
||||
|
||||
void
|
||||
Env::close(NetClock::time_point const& closeTime)
|
||||
Env::close(NetClock::time_point const& closeTime,
|
||||
OpenLedger::modify_type const& f)
|
||||
{
|
||||
clock.set(closeTime);
|
||||
// VFALCO TODO Fix the Ledger constructor
|
||||
@@ -134,7 +135,7 @@ Env::close(NetClock::time_point const& closeTime)
|
||||
ledgerPossibleTimeResolutions[0], false, app().config());
|
||||
OrderedTxs locals({});
|
||||
openLedger.accept(app(), next->rules(), next,
|
||||
locals, false, retries, applyFlags(), *router);
|
||||
locals, false, retries, applyFlags(), *router, "", f);
|
||||
closed_ = next;
|
||||
cachedSLEs_.expire();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user