Make preflight1 and preflight2 private static Transactor functions

- They should never be called by derived classes.
This commit is contained in:
Ed Hennis
2025-07-11 18:42:39 -04:00
parent 96ad348fb0
commit 6c5945f9e8
3 changed files with 75 additions and 58 deletions

View File

@@ -650,14 +650,6 @@ EscrowFinish::doPreflight(PreflightContext const& ctx)
if (static_cast<bool>(cb) != static_cast<bool>(fb))
return temMALFORMED;
// Verify the transaction signature. If it doesn't work
// then don't do any more work.
{
auto const ret = detail::preflight2(ctx);
if (!isTesSuccess(ret))
return ret;
}
if (cb && fb)
{
auto& router = ctx.app.getHashRouter();

View File

@@ -112,9 +112,53 @@ preflightCheckSigningKey(STObject const& sigObject, beast::Journal j)
return tesSUCCESS;
}
std::optional<NotTEC>
preflightCheckSimulateKeys(
ApplyFlags flags,
STObject const& sigObject,
beast::Journal j)
{
if (ctx.flags & tapDRY_RUN) // simulation
{
if (!ctx.tx.getSignature().empty())
{
// NOTE: This code should never be hit because it's checked in the
// `simulate` RPC
return temINVALID; // LCOV_EXCL_LINE
}
if (!ctx.tx.isFieldPresent(sfSigners))
{
// no signers, no signature - a valid simulation
return tesSUCCESS;
}
for (auto const& signer : ctx.tx.getFieldArray(sfSigners))
{
if (signer.isFieldPresent(sfTxnSignature) &&
!signer[sfTxnSignature].empty())
{
// NOTE: This code should never be hit because it's
// checked in the `simulate` RPC
return temINVALID; // LCOV_EXCL_LINE
}
}
if (!ctx.tx.getSigningPubKey().empty())
{
// trying to single-sign _and_ multi-sign a transaction
return temINVALID;
}
return tesSUCCESS;
}
return {};
}
} // namespace detail
/** Performs early sanity checks on the account and fee fields */
NotTEC
preflight1(PreflightContext const& ctx, std::uint32_t flagMask)
Transactor::preflight1(PreflightContext const& ctx, std::uint32_t flagMask)
{
// This is inappropriate in preflight0, because only Change transactions
// skip this function, and those do not allow an sfTicketSequence field.
@@ -151,7 +195,7 @@ preflight1(PreflightContext const& ctx, std::uint32_t flagMask)
return temBAD_FEE;
}
if (auto const ret = preflightCheckSigningKey(ctx.tx, ctx.j))
if (auto const ret = detail::preflightCheckSigningKey(ctx.tx, ctx.j))
return ret;
// An AccountTxnID field constrains transaction ordering more than the
@@ -177,41 +221,13 @@ preflight1(PreflightContext const& ctx, std::uint32_t flagMask)
/** Checks whether the signature appears valid */
NotTEC
preflight2(PreflightContext const& ctx)
Transactor::preflight2(PreflightContext const& ctx)
{
if (ctx.flags & tapDRY_RUN) // simulation
{
if (!ctx.tx.getSignature().empty())
{
// NOTE: This code should never be hit because it's checked in the
// `simulate` RPC
return temINVALID; // LCOV_EXCL_LINE
}
if (!ctx.tx.isFieldPresent(sfSigners))
{
// no signers, no signature - a valid simulation
return tesSUCCESS;
}
for (auto const& signer : ctx.tx.getFieldArray(sfSigners))
{
if (signer.isFieldPresent(sfTxnSignature) &&
!signer[sfTxnSignature].empty())
{
// NOTE: This code should never be hit because it's
// checked in the `simulate` RPC
return temINVALID; // LCOV_EXCL_LINE
}
}
if (!ctx.tx.getSigningPubKey().empty())
{
// trying to single-sign _and_ multi-sign a transaction
return temINVALID;
}
return tesSUCCESS;
}
if (auto const ret =
detail::preflightCheckSimulateKeys(ctx.flags, ctx.tx, ctx.j))
// Skips following checks if the transaction is being simulated,
// regardless of success or failure
return *ret;
auto const sigValid = checkValidity(
ctx.app.getHashRouter(), ctx.tx, ctx.rules, ctx.app.config());
@@ -223,8 +239,6 @@ preflight2(PreflightContext const& ctx)
return tesSUCCESS;
}
} // namespace detail
//------------------------------------------------------------------------------
Transactor::Transactor(ApplyContext& ctx)

View File

@@ -316,6 +316,18 @@ private:
beast::Journal j);
void trapTransaction(uint256) const;
// Helper functions for preflight checks. Do not use directly.
/** Performs early sanity checks on the account and fee fields.
(And passes flagMask to preflight0)
*/
static NotTEC
preflight1(PreflightContext const& ctx, std::uint32_t flagMask);
/** Checks whether the signature appears valid */
static NotTEC
preflight2(PreflightContext const& ctx);
};
inline bool
@@ -337,16 +349,15 @@ namespace detail {
NotTEC
preflightCheckSigningKey(STObject const& sigObject, beast::Journal j);
/** Performs early sanity checks on the account and fee fields.
(And passes flagMask to preflight0)
*/
NotTEC
preflight1(PreflightContext const& ctx, std::uint32_t flagMask);
/** Checks whether the signature appears valid */
NotTEC
preflight2(PreflightContext const& ctx);
/** Checks the special signing key state needed for simulation
*
* Normally called from preflight2 with ctx.tx.
*/
std::optional<NotTEC>
preflightCheckSimulateKeys(
ApplyFlags flags,
STObject const& sigObject,
beast::Journal j);
} // namespace detail
// Defined in Change.cpp
@@ -361,13 +372,13 @@ Transactor::preflight(PreflightContext const& ctx)
if (!T::isEnabled(ctx))
return temDISABLED;
if (auto const ret = ripple::detail::preflight1(ctx, T::getFlagsMask(ctx)))
if (auto const ret = preflight1(ctx, T::getFlagsMask(ctx)))
return ret;
if (auto const ret = T::doPreflight(ctx))
return ret;
return ripple::detail::preflight2(ctx);
return preflight2(ctx);
}
template <class T>