Skip to content

Commit

Permalink
Merge pull request #3885 from dmkozh/init_config
Browse files Browse the repository at this point in the history
Reduce the default resource limits to minimum.

Reviewed-by: sisuresh
  • Loading branch information
latobarita authored Aug 17, 2023
2 parents 0df2e0c + ef847f0 commit 2920f3e
Show file tree
Hide file tree
Showing 18 changed files with 991 additions and 1,010 deletions.
229 changes: 122 additions & 107 deletions src/herder/test/HerderTests.cpp

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions src/herder/test/TransactionQueueTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,10 +1096,15 @@ TEST_CASE("Soroban TransactionQueue limits",
VirtualClock clock;
auto cfg = getTestConfig();
cfg.TESTING_UPGRADE_MAX_TX_SET_SIZE = 4;
cfg.TESTING_LEDGER_MAX_SOROBAN_TX_COUNT = 4;

cfg.FLOOD_TX_PERIOD_MS = 100;
auto app = createTestApplication(clock, cfg);
overrideSorobanNetworkConfigForTest(*app);
modifySorobanNetworkConfig(*app, [](SorobanNetworkConfig& cfg) {
cfg.mLedgerMaxTxCount = 4;
// Restrict instructions to only allow 1 max instructions tx.
cfg.mLedgerMaxInstructions = cfg.mTxMaxInstructions;
});
auto const minBalance2 = app->getLedgerManager().getLastMinBalance(2);
auto root = TestAccount::createRoot(*app);
auto account1 = root.create("a1", minBalance2);
Expand All @@ -1121,8 +1126,7 @@ TEST_CASE("Soroban TransactionQueue limits",
int initialFee = 10'000'000;

auto resAdjusted = resources;
resAdjusted.instructions =
static_cast<uint32>(conf.ledgerMaxInstructions());
resAdjusted.instructions = static_cast<uint32>(conf.txMaxInstructions());

auto tx =
createUploadWasmTx(*app, root, initialFee, refundableFee, resAdjusted);
Expand Down Expand Up @@ -1192,7 +1196,7 @@ TEST_CASE("Soroban TransactionQueue limits",
{
auto tx2 = createUploadWasmTx(
*app, account2, initialFee * 2, refundableFee, resources,
std::nullopt, /* addInvalidOps */ 99);
std::nullopt, /* addInvalidOps */ 1);

REQUIRE(app->getHerder().recvTransaction(tx2, false) ==
TransactionQueue::AddResult::ADD_STATUS_ERROR);
Expand Down
10 changes: 8 additions & 2 deletions src/herder/test/TxSetTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,11 @@ TEST_CASE("generalized tx set XDR conversion", "[txset]")
static_cast<uint32_t>(GENERALIZED_TX_SET_PROTOCOL_VERSION);
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION =
static_cast<uint32_t>(GENERALIZED_TX_SET_PROTOCOL_VERSION);
cfg.TESTING_LEDGER_MAX_SOROBAN_TX_COUNT = 5;
Application::pointer app = createTestApplication(clock, cfg);
overrideSorobanNetworkConfigForTest(*app);
modifySorobanNetworkConfig(*app, [](SorobanNetworkConfig& sorobanCfg) {
sorobanCfg.mLedgerMaxTxCount = 5;
});
auto root = TestAccount::createRoot(*app);
int accountId = 0;
auto createTxs = [&](int cnt, int fee, bool isSoroban = false) {
Expand Down Expand Up @@ -802,9 +805,12 @@ TEST_CASE("generalized tx set fees", "[txset]")
static_cast<uint32_t>(GENERALIZED_TX_SET_PROTOCOL_VERSION);
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION =
static_cast<uint32_t>(GENERALIZED_TX_SET_PROTOCOL_VERSION);
cfg.TESTING_LEDGER_MAX_SOROBAN_TX_COUNT = 10;

Application::pointer app = createTestApplication(clock, cfg);
overrideSorobanNetworkConfigForTest(*app);
modifySorobanNetworkConfig(*app, [](SorobanNetworkConfig& sorobanCfg) {
sorobanCfg.mLedgerMaxTxCount = 10;
});
auto root = TestAccount::createRoot(*app);
int accountId = 1;
uint32_t refundableFee = 10'000;
Expand Down
6 changes: 3 additions & 3 deletions src/herder/test/UpgradesTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,12 +841,12 @@ TEST_CASE("config upgrades applied to ledger", "[soroban][upgrades]")
auto& configEntry = configUpgradeSetXdr.updatedEntry.emplace_back();
configEntry.configSettingID(CONFIG_SETTING_CONTRACT_COMPUTE_V0);
configEntry.contractCompute().feeRatePerInstructionsIncrement = 111;
configEntry.contractCompute().ledgerMaxInstructions =
MinimumSorobanNetworkConfig::LEDGER_MAX_INSTRUCTIONS;
configEntry.contractCompute().txMemoryLimit =
MinimumSorobanNetworkConfig::MEMORY_LIMIT;
configEntry.contractCompute().txMaxInstructions =
MinimumSorobanNetworkConfig::TX_MAX_INSTRUCTIONS;
configEntry.contractCompute().ledgerMaxInstructions =
configEntry.contractCompute().txMaxInstructions;
auto& configEntry2 =
configUpgradeSetXdr.updatedEntry.emplace_back();
configEntry2.configSettingID(
Expand All @@ -859,7 +859,7 @@ TEST_CASE("config upgrades applied to ledger", "[soroban][upgrades]")
executeUpgrade(*app, makeConfigUpgrade(*configUpgradeSet));
REQUIRE(sorobanConfig.feeRatePerInstructionsIncrement() == 111);
REQUIRE(sorobanConfig.ledgerMaxInstructions() ==
MinimumSorobanNetworkConfig::LEDGER_MAX_INSTRUCTIONS);
MinimumSorobanNetworkConfig::TX_MAX_INSTRUCTIONS);
REQUIRE(sorobanConfig.txMemoryLimit() ==
MinimumSorobanNetworkConfig::MEMORY_LIMIT);
REQUIRE(sorobanConfig.txMaxInstructions() ==
Expand Down
3 changes: 0 additions & 3 deletions src/ledger/LedgerManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ class LedgerManager
getSorobanNetworkConfig(AbstractLedgerTxn& ltx) = 0;

#ifdef BUILD_TESTS
virtual void
setSorobanNetworkConfig(SorobanNetworkConfig const& config) = 0;

virtual SorobanNetworkConfig&
getMutableSorobanNetworkConfig(AbstractLedgerTxn& ltx) = 0;
#endif
Expand Down
6 changes: 0 additions & 6 deletions src/ledger/LedgerManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,12 +541,6 @@ LedgerManagerImpl::getSorobanNetworkConfig(AbstractLedgerTxn& ltx)
}

#ifdef BUILD_TESTS
void
LedgerManagerImpl::setSorobanNetworkConfig(SorobanNetworkConfig const& config)
{
mSorobanNetworkConfig = config;
}

SorobanNetworkConfig&
LedgerManagerImpl::getMutableSorobanNetworkConfig(AbstractLedgerTxn& ltx)
{
Expand Down
1 change: 0 additions & 1 deletion src/ledger/LedgerManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class LedgerManagerImpl : public LedgerManager
getSorobanNetworkConfig(AbstractLedgerTxn& ltx) override;

#ifdef BUILD_TESTS
void setSorobanNetworkConfig(SorobanNetworkConfig const& config) override;
SorobanNetworkConfig&
getMutableSorobanNetworkConfig(AbstractLedgerTxn& ltx) override;
#endif
Expand Down
Loading

0 comments on commit 2920f3e

Please sign in to comment.