Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch Soroban tests to always use closeLedger to apply txs. #4455

Merged
merged 1 commit into from
Sep 10, 2024
Merged
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
2 changes: 2 additions & 0 deletions src/ledger/LedgerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class LedgerManager

#ifdef BUILD_TESTS
virtual SorobanNetworkConfig& getMutableSorobanNetworkConfig() = 0;
virtual std::vector<TransactionMetaFrame> const&
getLastClosedLedgerTxMeta() = 0;
#endif

// Return the (changing) number of seconds since the LCL closed.
Expand Down
12 changes: 12 additions & 0 deletions src/ledger/LedgerManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@ LedgerManagerImpl::getMutableSorobanNetworkConfig()
{
return getSorobanNetworkConfigInternal();
}
std::vector<TransactionMetaFrame> const&
LedgerManagerImpl::getLastClosedLedgerTxMeta()
{
return mLastLedgerTxMeta;
}
#endif

SorobanMetrics&
Expand Down Expand Up @@ -791,6 +796,9 @@ during replays.
void
LedgerManagerImpl::closeLedger(LedgerCloseData const& ledgerData)
{
#ifdef BUILD_TESTS
mLastLedgerTxMeta.clear();
#endif
ZoneScoped;
auto ledgerTime = mLedgerClose.TimeScope();
LogSlowExecution closeLedgerTime{"closeLedger",
Expand Down Expand Up @@ -1573,6 +1581,10 @@ LedgerManagerImpl::applyTransactions(
// hashing into the ledger header.
txResultSet.results.emplace_back(results);

#ifdef BUILD_TESTS
mLastLedgerTxMeta.push_back(tm);
#endif

// Then potentially add that TRP and its associated TransactionMeta
// into the associated slot of any LedgerCloseMeta we're collecting.
if (ledgerCloseMeta)
Expand Down
7 changes: 7 additions & 0 deletions src/ledger/LedgerManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ class LedgerManagerImpl : public LedgerManager
void closeLedgerIf(LedgerCloseData const& ledgerData);

State mState;

#ifdef BUILD_TESTS
std::vector<TransactionMetaFrame> mLastLedgerTxMeta;
#endif

void setState(State s);

void emitNextMeta();
Expand Down Expand Up @@ -154,6 +159,8 @@ class LedgerManagerImpl : public LedgerManager

#ifdef BUILD_TESTS
SorobanNetworkConfig& getMutableSorobanNetworkConfig() override;
std::vector<TransactionMetaFrame> const&
getLastClosedLedgerTxMeta() override;
#endif

uint64_t secondsSinceLastLedgerClose() const override;
Expand Down
6 changes: 3 additions & 3 deletions src/ledger/test/LedgerCloseMetaStreamTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ TEST_CASE_VERSIONS("meta stream contains reasonable meta", "[ledgerclosemeta]")
ContractDataDurability::PERSISTENT);

uint32_t liveUntilLedger =
test.getLedgerSeq() +
test.getLCLSeq() +
test.getNetworkCfg().stateArchivalSettings().minPersistentTTL -
1;

Expand All @@ -546,7 +546,7 @@ TEST_CASE_VERSIONS("meta stream contains reasonable meta", "[ledgerclosemeta]")
{
closeLedgerOn(test.getApp(), i, 2, 1, 2016);
}
REQUIRE(!test.isEntryLive(archivedLk, test.getLedgerSeq()));
REQUIRE(!test.isEntryLive(archivedLk, test.getLCLSeq()));

// Restore archived entry
SorobanResources restoreResources;
Expand Down Expand Up @@ -605,7 +605,7 @@ TEST_CASE_VERSIONS("meta stream contains reasonable meta", "[ledgerclosemeta]")
createResources, 1000);

closeLedger(test.getApp(), {tx1, tx2, tx3, tx4, tx5});
targetSeq = 23;
targetSeq = 27;
}
else
{
Expand Down
52 changes: 26 additions & 26 deletions src/simulation/LoadGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ LoadGenerator::generateLoad(GeneratedLoadConfig cfg)
uint64_t sourceAccountId = getNextAvailableAccount(ledgerNum);

std::function<std::pair<LoadGenerator::TestAccountPtr,
TransactionTestFramePtr>()>
TransactionFrameBaseConstPtr>()>
generateTx;

switch (cfg.mode)
Expand Down Expand Up @@ -858,7 +858,7 @@ LoadGenerator::submitCreationTx(uint32_t nAccounts, uint32_t offset,
bool
LoadGenerator::submitTx(GeneratedLoadConfig const& cfg,
std::function<std::pair<LoadGenerator::TestAccountPtr,
TransactionTestFramePtr>()>
TransactionFrameBaseConstPtr>()>
generateTx)
{
auto [from, tx] = generateTx();
Expand Down Expand Up @@ -1010,7 +1010,7 @@ LoadGenerator::logProgress(std::chrono::nanoseconds submitTimer,
txm.report();
}

std::pair<LoadGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<LoadGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
LoadGenerator::creationTransaction(uint64_t startAccount, uint64_t numItems,
uint32_t ledgerNum)
{
Expand All @@ -1021,9 +1021,9 @@ LoadGenerator::creationTransaction(uint64_t startAccount, uint64_t numItems,
vector<Operation> creationOps = createAccounts(
startAccount, numItems, ledgerNum, !mInitialAccountsCreated);
mInitialAccountsCreated = true;
return std::make_pair(sourceAcc, createTransactionTestFramePtr(
sourceAcc, creationOps,
LoadGenMode::CREATE, std::nullopt));
return std::make_pair(
sourceAcc, createTransactionFrame(sourceAcc, creationOps,
LoadGenMode::CREATE, std::nullopt));
}

void
Expand Down Expand Up @@ -1131,7 +1131,7 @@ LoadGenerator::findAccount(uint64_t accountId, uint32_t ledgerNum)
return newAccountPtr;
}

std::pair<LoadGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<LoadGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
LoadGenerator::paymentTransaction(uint32_t numAccounts, uint32_t offset,
uint32_t ledgerNum, uint64_t sourceAccount,
uint32_t opCount,
Expand All @@ -1148,12 +1148,12 @@ LoadGenerator::paymentTransaction(uint32_t numAccounts, uint32_t offset,
paymentOps.emplace_back(txtest::payment(to->getPublicKey(), amount));
}

return std::make_pair(
from, createTransactionTestFramePtr(from, paymentOps, LoadGenMode::PAY,
maxGeneratedFeeRate));
return std::make_pair(from, createTransactionFrame(from, paymentOps,
LoadGenMode::PAY,
maxGeneratedFeeRate));
}

std::pair<LoadGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<LoadGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
LoadGenerator::manageOfferTransaction(
uint32_t ledgerNum, uint64_t accountId, uint32_t opCount,
std::optional<uint32_t> maxGeneratedFeeRate)
Expand All @@ -1170,7 +1170,7 @@ LoadGenerator::manageOfferTransaction(
Price{rand_uniform<int32_t>(1, 100), rand_uniform<int32_t>(1, 100)},
100));
}
return std::make_pair(account, createTransactionTestFramePtr(
return std::make_pair(account, createTransactionFrame(
account, ops, LoadGenMode::MIXED_CLASSIC,
maxGeneratedFeeRate));
}
Expand Down Expand Up @@ -1204,7 +1204,7 @@ increaseOpSize(Operation& op, uint32_t increaseUpToBytes)
op.body.invokeHostFunctionOp().auth = {auth};
}

std::pair<LoadGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<LoadGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
LoadGenerator::createUploadWasmTransaction(uint32_t ledgerNum,
uint64_t accountId,
GeneratedLoadConfig const& cfg)
Expand Down Expand Up @@ -1247,7 +1247,7 @@ LoadGenerator::createUploadWasmTransaction(uint32_t ledgerNum,
return std::make_pair(account, tx);
}

std::pair<LoadGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<LoadGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
LoadGenerator::createContractTransaction(uint32_t ledgerNum, uint64_t accountId,
GeneratedLoadConfig const& cfg)
{
Expand Down Expand Up @@ -1275,7 +1275,7 @@ LoadGenerator::createContractTransaction(uint32_t ledgerNum, uint64_t accountId,
return std::make_pair(account, tx);
}

std::pair<LoadGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<LoadGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
LoadGenerator::invokeSorobanLoadTransaction(uint32_t ledgerNum,
uint64_t accountId,
GeneratedLoadConfig const& cfg)
Expand Down Expand Up @@ -1649,7 +1649,7 @@ LoadGenerator::getConfigUpgradeSetFromLoadConfig(
return xdr::xdr_to_opaque(upgradeSet);
}

std::pair<LoadGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<LoadGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
LoadGenerator::invokeSorobanCreateUpgradeTransaction(
uint32_t ledgerNum, uint64_t accountId, GeneratedLoadConfig const& cfg)
{
Expand Down Expand Up @@ -1705,7 +1705,7 @@ LoadGenerator::invokeSorobanCreateUpgradeTransaction(
return std::make_pair(account, tx);
}

std::pair<LoadGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<LoadGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
LoadGenerator::sorobanRandomWasmTransaction(uint32_t ledgerNum,
uint64_t accountId,
uint32_t inclusionFee)
Expand Down Expand Up @@ -1773,7 +1773,7 @@ LoadGenerator::sorobanRandomUploadResources()
return {resources, wasmSize};
}

std::pair<LoadGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<LoadGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
LoadGenerator::pretendTransaction(uint32_t numAccounts, uint32_t offset,
uint32_t ledgerNum, uint64_t sourceAccount,
uint32_t opCount,
Expand All @@ -1799,12 +1799,12 @@ LoadGenerator::pretendTransaction(uint32_t numAccounts, uint32_t offset,
}
ops.push_back(txtest::setOptions(args));
}
return std::make_pair(
acc, createTransactionTestFramePtr(acc, ops, LoadGenMode::PRETEND,
maxGeneratedFeeRate));
return std::make_pair(acc,
createTransactionFrame(acc, ops, LoadGenMode::PRETEND,
maxGeneratedFeeRate));
}

std::pair<LoadGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<LoadGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
LoadGenerator::createMixedClassicSorobanTransaction(
uint32_t ledgerNum, uint64_t sourceAccountId,
GeneratedLoadConfig const& cfg)
Expand Down Expand Up @@ -1843,7 +1843,7 @@ LoadGenerator::createMixedClassicSorobanTransaction(
}

void
LoadGenerator::maybeHandleFailedTx(TransactionTestFramePtr tx,
LoadGenerator::maybeHandleFailedTx(TransactionFrameBaseConstPtr tx,
TestAccountPtr sourceAccount,
TransactionQueue::AddResultCode status,
TransactionResultCode code)
Expand Down Expand Up @@ -2119,8 +2119,8 @@ LoadGenerator::TxMetrics::report()
mSorobanCreateUpgradeTxs.one_minute_rate());
}

