Skip to content

Commit

Permalink
soroban upgrades for simulation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBrady committed Aug 12, 2024
1 parent 55ec348 commit ebb09ed
Show file tree
Hide file tree
Showing 8 changed files with 363 additions and 114 deletions.
4 changes: 2 additions & 2 deletions src/herder/Upgrades.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class ConfigUpgradeSetFrame
static ConfigUpgradeSetFrameConstPtr
makeFromKey(AbstractLedgerTxn& ltx, ConfigUpgradeSetKey const& key);

static LedgerKey getLedgerKey(ConfigUpgradeSetKey const& upgradeKey);

ConfigUpgradeSet const& toXDR() const;

ConfigUpgradeSetKey const& getKey() const;
Expand All @@ -182,8 +184,6 @@ class ConfigUpgradeSetFrame
ConfigUpgradeSetKey const& key,
uint32_t ledgerVersion);

static LedgerKey getLedgerKey(ConfigUpgradeSetKey const& upgradeKey);

bool isValidXDR(ConfigUpgradeSet const& upgradeSetXDR,
ConfigUpgradeSetKey const& key) const;

Expand Down
103 changes: 51 additions & 52 deletions src/herder/test/HerderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3213,32 +3213,31 @@ TEST_CASE("soroban txs each parameter surge priced", "[soroban][herder]")
});
simulation->startAllNodes();
auto nodes = simulation->getNodes();
for (auto& node : nodes)
{
overrideSorobanNetworkConfigForTest(*node);
modifySorobanNetworkConfig(
*node, [&tweakSorobanConfig](SorobanNetworkConfig& cfg) {
auto mx = std::numeric_limits<uint32_t>::max();
// Set all Soroban resources to maximum initially; each
// section will adjust the config as desired
cfg.mLedgerMaxTxCount = mx;
cfg.mLedgerMaxInstructions = mx;
cfg.mLedgerMaxTransactionsSizeBytes = mx;
cfg.mLedgerMaxReadLedgerEntries = mx;
cfg.mLedgerMaxReadBytes = mx;
cfg.mLedgerMaxWriteLedgerEntries = mx;
cfg.mLedgerMaxWriteBytes = mx;
tweakSorobanConfig(cfg);
});
}
upgradeSorobanNetworkConfig(
[&tweakSorobanConfig](SorobanNetworkConfig& cfg) {
auto mx = std::numeric_limits<uint32_t>::max();
// Set all Soroban resources to maximum initially; each
// section will adjust the config as desired
cfg.mLedgerMaxTxCount = mx;
cfg.mLedgerMaxInstructions = mx;
cfg.mLedgerMaxTransactionsSizeBytes = mx;
cfg.mLedgerMaxReadLedgerEntries = mx;
cfg.mLedgerMaxReadBytes = mx;
cfg.mLedgerMaxWriteLedgerEntries = mx;
cfg.mLedgerMaxWriteBytes = mx;
tweakSorobanConfig(cfg);
},
simulation);
auto& loadGen = nodes[0]->getLoadGenerator();

