mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Cache tid in STTx:
The digest for a transaction (its transaction ID, or tid) is computed once upon constructed when the STTx is deserialized. Subsequent calls to retrieve the digest use the cached value. Any code which modifies the STTx and then attempts to retrieve the digest will terminate the process with a logic error contract violation. * Nested types removed * All STTx are contained as const (Except in transaction sign, which must modify) * tid in STTx is computed once on deserialization
This commit is contained in:
@@ -54,7 +54,7 @@ AcceptedLedgerTx::AcceptedLedgerTx (
|
||||
|
||||
AcceptedLedgerTx::AcceptedLedgerTx (
|
||||
std::shared_ptr<ReadView const> const& ledger,
|
||||
STTx::ref txn,
|
||||
std::shared_ptr<STTx const> const& txn,
|
||||
TER result,
|
||||
AccountIDCache const& accountCache,
|
||||
Logs& logs)
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
Logs&);
|
||||
AcceptedLedgerTx (
|
||||
std::shared_ptr<ReadView const> const&,
|
||||
STTx::ref,
|
||||
std::shared_ptr<STTx const> const&,
|
||||
TER,
|
||||
AccountIDCache const&,
|
||||
Logs&);
|
||||
|
||||
@@ -57,7 +57,7 @@ void ConsensusTransSetSF::gotNode (
|
||||
// skip prefix
|
||||
Serializer s (nodeData.data() + 4, nodeData.size() - 4);
|
||||
SerialIter sit (s.slice());
|
||||
STTx::pointer stx = std::make_shared<STTx> (std::ref (sit));
|
||||
auto stx = std::make_shared<STTx const> (std::ref (sit));
|
||||
assert (stx->getTransactionID () == nodeHash);
|
||||
auto const pap = &app_;
|
||||
app_.getJobQueue ().addJob (
|
||||
|
||||
@@ -1164,7 +1164,7 @@ void LedgerConsensusImp::accept (std::shared_ptr<SHAMap> set)
|
||||
<< " not get in";
|
||||
SerialIter sit (it.second->peekTransaction().slice());
|
||||
|
||||
auto txn = std::make_shared<STTx>(sit);
|
||||
auto txn = std::make_shared<STTx const>(sit);
|
||||
|
||||
retriableTxs.insert (txn);
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ public:
|
||||
//
|
||||
|
||||
// Must complete immediately.
|
||||
void submitTransaction (STTx::pointer) override;
|
||||
void submitTransaction (std::shared_ptr<STTx const> const&) override;
|
||||
|
||||
void processTransaction (
|
||||
Transaction::pointer& transaction,
|
||||
@@ -339,7 +339,7 @@ public:
|
||||
void pubLedger (Ledger::ref lpAccepted) override;
|
||||
void pubProposedTransaction (
|
||||
std::shared_ptr<ReadView const> const& lpCurrent,
|
||||
STTx::ref stTxn, TER terResult) override;
|
||||
std::shared_ptr<STTx const> const& stTxn, TER terResult) override;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//
|
||||
@@ -639,7 +639,7 @@ std::string NetworkOPsImp::strOperatingMode () const
|
||||
return paStatusToken[mMode];
|
||||
}
|
||||
|
||||
void NetworkOPsImp::submitTransaction (STTx::pointer iTrans)
|
||||
void NetworkOPsImp::submitTransaction (std::shared_ptr<STTx const> const& iTrans)
|
||||
{
|
||||
if (isNeedNetworkLedger ())
|
||||
{
|
||||
@@ -648,11 +648,7 @@ void NetworkOPsImp::submitTransaction (STTx::pointer iTrans)
|
||||
}
|
||||
|
||||
// this is an asynchronous interface
|
||||
Serializer s;
|
||||
iTrans->add (s);
|
||||
|
||||
SerialIter sit (s.slice());
|
||||
auto trans = std::make_shared<STTx> (std::ref (sit));
|
||||
auto const trans = sterilize(*iTrans);
|
||||
|
||||
auto const txid = trans->getTransactionID ();
|
||||
auto const flags = app_.getHashRouter().getFlags(txid);
|
||||
@@ -2005,7 +2001,7 @@ Json::Value NetworkOPsImp::getLedgerFetchInfo ()
|
||||
|
||||
void NetworkOPsImp::pubProposedTransaction (
|
||||
std::shared_ptr<ReadView const> const& lpCurrent,
|
||||
STTx::ref stTxn, TER terResult)
|
||||
std::shared_ptr<STTx const> const& stTxn, TER terResult)
|
||||
{
|
||||
Json::Value jvObj = transJson (*stTxn, terResult, false, lpCurrent);
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ public:
|
||||
//
|
||||
|
||||
// must complete immediately
|
||||
virtual void submitTransaction (STTx::pointer) = 0;
|
||||
virtual void submitTransaction (std::shared_ptr<STTx const> const&) = 0;
|
||||
|
||||
/**
|
||||
* Process transactions as they arrive from the network or which are
|
||||
@@ -229,7 +229,7 @@ public:
|
||||
virtual void pubLedger (Ledger::ref lpAccepted) = 0;
|
||||
virtual void pubProposedTransaction (
|
||||
std::shared_ptr<ReadView const> const& lpCurrent,
|
||||
STTx::ref stTxn, TER terResult) = 0;
|
||||
std::shared_ptr<STTx const> const& stTxn, TER terResult) = 0;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -40,7 +40,7 @@ convertBlobsToTxResult (
|
||||
Application& app)
|
||||
{
|
||||
SerialIter it (makeSlice(rawTxn));
|
||||
STTx::pointer txn = std::make_shared<STTx> (it);
|
||||
auto txn = std::make_shared<STTx const> (it);
|
||||
std::string reason;
|
||||
|
||||
auto tr = std::make_shared<Transaction> (txn, reason, app);
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
virtual ~LocalTxs () = default;
|
||||
|
||||
// Add a new local transaction
|
||||
virtual void push_back (LedgerIndex index, STTx::ref txn) = 0;
|
||||
virtual void push_back (LedgerIndex index, std::shared_ptr<STTx const> const& txn) = 0;
|
||||
|
||||
// Return the set of local transactions to a new open ledger
|
||||
virtual CanonicalTXSet getTxSet () = 0;
|
||||
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
|
||||
public:
|
||||
Transaction (
|
||||
STTx::ref, std::string&, Application&) noexcept;
|
||||
std::shared_ptr<STTx const> const&, std::string&, Application&) noexcept;
|
||||
|
||||
static
|
||||
Transaction::pointer
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
TransStatus
|
||||
sqlTransactionStatus(boost::optional<std::string> const& status);
|
||||
|
||||
STTx::ref getSTransaction ()
|
||||
std::shared_ptr<STTx const> const& getSTransaction ()
|
||||
{
|
||||
return mTransaction;
|
||||
}
|
||||
@@ -170,7 +170,7 @@ private:
|
||||
TER mResult = temUNCERTAIN;
|
||||
bool mApplying = false;
|
||||
|
||||
STTx::pointer mTransaction;
|
||||
std::shared_ptr<STTx const> mTransaction;
|
||||
Application& mApp;
|
||||
beast::Journal j_;
|
||||
};
|
||||
|
||||
@@ -37,15 +37,23 @@ public:
|
||||
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,
|
||||
bool checkDisk, std::uint32_t uCommitLedger);
|
||||
Transaction::pointer
|
||||
fetch (uint256 const& , bool checkDisk);
|
||||
|
||||
std::shared_ptr<STTx const>
|
||||
fetch (std::shared_ptr<SHAMapItem> const& item,
|
||||
SHAMapTreeNode:: TNType type,
|
||||
bool checkDisk, std::uint32_t uCommitLedger);
|
||||
|
||||
// return value: true = we had the transaction already
|
||||
bool inLedger (uint256 const& hash, std::uint32_t ledger);
|
||||
|
||||
void canonicalize (Transaction::pointer* pTransaction);
|
||||
|
||||
void sweep (void);
|
||||
TaggedCache <uint256, Transaction>& getCache();
|
||||
|
||||
TaggedCache <uint256, Transaction>&
|
||||
getCache();
|
||||
|
||||
private:
|
||||
Application& mApp;
|
||||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
// get into a fully-validated ledger.
|
||||
static int const holdLedgers = 5;
|
||||
|
||||
LocalTx (LedgerIndex index, STTx::ref txn)
|
||||
LocalTx (LedgerIndex index, std::shared_ptr<STTx const> const& txn)
|
||||
: m_txn (txn)
|
||||
, m_expire (index + holdLedgers)
|
||||
, m_id (txn->getTransactionID ())
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
return i > m_expire;
|
||||
}
|
||||
|
||||
STTx::ref getTX () const
|
||||
std::shared_ptr<STTx const> const& getTX () const
|
||||
{
|
||||
return m_txn;
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
STTx::pointer m_txn;
|
||||
std::shared_ptr<STTx const> m_txn;
|
||||
LedgerIndex m_expire;
|
||||
uint256 m_id;
|
||||
AccountID m_account;
|
||||
@@ -113,7 +113,7 @@ public:
|
||||
LocalTxsImp() = default;
|
||||
|
||||
// Add a new transaction to the set of local transactions
|
||||
void push_back (LedgerIndex index, STTx::ref txn) override
|
||||
void push_back (LedgerIndex index, std::shared_ptr<STTx const> const& txn) override
|
||||
{
|
||||
std::lock_guard <std::mutex> lock (m_lock);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
Transaction::Transaction (STTx::ref stx,
|
||||
Transaction::Transaction (std::shared_ptr<STTx const> const& stx,
|
||||
std::string& reason, Application& app)
|
||||
noexcept
|
||||
: mTransaction (stx)
|
||||
@@ -62,7 +62,7 @@ Transaction::pointer Transaction::sharedTransaction (
|
||||
try
|
||||
{
|
||||
SerialIter sit (makeSlice(vucTransaction));
|
||||
auto txn = std::make_shared<STTx>(sit);
|
||||
auto txn = std::make_shared<STTx const>(sit);
|
||||
std::string reason;
|
||||
auto result = std::make_shared<Transaction> (
|
||||
txn, reason, app);
|
||||
@@ -125,7 +125,7 @@ Transaction::pointer Transaction::transactionFromSQL (
|
||||
rangeCheckedCast<std::uint32_t>(ledgerSeq.value_or (0));
|
||||
|
||||
SerialIter it (makeSlice(rawTxn));
|
||||
auto txn = std::make_shared<STTx> (it);
|
||||
auto txn = std::make_shared<STTx const> (it);
|
||||
std::string reason;
|
||||
auto tr = std::make_shared<Transaction> (
|
||||
txn, reason, app);
|
||||
|
||||
@@ -60,11 +60,12 @@ Transaction::pointer TransactionMaster::fetch (uint256 const& txnID, bool checkD
|
||||
return txn;
|
||||
}
|
||||
|
||||
STTx::pointer TransactionMaster::fetch (std::shared_ptr<SHAMapItem> const& item,
|
||||
std::shared_ptr<STTx const>
|
||||
TransactionMaster::fetch (std::shared_ptr<SHAMapItem> const& item,
|
||||
SHAMapTreeNode::TNType type,
|
||||
bool checkDisk, std::uint32_t uCommitLedger)
|
||||
{
|
||||
STTx::pointer txn;
|
||||
std::shared_ptr<STTx const> txn;
|
||||
auto iTx = fetch (item->key(), false);
|
||||
|
||||
if (!iTx)
|
||||
@@ -73,12 +74,12 @@ STTx::pointer TransactionMaster::fetch (std::shared_ptr<SHAMapItem> const& item,
|
||||
if (type == SHAMapTreeNode::tnTRANSACTION_NM)
|
||||
{
|
||||
SerialIter sit (item->slice());
|
||||
txn = std::make_shared<STTx> (std::ref (sit));
|
||||
txn = std::make_shared<STTx const> (std::ref (sit));
|
||||
}
|
||||
else if (type == SHAMapTreeNode::tnTRANSACTION_MD)
|
||||
{
|
||||
auto blob = SerialIter{item->data(), item->size()}.getVL();
|
||||
txn = std::make_shared<STTx>(SerialIter{blob.data(), blob.size()});
|
||||
txn = std::make_shared<STTx const>(SerialIter{blob.data(), blob.size()});
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user