TransactionTestFramePtr
LoadGenerator::createTransactionTestFramePtr(
TransactionFrameBaseConstPtr
LoadGenerator::createTransactionFrame(
TestAccountPtr from, std::vector<Operation> ops, LoadGenMode mode,
std::optional<uint32_t> maxGeneratedFeeRate)
{
Expand All @@ -2144,7 +2144,7 @@ LoadGenerator::createTransactionTestFramePtr(
}

TransactionQueue::AddResultCode
LoadGenerator::execute(TransactionTestFramePtr& txf, LoadGenMode mode,
LoadGenerator::execute(TransactionFrameBasePtr txf, LoadGenMode mode,
TransactionResultCode& code)
{
TxMetrics txm(mApp.getMetrics());
Expand Down
34 changes: 17 additions & 17 deletions src/simulation/LoadGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,13 @@ class LoadGenerator
// re-submit. Any other code points to a loadgen misconfigurations, as
// transactions must have valid (pre-generated) source accounts,
// sufficient balances etc.
TransactionQueue::AddResultCode execute(TransactionTestFramePtr& txf,
TransactionQueue::AddResultCode execute(TransactionFrameBasePtr txf,
LoadGenMode mode,
TransactionResultCode& code);
TransactionTestFramePtr
createTransactionTestFramePtr(TestAccountPtr from,
std::vector<Operation> ops, LoadGenMode mode,
std::optional<uint32_t> maxGeneratedFeeRate);
TransactionFrameBaseConstPtr
createTransactionFrame(TestAccountPtr from, std::vector<Operation> ops,
LoadGenMode mode,
std::optional<uint32_t> maxGeneratedFeeRate);

static const uint32_t STEP_MSECS;
static const uint32_t TX_SUBMIT_MAX_TRIES;
Expand Down Expand Up @@ -386,51 +386,51 @@ class LoadGenerator
uint64_t sourceAccountId);
TestAccountPtr findAccount(uint64_t accountId, uint32_t ledgerNum);

std::pair<TestAccountPtr, TransactionTestFramePtr>
std::pair<TestAccountPtr, TransactionFrameBaseConstPtr>
paymentTransaction(uint32_t numAccounts, uint32_t offset,
uint32_t ledgerNum, uint64_t sourceAccount,
uint32_t opCount,
std::optional<uint32_t> maxGeneratedFeeRate);
std::pair<TestAccountPtr, TransactionTestFramePtr>
std::pair<TestAccountPtr, TransactionFrameBaseConstPtr>
pretendTransaction(uint32_t numAccounts, uint32_t offset,
uint32_t ledgerNum, uint64_t sourceAccount,
uint32_t opCount,
std::optional<uint32_t> maxGeneratedFeeRate);
std::pair<LoadGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<LoadGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
manageOfferTransaction(uint32_t ledgerNum, uint64_t accountId,
uint32_t opCount,
std::optional<uint32_t> maxGeneratedFeeRate);
std::pair<LoadGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<LoadGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
createUploadWasmTransaction(uint32_t ledgerNum, uint64_t accountId,
GeneratedLoadConfig const& cfg);
std::pair<LoadGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<LoadGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
createContractTransaction(uint32_t ledgerNum, uint64_t accountId,
GeneratedLoadConfig const& cfg);
std::pair<LoadGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<LoadGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
invokeSorobanLoadTransaction(uint32_t ledgerNum, uint64_t accountId,
GeneratedLoadConfig const& cfg);
std::pair<LoadGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<LoadGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
invokeSorobanCreateUpgradeTransaction(uint32_t ledgerNum,
uint64_t accountId,
GeneratedLoadConfig const& cfg);
std::pair<LoadGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<LoadGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
sorobanRandomWasmTransaction(uint32_t ledgerNum, uint64_t accountId,
uint32_t inclusionFee);

// Create a transaction in MIXED_CLASSIC_SOROBAN mode
std::pair<LoadGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<LoadGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
createMixedClassicSorobanTransaction(uint32_t ledgerNum,
uint64_t sourceAccountId,
GeneratedLoadConfig const& cfg);
// Samples a random wasm size from the `LOADGEN_WASM_BYTES_FOR_TESTING`
// distribution. Returns a pair containing the appropriate resources for a
// wasm of that size as well as the size itself.
std::pair<SorobanResources, uint32_t> sorobanRandomUploadResources();
void maybeHandleFailedTx(TransactionTestFramePtr tx,
void maybeHandleFailedTx(TransactionFrameBaseConstPtr tx,
TestAccountPtr sourceAccount,
TransactionQueue::AddResultCode status,
TransactionResultCode code);
std::pair<TestAccountPtr, TransactionTestFramePtr>
std::pair<TestAccountPtr, TransactionFrameBaseConstPtr>
creationTransaction(uint64_t startAccount, uint64_t numItems,
uint32_t ledgerNum);
void logProgress(std::chrono::nanoseconds submitTimer,
Expand All @@ -440,7 +440,7 @@ class LoadGenerator
uint32_t ledgerNum);
bool submitTx(GeneratedLoadConfig const& cfg,
std::function<std::pair<LoadGenerator::TestAccountPtr,
TransactionTestFramePtr>()>
TransactionFrameBaseConstPtr>()>
generateTx);
void waitTillComplete(GeneratedLoadConfig cfg);
void waitTillCompleteWithoutChecks();
Expand Down
15 changes: 9 additions & 6 deletions src/test/TxTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,12 +906,9 @@ sorobanResourceFee(Application& app, SorobanResources const& resources,
size_t txSize, uint32_t eventsSize)
{
releaseAssert(txSize <= INT32_MAX);
LedgerTxn ltx(app.getLedgerTxnRoot(),
/* shouldUpdateLastModified */ true,
TransactionMode::READ_ONLY_WITHOUT_SQL_TXN);
auto feePair = TransactionFrame::computeSorobanResourceFee(
ltx.loadHeader().current().ledgerVersion, resources,
static_cast<uint32>(txSize), eventsSize,
app.getLedgerManager().getLastClosedLedgerHeader().header.ledgerVersion,
resources, static_cast<uint32>(txSize), eventsSize,
app.getLedgerManager().getSorobanNetworkConfig(), app.getConfig());
return feePair.non_refundable_fee + feePair.refundable_fee;
}
Expand Down Expand Up @@ -1926,5 +1923,11 @@ getLclProtocolVersion(Application& app)
return lcl.header.ledgerVersion;
}

bool
isSuccessResult(TransactionResult const& res)
{
return res.result.code() == txSUCCESS;
}
}

} // namespace txtest
} // namespace stellar
2 changes: 2 additions & 0 deletions src/test/TxTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,5 +333,7 @@ int64_t getBalance(Application& app, AccountID const& accountID,

uint32_t getLclProtocolVersion(Application& app);

bool isSuccessResult(TransactionResult const& res);

} // end txtest namespace
}
Loading
Loading