mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 02:55:50 +00:00
Refactor View, MetaView, and tx processing:
This tidies up the View interface and makes transaction application a free function, with the removal of the TransactionEngine class. A new class ApplyContext provides all the state information needed to apply a Transactor. The Transactor is refactored to perform all the processing activities previously part of TransactionEngine. The calculation of metadata from a MetaView is improved. A new apply function performs all the steps for calculating and inserting metadata into the tx map. Transaction processing code path is passed a Config instead of retrieving the global, and uses the Journal supplied in the call to apply() consistently. To support transaction processing and RPC operations, a new POD type ViewInfo is added which consolidates static information about open and closed ledgers, such as the ledger sequence number or the closing times. Ledger and MetaView are refactored to use this info. The ViewInfo now contains the "open ledger" setting. The tapOPEN_LEDGER ViewFlag is removed. The view property of being an open ledger is obtained from the base or by using the MetaView constructor which presents a closed ledger as an open one. View, MetaView: * Fix missing includes * Add apply free function * Use Journal in TransactionEngine * Use BasicView in TransactionEngine * inline NetworkOPs::batchApply * Add shallow_copy, open_ledger MetaView ctor tags * Add ViewInfo with open flag, seq, close times * Make parent_ a reference * Tidy up ctor arguments and base_ name * Remove tapOPEN_LEDGER * add assert to MetaView::apply * ViewInfo comment * Throw, pass Journal in txInsert * Add BasicView::txCount TransactionEngine: * Add apply * Make TransactionEngine private * Refactor MetaView::apply and apply() * Rename to TxMeta * Refactor treatment of metadata in MetaView, TransactionEngine * Rename to ApplyContext * Use ApplyContext& in Transactor * Pass Config in ApplyContext * Declare Transactor classes in headers * Use view flags in Transactor
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include <ripple/protocol/TER.h>
|
||||
#include <ripple/core/Config.h>
|
||||
#include <ripple/ledger/View.h>
|
||||
#include <beast/utility/Journal.h>
|
||||
#include <boost/optional.hpp>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
@@ -65,11 +66,40 @@ struct Fees
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** A view into a ledger's state items.
|
||||
/** Information about the notional ledger backing the view. */
|
||||
struct ViewInfo
|
||||
{
|
||||
// Fields for all ledgers
|
||||
bool open = true;
|
||||
LedgerIndex seq = 0;
|
||||
std::uint32_t parentCloseTime = 0;
|
||||
|
||||
The interface provides raw access for state item
|
||||
modification operations. There is no checkpointing
|
||||
// Fields for closed ledgers
|
||||
// Closed means "tx set already determined"
|
||||
//uint256 hash;
|
||||
//uint256 txHash;
|
||||
//uint256 stateHash;
|
||||
//uint256 parentHash;
|
||||
//std::uint64_t coins = 0;
|
||||
//bool validated = false;
|
||||
//int closeTimeRes = 0;
|
||||
|
||||
// For closed ledgers, the time the ledger
|
||||
// closed. For open ledgers, the time the ledger
|
||||
// will close if there's no transactions.
|
||||
//
|
||||
std::uint32_t closeTime = 0;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** A view into a ledger.
|
||||
|
||||
This interface provides read access to state
|
||||
and transaction items. There is no checkpointing
|
||||
or calculation of metadata.
|
||||
|
||||
A raw interace is provided for mutable ledgers.
|
||||
*/
|
||||
class BasicView
|
||||
{
|
||||
@@ -80,24 +110,44 @@ public:
|
||||
|
||||
virtual ~BasicView() = default;
|
||||
|
||||
/** Returns information about the ledger. */
|
||||
virtual
|
||||
ViewInfo const&
|
||||
info() const = 0;
|
||||
|
||||
/** Returns true if this reflects an open ledger. */
|
||||
bool
|
||||
open() const
|
||||
{
|
||||
return info().open;
|
||||
}
|
||||
|
||||
/** Returns true if this reflects a closed ledger. */
|
||||
bool
|
||||
closed() const
|
||||
{
|
||||
return ! info().open;
|
||||
}
|
||||
|
||||
/** Returns the close time of the previous ledger. */
|
||||
std::uint32_t
|
||||
parentCloseTime() const
|
||||
{
|
||||
return info().parentCloseTime;
|
||||
}
|
||||
|
||||
/** Returns the sequence number of the base ledger. */
|
||||
LedgerIndex
|
||||
seq() const
|
||||
{
|
||||
return info().seq;
|
||||
}
|
||||
|
||||
/** Returns the fees for the base ledger. */
|
||||
virtual
|
||||
Fees const&
|
||||
fees() const = 0;
|
||||
|
||||
/** Returns the sequence number of the base ledger. */
|
||||
virtual
|
||||
LedgerIndex
|
||||
seq() const = 0;
|
||||
|
||||
/** Return the last known close time.
|
||||
|
||||
The epoch is based on the Ripple network clock.
|
||||
*/
|
||||
virtual
|
||||
std::uint32_t
|
||||
time() const = 0;
|
||||
|
||||
/** Determine if a state item exists.
|
||||
|
||||
@note This can be more efficient than calling read.
|
||||
@@ -204,6 +254,18 @@ public:
|
||||
void
|
||||
destroyCoins (std::uint64_t feeDrops) = 0;
|
||||
|
||||
/** Returns the number of newly inserted transactions.
|
||||
|
||||
This will always be zero for closed ledgers, there
|
||||
is no efficient way to count the number of tx in
|
||||
the map. For views representing open ledgers this
|
||||
starts out as one and gets incremented for each
|
||||
transaction that is applied.
|
||||
*/
|
||||
virtual
|
||||
std::size_t
|
||||
txCount() const = 0;
|
||||
|
||||
/** Returns `true` if a tx exists in the tx map. */
|
||||
virtual
|
||||
bool
|
||||
@@ -214,10 +276,11 @@ public:
|
||||
@param metaData Optional metadata (may be nullptr)
|
||||
*/
|
||||
virtual
|
||||
bool
|
||||
void
|
||||
txInsert (uint256 const& key,
|
||||
std::shared_ptr<Serializer const> const& txn,
|
||||
std::shared_ptr<Serializer const> const& metaData) = 0;
|
||||
std::shared_ptr<Serializer const
|
||||
> const& txn, std::shared_ptr<
|
||||
Serializer const> const& metaData) = 0;
|
||||
|
||||
// DEBUG ROUTINE
|
||||
// Return a list of transaction keys in the tx map.
|
||||
@@ -255,11 +318,6 @@ enum ViewFlags
|
||||
//
|
||||
tapENABLE_TESTING = 0x02,
|
||||
|
||||
// Transaction is running against an open ledger
|
||||
// true = failures are not forwarded, check transaction fee
|
||||
// false = debit ledger for consumed funds
|
||||
tapOPEN_LEDGER = 0x10,
|
||||
|
||||
// This is not the transaction's last pass
|
||||
// Transaction can be retried, soft failures allowed
|
||||
tapRETRY = 0x20,
|
||||
@@ -268,6 +326,27 @@ enum ViewFlags
|
||||
tapADMIN = 0x400,
|
||||
};
|
||||
|
||||
inline
|
||||
ViewFlags operator|(
|
||||
ViewFlags const& lhs,
|
||||
ViewFlags const& rhs)
|
||||
{
|
||||
return static_cast<ViewFlags>(
|
||||
static_cast<int>(lhs) |
|
||||
static_cast<int>(rhs));
|
||||
}
|
||||
|
||||
inline
|
||||
ViewFlags
|
||||
operator&(
|
||||
ViewFlags const& lhs,
|
||||
ViewFlags const& rhs)
|
||||
{
|
||||
return static_cast<ViewFlags>(
|
||||
static_cast<int>(lhs) &
|
||||
static_cast<int>(rhs));
|
||||
}
|
||||
|
||||
/** A contextual view into a ledger's state items.
|
||||
|
||||
This refinement of BasicView provides an interface where
|
||||
@@ -422,24 +501,18 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
ViewInfo const&
|
||||
info() const
|
||||
{
|
||||
return view_.info();
|
||||
}
|
||||
|
||||
Fees const&
|
||||
fees() const override
|
||||
{
|
||||
return view_.fees();
|
||||
}
|
||||
|
||||
LedgerIndex
|
||||
seq() const override
|
||||
{
|
||||
return view_.seq();
|
||||
}
|
||||
|
||||
std::uint32_t
|
||||
time() const override
|
||||
{
|
||||
return view_.time();
|
||||
}
|
||||
|
||||
bool
|
||||
exists (Keylet const& k) const override
|
||||
{
|
||||
@@ -488,20 +561,25 @@ public:
|
||||
return view_.destroyCoins(feeDrops);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
txCount() const override
|
||||
{
|
||||
return view_.txCount();
|
||||
}
|
||||
|
||||
bool
|
||||
txExists (uint256 const& key) const override
|
||||
{
|
||||
return view_.txExists(key);
|
||||
}
|
||||
|
||||
bool
|
||||
void
|
||||
txInsert (uint256 const& key,
|
||||
std::shared_ptr<Serializer const
|
||||
> const& txn, std::shared_ptr<
|
||||
Serializer const> const& metaData) override
|
||||
{
|
||||
return view_.txInsert(
|
||||
key, txn, metaData);
|
||||
view_.txInsert(key, txn, metaData);
|
||||
}
|
||||
|
||||
std::vector<uint256>
|
||||
@@ -528,24 +606,18 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
ViewInfo const&
|
||||
info() const
|
||||
{
|
||||
return view_.info();
|
||||
}
|
||||
|
||||
Fees const&
|
||||
fees() const override
|
||||
{
|
||||
return view_.fees();
|
||||
}
|
||||
|
||||
LedgerIndex
|
||||
seq() const override
|
||||
{
|
||||
return view_.seq();
|
||||
}
|
||||
|
||||
std::uint32_t
|
||||
time() const override
|
||||
{
|
||||
return view_.time();
|
||||
}
|
||||
|
||||
bool
|
||||
exists (Keylet const& k) const override
|
||||
{
|
||||
@@ -594,20 +666,25 @@ public:
|
||||
return view_.destroyCoins(feeDrops);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
txCount() const override
|
||||
{
|
||||
return view_.txCount();
|
||||
}
|
||||
|
||||
bool
|
||||
txExists (uint256 const& key) const override
|
||||
{
|
||||
return view_.txExists(key);
|
||||
}
|
||||
|
||||
bool
|
||||
void
|
||||
txInsert (uint256 const& key,
|
||||
std::shared_ptr<Serializer const
|
||||
> const& txn, std::shared_ptr<
|
||||
Serializer const> const& metaData) override
|
||||
{
|
||||
return view_.txInsert(
|
||||
key, txn, metaData);
|
||||
view_.txInsert(key, txn, metaData);
|
||||
}
|
||||
|
||||
std::vector<uint256>
|
||||
|
||||
Reference in New Issue
Block a user