Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 43 additions & 14 deletions src/herder/TxSetFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include "util/XDROperators.h"
#include "util/numeric.h"
#include "xdrpp/marshal.h"
#ifdef BUILD_TESTS
#include "test/Catch2.h"
#endif

#include <Tracy.hpp>
#include <algorithm>
Expand Down Expand Up @@ -799,8 +802,9 @@ makeTxSetFromTransactions(
uint64_t lowerBoundCloseTimeOffset, uint64_t upperBoundCloseTimeOffset
#ifdef BUILD_TESTS
,
bool skipValidation,
txtest::ParallelSorobanOrder const& parallelSorobanOrder
bool enforceTxsApplyOrder,
txtest::ParallelSorobanOrder const& parallelSorobanOrder,
bool disableTxValidationForLegacyScenario
#endif
)
{
Expand All @@ -810,7 +814,8 @@ makeTxSetFromTransactions(
upperBoundCloseTimeOffset, invalidTxs
#ifdef BUILD_TESTS
,
skipValidation, parallelSorobanOrder
enforceTxsApplyOrder, parallelSorobanOrder,
disableTxValidationForLegacyScenario
#endif
);
}
Expand All @@ -822,8 +827,9 @@ makeTxSetFromTransactions(
PerPhaseTransactionList& invalidTxs
#ifdef BUILD_TESTS
,
bool skipValidation,
txtest::ParallelSorobanOrder const& parallelSorobanOrder
bool enforceTxsApplyOrder,
txtest::ParallelSorobanOrder const& parallelSorobanOrder,
bool disableTxValidationForLegacyScenario
#endif
)
{
Expand All @@ -850,8 +856,12 @@ makeTxSetFromTransactions(
auto& invalid = invalidTxs[i];
TxFrameList validatedTxs;
#ifdef BUILD_TESTS
if (skipValidation)
if (disableTxValidationForLegacyScenario)
{
REQUIRE(protocolVersionIsBefore(app.getLedgerManager()
.getLastClosedLedgerHeader()
.header.ledgerVersion,
ProtocolVersion::V_20));
validatedTxs = phaseTxs;
}
else
Expand All @@ -861,14 +871,29 @@ makeTxSetFromTransactions(
phaseTxs, app, accountFeeMap, lowerBoundCloseTimeOffset,
upperBoundCloseTimeOffset, invalid);
#ifdef BUILD_TESTS
// In tests we shouldn't be really trying to close ledgers with
// invalid transactions trimmed (which is unfortunately a very
// common footgun that many tests have hit).
// However, enforcing that generically is quite involved as test
// builds are used for e.g. loadgen scenarios. This method is also
// expectedly used in the tests that test tx trimming.
// So for now we only ensure that a subset of test-only scenarios
// which also historically had a lot of issues due to skipping
// validation only deals with the valid transactions now.
// Ideally we clean this up further in the future and ensure that
// tests always close ledgers with valid transactions.
if (enforceTxsApplyOrder)
{
REQUIRE(invalid.empty());
}
}
#endif
auto phaseType = static_cast<TxSetPhase>(i);
auto [includedTxs, inclusionFeeMapBinding] =
applySurgePricing(phaseType, validatedTxs, app
#ifdef BUILD_TESTS
,
skipValidation, parallelSorobanOrder
enforceTxsApplyOrder, parallelSorobanOrder
#endif
);
auto inclusionFeeMap = inclusionFeeMapBinding;
Expand Down Expand Up @@ -908,7 +933,7 @@ makeTxSetFromTransactions(
// for nomination.
auto outputTxSet = preliminaryApplicableTxSet->toWireTxSetFrame();
#ifdef BUILD_TESTS
if (skipValidation)
if (enforceTxsApplyOrder)
{
// Fill in the contents hash if we're skipping the normal roundtrip
// and validation flow.
Expand Down Expand Up @@ -1005,20 +1030,23 @@ std::pair<TxSetXDRFrameConstPtr, ApplicableTxSetFrameConstPtr>
makeTxSetFromTransactions(
TxFrameList txs, Application& app, uint64_t lowerBoundCloseTimeOffset,
uint64_t upperBoundCloseTimeOffset, bool enforceTxsApplyOrder,
txtest::ParallelSorobanOrder const& parallelSorobanOrder)
txtest::ParallelSorobanOrder const& parallelSorobanOrder,
bool disableTxValidationForLegacyScenario)
{
TxFrameList invalid;
return makeTxSetFromTransactions(
txs, app, lowerBoundCloseTimeOffset, upperBoundCloseTimeOffset, invalid,
enforceTxsApplyOrder, parallelSorobanOrder);
return makeTxSetFromTransactions(txs, app, lowerBoundCloseTimeOffset,
upperBoundCloseTimeOffset, invalid,
enforceTxsApplyOrder, parallelSorobanOrder,
disableTxValidationForLegacyScenario);
}

std::pair<TxSetXDRFrameConstPtr, ApplicableTxSetFrameConstPtr>
makeTxSetFromTransactions(
TxFrameList txs, Application& app, uint64_t lowerBoundCloseTimeOffset,
uint64_t upperBoundCloseTimeOffset, TxFrameList& invalidTxs,
bool enforceTxsApplyOrder,
txtest::ParallelSorobanOrder const& parallelSorobanOrder)
txtest::ParallelSorobanOrder const& parallelSorobanOrder,
bool disableTxValidationForLegacyScenario)
{
releaseAssert(threadIsMain());
releaseAssert(!app.getLedgerManager().isApplying());
Expand All @@ -1043,7 +1071,8 @@ makeTxSetFromTransactions(
invalid.resize(perPhaseTxs.size());
auto res = makeTxSetFromTransactions(
perPhaseTxs, app, lowerBoundCloseTimeOffset, upperBoundCloseTimeOffset,
invalid, enforceTxsApplyOrder, parallelSorobanOrder);
invalid, enforceTxsApplyOrder, parallelSorobanOrder,
disableTxValidationForLegacyScenario);
if (enforceTxsApplyOrder)
{
auto const& resPhases = res.second->getPhases();
Expand Down
48 changes: 30 additions & 18 deletions src/herder/TxSetFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,15 @@ makeTxSetFromTransactions(
uint64_t lowerBoundCloseTimeOffset,
uint64_t upperBoundCloseTimeOffset
#ifdef BUILD_TESTS
// Skips the tx set validation and preserves the pointers
// to the passed-in transactions - use in conjunction with
// `enforceTxsApplyOrder` argument in test-only overrides.
// `enforceTxsApplyOrder` forces the transactions to be ordered the same
// way as in the provided container. This is used by the test `closeLedger`
// helpers with the `strictOrder` flag enabled.
// `disableTxValidationForLegacyScenario` is used in the same helpers
// and it disables the input transaction validation.
,
bool skipValidation = false,
txtest::ParallelSorobanOrder const& parallelSorobanOrder = {}
bool enforceTxsApplyOrder = false,
txtest::ParallelSorobanOrder const& parallelSorobanOrder = {},
bool disableTxValidationForLegacyScenario = false
#endif
);
std::pair<TxSetXDRFrameConstPtr, ApplicableTxSetFrameConstPtr>
Expand All @@ -133,12 +136,15 @@ makeTxSetFromTransactions(
uint64_t lowerBoundCloseTimeOffset, uint64_t upperBoundCloseTimeOffset,
PerPhaseTransactionList& invalidTxsPerPhase
#ifdef BUILD_TESTS
// Skips the tx set validation and preserves the pointers
// to the passed-in transactions - use in conjunction with
// `enforceTxsApplyOrder` argument in test-only overrides.
// `enforceTxsApplyOrder` forces the transactions to be ordered the same
// way as in the provided container. This is used by the test `closeLedger`
// helpers with the `strictOrder` flag enabled.
// `disableTxValidationForLegacyScenario` is used in the same helpers
// and it disables the input transaction validation.
,
bool skipValidation = false,
txtest::ParallelSorobanOrder const& parallelSorobanOrder = {}
bool enforceTxsApplyOrder = false,
txtest::ParallelSorobanOrder const& parallelSorobanOrder = {},
bool disableTxValidationForLegacyScenario = false
#endif
);

Expand All @@ -147,13 +153,15 @@ std::pair<TxSetXDRFrameConstPtr, ApplicableTxSetFrameConstPtr>
makeTxSetFromTransactions(
TxFrameList txs, Application& app, uint64_t lowerBoundCloseTimeOffset,
uint64_t upperBoundCloseTimeOffset, bool enforceTxsApplyOrder = false,
txtest::ParallelSorobanOrder const& parallelSorobanOrder = {});
txtest::ParallelSorobanOrder const& parallelSorobanOrder = {},
bool disableTxValidationForLegacyScenario = false);
std::pair<TxSetXDRFrameConstPtr, ApplicableTxSetFrameConstPtr>
makeTxSetFromTransactions(
TxFrameList txs, Application& app, uint64_t lowerBoundCloseTimeOffset,
uint64_t upperBoundCloseTimeOffset, TxFrameList& invalidTxs,
bool enforceTxsApplyOrder = false,
txtest::ParallelSorobanOrder const& parallelSorobanOrder = {});
txtest::ParallelSorobanOrder const& parallelSorobanOrder = {},
bool disableTxValidationForLegacyScenario = false);
#endif

// `TxSetFrame` is a wrapper around `TransactionSet` or
Expand Down Expand Up @@ -378,8 +386,9 @@ class TxSetPhaseFrame
PerPhaseTransactionList& invalidTxsPerPhase
#ifdef BUILD_TESTS
,
bool skipValidation,
txtest::ParallelSorobanOrder const& parallelSorobanOrder
bool enforceTxsApplyOrder,
txtest::ParallelSorobanOrder const& parallelSorobanOrder,
bool disableTxValidationForLegacyScenario
#endif
);
#ifdef BUILD_TESTS
Expand All @@ -388,7 +397,8 @@ class TxSetPhaseFrame
TxFrameList txs, Application& app, uint64_t lowerBoundCloseTimeOffset,
uint64_t upperBoundCloseTimeOffset, TxFrameList& invalidTxs,
bool enforceTxsApplyOrder,
txtest::ParallelSorobanOrder const& parallelSorobanOrder);
txtest::ParallelSorobanOrder const& parallelSorobanOrder,
bool disableTxValidationForLegacyScenario);
#endif
TxSetPhaseFrame(TxSetPhase phase, TxFrameList const& txs,
std::shared_ptr<InclusionFeeMap> inclusionFeeMap);
Expand Down Expand Up @@ -551,8 +561,9 @@ class ApplicableTxSetFrame
PerPhaseTransactionList& invalidTxsPerPhase
#ifdef BUILD_TESTS
,
bool skipValidation,
txtest::ParallelSorobanOrder const& parallelSorobanOrder
bool enforceTxsApplyOrder,
txtest::ParallelSorobanOrder const& parallelSorobanOrder,
bool disableTxValidationForLegacyScenario
#endif
);
#ifdef BUILD_TESTS
Expand All @@ -561,7 +572,8 @@ class ApplicableTxSetFrame
TxFrameList txs, Application& app, uint64_t lowerBoundCloseTimeOffset,
uint64_t upperBoundCloseTimeOffset, TxFrameList& invalidTxs,
bool enforceTxsApplyOrder,
txtest::ParallelSorobanOrder const& parallelSorobanOrder);
txtest::ParallelSorobanOrder const& parallelSorobanOrder,
bool disableTxValidationForLegacyScenario);
#endif

ApplicableTxSetFrame(Application& app,
Expand Down
Loading
Loading