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

Apply time benchmarking #4402

Merged
merged 6 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Rebase fixes
  • Loading branch information
sisuresh committed Sep 17, 2024
commit b6fbe26f53bd4220d37fec23ec48d8ec45479226
16 changes: 10 additions & 6 deletions src/simulation/LoadGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,13 @@ LoadGenerator::start(GeneratedLoadConfig& cfg)
}

ConfigUpgradeSetKey
LoadGenerator::getConfigUpgradeSetKey(SorobanUpgradeConfig const& upgradeCfg,
Hash const& contractId) const
LoadGenerator::getConfigUpgradeSetKey(
SorobanUpgradeConfig const& upgradeCfg) const
{
auto testingKeys = getContractInstanceKeysForTesting();
releaseAssert(testingKeys.size() == 1);
auto contractId = testingKeys.begin()->contractData().contract.contractId();

return mTxGenerator.getConfigUpgradeSetKey(upgradeCfg, contractId);
}

Expand Down Expand Up @@ -1011,11 +1015,11 @@ LoadGenerator::creationTransaction(uint64_t startAccount, uint64_t numItems,
}
mInitialAccountsCreated = true;
return std::make_pair(sourceAcc,
mTxGenerator.createTransactionTestFramePtr(
mTxGenerator.createTransactionFramePtr(
sourceAcc, creationOps, false, std::nullopt));
}

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

std::pair<TxGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<TxGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
LoadGenerator::createUploadWasmTransaction(GeneratedLoadConfig const& cfg,
uint32_t ledgerNum,
uint64_t sourceAccountId)
Expand All @@ -1084,7 +1088,7 @@ LoadGenerator::createUploadWasmTransaction(GeneratedLoadConfig const& cfg,
cfg.maxGeneratedFeeRate);
}

std::pair<TxGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<TxGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
LoadGenerator::createInstanceTransaction(GeneratedLoadConfig const& cfg,
uint32_t ledgerNum,
uint64_t sourceAccountId)
Expand Down
7 changes: 3 additions & 4 deletions src/simulation/LoadGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ class LoadGenerator
void generateLoad(GeneratedLoadConfig cfg);

ConfigUpgradeSetKey
getConfigUpgradeSetKey(SorobanUpgradeConfig const& upgradeCfg,
Hash const& contractId) const;
getConfigUpgradeSetKey(SorobanUpgradeConfig const& upgradeCfg) const;

// Verify cached accounts are properly reflected in the database
// return any accounts that are inconsistent.
Expand Down Expand Up @@ -327,11 +326,11 @@ class LoadGenerator
uint64_t sourceAccountId,
GeneratedLoadConfig const& cfg);

std::pair<TxGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<TxGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
createUploadWasmTransaction(GeneratedLoadConfig const& cfg,
uint32_t ledgerNum, uint64_t sourceAccountId);

std::pair<TxGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<TxGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
createInstanceTransaction(GeneratedLoadConfig const& cfg,
uint32_t ledgerNum, uint64_t sourceAccountId);

