Skip to content

Commit

Permalink
Fix timing out 'generate soroban load' by special casing two-part upg…
Browse files Browse the repository at this point in the history
…rade sequence retries
  • Loading branch information
ThomasBrady committed Nov 26, 2024
1 parent aa6ab6c commit 263942e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
38 changes: 31 additions & 7 deletions src/simulation/LoadGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,19 @@ LoadGenerator::generateLoad(GeneratedLoadConfig cfg)
{
--cfg.nTxs;
}
else if (cfg.mode == LoadGenMode::SOROBAN_UPGRADE_SETUP &&
cfg.useRootAccountForSorobanUpgradeFlow)
{
// If submission failed during SOROBAN_UPGRADE_SETUP, the
// contract instance key must be regenerated
// so we reset the nInstances to 1 to prevent
// subtracting past zero.
auto& sorobanCfg = cfg.getMutSorobanConfig();
if (sorobanCfg.nInstances == 0)
{
sorobanCfg.nInstances = 1;
}
}
else if (mFailed)
{
break;
Expand Down Expand Up @@ -864,11 +877,9 @@ LoadGenerator::submitTx(GeneratedLoadConfig const& cfg,
TransactionResultCode code;
TransactionQueue::AddResultCode status;
uint32_t numTries = 0;

while ((status = execute(tx, cfg.mode, code)) !=
TransactionQueue::AddResultCode::ADD_STATUS_PENDING)
{

if (cfg.skipLowFeeTxs &&
(status ==
TransactionQueue::AddResultCode::ADD_STATUS_TRY_AGAIN_LATER ||
Expand All @@ -882,6 +893,24 @@ LoadGenerator::submitTx(GeneratedLoadConfig const& cfg,
tx->getInclusionFee());
return false;
}
// If we are using the root account to perform a soroban upgrade flow,
// retry the transaction.
if (cfg.mode == LoadGenMode::SOROBAN_UPGRADE_SETUP &&
cfg.useRootAccountForSorobanUpgradeFlow)
{
if (status == TransactionQueue::AddResultCode::
ADD_STATUS_TRY_AGAIN_LATER ||
(status == TransactionQueue::AddResultCode::ADD_STATUS_ERROR &&
code == txBAD_SEQ))
{
// The next attempt will regenerate a contract instance key.
mContractInstanceKeys.clear();
maybeHandleFailedTx(tx, from, status, code); // Update seq num
return false;
}
mFailed = true;
return false;
}
if (++numTries >= TX_SUBMIT_MAX_TRIES ||
status != TransactionQueue::AddResultCode::ADD_STATUS_ERROR)
{
Expand Down Expand Up @@ -1594,7 +1623,6 @@ GeneratedLoadConfig::createSorobanUpgradeSetupLoad()
cfg.nAccounts = 1;
cfg.getMutSorobanConfig().nInstances = 1;
cfg.txRate = 1;
cfg.useRootAccountForSorobanUpgradeFlow = true;
return cfg;
}

Expand All @@ -1604,10 +1632,6 @@ GeneratedLoadConfig::txLoad(LoadGenMode mode, uint32_t nAccounts, uint32_t nTxs,
std::optional<uint32_t> maxFee)
{
GeneratedLoadConfig cfg;
if (mode == LoadGenMode::SOROBAN_CREATE_UPGRADE)
{
cfg.useRootAccountForSorobanUpgradeFlow = true;
}
cfg.mode = mode;
cfg.nAccounts = nAccounts;
cfg.nTxs = nTxs;
Expand Down
5 changes: 3 additions & 2 deletions src/test/TestUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,22 @@ upgradeSorobanNetworkConfig(std::function<void(SorobanNetworkConfig&)> modifyFn,
auto nodes = simulation->getNodes();
auto& lg = nodes[0]->getLoadGenerator();
auto& app = *nodes[0];

auto& complete =
app.getMetrics().NewMeter({"loadgen", "run", "complete"}, "run");

// Create upload wasm transaction.
auto createUploadCfg = GeneratedLoadConfig::createSorobanUpgradeSetupLoad();
createUploadCfg.useRootAccountForSorobanUpgradeFlow = true;
lg.generateLoad(createUploadCfg);
auto completeCount = complete.count();
simulation->crankUntil(
[&]() { return complete.count() == completeCount + 1; },
[&]() { return complete.count() >= completeCount + 1; },
300 * Herder::EXP_LEDGER_TIMESPAN_SECONDS, false);

// Create upgrade transaction.
auto createUpgradeLoadGenConfig = GeneratedLoadConfig::txLoad(
LoadGenMode::SOROBAN_CREATE_UPGRADE, 1, 1, 1);
createUpgradeLoadGenConfig.useRootAccountForSorobanUpgradeFlow = true;
// Get current network config.
auto cfg = nodes[0]->getLedgerManager().getSorobanNetworkConfig();
modifyFn(cfg);
Expand Down

0 comments on commit 263942e

Please sign in to comment.