// Generate some accounts
auto& loadGenDone = nodes[0]->getMetrics().NewMeter(
{"loadgen", "run", "complete"}, "run");
auto currLoadGenCount = loadGenDone.count();
loadGen.generateLoad(GeneratedLoadConfig::createAccountsLoad(
numAccounts, baseTxRate));
auto creationConfig = GeneratedLoadConfig::createAccountsLoad(
numAccounts, baseTxRate);
creationConfig.offset = 1;
loadGen.generateLoad(creationConfig);
simulation->crankUntil(
[&]() { return loadGenDone.count() > currLoadGenCount; },
10 * Herder::EXP_LEDGER_TIMESPAN_SECONDS, false);
Expand Down Expand Up @@ -3435,6 +3434,7 @@ TEST_CASE("accept soroban txs after network upgrade", "[soroban][herder]")
15);
scheduledUpgrades.mProtocolVersion =
static_cast<uint32_t>(SOROBAN_PROTOCOL_VERSION);
// TODO maybe use loadgen for these upgrades
for (auto const& app : nodes)
{
app->getHerder().setUpgrades(scheduledUpgrades);
Expand Down Expand Up @@ -3513,22 +3513,23 @@ TEST_CASE("overlay parallel processing")
uint32_t desiredTxRate = 1;
uint32_t ledgerWideLimit = static_cast<uint32>(
desiredTxRate * Herder::EXP_LEDGER_TIMESPAN_SECONDS.count() * 2);
uint32_t const numAccounts = 100;
for (auto& node : nodes)
{
overrideSorobanNetworkConfigForTest(*node);
modifySorobanNetworkConfig(*node, [&](SorobanNetworkConfig& cfg) {
upgradeSorobanNetworkConfig(
[&](SorobanNetworkConfig& cfg) {
setSorobanNetworkConfigForTest(cfg);
cfg.mLedgerMaxTxCount = ledgerWideLimit;
});
}
},
simulation);
auto& loadGen = nodes[0]->getLoadGenerator();

// Generate some accounts
auto& loadGenDone =
nodes[0]->getMetrics().NewMeter({"loadgen", "run", "complete"}, "run");
auto currLoadGenCount = loadGenDone.count();
loadGen.generateLoad(
GeneratedLoadConfig::createAccountsLoad(numAccounts, desiredTxRate));
uint32_t const numAccounts = 100;
auto creationConfig =
GeneratedLoadConfig::createAccountsLoad(numAccounts, desiredTxRate);
creationConfig.offset = 1;
loadGen.generateLoad(creationConfig);
simulation->crankUntil(
[&]() { return loadGenDone.count() > currLoadGenCount; },
10 * Herder::EXP_LEDGER_TIMESPAN_SECONDS, false);
Expand Down Expand Up @@ -3583,13 +3584,13 @@ TEST_CASE("soroban txs accepted by the network",
uint32_t ledgerWideLimit = static_cast<uint32>(
desiredTxRate * Herder::EXP_LEDGER_TIMESPAN_SECONDS.count() * 2);
uint32_t const numAccounts = 100;
for (auto& node : nodes)
{
overrideSorobanNetworkConfigForTest(*node);
modifySorobanNetworkConfig(*node, [&](SorobanNetworkConfig& cfg) {
upgradeSorobanNetworkConfig(
[&](SorobanNetworkConfig& cfg) {
setSorobanNetworkConfigForTest(cfg);
cfg.mLedgerMaxTxCount = ledgerWideLimit;
});
}
},
simulation);

auto& loadGen = nodes[0]->getLoadGenerator();
auto& txsSucceeded =
nodes[0]->getMetrics().NewCounter({"ledger", "apply", "success"});
Expand All @@ -3604,8 +3605,10 @@ TEST_CASE("soroban txs accepted by the network",
auto& loadGenDone =
nodes[0]->getMetrics().NewMeter({"loadgen", "run", "complete"}, "run");
auto currLoadGenCount = loadGenDone.count();
loadGen.generateLoad(
GeneratedLoadConfig::createAccountsLoad(numAccounts, desiredTxRate));
auto creationConfig =
GeneratedLoadConfig::createAccountsLoad(numAccounts, desiredTxRate);
creationConfig.offset = 1;
loadGen.generateLoad(creationConfig);
simulation->crankUntil(
[&]() { return loadGenDone.count() > currLoadGenCount; },
10 * Herder::EXP_LEDGER_TIMESPAN_SECONDS, false);
Expand Down Expand Up @@ -3864,12 +3867,11 @@ herderExternalizesValuesWithProtocol(uint32_t version)

if (protocolVersionStartsFrom(version, SOROBAN_PROTOCOL_VERSION))
{
for (auto const& node : simulation->getNodes())
{
modifySorobanNetworkConfig(*node, [&](SorobanNetworkConfig& cfg) {
upgradeSorobanNetworkConfig(
[&](SorobanNetworkConfig& cfg) {
cfg.mStateArchivalSettings.bucketListWindowSamplePeriod = 1;
});
}
},
simulation);
}
simulation->startAllNodes();

Expand Down Expand Up @@ -4660,20 +4662,17 @@ TEST_CASE("do not flood too many soroban transactions",
simulation->addNode(mainKey, qset);
simulation->addNode(otherKey, qset);

auto updateSorobanConfig = [](Application& app) {
overrideSorobanNetworkConfigForTest(app);
modifySorobanNetworkConfig(app, [](SorobanNetworkConfig& cfg) {
auto app = simulation->getNode(mainKey.getPublicKey());

upgradeSorobanNetworkConfig(
[](SorobanNetworkConfig& cfg) {
setSorobanNetworkConfigForTest(cfg);
// Update read entries to allow flooding at most 1 tx per broadcast
// interval.
cfg.mLedgerMaxReadLedgerEntries = 40;
cfg.mLedgerMaxReadBytes = cfg.mTxMaxReadBytes;
});
};

auto app = simulation->getNode(mainKey.getPublicKey());

updateSorobanConfig(*app);
updateSorobanConfig(*simulation->getNode(otherKey.getPublicKey()));
},
simulation);

simulation->addPendingConnection(mainKey.getPublicKey(),
otherKey.getPublicKey());
Expand Down
27 changes: 14 additions & 13 deletions src/overlay/test/OverlayTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2141,18 +2141,17 @@ TEST_CASE("overlay flow control", "[overlay][flowcontrol]")
simulation->addPendingConnection(vNode2NodeID, vNode3NodeID);
simulation->addPendingConnection(vNode3NodeID, vNode1NodeID);

for (auto& node2 : simulation->getNodes())
simulation->startAllNodes();
if (appProtocolVersionStartsFrom(*simulation->getNodes()[0],
SOROBAN_PROTOCOL_VERSION))
{
if (appProtocolVersionStartsFrom(*node2, SOROBAN_PROTOCOL_VERSION))
{
modifySorobanNetworkConfig(
*node2, [](SorobanNetworkConfig& cfg) {
cfg.mTxMaxSizeBytes =
MinimumSorobanNetworkConfig::TX_MAX_SIZE_BYTES;
});
}
upgradeSorobanNetworkConfig(
[](SorobanNetworkConfig& cfg) {
cfg.mTxMaxSizeBytes =
MinimumSorobanNetworkConfig::TX_MAX_SIZE_BYTES;
},
simulation);
}
simulation->startAllNodes();
};

SECTION("enabled")
Expand All @@ -2165,9 +2164,11 @@ TEST_CASE("overlay flow control", "[overlay][flowcontrol]")
// Generate a bit of load to flood transactions, make sure nodes can
// close ledgers properly
auto& loadGen = node->getLoadGenerator();
loadGen.generateLoad(
GeneratedLoadConfig::createAccountsLoad(/* nAccounts */ 150,
/* txRate */ 1));
auto createAccountCfg = GeneratedLoadConfig::createAccountsLoad(
/* nAccounts */ 150,
/* txRate */ 1);
createAccountCfg.offset = 1;
loadGen.generateLoad(createAccountCfg);

auto& loadGenDone =
node->getMetrics().NewMeter({"loadgen", "run", "complete"}, "run");
Expand Down
92 changes: 90 additions & 2 deletions src/simulation/LoadGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0

#include "simulation/LoadGenerator.h"
#include "database/Database.h"
#include "herder/Herder.h"
#include "ledger/LedgerManager.h"
#include "ledger/LedgerTxn.h"
Expand All @@ -23,8 +24,6 @@
#include "util/numeric.h"
#include "util/types.h"

#include "database/Database.h"

#include "xdrpp/marshal.h"

#include "medida/meter.h"
Expand Down Expand Up @@ -1565,12 +1564,50 @@ LoadGenerator::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 Down Expand Up @@ -2202,6 +2239,57 @@ LoadGenerator::execute(TransactionTestFramePtr& txf, LoadGenMode mode,
return addResult.code;
}

void
GeneratedLoadConfig::copySorobanNetworkConfigToUpgradeConfig(
SorobanNetworkConfig const& cfg)
{
releaseAssert(mode == LoadGenMode::SOROBAN_CREATE_UPGRADE);
auto& upgradeCfg = getMutSorobanUpgradeConfig();

upgradeCfg.maxContractSizeBytes = cfg.maxContractSizeBytes();
upgradeCfg.maxContractDataKeySizeBytes = cfg.maxContractDataKeySizeBytes();
upgradeCfg.maxContractDataEntrySizeBytes =
cfg.maxContractDataEntrySizeBytes();

upgradeCfg.ledgerMaxInstructions = cfg.ledgerMaxInstructions();
upgradeCfg.txMaxInstructions = cfg.txMaxInstructions();
upgradeCfg.txMemoryLimit = cfg.txMemoryLimit();

upgradeCfg.ledgerMaxReadLedgerEntries = cfg.ledgerMaxReadLedgerEntries();
upgradeCfg.ledgerMaxReadBytes = cfg.ledgerMaxReadBytes();
upgradeCfg.ledgerMaxWriteLedgerEntries = cfg.ledgerMaxWriteLedgerEntries();
upgradeCfg.ledgerMaxWriteBytes = cfg.ledgerMaxWriteBytes();
upgradeCfg.ledgerMaxTxCount = cfg.ledgerMaxTxCount();
upgradeCfg.txMaxReadLedgerEntries = cfg.txMaxReadLedgerEntries();
upgradeCfg.txMaxReadBytes = cfg.txMaxReadBytes();
upgradeCfg.txMaxWriteLedgerEntries = cfg.txMaxWriteLedgerEntries();
upgradeCfg.txMaxWriteBytes = cfg.txMaxWriteBytes();

upgradeCfg.txMaxContractEventsSizeBytes =
cfg.txMaxContractEventsSizeBytes();

upgradeCfg.ledgerMaxTransactionsSizeBytes =
cfg.ledgerMaxTransactionSizesBytes();
upgradeCfg.txMaxSizeBytes = cfg.txMaxSizeBytes();

upgradeCfg.maxEntryTTL = cfg.stateArchivalSettings().maxEntryTTL;
upgradeCfg.minTemporaryTTL = cfg.stateArchivalSettings().minTemporaryTTL;
upgradeCfg.minPersistentTTL = cfg.stateArchivalSettings().minPersistentTTL;
upgradeCfg.persistentRentRateDenominator =
cfg.stateArchivalSettings().persistentRentRateDenominator;
upgradeCfg.tempRentRateDenominator =
cfg.stateArchivalSettings().tempRentRateDenominator;
upgradeCfg.maxEntriesToArchive =
cfg.stateArchivalSettings().maxEntriesToArchive;
upgradeCfg.bucketListSizeWindowSampleSize =
cfg.stateArchivalSettings().bucketListSizeWindowSampleSize;
upgradeCfg.bucketListWindowSamplePeriod =
cfg.stateArchivalSettings().bucketListWindowSamplePeriod;
upgradeCfg.evictionScanSize = cfg.stateArchivalSettings().evictionScanSize;
upgradeCfg.startingEvictionScanLevel =
cfg.stateArchivalSettings().startingEvictionScanLevel;
}

GeneratedLoadConfig
GeneratedLoadConfig::createAccountsLoad(uint32_t nAccounts, uint32_t txRate)
{
Expand Down
10 changes: 10 additions & 0 deletions src/simulation/LoadGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ struct GeneratedLoadConfig
uint32_t txMaxSizeBytes{};

// State Archival Settings
uint32_t maxEntryTTL{};
uint32_t minTemporaryTTL{};
uint32_t minPersistentTTL{};
int64_t persistentRentRateDenominator{};
int64_t tempRentRateDenominator{};
uint32_t maxEntriesToArchive{};
uint32_t bucketListSizeWindowSampleSize{};
uint32_t bucketListWindowSamplePeriod{};
uint32_t evictionScanSize{};
uint32_t startingEvictionScanLevel{};
};
Expand All @@ -107,6 +114,9 @@ struct GeneratedLoadConfig
double sorobanInvokeWeight = 0;
};

void
copySorobanNetworkConfigToUpgradeConfig(SorobanNetworkConfig const& cfg);

static GeneratedLoadConfig createAccountsLoad(uint32_t nAccounts,
uint32_t txRate);

Expand Down
Loading

0 comments on commit ebb09ed

Please sign in to comment.