mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Framework for double-checking that transactions, as they will be applied,
don't break invariants.
This commit is contained in:
@@ -175,6 +175,7 @@
|
||||
<ClCompile Include="src\cpp\ripple\Suppression.cpp" />
|
||||
<ClCompile Include="src\cpp\ripple\Transaction.cpp" />
|
||||
<ClCompile Include="src\cpp\ripple\TransactionAcquire.cpp" />
|
||||
<ClCompile Include="src\cpp\ripple\TransactionCheck.cpp" />
|
||||
<ClCompile Include="src\cpp\ripple\TransactionEngine.cpp" />
|
||||
<ClCompile Include="src\cpp\ripple\TransactionErr.cpp" />
|
||||
<ClCompile Include="src\cpp\ripple\TransactionFormats.cpp" />
|
||||
|
||||
@@ -249,6 +249,9 @@
|
||||
<ClCompile Include="src\cpp\ripple\TransactionEngine.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\ripple\TransactionCheck.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\ripple\TransactionErr.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
||||
@@ -175,6 +175,7 @@
|
||||
<ClCompile Include="src\cpp\ripple\Suppression.cpp" />
|
||||
<ClCompile Include="src\cpp\ripple\Transaction.cpp" />
|
||||
<ClCompile Include="src\cpp\ripple\TransactionAcquire.cpp" />
|
||||
<ClCompile Include="src\cpp\ripple\TransactionCheck.cpp" />
|
||||
<ClCompile Include="src\cpp\ripple\TransactionEngine.cpp" />
|
||||
<ClCompile Include="src\cpp\ripple\TransactionErr.cpp" />
|
||||
<ClCompile Include="src\cpp\ripple\TransactionFormats.cpp" />
|
||||
|
||||
@@ -243,6 +243,9 @@
|
||||
<ClCompile Include="src\cpp\ripple\TransactionAcquire.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\ripple\TransactionCheck.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\cpp\ripple\TransactionEngine.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
||||
11
src/cpp/ripple/TransactionCheck.cpp
Normal file
11
src/cpp/ripple/TransactionCheck.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
#include "TransactionErr.h"
|
||||
#include "TransactionEngine.h"
|
||||
|
||||
// Double check a transaction's metadata to make sure no system invariants were broken
|
||||
// Call right before 'calcRawMeta'
|
||||
|
||||
bool TransactionEngine::checkInvariants(TER result, const SerializedTransaction& txn, TransactionEngineParams params)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn, Transa
|
||||
}
|
||||
#endif
|
||||
|
||||
UPTR_T<Transactor> transactor = Transactor::makeTransactor(txn,params,this);
|
||||
UPTR_T<Transactor> transactor = Transactor::makeTransactor(txn, params, this);
|
||||
if (transactor.get() != NULL)
|
||||
{
|
||||
uint256 txID = txn.getTransactionID();
|
||||
@@ -153,28 +153,39 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn, Transa
|
||||
|
||||
if (didApply)
|
||||
{
|
||||
// Transaction succeeded fully or (retries are not allowed and the transaction could claim a fee)
|
||||
Serializer m;
|
||||
mNodes.calcRawMeta(m, terResult, mTxnSeq++);
|
||||
|
||||
txnWrite();
|
||||
|
||||
Serializer s;
|
||||
txn.add(s);
|
||||
|
||||
if (isSetBit(params, tapOPEN_LEDGER))
|
||||
if (!checkInvariants(terResult, txn, params))
|
||||
{
|
||||
if (!mLedger->addTransaction(txID, s))
|
||||
assert(false);
|
||||
cLog(lsFATAL) << "Transaction violates invariants";
|
||||
cLog(lsFATAL) << txn.getJson(0);
|
||||
cLog(lsFATAL) << transToken(terResult) << ": " << transHuman(terResult);
|
||||
cLog(lsFATAL) << mNodes.getJson(0);
|
||||
didApply = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!mLedger->addTransaction(txID, s, m))
|
||||
// Transaction succeeded fully or (retries are not allowed and the transaction could claim a fee)
|
||||
Serializer m;
|
||||
mNodes.calcRawMeta(m, terResult, mTxnSeq++);
|
||||
|
||||
txnWrite();
|
||||
|
||||
Serializer s;
|
||||
txn.add(s);
|
||||
|
||||
if (isSetBit(params, tapOPEN_LEDGER))
|
||||
{
|
||||
if (!mLedger->addTransaction(txID, s))
|
||||
assert(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!mLedger->addTransaction(txID, s, m))
|
||||
assert(false);
|
||||
|
||||
// Charge whatever fee they specified.
|
||||
STAmount saPaid = txn.getTransactionFee();
|
||||
mLedger->destroyCoins(saPaid.getNValue());
|
||||
// Charge whatever fee they specified.
|
||||
STAmount saPaid = txn.getTransactionFee();
|
||||
mLedger->destroyCoins(saPaid.getNValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ public:
|
||||
void entryModify(SLE::ref sleEntry) { mNodes.entryModify(sleEntry); }
|
||||
|
||||
TER applyTransaction(const SerializedTransaction&, TransactionEngineParams, bool& didApply);
|
||||
bool checkInvariants(TER result, const SerializedTransaction& txn, TransactionEngineParams params);
|
||||
};
|
||||
|
||||
inline TransactionEngineParams operator|(const TransactionEngineParams& l1, const TransactionEngineParams& l2)
|
||||
|
||||
Reference in New Issue
Block a user