Expand Down
98 changes: 68 additions & 30 deletions src/simulation/TxGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ TxGenerator::generateFee(std::optional<uint32_t> maxGeneratedFeeRate,
uint64_t
TxGenerator::bytesToRead(xdr::xvector<stellar::LedgerKey> const& keys)
{
LedgerTxn ltx(mApp.getLedgerTxnRoot());
LedgerSnapshot lsg(mApp);
uint64_t total = 0;
for (auto const& key : keys)
{
auto ltxe = ltx.loadWithoutRecord(key);
if (ltxe)
auto entry = lsg.load(key);
if (entry)
{
total += xdr::xdr_size(ltxe.current());
total += xdr::xdr_size(entry.current());
}
}
return total;
Expand All @@ -109,8 +109,8 @@ TxGenerator::bytesToRead(xdr::xvector<stellar::LedgerKey> const& keys)
bool
TxGenerator::loadAccount(TestAccount& account)
{
LedgerTxn ltx(mApp.getLedgerTxnRoot());
auto entry = stellar::loadAccount(ltx, account.getPublicKey());
LedgerSnapshot lsg(mApp);
auto const entry = lsg.getAccount(account.getPublicKey());
if (!entry)
{
return false;
Expand Down Expand Up @@ -197,8 +197,8 @@ TxGenerator::createAccounts(uint64_t start, uint64_t count, uint32_t ledgerNum,
return ops;
}

TransactionTestFramePtr
TxGenerator::createTransactionTestFramePtr(
TransactionFrameBasePtr
TxGenerator::createTransactionFramePtr(
TxGenerator::TestAccountPtr from, std::vector<Operation> ops, bool pretend,
std::optional<uint32_t> maxGeneratedFeeRate)
{
Expand All @@ -220,7 +220,7 @@ TxGenerator::createTransactionTestFramePtr(
return txf;
}

std::pair<TxGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<TxGenerator::TestAccountPtr, TransactionFrameBasePtr>
TxGenerator::paymentTransaction(uint32_t numAccounts, uint32_t offset,
uint32_t ledgerNum, uint64_t sourceAccount,
uint32_t opCount,
Expand All @@ -238,11 +238,11 @@ TxGenerator::paymentTransaction(uint32_t numAccounts, uint32_t offset,
}

return std::make_pair(from,
createTransactionTestFramePtr(from, paymentOps, false,
maxGeneratedFeeRate));
createTransactionFramePtr(from, paymentOps, false,
maxGeneratedFeeRate));
}

std::pair<TxGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<TxGenerator::TestAccountPtr, TransactionFrameBasePtr>
TxGenerator::manageOfferTransaction(uint32_t ledgerNum, uint64_t accountId,
uint32_t opCount,
std::optional<uint32_t> maxGeneratedFeeRate)
Expand All @@ -259,12 +259,12 @@ TxGenerator::manageOfferTransaction(uint32_t ledgerNum, uint64_t accountId,
Price{rand_uniform<int32_t>(1, 100), rand_uniform<int32_t>(1, 100)},
100));
}
return std::make_pair(account,
createTransactionTestFramePtr(account, ops, false,
maxGeneratedFeeRate));
return std::make_pair(
account,
createTransactionFramePtr(account, ops, false, maxGeneratedFeeRate));
}

std::pair<TxGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<TxGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
TxGenerator::createUploadWasmTransaction(
uint32_t ledgerNum, uint64_t accountId, xdr::opaque_vec<> const& wasm,
LedgerKey const& contractCodeLedgerKey,
Expand Down Expand Up @@ -297,7 +297,7 @@ TxGenerator::createUploadWasmTransaction(
return std::make_pair(account, tx);
}

std::pair<TxGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<TxGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
TxGenerator::createContractTransaction(
uint32_t ledgerNum, uint64_t accountId, LedgerKey const& codeKey,
uint64_t contractOverheadBytes, uint256 const& salt,
Expand Down Expand Up @@ -349,7 +349,7 @@ increaseOpSize(Operation& op, uint32_t increaseUpToBytes)
op.body.invokeHostFunctionOp().auth = {auth};
}

std::pair<TxGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<TxGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
TxGenerator::invokeSorobanLoadTransaction(
uint32_t ledgerNum, uint64_t accountId, ContractInstance const& instance,
uint64_t contractOverheadBytes, std::optional<uint32_t> maxGeneratedFeeRate)
Expand Down Expand Up @@ -552,13 +552,13 @@ TxGenerator::getConfigUpgradeSetFromLoadConfig(
{
xdr::xvector<ConfigSettingEntry> updatedEntries;

LedgerTxn ltx(mApp.getLedgerTxnRoot());
LedgerSnapshot lsg(mApp);
for (uint32_t i = 0;
i < static_cast<uint32_t>(CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW); ++i)
{
auto entry =
ltx.load(configSettingKey(static_cast<ConfigSettingID>(i)));
auto& setting = entry.current().data.configSetting();
auto entry = lsg.load(configSettingKey(static_cast<ConfigSettingID>(i)))
.current();
auto& setting = entry.data.configSetting();
switch (static_cast<ConfigSettingID>(i))
{
case CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES:
Expand Down Expand Up @@ -678,12 +678,50 @@ TxGenerator::getConfigUpgradeSetFromLoadConfig(
case CONFIG_SETTING_STATE_ARCHIVAL:
{
auto& ses = setting.stateArchivalSettings();
if (upgradeCfg.maxEntryTTL > 0)
{
ses.maxEntryTTL = upgradeCfg.maxEntryTTL;
}

if (upgradeCfg.minTemporaryTTL > 0)
{
ses.minTemporaryTTL = upgradeCfg.minTemporaryTTL;
}

if (upgradeCfg.minPersistentTTL > 0)
{
ses.minPersistentTTL = upgradeCfg.minPersistentTTL;
}

if (upgradeCfg.persistentRentRateDenominator > 0)
{
ses.persistentRentRateDenominator =
upgradeCfg.persistentRentRateDenominator;
}

if (upgradeCfg.tempRentRateDenominator > 0)
{
ses.tempRentRateDenominator =
upgradeCfg.tempRentRateDenominator;
}

if (upgradeCfg.maxEntriesToArchive > 0)
{
ses.maxEntriesToArchive = upgradeCfg.maxEntriesToArchive;
}

if (upgradeCfg.bucketListSizeWindowSampleSize > 0)
{
ses.bucketListSizeWindowSampleSize =
upgradeCfg.bucketListSizeWindowSampleSize;
}

if (upgradeCfg.bucketListWindowSamplePeriod > 0)
{
ses.bucketListWindowSamplePeriod =
upgradeCfg.bucketListWindowSamplePeriod;
}

if (upgradeCfg.evictionScanSize > 0)
{
ses.evictionScanSize = upgradeCfg.evictionScanSize;
Expand All @@ -710,12 +748,12 @@ TxGenerator::getConfigUpgradeSetFromLoadConfig(

// These two definitely aren't changing, and including both will hit the
// contractDataEntrySizeBytes limit
if (entry.current().data.configSetting().configSettingID() !=
if (entry.data.configSetting().configSettingID() !=
CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS &&
entry.current().data.configSetting().configSettingID() !=
entry.data.configSetting().configSettingID() !=
CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES)
{
updatedEntries.emplace_back(entry.current().data.configSetting());
updatedEntries.emplace_back(entry.data.configSetting());
}
}

Expand All @@ -725,7 +763,7 @@ TxGenerator::getConfigUpgradeSetFromLoadConfig(
return xdr::xdr_to_opaque(upgradeSet);
}

std::pair<TxGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<TxGenerator::TestAccountPtr, TransactionFrameBasePtr>
TxGenerator::invokeSorobanCreateUpgradeTransaction(
uint32_t ledgerNum, uint64_t accountId, SCBytes const& upgradeBytes,
LedgerKey const& codeKey, LedgerKey const& instanceKey,
Expand Down Expand Up @@ -777,7 +815,7 @@ TxGenerator::invokeSorobanCreateUpgradeTransaction(
return std::make_pair(account, tx);
}

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

std::pair<TxGenerator::TestAccountPtr, TransactionTestFramePtr>
std::pair<TxGenerator::TestAccountPtr, TransactionFrameBaseConstPtr>
TxGenerator::pretendTransaction(uint32_t numAccounts, uint32_t offset,
uint32_t ledgerNum, uint64_t sourceAccount,
uint32_t opCount,
Expand All @@ -871,8 +909,8 @@ TxGenerator::pretendTransaction(uint32_t numAccounts, uint32_t offset,
}
ops.push_back(txtest::setOptions(args));
}
return std::make_pair(acc, createTransactionTestFramePtr(
acc, ops, true, maxGeneratedFeeRate));
return std::make_pair(
acc, createTransactionFramePtr(acc, ops, true, maxGeneratedFeeRate));
}

}
24 changes: 12 additions & 12 deletions src/simulation/TxGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,49 +76,49 @@ class TxGenerator
uint32_t ledgerNum,
bool initialAccounts);

TransactionTestFramePtr
createTransactionTestFramePtr(TestAccountPtr from,
std::vector<Operation> ops, bool pretend,
std::optional<uint32_t> maxGeneratedFeeRate);
TransactionFrameBaseConstPtr
createTransactionFramePtr(TestAccountPtr from, std::vector<Operation> ops,
bool pretend,
std::optional<uint32_t> maxGeneratedFeeRate);

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>
manageOfferTransaction(uint32_t ledgerNum, uint64_t accountId,
uint32_t opCount,
std::optional<uint32_t> maxGeneratedFeeRate);

std::pair<TestAccountPtr, TransactionTestFramePtr>
std::pair<TestAccountPtr, TransactionFrameBaseConstPtr>
createUploadWasmTransaction(uint32_t ledgerNum, uint64_t accountId,
xdr::opaque_vec<> const& wasm,
LedgerKey const& contractCodeLedgerKey,
std::optional<uint32_t> maxGeneratedFeeRate);
std::pair<TestAccountPtr, TransactionTestFramePtr>
std::pair<TestAccountPtr, TransactionFrameBaseConstPtr>
createContractTransaction(uint32_t ledgerNum, uint64_t accountId,
LedgerKey const& codeKey,
uint64_t contractOverheadBytes,
uint256 const& salt,
std::optional<uint32_t> maxGeneratedFeeRate);

std::pair<TestAccountPtr, TransactionTestFramePtr>
std::pair<TestAccountPtr, TransactionFrameBaseConstPtr>
invokeSorobanLoadTransaction(uint32_t ledgerNum, uint64_t accountId,
TxGenerator::ContractInstance const& instance,
uint64_t contractOverheadBytes,
std::optional<uint32_t> maxGeneratedFeeRate);
std::pair<TestAccountPtr, TransactionTestFramePtr>
std::pair<TestAccountPtr, TransactionFrameBaseConstPtr>
invokeSorobanCreateUpgradeTransaction(
uint32_t ledgerNum, uint64_t accountId, SCBytes const& upgradeBytes,
LedgerKey const& codeKey, LedgerKey const& instanceKey,
std::optional<uint32_t> maxGeneratedFeeRate);
std::pair<TestAccountPtr, TransactionTestFramePtr>
std::pair<TestAccountPtr, TransactionFrameBaseConstPtr>
sorobanRandomWasmTransaction(uint32_t ledgerNum, uint64_t accountId,
uint32_t inclusionFee);

std::pair<TestAccountPtr, TransactionTestFramePtr>
std::pair<TestAccountPtr, TransactionFrameBaseConstPtr>
pretendTransaction(uint32_t numAccounts, uint32_t offset,
uint32_t ledgerNum, uint64_t sourceAccount,
uint32_t opCount,
Expand Down
7 changes: 1 addition & 6 deletions src/simulation/test/LoadGeneratorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,8 @@ TEST_CASE("generate soroban load", "[loadgen][soroban]")
rand_uniform<int64_t>(INT64_MAX - 10'000, INT64_MAX);
upgradeCfg.startingEvictionScanLevel = rand_uniform<uint32_t>(4, 8);

auto testingKeys =
app.getLoadGenerator().getContractInstanceKeysForTesting();
REQUIRE(testingKeys.size() == 1);
auto contractId = testingKeys.begin()->contractData().contract.contractId();

auto upgradeSetKey = loadGen.getConfigUpgradeSetKey(
createUpgradeLoadGenConfig.getSorobanUpgradeConfig(), contractId);
createUpgradeLoadGenConfig.getSorobanUpgradeConfig());

numTxsBefore = getSuccessfulTxCount();
loadGen.generateLoad(createUpgradeLoadGenConfig);
Expand Down
3 changes: 2 additions & 1 deletion src/test/TestUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ upgradeSorobanNetworkConfig(std::function<void(SorobanNetworkConfig&)> modifyFn,
auto cfg = nodes[0]->getLedgerManager().getSorobanNetworkConfig();
modifyFn(cfg);
createUpgradeLoadGenConfig.copySorobanNetworkConfigToUpgradeConfig(cfg);
auto upgradeSetKey = lg.getConfigUpgradeSetKey(createUpgradeLoadGenConfig);
auto upgradeSetKey = lg.getConfigUpgradeSetKey(
createUpgradeLoadGenConfig.getSorobanUpgradeConfig());
lg.generateLoad(createUpgradeLoadGenConfig);
completeCount = complete.count();
simulation->crankUntil(
Expand Down