diff --git a/src/herder/test/HerderTests.cpp b/src/herder/test/HerderTests.cpp index 3239273291..77d0574b48 100644 --- a/src/herder/test/HerderTests.cpp +++ b/src/herder/test/HerderTests.cpp @@ -1563,11 +1563,9 @@ TEST_CASE("surge pricing", "[herder][txset]") { Config cfg(getTestConfig()); cfg.TESTING_UPGRADE_MAX_TX_SET_SIZE = 0; - cfg.TESTING_LEDGER_MAX_SOROBAN_TX_COUNT = 0; VirtualClock clock; Application::pointer app = createTestApplication(clock, cfg); - auto root = TestAccount::createRoot(*app); auto destAccount = root.create("destAccount", 500000000); @@ -1588,6 +1586,9 @@ TEST_CASE("surge pricing", "[herder][txset]") { #ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION uint32_t const baseFee = 10'000'000; + modifySorobanNetworkConfig(*app, [](SorobanNetworkConfig& cfg) { + cfg.mLedgerMaxTxCount = 0; + }); SorobanResources resources; auto sorobanTx = createUploadWasmTx(*app, root, baseFee, @@ -1613,11 +1614,12 @@ TEST_CASE("surge pricing", "[herder][txset]") static_cast(GENERALIZED_TX_SET_PROTOCOL_VERSION); // Max 1 classic op cfg.TESTING_UPGRADE_MAX_TX_SET_SIZE = 1; - // Max 2 soroban ops - cfg.TESTING_LEDGER_MAX_SOROBAN_TX_COUNT = 2; VirtualClock clock; Application::pointer app = createTestApplication(clock, cfg); + // Max 2 soroban ops + modifySorobanNetworkConfig( + *app, [](SorobanNetworkConfig& cfg) { cfg.mLedgerMaxTxCount = 2; }); auto root = TestAccount::createRoot(*app); auto acc1 = root.create("account1", 500000000); @@ -3425,89 +3427,98 @@ TEST_CASE("soroban txs each parameter surge priced") auto networkID = sha256(getTestConfig().NETWORK_PASSPHRASE); uint32_t baseTxRate = 1; uint32_t numAccounts = 100; - auto test = [&](std::function tweakConfig) { - auto simulation = Topologies::core( - 4, 1, Simulation::OVER_LOOPBACK, networkID, [&](int i) { - auto cfg = getTestConfig(i, Config::TESTDB_ON_DISK_SQLITE); - cfg.TESTING_UPGRADE_MAX_TX_SET_SIZE = 100; - // Set all Soroban resources to maximum initially; each section - // will adjust the config as desired - cfg.TESTING_LEDGER_MAX_SOROBAN_TX_COUNT = UINT32_MAX; - cfg.TESTING_LEDGER_MAX_INSTRUCTIONS = UINT32_MAX; - cfg.TESTING_LEDGER_MAX_TRANSACTIONS_SIZE_BYTES = UINT32_MAX; - cfg.TESTING_LEDGER_MAX_READ_LEDGER_ENTRIES = UINT32_MAX; - cfg.TESTING_LEDGER_MAX_READ_BYTES = UINT32_MAX; - cfg.TESTING_LEDGER_MAX_WRITE_LEDGER_ENTRIES = UINT32_MAX; - cfg.TESTING_LEDGER_MAX_WRITE_BYTES = UINT32_MAX; - tweakConfig(cfg); - return cfg; - }); - simulation->startAllNodes(); - auto nodes = simulation->getNodes(); - auto& loadGen = nodes[0]->getLoadGenerator(); + auto test = + [&](std::function tweakConfig) { + auto simulation = Topologies::core( + 4, 1, Simulation::OVER_LOOPBACK, networkID, [&](int i) { + auto cfg = getTestConfig(i, Config::TESTDB_ON_DISK_SQLITE); + cfg.TESTING_UPGRADE_MAX_TX_SET_SIZE = 100; + return cfg; + }); + simulation->startAllNodes(); + auto nodes = simulation->getNodes(); + for (auto& node : nodes) + { + modifySorobanNetworkConfig( + *node, [&tweakConfig](SorobanNetworkConfig& cfg) { + auto mx = std::numeric_limits::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; + tweakConfig(cfg); + }); + } + 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)); + simulation->crankUntil( + [&]() { return loadGenDone.count() > currLoadGenCount; }, + 10 * Herder::EXP_LEDGER_TIMESPAN_SECONDS, false); - // Generate some accounts - auto& loadGenDone = nodes[0]->getMetrics().NewMeter( - {"loadgen", "run", "complete"}, "run"); - auto currLoadGenCount = loadGenDone.count(); - loadGen.generateLoad( - GeneratedLoadConfig::createAccountsLoad(numAccounts, baseTxRate)); - simulation->crankUntil( - [&]() { return loadGenDone.count() > currLoadGenCount; }, - 10 * Herder::EXP_LEDGER_TIMESPAN_SECONDS, false); + auto& secondLoadGen = nodes[1]->getLoadGenerator(); + auto& secondLoadGenDone = nodes[1]->getMetrics().NewMeter( + {"loadgen", "run", "complete"}, "run"); + // Generate load from several nodes, to produce both classic and + // soroban traffic + currLoadGenCount = loadGenDone.count(); + auto secondLoadGenCount = secondLoadGenDone.count(); - auto& secondLoadGen = nodes[1]->getLoadGenerator(); - auto& secondLoadGenDone = nodes[1]->getMetrics().NewMeter( - {"loadgen", "run", "complete"}, "run"); - // Generate load from several nodes, to produce both classic and soroban - // traffic - currLoadGenCount = loadGenDone.count(); - auto secondLoadGenCount = secondLoadGenDone.count(); - - uint32_t maxInclusionFee = 100'000; - auto sorobanConfig = GeneratedLoadConfig::txLoad( - LoadGenMode::SOROBAN, 50, - /* nTxs */ 100, baseTxRate * 3, /* offset */ 0, maxInclusionFee); + uint32_t maxInclusionFee = 100'000; + auto sorobanConfig = + GeneratedLoadConfig::txLoad(LoadGenMode::SOROBAN, 50, + /* nTxs */ 100, baseTxRate * 3, + /* offset */ 0, maxInclusionFee); - // Ignore low fees, submit at a tx rate higher than the network allows - // to trigger surge pricing - sorobanConfig.skipLowFeeTxs = true; - loadGen.generateLoad(sorobanConfig); + // Ignore low fees, submit at a tx rate higher than the network + // allows to trigger surge pricing + sorobanConfig.skipLowFeeTxs = true; + loadGen.generateLoad(sorobanConfig); - // Generate Soroban txs from one node - secondLoadGen.generateLoad(GeneratedLoadConfig::txLoad( - LoadGenMode::PAY, 50, - /* nTxs */ 50, baseTxRate, /* offset */ 50, maxInclusionFee)); + // Generate Soroban txs from one node + secondLoadGen.generateLoad(GeneratedLoadConfig::txLoad( + LoadGenMode::PAY, 50, + /* nTxs */ 50, baseTxRate, /* offset */ 50, maxInclusionFee)); - simulation->crankUntil( - [&]() { - return loadGenDone.count() > currLoadGenCount && - secondLoadGenDone.count() > secondLoadGenCount; - }, - 200 * Herder::EXP_LEDGER_TIMESPAN_SECONDS, false); - auto& loadGenFailed = nodes[0]->getMetrics().NewMeter( - {"loadgen", "run", "failed"}, "run"); - REQUIRE(loadGenFailed.count() == 0); - auto& secondLoadGenFailed = nodes[1]->getMetrics().NewMeter( - {"loadgen", "run", "failed"}, "run"); - REQUIRE(secondLoadGenFailed.count() == 0); - }; + simulation->crankUntil( + [&]() { + return loadGenDone.count() > currLoadGenCount && + secondLoadGenDone.count() > secondLoadGenCount; + }, + 200 * Herder::EXP_LEDGER_TIMESPAN_SECONDS, false); + auto& loadGenFailed = nodes[0]->getMetrics().NewMeter( + {"loadgen", "run", "failed"}, "run"); + REQUIRE(loadGenFailed.count() == 0); + auto& secondLoadGenFailed = nodes[1]->getMetrics().NewMeter( + {"loadgen", "run", "failed"}, "run"); + REQUIRE(secondLoadGenFailed.count() == 0); + }; // We will be submitting soroban txs at desiredTxRate * 3, but the network // can only accept up to desiredTxRate for each resource dimension, // triggering surge pricing SECTION("operations") { - auto tweakConfig = [&](Config& cfg) { - cfg.TESTING_LEDGER_MAX_SOROBAN_TX_COUNT = + auto tweakConfig = [&](SorobanNetworkConfig& cfg) { + cfg.mLedgerMaxTxCount = baseTxRate * Herder::EXP_LEDGER_TIMESPAN_SECONDS.count(); }; test(tweakConfig); } SECTION("instructions") { - auto tweakConfig = [&](Config& cfg) { - cfg.TESTING_LEDGER_MAX_INSTRUCTIONS = + auto tweakConfig = [&](SorobanNetworkConfig& cfg) { + cfg.mLedgerMaxInstructions = baseTxRate * Herder::EXP_LEDGER_TIMESPAN_SECONDS.count() * InitialSorobanNetworkConfig::TX_MAX_INSTRUCTIONS; }; @@ -3515,8 +3526,8 @@ TEST_CASE("soroban txs each parameter surge priced") } SECTION("tx size") { - auto tweakConfig = [&](Config& cfg) { - cfg.TESTING_LEDGER_MAX_TRANSACTIONS_SIZE_BYTES = + auto tweakConfig = [&](SorobanNetworkConfig& cfg) { + cfg.mLedgerMaxTransactionsSizeBytes = baseTxRate * Herder::EXP_LEDGER_TIMESPAN_SECONDS.count() * InitialSorobanNetworkConfig::TX_MAX_SIZE_BYTES; }; @@ -3524,8 +3535,8 @@ TEST_CASE("soroban txs each parameter surge priced") } SECTION("read entries") { - auto tweakConfig = [&](Config& cfg) { - cfg.TESTING_LEDGER_MAX_READ_LEDGER_ENTRIES = + auto tweakConfig = [&](SorobanNetworkConfig& cfg) { + cfg.mLedgerMaxReadLedgerEntries = baseTxRate * Herder::EXP_LEDGER_TIMESPAN_SECONDS.count() * InitialSorobanNetworkConfig::TX_MAX_READ_LEDGER_ENTRIES; }; @@ -3533,8 +3544,8 @@ TEST_CASE("soroban txs each parameter surge priced") } SECTION("write entries") { - auto tweakConfig = [&](Config& cfg) { - cfg.TESTING_LEDGER_MAX_WRITE_LEDGER_ENTRIES = + auto tweakConfig = [&](SorobanNetworkConfig& cfg) { + cfg.mLedgerMaxWriteLedgerEntries = baseTxRate * Herder::EXP_LEDGER_TIMESPAN_SECONDS.count() * InitialSorobanNetworkConfig::TX_MAX_WRITE_LEDGER_ENTRIES; }; @@ -3542,8 +3553,8 @@ TEST_CASE("soroban txs each parameter surge priced") } SECTION("read bytes") { - auto tweakConfig = [&](Config& cfg) { - cfg.TESTING_LEDGER_MAX_READ_BYTES = + auto tweakConfig = [&](SorobanNetworkConfig& cfg) { + cfg.mLedgerMaxReadBytes = baseTxRate * Herder::EXP_LEDGER_TIMESPAN_SECONDS.count() * InitialSorobanNetworkConfig::TX_MAX_READ_BYTES; }; @@ -3551,9 +3562,8 @@ TEST_CASE("soroban txs each parameter surge priced") } SECTION("write bytes") { - auto tweakConfig = [&](Config& cfg) { - cfg.TESTING_LEDGER_MAX_SOROBAN_TX_COUNT = UINT32_MAX; - cfg.TESTING_LEDGER_MAX_WRITE_BYTES = + auto tweakConfig = [&](SorobanNetworkConfig& cfg) { + cfg.mLedgerMaxWriteBytes = baseTxRate * Herder::EXP_LEDGER_TIMESPAN_SECONDS.count() * InitialSorobanNetworkConfig::TX_MAX_WRITE_BYTES; }; @@ -3565,34 +3575,28 @@ TEST_CASE("soroban txs accepted by the network", "[herder][soroban][transactionqueue]") { auto networkID = sha256(getTestConfig().NETWORK_PASSPHRASE); - uint32_t desiredTxRate = 1; - uint32_t numAccounts = 100; // Set threshold to 1 so all have to vote - auto simulation = Topologies::core( - 4, 1, Simulation::OVER_LOOPBACK, networkID, [desiredTxRate](int i) { + auto simulation = + Topologies::core(4, 1, Simulation::OVER_LOOPBACK, networkID, [](int i) { auto cfg = getTestConfig(i, Config::TESTDB_ON_DISK_SQLITE); - cfg.TESTING_LEDGER_MAX_SOROBAN_TX_COUNT = - 2 * desiredTxRate * Herder::EXP_LEDGER_TIMESPAN_SECONDS.count(); cfg.TESTING_UPGRADE_MAX_TX_SET_SIZE = 100; - cfg.TESTING_LEDGER_MAX_TRANSACTIONS_SIZE_BYTES = - 10 * InitialSorobanNetworkConfig::TX_MAX_SIZE_BYTES; - cfg.TESTING_LEDGER_MAX_INSTRUCTIONS = - 10 * InitialSorobanNetworkConfig::TX_MAX_INSTRUCTIONS; - cfg.TESTING_LEDGER_MAX_READ_LEDGER_ENTRIES = - 10 * InitialSorobanNetworkConfig::TX_MAX_READ_LEDGER_ENTRIES; - cfg.TESTING_LEDGER_MAX_READ_BYTES = - 10 * InitialSorobanNetworkConfig::TX_MAX_READ_BYTES; - cfg.TESTING_LEDGER_MAX_WRITE_LEDGER_ENTRIES = - 10 * InitialSorobanNetworkConfig::TX_MAX_WRITE_LEDGER_ENTRIES; - cfg.TESTING_LEDGER_MAX_WRITE_BYTES = - 10 * InitialSorobanNetworkConfig::TX_MAX_WRITE_BYTES; - cfg.TESTING_TX_MAX_SIZE_BYTES = - 10 * InitialSorobanNetworkConfig::TX_MAX_SIZE_BYTES; return cfg; }); simulation->startAllNodes(); auto nodes = simulation->getNodes(); + uint32_t desiredTxRate = 1; + uint32_t numAccounts = 100; + for (auto& node : nodes) + { + overrideSorobanNetworkConfigForTest(*node); + modifySorobanNetworkConfig(*node, [desiredTxRate]( + SorobanNetworkConfig& cfg) { + cfg.mLedgerMaxTxCount = + 2 * desiredTxRate * Herder::EXP_LEDGER_TIMESPAN_SECONDS.count(); + ; + }); + } auto& loadGen = nodes[0]->getLoadGenerator(); // Generate some accounts @@ -4449,7 +4453,6 @@ TEST_CASE("do not flood too many soroban transactions", Simulation::OVER_LOOPBACK, networkID, [&](int i) { auto cfg = getTestConfig(i); cfg.TESTING_UPGRADE_MAX_TX_SET_SIZE = 1000; - cfg.TESTING_LEDGER_MAX_SOROBAN_TX_COUNT = 100; cfg.NODE_IS_VALIDATOR = false; cfg.FORCE_SCP = false; cfg.FLOOD_TX_PERIOD_MS = 100; @@ -4469,12 +4472,26 @@ 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) { + // 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->addPendingConnection(mainKey.getPublicKey(), otherKey.getPublicKey()); simulation->startAllNodes(); simulation->crankForAtLeast(std::chrono::seconds(1), false); - auto app = simulation->getNode(mainKey.getPublicKey()); auto const& cfg = app->getConfig(); auto& lm = app->getLedgerManager(); auto& herder = static_cast(app->getHerder()); @@ -4520,7 +4537,6 @@ TEST_CASE("do not flood too many soroban transactions", auto tx = createUploadWasmTx(*app, source, txFee, /* refundableFee */ 1200, resources); - REQUIRE(herder.recvTransaction(tx, false) == TransactionQueue::AddResult::ADD_STATUS_PENDING); return tx; @@ -4596,10 +4612,9 @@ TEST_CASE("do not flood too many soroban transactions", SECTION("large tx waits to accumulate enough quota") { REQUIRE(numBroadcast == 0); - // For large txs, there might not be enough resources allocated for this - // flooding period. In this case, wait a few periods to accumulate + // For large txs, there might not be enough resources allocated for + // this flooding period. In this case, wait a few periods to accumulate // enough quota - resources.instructions = 40'000'000; resources.readBytes = 200 * 1024; genTx(root, true); diff --git a/src/herder/test/TransactionQueueTests.cpp b/src/herder/test/TransactionQueueTests.cpp index 973175b93e..df963056fc 100644 --- a/src/herder/test/TransactionQueueTests.cpp +++ b/src/herder/test/TransactionQueueTests.cpp @@ -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); @@ -1121,8 +1126,7 @@ TEST_CASE("Soroban TransactionQueue limits", int initialFee = 10'000'000; auto resAdjusted = resources; - resAdjusted.instructions = - static_cast(conf.ledgerMaxInstructions()); + resAdjusted.instructions = static_cast(conf.txMaxInstructions()); auto tx = createUploadWasmTx(*app, root, initialFee, refundableFee, resAdjusted); @@ -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); diff --git a/src/herder/test/TxSetTests.cpp b/src/herder/test/TxSetTests.cpp index 78710ba9f1..c05086fc41 100644 --- a/src/herder/test/TxSetTests.cpp +++ b/src/herder/test/TxSetTests.cpp @@ -482,8 +482,11 @@ TEST_CASE("generalized tx set XDR conversion", "[txset]") static_cast(GENERALIZED_TX_SET_PROTOCOL_VERSION); cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION = static_cast(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) { @@ -802,9 +805,12 @@ TEST_CASE("generalized tx set fees", "[txset]") static_cast(GENERALIZED_TX_SET_PROTOCOL_VERSION); cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION = static_cast(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; diff --git a/src/herder/test/UpgradesTests.cpp b/src/herder/test/UpgradesTests.cpp index 5826e5d7bf..8cf3f815f2 100644 --- a/src/herder/test/UpgradesTests.cpp +++ b/src/herder/test/UpgradesTests.cpp @@ -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( @@ -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() == diff --git a/src/ledger/LedgerManager.h b/src/ledger/LedgerManager.h index 824682aada..a6a2fa1d5c 100644 --- a/src/ledger/LedgerManager.h +++ b/src/ledger/LedgerManager.h @@ -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 diff --git a/src/ledger/LedgerManagerImpl.cpp b/src/ledger/LedgerManagerImpl.cpp index bfe91e2513..4c4df96255 100644 --- a/src/ledger/LedgerManagerImpl.cpp +++ b/src/ledger/LedgerManagerImpl.cpp @@ -541,12 +541,6 @@ LedgerManagerImpl::getSorobanNetworkConfig(AbstractLedgerTxn& ltx) } #ifdef BUILD_TESTS -void -LedgerManagerImpl::setSorobanNetworkConfig(SorobanNetworkConfig const& config) -{ - mSorobanNetworkConfig = config; -} - SorobanNetworkConfig& LedgerManagerImpl::getMutableSorobanNetworkConfig(AbstractLedgerTxn& ltx) { diff --git a/src/ledger/LedgerManagerImpl.h b/src/ledger/LedgerManagerImpl.h index e2aad0afc8..abcf61e221 100644 --- a/src/ledger/LedgerManagerImpl.h +++ b/src/ledger/LedgerManagerImpl.h @@ -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 diff --git a/src/ledger/NetworkConfig.cpp b/src/ledger/NetworkConfig.cpp index 4c9ffb81e3..8b2a20a59b 100644 --- a/src/ledger/NetworkConfig.cpp +++ b/src/ledger/NetworkConfig.cpp @@ -31,7 +31,7 @@ createConfigSettingEntry(ConfigSettingEntry const& configSetting, } ConfigSettingEntry -initialMaxContractSizeEntry(Config const& cfg) +initialMaxContractSizeEntry() { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES); @@ -42,7 +42,7 @@ initialMaxContractSizeEntry(Config const& cfg) } ConfigSettingEntry -initialMaxContractDataKeySizeEntry(Config const& cfg) +initialMaxContractDataKeySizeEntry() { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_DATA_KEY_SIZE_BYTES); @@ -53,7 +53,7 @@ initialMaxContractDataKeySizeEntry(Config const& cfg) } ConfigSettingEntry -initialMaxContractDataEntrySizeEntry(Config const& cfg) +initialMaxContractDataEntrySizeEntry() { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES); @@ -64,20 +64,14 @@ initialMaxContractDataEntrySizeEntry(Config const& cfg) } ConfigSettingEntry -initialContractComputeSettingsEntry(Config const& cfg) +initialContractComputeSettingsEntry() { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_COMPUTE_V0); auto& e = entry.contractCompute(); - if (cfg.USE_CONFIG_FOR_GENESIS) - { - e.ledgerMaxInstructions = cfg.TESTING_LEDGER_MAX_INSTRUCTIONS; - } - else - { - e.ledgerMaxInstructions = - InitialSorobanNetworkConfig::LEDGER_MAX_INSTRUCTIONS; - } + e.ledgerMaxInstructions = + InitialSorobanNetworkConfig::LEDGER_MAX_INSTRUCTIONS; + e.txMaxInstructions = InitialSorobanNetworkConfig::TX_MAX_INSTRUCTIONS; e.feeRatePerInstructionsIncrement = InitialSorobanNetworkConfig::FEE_RATE_PER_INSTRUCTIONS_INCREMENT; @@ -87,49 +81,21 @@ initialContractComputeSettingsEntry(Config const& cfg) } ConfigSettingEntry -initialContractLedgerAccessSettingsEntry(Config const& cfg) +initialContractLedgerAccessSettingsEntry() { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_LEDGER_COST_V0); auto& e = entry.contractLedgerCost(); - if (cfg.USE_CONFIG_FOR_GENESIS) - { - e.ledgerMaxReadLedgerEntries = - cfg.TESTING_LEDGER_MAX_READ_LEDGER_ENTRIES; - } - else - { - e.ledgerMaxReadLedgerEntries = - InitialSorobanNetworkConfig::LEDGER_MAX_READ_LEDGER_ENTRIES; - } - if (cfg.USE_CONFIG_FOR_GENESIS) - { - e.ledgerMaxReadBytes = cfg.TESTING_LEDGER_MAX_READ_BYTES; - } - else - { - e.ledgerMaxReadBytes = - InitialSorobanNetworkConfig::LEDGER_MAX_READ_BYTES; - } - if (cfg.USE_CONFIG_FOR_GENESIS) - { - e.ledgerMaxWriteLedgerEntries = - cfg.TESTING_LEDGER_MAX_WRITE_LEDGER_ENTRIES; - } - else - { - e.ledgerMaxWriteLedgerEntries = - InitialSorobanNetworkConfig::LEDGER_MAX_WRITE_LEDGER_ENTRIES; - } - if (cfg.USE_CONFIG_FOR_GENESIS) - { - e.ledgerMaxWriteBytes = cfg.TESTING_LEDGER_MAX_WRITE_BYTES; - } - else - { - e.ledgerMaxWriteBytes = - InitialSorobanNetworkConfig::LEDGER_MAX_WRITE_BYTES; - } + e.ledgerMaxReadLedgerEntries = + InitialSorobanNetworkConfig::LEDGER_MAX_READ_LEDGER_ENTRIES; + + e.ledgerMaxReadBytes = InitialSorobanNetworkConfig::LEDGER_MAX_READ_BYTES; + + e.ledgerMaxWriteLedgerEntries = + InitialSorobanNetworkConfig::LEDGER_MAX_WRITE_LEDGER_ENTRIES; + + e.ledgerMaxWriteBytes = InitialSorobanNetworkConfig::LEDGER_MAX_WRITE_BYTES; + e.txMaxReadLedgerEntries = InitialSorobanNetworkConfig::TX_MAX_READ_LEDGER_ENTRIES; e.txMaxReadBytes = InitialSorobanNetworkConfig::TX_MAX_READ_BYTES; @@ -152,7 +118,7 @@ initialContractLedgerAccessSettingsEntry(Config const& cfg) } ConfigSettingEntry -initialContractHistoricalDataSettingsEntry(Config const& cfg) +initialContractHistoricalDataSettingsEntry() { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0); auto& e = entry.contractHistoricalData(); @@ -163,7 +129,7 @@ initialContractHistoricalDataSettingsEntry(Config const& cfg) } ConfigSettingEntry -initialContractEventsSettingsEntry(Config const& cfg) +initialContractEventsSettingsEntry() { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_EVENTS_V0); auto& e = entry.contractEvents(); @@ -177,23 +143,14 @@ initialContractEventsSettingsEntry(Config const& cfg) } ConfigSettingEntry -initialContractBandwidthSettingsEntry(Config const& cfg) +initialContractBandwidthSettingsEntry() { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_BANDWIDTH_V0); auto& e = entry.contractBandwidth(); - if (cfg.USE_CONFIG_FOR_GENESIS) - { - e.ledgerMaxTxsSizeBytes = - cfg.TESTING_LEDGER_MAX_TRANSACTIONS_SIZE_BYTES; - e.txMaxSizeBytes = cfg.TESTING_TX_MAX_SIZE_BYTES; - } - else - { - e.ledgerMaxTxsSizeBytes = - InitialSorobanNetworkConfig::LEDGER_MAX_TRANSACTION_SIZES_BYTES; - e.txMaxSizeBytes = InitialSorobanNetworkConfig::TX_MAX_SIZE_BYTES; - } + e.ledgerMaxTxsSizeBytes = + InitialSorobanNetworkConfig::LEDGER_MAX_TRANSACTION_SIZES_BYTES; + e.txMaxSizeBytes = InitialSorobanNetworkConfig::TX_MAX_SIZE_BYTES; e.feeTxSize1KB = InitialSorobanNetworkConfig::FEE_TRANSACTION_SIZE_1KB; @@ -201,25 +158,16 @@ initialContractBandwidthSettingsEntry(Config const& cfg) } ConfigSettingEntry -initialContractExecutionLanesSettingsEntry(Config const& cfg) +initialContractExecutionLanesSettingsEntry() { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_EXECUTION_LANES); auto& e = entry.contractExecutionLanes(); - - if (cfg.USE_CONFIG_FOR_GENESIS) - { - e.ledgerMaxTxCount = cfg.TESTING_LEDGER_MAX_SOROBAN_TX_COUNT; - } - else - { - e.ledgerMaxTxCount = InitialSorobanNetworkConfig::LEDGER_MAX_TX_COUNT; - } - + e.ledgerMaxTxCount = InitialSorobanNetworkConfig::LEDGER_MAX_TX_COUNT; return entry; } ConfigSettingEntry -initialCpuCostParamsEntry(Config const& cfg) +initialCpuCostParamsEntry() { ConfigSettingEntry entry( CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS); @@ -335,10 +283,13 @@ initialStateExpirationSettings(Config const& cfg) entry.stateExpirationSettings().maxEntryExpiration = InitialSorobanNetworkConfig::MAXIMUM_ENTRY_LIFETIME; - // TESTING_MINIMUM_PERSISTENT_ENTRY_LIFETIME defaults to - // InitialSorobanNetworkConfig::MINIMUM_PERSISTENT_ENTRY_LIFETIME entry.stateExpirationSettings().minPersistentEntryExpiration = - cfg.TESTING_MINIMUM_PERSISTENT_ENTRY_LIFETIME; + InitialSorobanNetworkConfig::MINIMUM_PERSISTENT_ENTRY_LIFETIME; + if (cfg.TESTING_MINIMUM_PERSISTENT_ENTRY_LIFETIME != 0) + { + entry.stateExpirationSettings().minPersistentEntryExpiration = + cfg.TESTING_MINIMUM_PERSISTENT_ENTRY_LIFETIME; + } entry.stateExpirationSettings().minTempEntryExpiration = InitialSorobanNetworkConfig::MINIMUM_TEMP_ENTRY_LIFETIME; @@ -360,7 +311,7 @@ initialStateExpirationSettings(Config const& cfg) } ConfigSettingEntry -initialMemCostParamsEntry(Config const& cfg) +initialMemCostParamsEntry() { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES); @@ -464,7 +415,7 @@ initialMemCostParamsEntry(Config const& cfg) } ConfigSettingEntry -initialbucketListSizeWindow(Application& app) +initialBucketListSizeWindow(Application& app) { ConfigSettingEntry entry(CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW); @@ -516,64 +467,47 @@ SorobanNetworkConfig::isValidConfigSettingEntry(ConfigSettingEntry const& cfg) break; case ConfigSettingID::CONFIG_SETTING_CONTRACT_BANDWIDTH_V0: valid = cfg.contractBandwidth().feeTxSize1KB >= 0 && - cfg.contractBandwidth().ledgerMaxTxsSizeBytes >= - MinimumSorobanNetworkConfig::LEDGER_MAX_TX_SIZE_BYTES && cfg.contractBandwidth().txMaxSizeBytes >= - MinimumSorobanNetworkConfig::TX_MAX_SIZE_BYTES; - - valid = valid && cfg.contractBandwidth().ledgerMaxTxsSizeBytes >= - cfg.contractBandwidth().txMaxSizeBytes; + MinimumSorobanNetworkConfig::TX_MAX_SIZE_BYTES && + cfg.contractBandwidth().ledgerMaxTxsSizeBytes >= + cfg.contractBandwidth().txMaxSizeBytes; break; case ConfigSettingID::CONFIG_SETTING_CONTRACT_COMPUTE_V0: valid = cfg.contractCompute().feeRatePerInstructionsIncrement >= 0 && - cfg.contractCompute().ledgerMaxInstructions >= - MinimumSorobanNetworkConfig::LEDGER_MAX_INSTRUCTIONS && cfg.contractCompute().txMaxInstructions >= MinimumSorobanNetworkConfig::TX_MAX_INSTRUCTIONS && + cfg.contractCompute().ledgerMaxInstructions >= + cfg.contractCompute().txMaxInstructions && cfg.contractCompute().txMemoryLimit >= MinimumSorobanNetworkConfig::MEMORY_LIMIT; - - valid = valid && cfg.contractCompute().ledgerMaxInstructions >= - cfg.contractCompute().txMaxInstructions; break; case ConfigSettingID::CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0: valid = cfg.contractHistoricalData().feeHistorical1KB >= 0; break; case ConfigSettingID::CONFIG_SETTING_CONTRACT_LEDGER_COST_V0: - valid = - cfg.contractLedgerCost().ledgerMaxReadLedgerEntries >= - MinimumSorobanNetworkConfig::LEDGER_MAX_READ_LEDGER_ENTRIES && - cfg.contractLedgerCost().ledgerMaxReadBytes >= - MinimumSorobanNetworkConfig::LEDGER_MAX_READ_BYTES && - cfg.contractLedgerCost().ledgerMaxWriteLedgerEntries >= - MinimumSorobanNetworkConfig::LEDGER_MAX_WRITE_LEDGER_ENTRIES && - cfg.contractLedgerCost().ledgerMaxWriteBytes >= - MinimumSorobanNetworkConfig::LEDGER_MAX_WRITE_BYTES && - cfg.contractLedgerCost().txMaxReadLedgerEntries >= - MinimumSorobanNetworkConfig::TX_MAX_READ_LEDGER_ENTRIES && - cfg.contractLedgerCost().txMaxReadBytes >= - MinimumSorobanNetworkConfig::TX_MAX_READ_BYTES && - cfg.contractLedgerCost().txMaxWriteLedgerEntries >= - MinimumSorobanNetworkConfig::TX_MAX_WRITE_LEDGER_ENTRIES && - cfg.contractLedgerCost().txMaxWriteBytes >= - MinimumSorobanNetworkConfig::TX_MAX_WRITE_BYTES && - cfg.contractLedgerCost().feeReadLedgerEntry >= 0 && - cfg.contractLedgerCost().feeWriteLedgerEntry >= 0 && - cfg.contractLedgerCost().feeRead1KB >= 0 && - cfg.contractLedgerCost().bucketListTargetSizeBytes > 0 && - cfg.contractLedgerCost().writeFee1KBBucketListLow >= 0 && - cfg.contractLedgerCost().writeFee1KBBucketListHigh >= 0 && - cfg.contractLedgerCost().bucketListWriteFeeGrowthFactor >= 0; - - valid = valid && cfg.contractLedgerCost().ledgerMaxReadLedgerEntries >= - cfg.contractLedgerCost().txMaxReadLedgerEntries; - valid = valid && cfg.contractLedgerCost().ledgerMaxReadBytes >= - cfg.contractLedgerCost().txMaxReadBytes; - - valid = valid && cfg.contractLedgerCost().ledgerMaxWriteLedgerEntries >= - cfg.contractLedgerCost().txMaxWriteLedgerEntries; - valid = valid && cfg.contractLedgerCost().ledgerMaxWriteBytes >= - cfg.contractLedgerCost().txMaxWriteBytes; + valid = cfg.contractLedgerCost().txMaxReadLedgerEntries >= + MinimumSorobanNetworkConfig::TX_MAX_READ_LEDGER_ENTRIES && + cfg.contractLedgerCost().ledgerMaxReadLedgerEntries >= + cfg.contractLedgerCost().txMaxReadLedgerEntries && + cfg.contractLedgerCost().txMaxReadBytes >= + MinimumSorobanNetworkConfig::TX_MAX_READ_BYTES && + cfg.contractLedgerCost().ledgerMaxReadBytes >= + cfg.contractLedgerCost().txMaxReadBytes && + cfg.contractLedgerCost().txMaxWriteLedgerEntries >= + MinimumSorobanNetworkConfig::TX_MAX_WRITE_LEDGER_ENTRIES && + cfg.contractLedgerCost().ledgerMaxWriteLedgerEntries >= + cfg.contractLedgerCost().txMaxWriteLedgerEntries && + cfg.contractLedgerCost().txMaxWriteBytes >= + MinimumSorobanNetworkConfig::TX_MAX_WRITE_BYTES && + cfg.contractLedgerCost().ledgerMaxWriteBytes >= + cfg.contractLedgerCost().txMaxWriteBytes && + cfg.contractLedgerCost().feeReadLedgerEntry >= 0 && + cfg.contractLedgerCost().feeWriteLedgerEntry >= 0 && + cfg.contractLedgerCost().feeRead1KB >= 0 && + cfg.contractLedgerCost().bucketListTargetSizeBytes > 0 && + cfg.contractLedgerCost().writeFee1KBBucketListLow >= 0 && + cfg.contractLedgerCost().writeFee1KBBucketListHigh >= 0 && + cfg.contractLedgerCost().bucketListWriteFeeGrowthFactor >= 0; break; case ConfigSettingID::CONFIG_SETTING_CONTRACT_EVENTS_V0: valid = cfg.contractEvents().txMaxContractEventsSizeBytes >= 0 && @@ -627,24 +561,20 @@ SorobanNetworkConfig::createLedgerEntriesForV20(AbstractLedgerTxn& ltx, Application& app) { #ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION - auto const& cfg = app.getConfig(); - createConfigSettingEntry(initialMaxContractSizeEntry(cfg), ltx); - createConfigSettingEntry(initialMaxContractDataKeySizeEntry(cfg), ltx); - createConfigSettingEntry(initialMaxContractDataEntrySizeEntry(cfg), ltx); - createConfigSettingEntry(initialContractComputeSettingsEntry(cfg), ltx); - createConfigSettingEntry(initialContractLedgerAccessSettingsEntry(cfg), + createConfigSettingEntry(initialMaxContractSizeEntry(), ltx); + createConfigSettingEntry(initialMaxContractDataKeySizeEntry(), ltx); + createConfigSettingEntry(initialMaxContractDataEntrySizeEntry(), ltx); + createConfigSettingEntry(initialContractComputeSettingsEntry(), ltx); + createConfigSettingEntry(initialContractLedgerAccessSettingsEntry(), ltx); + createConfigSettingEntry(initialContractHistoricalDataSettingsEntry(), ltx); + createConfigSettingEntry(initialContractEventsSettingsEntry(), ltx); + createConfigSettingEntry(initialContractBandwidthSettingsEntry(), ltx); + createConfigSettingEntry(initialContractExecutionLanesSettingsEntry(), ltx); + createConfigSettingEntry(initialCpuCostParamsEntry(), ltx); + createConfigSettingEntry(initialMemCostParamsEntry(), ltx); + createConfigSettingEntry(initialStateExpirationSettings(app.getConfig()), ltx); - createConfigSettingEntry(initialContractHistoricalDataSettingsEntry(cfg), - ltx); - createConfigSettingEntry(initialContractEventsSettingsEntry(cfg), ltx); - createConfigSettingEntry(initialContractBandwidthSettingsEntry(cfg), ltx); - createConfigSettingEntry(initialContractExecutionLanesSettingsEntry(cfg), - ltx); - createConfigSettingEntry(initialCpuCostParamsEntry(cfg), ltx); - createConfigSettingEntry(initialMemCostParamsEntry(cfg), ltx); - createConfigSettingEntry(initialStateExpirationSettings(cfg), ltx); - - createConfigSettingEntry(initialbucketListSizeWindow(app), ltx); + createConfigSettingEntry(initialBucketListSizeWindow(app), ltx); #endif } @@ -1174,18 +1104,6 @@ SorobanNetworkConfig::getAverageBucketListSize() const } #ifdef BUILD_TESTS -uint32_t& -SorobanNetworkConfig::maxContractDataKeySizeBytes() -{ - return mMaxContractDataKeySizeBytes; -} - -uint32_t& -SorobanNetworkConfig::maxContractDataEntrySizeBytes() -{ - return mMaxContractDataEntrySizeBytes; -} - void SorobanNetworkConfig::setBucketListSnapshotPeriodForTesting(uint32_t period) { @@ -1219,14 +1137,6 @@ SorobanNetworkConfig::stateExpirationSettings() const return mStateExpirationSettings; } -#ifdef BUILD_TESTS -StateExpirationSettings& -SorobanNetworkConfig::stateExpirationSettings() -{ - return mStateExpirationSettings; -} -#endif - bool SorobanNetworkConfig::isValidCostParams(ContractCostParams const& params) { diff --git a/src/ledger/NetworkConfig.h b/src/ledger/NetworkConfig.h index e1679d0add..ce83689184 100644 --- a/src/ledger/NetworkConfig.h +++ b/src/ledger/NetworkConfig.h @@ -17,6 +17,30 @@ namespace stellar class Application; +// Defines the minimum values allowed for the network configuration +// settings during upgrades. An upgrade that does not follow the minimums +// will be rejected. +struct MinimumSorobanNetworkConfig +{ + static constexpr uint32_t TX_MAX_READ_LEDGER_ENTRIES = 3; + static constexpr uint32_t TX_MAX_READ_BYTES = 5'000; + + static constexpr uint32_t TX_MAX_WRITE_LEDGER_ENTRIES = 2; + static constexpr uint32_t TX_MAX_WRITE_BYTES = 2'000; + + static constexpr uint32_t TX_MAX_SIZE_BYTES = 10'000; + + static constexpr uint32_t TX_MAX_INSTRUCTIONS = 5'000'000; + static constexpr uint32_t MEMORY_LIMIT = 5'000'000; + + static constexpr uint32_t MAX_CONTRACT_DATA_KEY_SIZE_BYTES = 300; + static constexpr uint32_t MAX_CONTRACT_DATA_ENTRY_SIZE_BYTES = 2'000; + static constexpr uint32_t MAX_CONTRACT_SIZE = 5'000; + + static constexpr uint32_t MINIMUM_PERSISTENT_ENTRY_LIFETIME = 4'096; + static constexpr uint32_t MAXIMUM_ENTRY_LIFETIME = 535'680; // 31 days +}; + // Defines the initial values of the network configuration // settings that are applied during the protocol version upgrade. // These values should never be changed after the protocol upgrade @@ -25,40 +49,45 @@ class Application; struct InitialSorobanNetworkConfig { // Contract size settings - static constexpr uint32_t MAX_CONTRACT_SIZE = 64 * 1024; // 64KB + static constexpr uint32_t MAX_CONTRACT_SIZE = + MinimumSorobanNetworkConfig::MAX_CONTRACT_SIZE; // Contract data settings - static constexpr uint32_t MAX_CONTRACT_DATA_KEY_SIZE_BYTES = 300; + static constexpr uint32_t MAX_CONTRACT_DATA_KEY_SIZE_BYTES = + MinimumSorobanNetworkConfig::MAX_CONTRACT_DATA_KEY_SIZE_BYTES; static constexpr uint32_t MAX_CONTRACT_DATA_ENTRY_SIZE_BYTES = - 64 * 1024; // 64KB + MinimumSorobanNetworkConfig::MAX_CONTRACT_DATA_ENTRY_SIZE_BYTES; // Compute settings - static constexpr int64_t TX_MAX_INSTRUCTIONS = 100'000'000; - static constexpr int64_t LEDGER_MAX_INSTRUCTIONS = 10 * TX_MAX_INSTRUCTIONS; - static constexpr int64_t FEE_RATE_PER_INSTRUCTIONS_INCREMENT = - 100; // 0.2 XLM/max tx - static constexpr uint32_t MEMORY_LIMIT = 100 * 1024 * 1024; // 100MB + static constexpr int64_t TX_MAX_INSTRUCTIONS = + MinimumSorobanNetworkConfig::TX_MAX_INSTRUCTIONS; + static constexpr int64_t LEDGER_MAX_INSTRUCTIONS = TX_MAX_INSTRUCTIONS; + static constexpr int64_t FEE_RATE_PER_INSTRUCTIONS_INCREMENT = 100; + static constexpr uint32_t MEMORY_LIMIT = + MinimumSorobanNetworkConfig::MEMORY_LIMIT; // 5MB // Ledger access settings - static constexpr uint32_t TX_MAX_READ_LEDGER_ENTRIES = 40; - static constexpr uint32_t TX_MAX_READ_BYTES = 200 * 1024; - static constexpr uint32_t TX_MAX_WRITE_LEDGER_ENTRIES = 20; - static constexpr uint32_t TX_MAX_WRITE_BYTES = 100 * 1024; + static constexpr uint32_t TX_MAX_READ_LEDGER_ENTRIES = + MinimumSorobanNetworkConfig::TX_MAX_READ_LEDGER_ENTRIES; + static constexpr uint32_t TX_MAX_READ_BYTES = + MinimumSorobanNetworkConfig::TX_MAX_READ_BYTES; + static constexpr uint32_t TX_MAX_WRITE_LEDGER_ENTRIES = + MinimumSorobanNetworkConfig::TX_MAX_WRITE_LEDGER_ENTRIES; + static constexpr uint32_t TX_MAX_WRITE_BYTES = + MinimumSorobanNetworkConfig::TX_MAX_WRITE_BYTES; static constexpr uint32_t LEDGER_MAX_READ_LEDGER_ENTRIES = - 10 * TX_MAX_READ_LEDGER_ENTRIES; - static constexpr uint32_t LEDGER_MAX_READ_BYTES = 10 * TX_MAX_READ_BYTES; + TX_MAX_READ_LEDGER_ENTRIES; + static constexpr uint32_t LEDGER_MAX_READ_BYTES = TX_MAX_READ_BYTES; static constexpr uint32_t LEDGER_MAX_WRITE_LEDGER_ENTRIES = - 10 * TX_MAX_WRITE_LEDGER_ENTRIES; - static constexpr uint32_t LEDGER_MAX_WRITE_BYTES = 10 * TX_MAX_WRITE_BYTES; - static constexpr int64_t FEE_READ_LEDGER_ENTRY = 5'000; // 0.02 XLM/max tx - static constexpr int64_t FEE_WRITE_LEDGER_ENTRY = 20'000; // 0.04 XLM/max tx - static constexpr int64_t FEE_READ_1KB = 1'000; // 0.02 XLM/max tx + TX_MAX_WRITE_LEDGER_ENTRIES; + static constexpr uint32_t LEDGER_MAX_WRITE_BYTES = TX_MAX_WRITE_BYTES; + static constexpr int64_t FEE_READ_LEDGER_ENTRY = 5'000; + static constexpr int64_t FEE_WRITE_LEDGER_ENTRY = 20'000; + static constexpr int64_t FEE_READ_1KB = 1'000; static constexpr int64_t BUCKET_LIST_TARGET_SIZE_BYTES = 30LL * 1024 * 1024 * 1024; // 30 GB - static constexpr int64_t BUCKET_LIST_FEE_1KB_BUCKET_LIST_LOW = - 1'000; // 0.01 XLM/max tx - static constexpr int64_t BUCKET_LIST_FEE_1KB_BUCKET_LIST_HIGH = - 10'000; // 0.1 XLM/max tx + static constexpr int64_t BUCKET_LIST_FEE_1KB_BUCKET_LIST_LOW = 1'000; + static constexpr int64_t BUCKET_LIST_FEE_1KB_BUCKET_LIST_HIGH = 10'000; // No growth fee initially to make sure fees are accessible static constexpr uint32_t BUCKET_LIST_WRITE_FEE_GROWTH_FACTOR = 1; @@ -66,25 +95,26 @@ struct InitialSorobanNetworkConfig 30; // 30 day average // Historical data settings - static constexpr int64_t FEE_HISTORICAL_1KB = 100; // 0.001 XLM/max tx + static constexpr int64_t FEE_HISTORICAL_1KB = 100; // Bandwidth settings - static constexpr uint32_t TX_MAX_SIZE_BYTES = 100 * 1024; + static constexpr uint32_t TX_MAX_SIZE_BYTES = + MinimumSorobanNetworkConfig::TX_MAX_SIZE_BYTES; static constexpr uint32_t LEDGER_MAX_TRANSACTION_SIZES_BYTES = - 10 * TX_MAX_SIZE_BYTES; - static constexpr int64_t FEE_TRANSACTION_SIZE_1KB = - 2'000; // 0.02 XLM/max tx + MinimumSorobanNetworkConfig::TX_MAX_SIZE_BYTES; + static constexpr int64_t FEE_TRANSACTION_SIZE_1KB = 2'000; // Contract events settings - static constexpr uint32_t TX_MAX_CONTRACT_EVENTS_SIZE_BYTES = 10 * 1024; + static constexpr uint32_t TX_MAX_CONTRACT_EVENTS_SIZE_BYTES = 1'000; static constexpr int64_t FEE_CONTRACT_EVENTS_SIZE_1KB = 200; // State expiration settings - // 1 year in ledgers - static constexpr uint32_t MAXIMUM_ENTRY_LIFETIME = 6'312'000; + static constexpr uint32_t MAXIMUM_ENTRY_LIFETIME = + MinimumSorobanNetworkConfig::MAXIMUM_ENTRY_LIFETIME; // Live until level 6 - static constexpr uint32_t MINIMUM_PERSISTENT_ENTRY_LIFETIME = 4096; + static constexpr uint32_t MINIMUM_PERSISTENT_ENTRY_LIFETIME = + MinimumSorobanNetworkConfig::MINIMUM_PERSISTENT_ENTRY_LIFETIME; static constexpr uint32_t MINIMUM_TEMP_ENTRY_LIFETIME = 16; static constexpr uint32_t AUTO_BUMP_NUM_LEDGERS = 0; @@ -98,38 +128,7 @@ struct InitialSorobanNetworkConfig static constexpr int64_t TEMP_RENT_RATE_DENOMINATOR = 2'524'800; // General execution settings - static constexpr uint32_t LEDGER_MAX_TX_COUNT = 10; -}; - -// Defines the minimum values allowed for the network configuration -// settings during upgrades. An upgrade that does not follow the minimums -// will be rejected. -struct MinimumSorobanNetworkConfig -{ - static constexpr uint32_t TX_MAX_READ_LEDGER_ENTRIES = 5; - static constexpr uint32_t TX_MAX_READ_BYTES = 5000; - - static constexpr uint32_t TX_MAX_WRITE_LEDGER_ENTRIES = 2; - static constexpr uint32_t TX_MAX_WRITE_BYTES = 5000; - - static constexpr uint32_t LEDGER_MAX_READ_LEDGER_ENTRIES = 5; - static constexpr uint32_t LEDGER_MAX_READ_BYTES = 5000; - static constexpr uint32_t LEDGER_MAX_WRITE_LEDGER_ENTRIES = 2; - static constexpr uint32_t LEDGER_MAX_WRITE_BYTES = 5000; - - static constexpr uint32_t TX_MAX_SIZE_BYTES = 10000; - static constexpr uint32_t LEDGER_MAX_TX_SIZE_BYTES = 10000; - - static constexpr uint32_t TX_MAX_INSTRUCTIONS = 5'000'000; - static constexpr uint32_t LEDGER_MAX_INSTRUCTIONS = 5'000'000; - static constexpr uint32_t MEMORY_LIMIT = 5'000'000; - - static constexpr uint32_t MAX_CONTRACT_DATA_KEY_SIZE_BYTES = 300; - static constexpr uint32_t MAX_CONTRACT_DATA_ENTRY_SIZE_BYTES = 5000; - static constexpr uint32_t MAX_CONTRACT_SIZE = 5000; - - static constexpr uint32_t MINIMUM_PERSISTENT_ENTRY_LIFETIME = 100; - static constexpr uint32_t MAXIMUM_ENTRY_LIFETIME = 535680; // 31 days + static constexpr uint32_t LEDGER_MAX_TX_COUNT = 1; }; // Wrapper for the contract-related network configuration. @@ -228,9 +227,6 @@ class SorobanNetworkConfig uint64_t getAverageBucketListSize() const; #ifdef BUILD_TESTS - uint32_t& maxContractDataKeySizeBytes(); - uint32_t& maxContractDataEntrySizeBytes(); - void setBucketListSnapshotPeriodForTesting(uint32_t period); std::deque const& getBucketListSizeWindowForTesting() const; #endif @@ -251,9 +247,6 @@ class SorobanNetworkConfig // State expiration settings StateExpirationSettings const& stateExpirationSettings() const; -#ifdef BUILD_TESTS - StateExpirationSettings& stateExpirationSettings(); -#endif #endif private: @@ -284,6 +277,16 @@ class SorobanNetworkConfig void writeBucketListSizeWindow(AbstractLedgerTxn& ltxRoot) const; void updateBucketListSizeAverage(); #endif +// Expose all the fields for testing overrides in order to avoid using +// special test-only field setters. +// Access this via +// `app.getLedgerManager().getMutableSorobanNetworkConfig(ltx)`. +// Important: any manual updates to this will be overwritten in case of +// **any** network upgrade - tests that perform updates should only update +// settings via upgrades as well. +#ifdef BUILD_TESTS + public: +#endif uint32_t mMaxContractSizeBytes{}; uint32_t mMaxContractDataKeySizeBytes{}; diff --git a/src/main/Config.cpp b/src/main/Config.cpp index 715e5f8361..f4558a3795 100644 --- a/src/main/Config.cpp +++ b/src/main/Config.cpp @@ -194,20 +194,6 @@ Config::Config() : NODE_SEED(SecretKey::random()) TESTING_UPGRADE_RESERVE = LedgerManager::GENESIS_LEDGER_BASE_RESERVE; TESTING_UPGRADE_MAX_TX_SET_SIZE = 50; TESTING_UPGRADE_FLAGS = 0; - TESTING_LEDGER_MAX_TRANSACTIONS_SIZE_BYTES = - 1 * InitialSorobanNetworkConfig::TX_MAX_SIZE_BYTES; - TESTING_LEDGER_MAX_INSTRUCTIONS = - 1 * InitialSorobanNetworkConfig::TX_MAX_INSTRUCTIONS; - TESTING_LEDGER_MAX_READ_LEDGER_ENTRIES = - 1 * InitialSorobanNetworkConfig::TX_MAX_READ_LEDGER_ENTRIES; - TESTING_LEDGER_MAX_READ_BYTES = - 1 * InitialSorobanNetworkConfig::TX_MAX_READ_BYTES; - TESTING_LEDGER_MAX_WRITE_LEDGER_ENTRIES = - 1 * InitialSorobanNetworkConfig::TX_MAX_WRITE_LEDGER_ENTRIES; - TESTING_LEDGER_MAX_WRITE_BYTES = - 1 * InitialSorobanNetworkConfig::TX_MAX_WRITE_BYTES; - TESTING_LEDGER_MAX_SOROBAN_TX_COUNT = 1; - TESTING_TX_MAX_SIZE_BYTES = InitialSorobanNetworkConfig::TX_MAX_SIZE_BYTES; HTTP_PORT = DEFAULT_PEER_PORT + 1; PUBLIC_HTTP_PORT = false; @@ -277,8 +263,7 @@ Config::Config() : NODE_SEED(SecretKey::random()) #ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION ENABLE_SOROBAN_DIAGNOSTIC_EVENTS = false; - TESTING_MINIMUM_PERSISTENT_ENTRY_LIFETIME = - InitialSorobanNetworkConfig::MINIMUM_PERSISTENT_ENTRY_LIFETIME; + TESTING_MINIMUM_PERSISTENT_ENTRY_LIFETIME = 0; #endif #ifdef BUILD_TESTS diff --git a/src/main/Config.h b/src/main/Config.h index 85d820d001..48d7b481bc 100644 --- a/src/main/Config.h +++ b/src/main/Config.h @@ -470,14 +470,6 @@ class Config : public std::enable_shared_from_this uint32_t TESTING_UPGRADE_RESERVE; // in stroops uint32_t TESTING_UPGRADE_MAX_TX_SET_SIZE; uint32_t TESTING_UPGRADE_FLAGS; - uint32_t TESTING_LEDGER_MAX_TRANSACTIONS_SIZE_BYTES; - int64_t TESTING_LEDGER_MAX_INSTRUCTIONS; - uint32_t TESTING_LEDGER_MAX_READ_LEDGER_ENTRIES; - uint32_t TESTING_LEDGER_MAX_READ_BYTES; - uint32_t TESTING_LEDGER_MAX_WRITE_LEDGER_ENTRIES; - uint32_t TESTING_LEDGER_MAX_WRITE_BYTES; - uint32_t TESTING_LEDGER_MAX_SOROBAN_TX_COUNT; - uint32_t TESTING_TX_MAX_SIZE_BYTES; unsigned short HTTP_PORT; // what port to listen for commands bool PUBLIC_HTTP_PORT; // if you accept commands from not localhost diff --git a/src/overlay/test/OverlayTests.cpp b/src/overlay/test/OverlayTests.cpp index 317165008a..47a11576ca 100644 --- a/src/overlay/test/OverlayTests.cpp +++ b/src/overlay/test/OverlayTests.cpp @@ -149,19 +149,25 @@ TEST_CASE("flow control byte capacity", "[overlay][flowcontrol]") VirtualClock clock; auto cfg1 = getTestConfig(0); auto cfg2 = getTestConfig(1); - cfg1.TESTING_TX_MAX_SIZE_BYTES = txSize; - cfg2.TESTING_TX_MAX_SIZE_BYTES = txSize; - REQUIRE(cfg1.PEER_FLOOD_READING_CAPACITY != cfg1.PEER_FLOOD_READING_CAPACITY_BYTES); auto test = [&](bool shouldRequestMore) { auto app1 = createTestApplication(clock, cfg1, true, false); auto app2 = createTestApplication(clock, cfg2, true, false); - app1->getHerder().setMaxClassicTxSize(txSize); - app2->getHerder().setMaxClassicTxSize(txSize); - app1->start(); - app2->start(); + auto setupApp = [txSize](Application& app) { + app.getHerder().setMaxClassicTxSize(txSize); +#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION + overrideSorobanNetworkConfigForTest(app); + modifySorobanNetworkConfig(app, + [txSize](SorobanNetworkConfig& cfg) { + cfg.mTxMaxSizeBytes = txSize; + }); +#endif + app.start(); + }; + setupApp(*app1); + setupApp(*app2); LoopbackPeerConnection conn(*app1, *app2); testutil::crankSome(clock); @@ -308,13 +314,14 @@ TEST_CASE("flow control byte capacity", "[overlay][flowcontrol]") InitialSorobanNetworkConfig::FEE_TRANSACTION_SIZE_1KB; configEntry.contractBandwidth().txMaxSizeBytes = maxTxSize; configEntry.contractBandwidth().ledgerMaxTxsSizeBytes = - InitialSorobanNetworkConfig:: - LEDGER_MAX_TRANSACTION_SIZES_BYTES; + maxTxSize * 10; res = txtest::makeConfigUpgradeSet(ltx, configUpgradeSet); ltx.commit(); } txtest::executeUpgrade(*app, txtest::makeConfigUpgrade(*res)); }; + upgradeApp(app1, txSize); + upgradeApp(app2, txSize); auto& txsRecv = app2->getMetrics().NewTimer({"overlay", "recv", "transaction"}); @@ -591,7 +598,6 @@ TEST_CASE("drop peers that dont respect capacity", "[overlay][flowcontrol]") { cfg1.PEER_FLOOD_READING_CAPACITY_BYTES = txSize + 1; cfg1.FLOW_CONTROL_SEND_MORE_BATCH_SIZE_BYTES = 1; - cfg1.TESTING_TX_MAX_SIZE_BYTES = txSize; } else { @@ -604,6 +610,15 @@ TEST_CASE("drop peers that dont respect capacity", "[overlay][flowcontrol]") cfg1.PEER_READING_CAPACITY = 2; } auto app1 = createTestApplication(clock, cfg1, true, false); +#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION + if (fcBytes) + { + modifySorobanNetworkConfig(*app1, + [txSize](SorobanNetworkConfig& cfg) { + cfg.mTxMaxSizeBytes = txSize; + }); + } +#endif auto app2 = createTestApplication(clock, cfg2, true, false); app1->getHerder().setMaxClassicTxSize(txSize); app2->getHerder().setMaxClassicTxSize(txSize); @@ -2134,8 +2149,6 @@ TEST_CASE("overlay flow control", "[overlay][flowcontrol]") MinimumSorobanNetworkConfig::TX_MAX_SIZE_BYTES + 100; cfg.FLOW_CONTROL_SEND_MORE_BATCH_SIZE_BYTES = 100; cfg.TESTING_UPGRADE_MAX_TX_SET_SIZE = 1000; - cfg.TESTING_TX_MAX_SIZE_BYTES = - MinimumSorobanNetworkConfig::TX_MAX_SIZE_BYTES; configs.push_back(cfg); } @@ -2151,6 +2164,15 @@ TEST_CASE("overlay flow control", "[overlay][flowcontrol]") simulation->addPendingConnection(vNode1NodeID, vNode2NodeID); simulation->addPendingConnection(vNode2NodeID, vNode3NodeID); simulation->addPendingConnection(vNode3NodeID, vNode1NodeID); +#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION + for (auto& node : simulation->getNodes()) + { + modifySorobanNetworkConfig(*node, [](SorobanNetworkConfig& cfg) { + cfg.mTxMaxSizeBytes = + MinimumSorobanNetworkConfig::TX_MAX_SIZE_BYTES; + }); + } +#endif simulation->startAllNodes(); }; diff --git a/src/test/TestUtils.cpp b/src/test/TestUtils.cpp index 4695656c4b..23f586728a 100644 --- a/src/test/TestUtils.cpp +++ b/src/test/TestUtils.cpp @@ -193,4 +193,44 @@ genesis(int minute, int second) return VirtualClock::tmToSystemPoint( getTestDateTime(1, 7, 2014, 0, minute, second)); } +#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION +void +modifySorobanNetworkConfig(Application& app, + std::function modifyFn) +{ + LedgerTxn ltx(app.getLedgerTxnRoot()); + auto& cfg = app.getLedgerManager().getMutableSorobanNetworkConfig(ltx); + modifyFn(cfg); +} + +void +overrideSorobanNetworkConfigForTest(Application& app) +{ + modifySorobanNetworkConfig(app, [](SorobanNetworkConfig& cfg) { + cfg.mMaxContractSizeBytes = 64 * 1024; + cfg.mMaxContractDataEntrySizeBytes = 64 * 1024; + + cfg.mTxMaxSizeBytes = 100 * 1024; + cfg.mLedgerMaxTransactionsSizeBytes = cfg.mTxMaxSizeBytes * 10; + + cfg.mTxMaxInstructions = 100'000'000; + cfg.mLedgerMaxInstructions = cfg.mTxMaxInstructions * 10; + cfg.mTxMemoryLimit = 100 * 1024 * 1024; + + cfg.mTxMaxReadLedgerEntries = 40; + cfg.mTxMaxReadBytes = 200 * 1024; + + cfg.mTxMaxWriteLedgerEntries = 20; + cfg.mTxMaxWriteBytes = 100 * 1024; + + cfg.mLedgerMaxReadLedgerEntries = cfg.mTxMaxReadLedgerEntries * 10; + cfg.mLedgerMaxReadBytes = cfg.mTxMaxReadBytes * 10; + cfg.mLedgerMaxWriteLedgerEntries = cfg.mTxMaxWriteLedgerEntries * 10; + cfg.mLedgerMaxWriteBytes = cfg.mTxMaxWriteBytes * 10; + + cfg.mStateExpirationSettings.maxEntryExpiration = 6'312'000; + cfg.mLedgerMaxTxCount = 100; + }); +} +#endif } diff --git a/src/test/TestUtils.h b/src/test/TestUtils.h index 946e237fb8..e6ffcf3f71 100644 --- a/src/test/TestUtils.h +++ b/src/test/TestUtils.h @@ -92,4 +92,14 @@ std::tm getTestDateTime(int day, int month, int year, int hour, int minute, int second); VirtualClock::system_time_point genesis(int minute, int second); + +#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION +// Override Soroban network config defaults with generous settings suitable +// for most of the unit tests (unless the test is meant to exercise the +// configuration limits). +void overrideSorobanNetworkConfigForTest(Application& app); +void +modifySorobanNetworkConfig(Application& app, + std::function modifyFn); +#endif } diff --git a/src/testdata/ledger-close-meta-v2-protocol-20.json b/src/testdata/ledger-close-meta-v2-protocol-20.json index 03562b38cf..f15a237fab 100644 --- a/src/testdata/ledger-close-meta-v2-protocol-20.json +++ b/src/testdata/ledger-close-meta-v2-protocol-20.json @@ -6,24 +6,24 @@ "v": 0 }, "ledgerHeader": { - "hash": "659fa6b436dc39256354cecf7ec65884aa567de52cdeff1bcd7868ba899034f3", + "hash": "cda5a15125767a9a799b93057936af8c8e9618f572af49e09aa512342f362157", "header": { "ledgerVersion": 20, - "previousLedgerHash": "4fd8bb2d20479737140fbb6d13d6403f15325ca218cbb1c2100c2504cf850ade", + "previousLedgerHash": "307fcf0d1508051dc71b55b05e480a18daf46d758efa3fa59abea51fcd578c2b", "scpValue": { - "txSetHash": "ba5a1172ff7a59e53e6fcce5f5501d8e6e7ce5c63690ee801575af7b4186f3d2", + "txSetHash": "626f2bb7317e540e963d27a343aae25d52aae8724ee662a732fb01b012f1764e", "closeTime": 0, "upgrades": [], "ext": { "v": "STELLAR_VALUE_SIGNED", "lcValueSignature": { "nodeID": "GDDOUW25MRFLNXQMN3OODP6JQEXSGLMHAFZV4XPQ2D3GA4QFIDMEJG2O", - "signature": "d66941ce90125e3bccbcfeb10cc8ff84ef871b458f16d8184d9c7ca5610c850c9662578e63dcde336785ad1c6da9e27c9a8e13c5fa78619831c475316f3ced0d" + "signature": "9a4de4e29305c8646b5d0bb729197c01cd797a6207fe15a8d447abb22156777c079ff0ea5afce8877ea39946dee6cfc63ac987a3f94f6c1e85962ec0055ca70f" } } }, - "txSetResultHash": "cd1398cda325d4eada631301e6501421cda30fd0b43da3e5d0ffb26caf073b0a", - "bucketListHash": "b79edf213f4385c3bd739d96b99ca2ab68b9dd4084b4a6fb168f2243300016e9", + "txSetResultHash": "cf65fee29665ff0c2a6910b24c420a487a7416ccd79c683b48aac1d45ad21faa", + "bucketListHash": "c9f98c81817139f78e1af89d45ba1991d8d3fbd662670ff53c1496ab1207da7e", "ledgerSeq": 6, "totalCoins": 1000000000000000000, "feePool": 800, @@ -49,7 +49,7 @@ "txSet": { "v": 1, "v1TxSet": { - "previousLedgerHash": "4fd8bb2d20479737140fbb6d13d6403f15325ca218cbb1c2100c2504cf850ade", + "previousLedgerHash": "307fcf0d1508051dc71b55b05e480a18daf46d758efa3fa59abea51fcd578c2b", "phases": [ { "v": 0, @@ -185,43 +185,22 @@ "txProcessing": [ { "result": { - "transactionHash": "66efe325ead9f52082c8908b7813bd96793fd5ff0f1e50fdc50b23f68938dd4d", + "transactionHash": "0db2322d85e9d8ea2421559922bb6107429650ebdad304c907480853d465c10d", "result": { - "feeCharged": 300, + "feeCharged": 100, "result": { - "code": "txFEE_BUMP_INNER_SUCCESS", - "innerResultPair": { - "transactionHash": "5ab197acffd4b32d320df39b2b1f76246e2279fa8070c6c690cca1343e5e7e0b", - "result": { - "feeCharged": 200, - "result": { - "code": "txSUCCESS", - "results": [ - { - "code": "opINNER", - "tr": { - "type": "PAYMENT", - "paymentResult": { - "code": "PAYMENT_SUCCESS" - } - } - }, - { - "code": "opINNER", - "tr": { - "type": "PAYMENT", - "paymentResult": { - "code": "PAYMENT_SUCCESS" - } - } - } - ] - }, - "ext": { - "v": 0 + "code": "txSUCCESS", + "results": [ + { + "code": "opINNER", + "tr": { + "type": "PAYMENT", + "paymentResult": { + "code": "PAYMENT_SUCCESS" + } } } - } + ] }, "ext": { "v": 0 @@ -232,13 +211,13 @@ { "type": "LEDGER_ENTRY_STATE", "state": { - "lastModifiedLedgerSeq": 3, + "lastModifiedLedgerSeq": 4, "data": { "type": "ACCOUNT", "account": { - "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", - "balance": 400000000, - "seqNum": 12884901888, + "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", + "balance": 999999998999989700, + "seqNum": 3, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -246,7 +225,31 @@ "thresholds": "01000000", "signers": [], "ext": { - "v": 0 + "v": 1, + "v1": { + "liabilities": { + "buying": 0, + "selling": 0 + }, + "ext": { + "v": 2, + "v2": { + "numSponsored": 0, + "numSponsoring": 0, + "signerSponsoringIDs": [], + "ext": { + "v": 3, + "v3": { + "ext": { + "v": 0 + }, + "seqLedger": 4, + "seqTime": 0 + } + } + } + } + } } } }, @@ -262,9 +265,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", - "balance": 399999700, - "seqNum": 12884901888, + "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", + "balance": 999999998999989600, + "seqNum": 3, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -272,7 +275,31 @@ "thresholds": "01000000", "signers": [], "ext": { - "v": 0 + "v": 1, + "v1": { + "liabilities": { + "buying": 0, + "selling": 0 + }, + "ext": { + "v": 2, + "v2": { + "numSponsored": 0, + "numSponsoring": 0, + "signerSponsoringIDs": [], + "ext": { + "v": 3, + "v3": { + "ext": { + "v": 0 + }, + "seqLedger": 4, + "seqTime": 0 + } + } + } + } + } } } }, @@ -296,61 +323,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", - "balance": 399999700, - "seqNum": 12884901888, - "numSubEntries": 0, - "inflationDest": null, - "flags": 0, - "homeDomain": "", - "thresholds": "01000000", - "signers": [], - "ext": { - "v": 0 - } - } - }, - "ext": { - "v": 0 - } - } - }, - { - "type": "LEDGER_ENTRY_UPDATED", - "updated": { - "lastModifiedLedgerSeq": 6, - "data": { - "type": "ACCOUNT", - "account": { - "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", - "balance": 399999700, - "seqNum": 12884901888, - "numSubEntries": 0, - "inflationDest": null, - "flags": 0, - "homeDomain": "", - "thresholds": "01000000", - "signers": [], - "ext": { - "v": 0 - } - } - }, - "ext": { - "v": 0 - } - } - }, - { - "type": "LEDGER_ENTRY_STATE", - "state": { - "lastModifiedLedgerSeq": 4, - "data": { - "type": "ACCOUNT", - "account": { - "accountID": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q", - "balance": 200010000, - "seqNum": 17179869184, + "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", + "balance": 999999998999989600, + "seqNum": 3, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -358,7 +333,31 @@ "thresholds": "01000000", "signers": [], "ext": { - "v": 0 + "v": 1, + "v1": { + "liabilities": { + "buying": 0, + "selling": 0 + }, + "ext": { + "v": 2, + "v2": { + "numSponsored": 0, + "numSponsoring": 0, + "signerSponsoringIDs": [], + "ext": { + "v": 3, + "v3": { + "ext": { + "v": 0 + }, + "seqLedger": 4, + "seqTime": 0 + } + } + } + } + } } } }, @@ -374,9 +373,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q", - "balance": 200010000, - "seqNum": 17179869185, + "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", + "balance": 999999998999989600, + "seqNum": 4, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -424,20 +423,45 @@ { "type": "LEDGER_ENTRY_STATE", "state": { - "lastModifiedLedgerSeq": 5, + "lastModifiedLedgerSeq": 6, "data": { - "type": "TRUSTLINE", - "trustLine": { - "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", - "asset": { - "assetCode": "CUR1", - "issuer": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q" - }, - "balance": 0, - "limit": 100, - "flags": 1, + "type": "ACCOUNT", + "account": { + "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", + "balance": 999999998999989600, + "seqNum": 4, + "numSubEntries": 0, + "inflationDest": null, + "flags": 0, + "homeDomain": "", + "thresholds": "01000000", + "signers": [], "ext": { - "v": 0 + "v": 1, + "v1": { + "liabilities": { + "buying": 0, + "selling": 0 + }, + "ext": { + "v": 2, + "v2": { + "numSponsored": 0, + "numSponsoring": 0, + "signerSponsoringIDs": [], + "ext": { + "v": 3, + "v3": { + "ext": { + "v": 0 + }, + "seqLedger": 6, + "seqTime": 0 + } + } + } + } + } } } }, @@ -451,18 +475,43 @@ "updated": { "lastModifiedLedgerSeq": 6, "data": { - "type": "TRUSTLINE", - "trustLine": { - "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", - "asset": { - "assetCode": "CUR1", - "issuer": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q" - }, - "balance": 50, - "limit": 100, - "flags": 1, + "type": "ACCOUNT", + "account": { + "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", + "balance": 999999998999988600, + "seqNum": 4, + "numSubEntries": 0, + "inflationDest": null, + "flags": 0, + "homeDomain": "", + "thresholds": "01000000", + "signers": [], "ext": { - "v": 0 + "v": 1, + "v1": { + "liabilities": { + "buying": 0, + "selling": 0 + }, + "ext": { + "v": 2, + "v2": { + "numSponsored": 0, + "numSponsoring": 0, + "signerSponsoringIDs": [], + "ext": { + "v": 3, + "v3": { + "ext": { + "v": 0 + }, + "seqLedger": 6, + "seqTime": 0 + } + } + } + } + } } } }, @@ -470,28 +519,49 @@ "v": 0 } } - } - ] - }, - { - "changes": [ + }, { "type": "LEDGER_ENTRY_STATE", "state": { - "lastModifiedLedgerSeq": 6, + "lastModifiedLedgerSeq": 5, "data": { - "type": "TRUSTLINE", - "trustLine": { + "type": "ACCOUNT", + "account": { "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", - "asset": { - "assetCode": "CUR1", - "issuer": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q" - }, - "balance": 50, - "limit": 100, - "flags": 1, + "balance": 399999900, + "seqNum": 8589934593, + "numSubEntries": 1, + "inflationDest": null, + "flags": 0, + "homeDomain": "", + "thresholds": "01000000", + "signers": [], "ext": { - "v": 0 + "v": 1, + "v1": { + "liabilities": { + "buying": 0, + "selling": 0 + }, + "ext": { + "v": 2, + "v2": { + "numSponsored": 0, + "numSponsoring": 0, + "signerSponsoringIDs": [], + "ext": { + "v": 3, + "v3": { + "ext": { + "v": 0 + }, + "seqLedger": 5, + "seqTime": 0 + } + } + } + } + } } } }, @@ -505,18 +575,43 @@ "updated": { "lastModifiedLedgerSeq": 6, "data": { - "type": "TRUSTLINE", - "trustLine": { + "type": "ACCOUNT", + "account": { "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", - "asset": { - "assetCode": "CUR1", - "issuer": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q" - }, - "balance": 100, - "limit": 100, - "flags": 1, + "balance": 400000900, + "seqNum": 8589934593, + "numSubEntries": 1, + "inflationDest": null, + "flags": 0, + "homeDomain": "", + "thresholds": "01000000", + "signers": [], "ext": { - "v": 0 + "v": 1, + "v1": { + "liabilities": { + "buying": 0, + "selling": 0 + }, + "ext": { + "v": 2, + "v2": { + "numSponsored": 0, + "numSponsoring": 0, + "signerSponsoringIDs": [], + "ext": { + "v": 3, + "v3": { + "ext": { + "v": 0 + }, + "seqLedger": 5, + "seqTime": 0 + } + } + } + } + } } } }, @@ -545,22 +640,43 @@ }, { "result": { - "transactionHash": "0db2322d85e9d8ea2421559922bb6107429650ebdad304c907480853d465c10d", + "transactionHash": "66efe325ead9f52082c8908b7813bd96793fd5ff0f1e50fdc50b23f68938dd4d", "result": { - "feeCharged": 100, + "feeCharged": 300, "result": { - "code": "txSUCCESS", - "results": [ - { - "code": "opINNER", - "tr": { - "type": "PAYMENT", - "paymentResult": { - "code": "PAYMENT_SUCCESS" - } + "code": "txFEE_BUMP_INNER_SUCCESS", + "innerResultPair": { + "transactionHash": "5ab197acffd4b32d320df39b2b1f76246e2279fa8070c6c690cca1343e5e7e0b", + "result": { + "feeCharged": 200, + "result": { + "code": "txSUCCESS", + "results": [ + { + "code": "opINNER", + "tr": { + "type": "PAYMENT", + "paymentResult": { + "code": "PAYMENT_SUCCESS" + } + } + }, + { + "code": "opINNER", + "tr": { + "type": "PAYMENT", + "paymentResult": { + "code": "PAYMENT_SUCCESS" + } + } + } + ] + }, + "ext": { + "v": 0 } } - ] + } }, "ext": { "v": 0 @@ -571,13 +687,13 @@ { "type": "LEDGER_ENTRY_STATE", "state": { - "lastModifiedLedgerSeq": 4, + "lastModifiedLedgerSeq": 3, "data": { "type": "ACCOUNT", "account": { - "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", - "balance": 999999998999989700, - "seqNum": 3, + "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", + "balance": 400000000, + "seqNum": 12884901888, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -585,31 +701,7 @@ "thresholds": "01000000", "signers": [], "ext": { - "v": 1, - "v1": { - "liabilities": { - "buying": 0, - "selling": 0 - }, - "ext": { - "v": 2, - "v2": { - "numSponsored": 0, - "numSponsoring": 0, - "signerSponsoringIDs": [], - "ext": { - "v": 3, - "v3": { - "ext": { - "v": 0 - }, - "seqLedger": 4, - "seqTime": 0 - } - } - } - } - } + "v": 0 } } }, @@ -625,9 +717,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", - "balance": 999999998999989600, - "seqNum": 3, + "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", + "balance": 399999700, + "seqNum": 12884901888, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -635,31 +727,7 @@ "thresholds": "01000000", "signers": [], "ext": { - "v": 1, - "v1": { - "liabilities": { - "buying": 0, - "selling": 0 - }, - "ext": { - "v": 2, - "v2": { - "numSponsored": 0, - "numSponsoring": 0, - "signerSponsoringIDs": [], - "ext": { - "v": 3, - "v3": { - "ext": { - "v": 0 - }, - "seqLedger": 4, - "seqTime": 0 - } - } - } - } - } + "v": 0 } } }, @@ -683,9 +751,9 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", - "balance": 999999998999989600, - "seqNum": 3, + "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", + "balance": 399999700, + "seqNum": 12884901888, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -693,31 +761,7 @@ "thresholds": "01000000", "signers": [], "ext": { - "v": 1, - "v1": { - "liabilities": { - "buying": 0, - "selling": 0 - }, - "ext": { - "v": 2, - "v2": { - "numSponsored": 0, - "numSponsoring": 0, - "signerSponsoringIDs": [], - "ext": { - "v": 3, - "v3": { - "ext": { - "v": 0 - }, - "seqLedger": 4, - "seqTime": 0 - } - } - } - } - } + "v": 0 } } }, @@ -733,9 +777,61 @@ "data": { "type": "ACCOUNT", "account": { - "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", - "balance": 999999998999989600, - "seqNum": 4, + "accountID": "GCAEBM3GKNR6SV6N73FSGBXU6NSMZ2URQVMJQHXFQFY2PJPX6YBCSAKZ", + "balance": 399999700, + "seqNum": 12884901888, + "numSubEntries": 0, + "inflationDest": null, + "flags": 0, + "homeDomain": "", + "thresholds": "01000000", + "signers": [], + "ext": { + "v": 0 + } + } + }, + "ext": { + "v": 0 + } + } + }, + { + "type": "LEDGER_ENTRY_STATE", + "state": { + "lastModifiedLedgerSeq": 4, + "data": { + "type": "ACCOUNT", + "account": { + "accountID": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q", + "balance": 200010000, + "seqNum": 17179869184, + "numSubEntries": 0, + "inflationDest": null, + "flags": 0, + "homeDomain": "", + "thresholds": "01000000", + "signers": [], + "ext": { + "v": 0 + } + } + }, + "ext": { + "v": 0 + } + } + }, + { + "type": "LEDGER_ENTRY_UPDATED", + "updated": { + "lastModifiedLedgerSeq": 6, + "data": { + "type": "ACCOUNT", + "account": { + "accountID": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q", + "balance": 200010000, + "seqNum": 17179869185, "numSubEntries": 0, "inflationDest": null, "flags": 0, @@ -783,45 +879,20 @@ { "type": "LEDGER_ENTRY_STATE", "state": { - "lastModifiedLedgerSeq": 6, + "lastModifiedLedgerSeq": 5, "data": { - "type": "ACCOUNT", - "account": { - "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", - "balance": 999999998999989600, - "seqNum": 4, - "numSubEntries": 0, - "inflationDest": null, - "flags": 0, - "homeDomain": "", - "thresholds": "01000000", - "signers": [], + "type": "TRUSTLINE", + "trustLine": { + "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", + "asset": { + "assetCode": "CUR1", + "issuer": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q" + }, + "balance": 0, + "limit": 100, + "flags": 1, "ext": { - "v": 1, - "v1": { - "liabilities": { - "buying": 0, - "selling": 0 - }, - "ext": { - "v": 2, - "v2": { - "numSponsored": 0, - "numSponsoring": 0, - "signerSponsoringIDs": [], - "ext": { - "v": 3, - "v3": { - "ext": { - "v": 0 - }, - "seqLedger": 6, - "seqTime": 0 - } - } - } - } - } + "v": 0 } } }, @@ -835,43 +906,18 @@ "updated": { "lastModifiedLedgerSeq": 6, "data": { - "type": "ACCOUNT", - "account": { - "accountID": "GC4EFXBN6BEENDAX7PBW5PGIIIVH3INMD3OEPQASXOLGOHVVP7ZEMG7X", - "balance": 999999998999988600, - "seqNum": 4, - "numSubEntries": 0, - "inflationDest": null, - "flags": 0, - "homeDomain": "", - "thresholds": "01000000", - "signers": [], + "type": "TRUSTLINE", + "trustLine": { + "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", + "asset": { + "assetCode": "CUR1", + "issuer": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q" + }, + "balance": 50, + "limit": 100, + "flags": 1, "ext": { - "v": 1, - "v1": { - "liabilities": { - "buying": 0, - "selling": 0 - }, - "ext": { - "v": 2, - "v2": { - "numSponsored": 0, - "numSponsoring": 0, - "signerSponsoringIDs": [], - "ext": { - "v": 3, - "v3": { - "ext": { - "v": 0 - }, - "seqLedger": 6, - "seqTime": 0 - } - } - } - } - } + "v": 0 } } }, @@ -879,49 +925,28 @@ "v": 0 } } - }, + } + ] + }, + { + "changes": [ { "type": "LEDGER_ENTRY_STATE", "state": { - "lastModifiedLedgerSeq": 5, + "lastModifiedLedgerSeq": 6, "data": { - "type": "ACCOUNT", - "account": { + "type": "TRUSTLINE", + "trustLine": { "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", - "balance": 399999900, - "seqNum": 8589934593, - "numSubEntries": 1, - "inflationDest": null, - "flags": 0, - "homeDomain": "", - "thresholds": "01000000", - "signers": [], + "asset": { + "assetCode": "CUR1", + "issuer": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q" + }, + "balance": 50, + "limit": 100, + "flags": 1, "ext": { - "v": 1, - "v1": { - "liabilities": { - "buying": 0, - "selling": 0 - }, - "ext": { - "v": 2, - "v2": { - "numSponsored": 0, - "numSponsoring": 0, - "signerSponsoringIDs": [], - "ext": { - "v": 3, - "v3": { - "ext": { - "v": 0 - }, - "seqLedger": 5, - "seqTime": 0 - } - } - } - } - } + "v": 0 } } }, @@ -935,43 +960,18 @@ "updated": { "lastModifiedLedgerSeq": 6, "data": { - "type": "ACCOUNT", - "account": { + "type": "TRUSTLINE", + "trustLine": { "accountID": "GB6MXQ5262ZJGDQNA6BL4TWE5SADVZXIKLPELFXKUE27X4SQTGQS44ZB", - "balance": 400000900, - "seqNum": 8589934593, - "numSubEntries": 1, - "inflationDest": null, - "flags": 0, - "homeDomain": "", - "thresholds": "01000000", - "signers": [], + "asset": { + "assetCode": "CUR1", + "issuer": "GCGE27HU2VYQANKL2VZWLCAOJYMEFST5DXPBWQ7BRRPOHUPK626DNG4Q" + }, + "balance": 100, + "limit": 100, + "flags": 1, "ext": { - "v": 1, - "v1": { - "liabilities": { - "buying": 0, - "selling": 0 - }, - "ext": { - "v": 2, - "v2": { - "numSponsored": 0, - "numSponsoring": 0, - "signerSponsoringIDs": [], - "ext": { - "v": 3, - "v3": { - "ext": { - "v": 0 - }, - "seqLedger": 5, - "seqTime": 0 - } - } - } - } - } + "v": 0 } } }, diff --git a/src/transactions/TransactionFrame.cpp b/src/transactions/TransactionFrame.cpp index eae2d13e25..3ec40b0acc 100644 --- a/src/transactions/TransactionFrame.cpp +++ b/src/transactions/TransactionFrame.cpp @@ -197,7 +197,8 @@ TransactionFrame::getResources() const return Resource({opCount, r.instructions, txSize, r.readBytes, r.writeBytes, - static_cast(r.footprint.readOnly.size()), + static_cast(r.footprint.readOnly.size() + + r.footprint.readWrite.size()), static_cast(r.footprint.readWrite.size())}); } #endif diff --git a/src/transactions/test/InvokeHostFunctionTests.cpp b/src/transactions/test/InvokeHostFunctionTests.cpp index 3a5d4cef70..eb22d9ade2 100644 --- a/src/transactions/test/InvokeHostFunctionTests.cpp +++ b/src/transactions/test/InvokeHostFunctionTests.cpp @@ -199,8 +199,11 @@ submitTxToCreateContract(Application& app, Operation const& op, } static xdr::xvector -deployContractWithSourceAccount(Application& app, RustBuf const& contractWasm, - uint256 salt = sha256("salt")) +deployContractWithSourceAccountWithResources(Application& app, + RustBuf const& contractWasm, + SorobanResources uploadResources, + SorobanResources createResources, + uint256 salt = sha256("salt")) { auto root = TestAccount::createRoot(app); @@ -214,13 +217,7 @@ deployContractWithSourceAccount(Application& app, RustBuf const& contractWasm, LedgerKey contractCodeLedgerKey; contractCodeLedgerKey.type(CONTRACT_CODE); contractCodeLedgerKey.contractCode().hash = sha256(uploadHF.wasm()); - - SorobanResources uploadResources; uploadResources.footprint.readWrite = {contractCodeLedgerKey}; - uploadResources.instructions = 200'000; - uploadResources.readBytes = 1000; - uploadResources.writeBytes = 5000; - uploadResources.contractEventsSizeBytes = 0; submitTxToUploadWasm(app, uploadOp, uploadResources, contractCodeLedgerKey.contractCode().hash, uploadHF.wasm(), 100'000, 1'200); @@ -287,13 +284,8 @@ deployContractWithSourceAccount(Application& app, RustBuf const& contractWasm, contractSourceRefLedgerKey.contractData().durability = CONTRACT_INSTANCE_CONTRACT_DURABILITY; - SorobanResources createResources; createResources.footprint.readOnly = {contractCodeLedgerKey}; createResources.footprint.readWrite = {contractSourceRefLedgerKey}; - createResources.instructions = 200'000; - createResources.readBytes = 5000; - createResources.writeBytes = 5000; - createResources.contractEventsSizeBytes = 0; submitTxToCreateContract( app, createOp, createResources, contractID, scContractSourceRefKey, @@ -315,12 +307,31 @@ deployContractWithSourceAccount(Application& app, RustBuf const& contractWasm, return {contractSourceRefLedgerKey, contractCodeLedgerKey}; } +static xdr::xvector +deployContractWithSourceAccount(Application& app, RustBuf const& contractWasm, + uint256 salt = sha256("salt")) +{ + SorobanResources uploadResources{}; + uploadResources.instructions = 200'000; + uploadResources.readBytes = 1000; + uploadResources.writeBytes = 5000; + + SorobanResources createResources{}; + createResources.instructions = 200'000; + createResources.readBytes = 5000; + createResources.writeBytes = 5000; + return deployContractWithSourceAccountWithResources( + app, contractWasm, uploadResources, createResources, salt); +} + TEST_CASE("basic contract invocation", "[tx][soroban]") { VirtualClock clock; auto cfg = getTestConfig(); cfg.EXPERIMENTAL_BUCKETLIST_DB = false; auto app = createTestApplication(clock, cfg); + overrideSorobanNetworkConfigForTest(*app); + auto root = TestAccount::createRoot(*app); int64_t initBalance = root.getBalance(); @@ -589,10 +600,17 @@ TEST_CASE("contract storage", "[tx][soroban]") { VirtualClock clock; auto app = createTestApplication(clock, getTestConfig()); + overrideSorobanNetworkConfigForTest(*app); auto root = TestAccount::createRoot(*app); auto const contractDataWasm = rust_bridge::get_test_wasm_contract_data(); auto contractKeys = deployContractWithSourceAccount(*app, contractDataWasm); auto const& contractID = contractKeys[0].contractData().contract; + LedgerTxn ltxCfg(app->getLedgerTxnRoot()); + SorobanNetworkConfig const& sorobanConfig = + app->getLedgerManager().getSorobanNetworkConfig(ltxCfg); + auto const& stateExpirationSettings = + sorobanConfig.stateExpirationSettings(); + ltxCfg.commit(); auto checkContractData = [&](SCVal const& key, ContractDataDurability type, SCVal const* val) { LedgerTxn ltx(app->getLedgerTxnRoot()); @@ -969,25 +987,15 @@ TEST_CASE("contract storage", "[tx][soroban]") getExpirationLedger(ltxe.current())); }; - SorobanNetworkConfig refConfig; - { - LedgerTxn ltx(app->getLedgerTxnRoot()); - refConfig = app->getLedgerManager().getSorobanNetworkConfig(ltx); - } - - auto const& stateExpirationSettings = refConfig.stateExpirationSettings(); auto ledgerSeq = getLedgerSeq(*app); // Autobump is disabled by default, enable it for some tests auto enableAutobump = [&]() { - auto autobumpAmount = 10; - LedgerTxn ltx(app->getLedgerTxnRoot()); - auto networkConfig = - app->getLedgerManager().getSorobanNetworkConfig(ltx); - auto newStateExpirationSettings = stateExpirationSettings; - newStateExpirationSettings.autoBumpLedgers = autobumpAmount; - networkConfig.stateExpirationSettings() = newStateExpirationSettings; - app->getLedgerManager().setSorobanNetworkConfig(networkConfig); + uint32_t autobumpAmount = 10; + modifySorobanNetworkConfig( + *app, [autobumpAmount](SorobanNetworkConfig& cfg) { + cfg.mStateExpirationSettings.autoBumpLedgers = autobumpAmount; + }); return autobumpAmount; }; @@ -1012,9 +1020,9 @@ TEST_CASE("contract storage", "[tx][soroban]") SECTION("failure: entry exceeds max size") { - refConfig.maxContractDataKeySizeBytes() = 300; - refConfig.maxContractDataEntrySizeBytes() = 1; - app->getLedgerManager().setSorobanNetworkConfig(refConfig); + modifySorobanNetworkConfig(*app, [](SorobanNetworkConfig& cfg) { + cfg.mMaxContractDataEntrySizeBytes = 1; + }); // this fails due to the contract code itself exceeding the entry limit putWithFootprint( "key2", 2, contractKeys, @@ -1051,7 +1059,7 @@ TEST_CASE("contract storage", "[tx][soroban]") SECTION("contract instance and wasm expiration") { - auto originalExpectedExpiration = + uint32_t originalExpectedExpiration = stateExpirationSettings.minPersistentEntryExpiration + ledgerSeq - 1; @@ -1498,6 +1506,7 @@ TEST_CASE("failed invocation with diagnostics", "[tx][soroban]") auto cfg = getTestConfig(); cfg.ENABLE_SOROBAN_DIAGNOSTIC_EVENTS = true; auto app = createTestApplication(clock, cfg); + overrideSorobanNetworkConfigForTest(*app); auto root = TestAccount::createRoot(*app); auto const addI32Wasm = rust_bridge::get_test_wasm_add_i32(); @@ -1558,6 +1567,7 @@ TEST_CASE("complex contract", "[tx][soroban]") auto cfg = getTestConfig(); cfg.ENABLE_SOROBAN_DIAGNOSTIC_EVENTS = enableDiagnostics; auto app = createTestApplication(clock, cfg); + overrideSorobanNetworkConfigForTest(*app); auto root = TestAccount::createRoot(*app); auto const complexWasm = rust_bridge::get_test_wasm_complex(); @@ -1660,6 +1670,7 @@ TEST_CASE("Stellar asset contract XLM transfer", { VirtualClock clock; auto app = createTestApplication(clock, getTestConfig()); + overrideSorobanNetworkConfigForTest(*app); auto root = TestAccount::createRoot(*app); auto xlm = txtest::makeNativeAsset(); @@ -1786,6 +1797,7 @@ TEST_CASE("errors roll back", "[tx][soroban]") auto call_fn_check_failure = [&](std::string const& name) { VirtualClock clock; auto app = createTestApplication(clock, getTestConfig()); + overrideSorobanNetworkConfigForTest(*app); auto root = TestAccount::createRoot(*app); auto const errWasm = rust_bridge::get_test_wasm_err(); @@ -1827,7 +1839,7 @@ TEST_CASE("errors roll back", "[tx][soroban]") } static void -overrideSettingsToMin(Application& app) +overrideNetworkSettingsToMin(Application& app) { LedgerTxn ltx(app.getLedgerTxnRoot()); @@ -1850,36 +1862,33 @@ overrideSettingsToMin(Application& app) .data.configSetting() .contractDataEntrySizeBytes() = MinimumSorobanNetworkConfig::MAX_CONTRACT_DATA_ENTRY_SIZE_BYTES; + auto& bandwidth = + ltx.load(configSettingKey( + ConfigSettingID::CONFIG_SETTING_CONTRACT_BANDWIDTH_V0)) + .current() + .data.configSetting() + .contractBandwidth(); - ConfigSettingContractBandwidthV0 bandwidth; - bandwidth.ledgerMaxTxsSizeBytes = - MinimumSorobanNetworkConfig::LEDGER_MAX_TX_SIZE_BYTES; bandwidth.txMaxSizeBytes = MinimumSorobanNetworkConfig::TX_MAX_SIZE_BYTES; - ltx.load(configSettingKey( - ConfigSettingID::CONFIG_SETTING_CONTRACT_BANDWIDTH_V0)) - .current() - .data.configSetting() - .contractBandwidth() = bandwidth; - - ConfigSettingContractComputeV0 compute; - compute.ledgerMaxInstructions = - MinimumSorobanNetworkConfig::LEDGER_MAX_INSTRUCTIONS; + bandwidth.ledgerMaxTxsSizeBytes = bandwidth.txMaxSizeBytes; + + auto& compute = + ltx.load(configSettingKey( + ConfigSettingID::CONFIG_SETTING_CONTRACT_COMPUTE_V0)) + .current() + .data.configSetting() + .contractCompute(); compute.txMaxInstructions = MinimumSorobanNetworkConfig::TX_MAX_INSTRUCTIONS; + compute.ledgerMaxInstructions = compute.txMaxInstructions; compute.txMemoryLimit = MinimumSorobanNetworkConfig::MEMORY_LIMIT; - ltx.load(configSettingKey( - ConfigSettingID::CONFIG_SETTING_CONTRACT_COMPUTE_V0)) - .current() - .data.configSetting() - .contractCompute() = compute; - ltx.load(configSettingKey( - ConfigSettingID::CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0)) - .current() - .data.configSetting() - .contractHistoricalData() - .feeHistorical1KB = 0; - ConfigSettingContractLedgerCostV0 costEntry; + auto& costEntry = + ltx.load(configSettingKey( + ConfigSettingID::CONFIG_SETTING_CONTRACT_LEDGER_COST_V0)) + .current() + .data.configSetting() + .contractLedgerCost(); costEntry.txMaxReadLedgerEntries = MinimumSorobanNetworkConfig::TX_MAX_READ_LEDGER_ENTRIES; costEntry.txMaxReadBytes = MinimumSorobanNetworkConfig::TX_MAX_READ_BYTES; @@ -1888,49 +1897,29 @@ overrideSettingsToMin(Application& app) MinimumSorobanNetworkConfig::TX_MAX_WRITE_LEDGER_ENTRIES; costEntry.txMaxWriteBytes = MinimumSorobanNetworkConfig::TX_MAX_WRITE_BYTES; - costEntry.ledgerMaxReadLedgerEntries = - MinimumSorobanNetworkConfig::LEDGER_MAX_READ_LEDGER_ENTRIES; - costEntry.ledgerMaxReadBytes = - MinimumSorobanNetworkConfig::LEDGER_MAX_READ_BYTES; - costEntry.ledgerMaxWriteLedgerEntries = - MinimumSorobanNetworkConfig::LEDGER_MAX_WRITE_LEDGER_ENTRIES; - costEntry.ledgerMaxWriteBytes = - MinimumSorobanNetworkConfig::LEDGER_MAX_WRITE_BYTES; - costEntry.bucketListTargetSizeBytes = 1; - ltx.load(configSettingKey( - ConfigSettingID::CONFIG_SETTING_CONTRACT_LEDGER_COST_V0)) - .current() - .data.configSetting() - .contractLedgerCost() = costEntry; + costEntry.ledgerMaxReadLedgerEntries = costEntry.txMaxReadLedgerEntries; + costEntry.ledgerMaxReadBytes = costEntry.txMaxReadBytes; + costEntry.ledgerMaxWriteLedgerEntries = costEntry.txMaxWriteLedgerEntries; + costEntry.ledgerMaxWriteBytes = costEntry.txMaxWriteBytes; - ConfigSettingContractEventsV0 events; - ltx.load( - configSettingKey(ConfigSettingID::CONFIG_SETTING_CONTRACT_EVENTS_V0)) - .current() - .data.configSetting() - .contractEvents() = events; - - StateExpirationSettings exp; + auto& exp = ltx.load(configSettingKey( + ConfigSettingID::CONFIG_SETTING_STATE_EXPIRATION)) + .current() + .data.configSetting() + .stateExpirationSettings(); exp.maxEntryExpiration = MinimumSorobanNetworkConfig::MAXIMUM_ENTRY_LIFETIME; - exp.minTempEntryExpiration = 1; exp.minPersistentEntryExpiration = MinimumSorobanNetworkConfig::MINIMUM_PERSISTENT_ENTRY_LIFETIME; - exp.persistentRentRateDenominator = 1; - exp.tempRentRateDenominator = 1; - exp.maxEntriesToExpire = 1; - exp.bucketListSizeWindowSampleSize = 1; - exp.evictionScanSize = 1; - - ltx.load(configSettingKey(ConfigSettingID::CONFIG_SETTING_STATE_EXPIRATION)) - .current() - .data.configSetting() - .stateExpirationSettings() = exp; - ltx.commit(); + + // submit a no-op upgrade so the cached soroban settings are updated. + auto upgrade = LedgerUpgrade{LEDGER_UPGRADE_MAX_SOROBAN_TX_SET_SIZE}; + upgrade.newMaxSorobanTxSetSize() = 1; + executeUpgrade(app, upgrade); } -TEST_CASE("settings upgrade with minimum settings", "[tx][soroban][upgrades]") +TEST_CASE("settings upgrade", "[tx][soroban][upgrades]") { VirtualClock clock; auto cfg = getTestConfig(); @@ -1940,130 +1929,148 @@ TEST_CASE("settings upgrade with minimum settings", "[tx][soroban][upgrades]") auto root = TestAccount::createRoot(*app); auto& lm = app->getLedgerManager(); - overrideSettingsToMin(*app); - - // submit an actual upgrade so the cached soroban settings are updated. - auto result = LedgerUpgrade{LEDGER_UPGRADE_MAX_SOROBAN_TX_SET_SIZE}; - result.newMaxSorobanTxSetSize() = - InitialSorobanNetworkConfig::LEDGER_MAX_TX_COUNT + 1; - executeUpgrade(*app, result); + auto runTest = [&]() { + { + LedgerTxn ltx(app->getLedgerTxnRoot()); - { - LedgerTxn ltx(app->getLedgerTxnRoot()); + // make sure LedgerManager picked up cached values by looking at + // a couple settings + auto const& networkConfig = lm.getSorobanNetworkConfig(ltx); - // make sure LedgerManager picked up cached values by looking at a - // couple settings - auto const& networkConfig = lm.getSorobanNetworkConfig(ltx); + REQUIRE(networkConfig.txMaxReadBytes() == + MinimumSorobanNetworkConfig::TX_MAX_READ_BYTES); + REQUIRE(networkConfig.ledgerMaxReadBytes() == + networkConfig.txMaxReadBytes()); + } - REQUIRE(networkConfig.txMaxReadBytes() == - MinimumSorobanNetworkConfig::TX_MAX_WRITE_BYTES); - REQUIRE(networkConfig.ledgerMaxReadBytes() == - MinimumSorobanNetworkConfig::LEDGER_MAX_WRITE_BYTES); - } + auto const writeByteWasm = rust_bridge::get_write_bytes(); - auto const writeByteWasm = rust_bridge::get_write_bytes(); + SorobanResources uploadResources{}; + uploadResources.instructions = 200'000; + uploadResources.readBytes = 1000; + uploadResources.writeBytes = 1000; - auto contractKeys = deployContractWithSourceAccount(*app, writeByteWasm); - auto const& contractID = contractKeys[0].contractData().contract; + SorobanResources createResources{}; + createResources.instructions = 200'000; + createResources.readBytes = 1000; + createResources.writeBytes = 300; + auto contractKeys = deployContractWithSourceAccountWithResources( + *app, writeByteWasm, uploadResources, createResources); + auto const& contractID = contractKeys[0].contractData().contract; - // build upgrade - auto costKey = configSettingKey( - ConfigSettingID::CONFIG_SETTING_CONTRACT_LEDGER_COST_V0); + // build upgrade + auto costKey = configSettingKey( + ConfigSettingID::CONFIG_SETTING_CONTRACT_LEDGER_COST_V0); - ConfigSettingEntry cost; - { - LedgerTxn ltx(app->getLedgerTxnRoot()); - auto costEntry = ltx.load(costKey); - cost = costEntry.current().data.configSetting(); - } + ConfigSettingEntry cost{}; + { + LedgerTxn ltx(app->getLedgerTxnRoot()); + auto costEntry = ltx.load(costKey); + cost = costEntry.current().data.configSetting(); + } - // check a couple settings to make sure they're at the minimum - REQUIRE(cost.contractLedgerCost().feeRead1KB == 0); - REQUIRE(cost.contractLedgerCost().writeFee1KBBucketListLow == 0); - REQUIRE(cost.contractLedgerCost().ledgerMaxReadLedgerEntries == - MinimumSorobanNetworkConfig::LEDGER_MAX_READ_LEDGER_ENTRIES); - REQUIRE(cost.contractLedgerCost().ledgerMaxReadBytes == - MinimumSorobanNetworkConfig::LEDGER_MAX_READ_BYTES); - REQUIRE(cost.contractLedgerCost().txMaxWriteBytes == - MinimumSorobanNetworkConfig::TX_MAX_WRITE_BYTES); - cost.contractLedgerCost().feeRead1KB = 1000; + // check a couple settings to make sure they're at the minimum + REQUIRE(cost.contractLedgerCost().txMaxReadLedgerEntries == + MinimumSorobanNetworkConfig::TX_MAX_READ_LEDGER_ENTRIES); + REQUIRE(cost.contractLedgerCost().txMaxReadBytes == + MinimumSorobanNetworkConfig::TX_MAX_READ_BYTES); + REQUIRE(cost.contractLedgerCost().txMaxWriteBytes == + MinimumSorobanNetworkConfig::TX_MAX_WRITE_BYTES); + REQUIRE(cost.contractLedgerCost().ledgerMaxReadLedgerEntries == + cost.contractLedgerCost().txMaxReadLedgerEntries); + REQUIRE(cost.contractLedgerCost().ledgerMaxReadBytes == + cost.contractLedgerCost().txMaxReadBytes); + REQUIRE(cost.contractLedgerCost().ledgerMaxWriteBytes == + cost.contractLedgerCost().txMaxWriteBytes); + cost.contractLedgerCost().feeRead1KB = 1000; - ConfigUpgradeSet upgradeSet; - upgradeSet.updatedEntry.emplace_back(cost); + ConfigUpgradeSet upgradeSet; + upgradeSet.updatedEntry.emplace_back(cost); - auto xdr = xdr::xdr_to_opaque(upgradeSet); - auto upgrade_hash = sha256(xdr); + auto xdr = xdr::xdr_to_opaque(upgradeSet); + auto upgrade_hash = sha256(xdr); - // write upgrade - Operation op; - op.body.type(INVOKE_HOST_FUNCTION); - auto& ihf = op.body.invokeHostFunctionOp().hostFunction; - ihf.type(HOST_FUNCTION_TYPE_INVOKE_CONTRACT); - ihf.invokeContract().contractAddress = contractID; - ihf.invokeContract().functionName = makeSymbol("write"); - ihf.invokeContract().args.emplace_back(makeBytes(xdr)); + // write upgrade + Operation op; + op.body.type(INVOKE_HOST_FUNCTION); + auto& ihf = op.body.invokeHostFunctionOp().hostFunction; + ihf.type(HOST_FUNCTION_TYPE_INVOKE_CONTRACT); + ihf.invokeContract().contractAddress = contractID; + ihf.invokeContract().functionName = makeSymbol("write"); + ihf.invokeContract().args.emplace_back(makeBytes(xdr)); - LedgerKey upgrade(CONTRACT_DATA); - upgrade.contractData().durability = TEMPORARY; - upgrade.contractData().contract = contractID; - upgrade.contractData().bodyType = DATA_ENTRY; - upgrade.contractData().key = makeBytes(xdr::xdr_to_opaque(upgrade_hash)); + LedgerKey upgrade(CONTRACT_DATA); + upgrade.contractData().durability = TEMPORARY; + upgrade.contractData().contract = contractID; + upgrade.contractData().bodyType = DATA_ENTRY; + upgrade.contractData().key = + makeBytes(xdr::xdr_to_opaque(upgrade_hash)); - SorobanResources resources; - resources.footprint.readOnly = contractKeys; - resources.footprint.readWrite = {upgrade}; - resources.instructions = 5'000'000; - resources.readBytes = 5000; - resources.writeBytes = 5000; - resources.contractEventsSizeBytes = 0; + SorobanResources resources{}; + resources.footprint.readOnly = contractKeys; + resources.footprint.readWrite = {upgrade}; + resources.instructions = 2'000'000; + resources.readBytes = 1000; + resources.writeBytes = 1000; + resources.contractEventsSizeBytes = 0; - auto tx = sorobanTransactionFrameFromOps(app->getNetworkID(), root, {op}, - {}, resources, 1'000'000, 60000); + auto tx = sorobanTransactionFrameFromOps( + app->getNetworkID(), root, {op}, {}, resources, 2'000'000, 30'000); - { - LedgerTxn ltx(app->getLedgerTxnRoot()); - REQUIRE(tx->checkValid(*app, ltx, 0, 0, 0)); - TransactionMetaFrame txm(ltx.loadHeader().current().ledgerVersion); - REQUIRE(tx->apply(*app, ltx, txm)); - ltx.commit(); - } + { + LedgerTxn ltx(app->getLedgerTxnRoot()); + REQUIRE(tx->checkValid(*app, ltx, 0, 0, 0)); + TransactionMetaFrame txm(ltx.loadHeader().current().ledgerVersion); + REQUIRE(tx->apply(*app, ltx, txm)); + ltx.commit(); + } - // arm the upgrade through commandHandler. This isn't required because we'll - // trigger the upgrade through externalizeValue, but this will test the - // submission and deserialization code. - ConfigUpgradeSetKey key; - key.contentHash = upgrade_hash; - key.contractID = contractID.contractId(); + // arm the upgrade through commandHandler. This isn't required + // because we'll trigger the upgrade through externalizeValue, but + // this will test the submission and deserialization code. + ConfigUpgradeSetKey key; + key.contentHash = upgrade_hash; + key.contractID = contractID.contractId(); - auto& commandHandler = app->getCommandHandler(); + auto& commandHandler = app->getCommandHandler(); - std::string command = "mode=set&configupgradesetkey="; - command += decoder::encode_b64(xdr::xdr_to_opaque(key)); - command += "&upgradetime=2000-07-21T22:04:00Z"; + std::string command = "mode=set&configupgradesetkey="; + command += decoder::encode_b64(xdr::xdr_to_opaque(key)); + command += "&upgradetime=2000-07-21T22:04:00Z"; - std::string ret; - commandHandler.upgrades(command, ret); - REQUIRE(ret == ""); + std::string ret; + commandHandler.upgrades(command, ret); + REQUIRE(ret == ""); - // trigger upgrade - auto ledgerUpgrade = LedgerUpgrade{LEDGER_UPGRADE_CONFIG}; - ledgerUpgrade.newConfig() = key; + // trigger upgrade + auto ledgerUpgrade = LedgerUpgrade{LEDGER_UPGRADE_CONFIG}; + ledgerUpgrade.newConfig() = key; - auto const& lcl = lm.getLastClosedLedgerHeader(); - auto txSet = TxSetFrame::makeEmpty(lcl); - auto lastCloseTime = lcl.header.scpValue.closeTime; - app->getHerder().externalizeValue( - txSet, lcl.header.ledgerSeq + 1, lastCloseTime, - {LedgerTestUtils::toUpgradeType(ledgerUpgrade)}); + auto const& lcl = lm.getLastClosedLedgerHeader(); + auto txSet = TxSetFrame::makeEmpty(lcl); + auto lastCloseTime = lcl.header.scpValue.closeTime; + app->getHerder().externalizeValue( + txSet, lcl.header.ledgerSeq + 1, lastCloseTime, + {LedgerTestUtils::toUpgradeType(ledgerUpgrade)}); - // validate upgrade succeeded + // validate upgrade succeeded + { + LedgerTxn ltx(app->getLedgerTxnRoot()); + auto costEntry = ltx.load(costKey); + REQUIRE(costEntry.current() + .data.configSetting() + .contractLedgerCost() + .feeRead1KB == 1000); + } + }; + SECTION("from init settings") { - LedgerTxn ltx(app->getLedgerTxnRoot()); - auto costEntry = ltx.load(costKey); - REQUIRE(costEntry.current() - .data.configSetting() - .contractLedgerCost() - .feeRead1KB == 1000); + runTest(); + } + SECTION("from min settings") + { + overrideNetworkSettingsToMin(*app); + runTest(); } } #endif diff --git a/src/transactions/test/TxEnvelopeTests.cpp b/src/transactions/test/TxEnvelopeTests.cpp index 4e794c5af3..eb31f738d9 100644 --- a/src/transactions/test/TxEnvelopeTests.cpp +++ b/src/transactions/test/TxEnvelopeTests.cpp @@ -2615,9 +2615,9 @@ TEST_CASE("soroban transaction validation", "[tx][envelope][soroban]") { SECTION("resource fee exceeds tx fee") { - auto tx = sorobanTransactionFrameFromOps(app->getNetworkID(), root, - {op0}, {}, resources, - 1'000'000, 100'000); + auto tx = + sorobanTransactionFrameFromOps(app->getNetworkID(), root, {op0}, + {}, resources, 1'000, 100'000); LedgerTxn ltx(app->getLedgerTxnRoot()); REQUIRE(!tx->checkValid(*app, ltx, 0, 0, 0)); REQUIRE(tx->getResult().result.code() == txINSUFFICIENT_FEE); @@ -2626,16 +2626,15 @@ TEST_CASE("soroban transaction validation", "[tx][envelope][soroban]") { auto tx = sorobanTransactionFrameFromOps(app->getNetworkID(), root, {op0}, {}, resources, - 4'000'000, 4'000'001); + 1'000'000, 1'000'001); LedgerTxn ltx(app->getLedgerTxnRoot()); REQUIRE(!tx->checkValid(*app, ltx, 0, 0, 0)); REQUIRE(tx->getResult().result.code() == txINSUFFICIENT_FEE); } SECTION("refundable fee exceeds tx refundable fee") { - auto tx = - sorobanTransactionFrameFromOps(app->getNetworkID(), root, {op0}, - {}, resources, 4'000'000, 100); + auto tx = sorobanTransactionFrameFromOps( + app->getNetworkID(), root, {op0}, {}, resources, 1'000'000, 10); LedgerTxn ltx(app->getLedgerTxnRoot()); REQUIRE(!tx->checkValid(*app, ltx, 0, 0, 0)); REQUIRE(tx->getResult().result.code() == txINSUFFICIENT_FEE); @@ -2690,11 +2689,6 @@ TEST_CASE("soroban transaction validation", "[tx][envelope][soroban]") op.body.type(INVOKE_HOST_FUNCTION); auto& ihf = op.body.invokeHostFunctionOp().hostFunction; ihf.type(HOST_FUNCTION_TYPE_INVOKE_CONTRACT); - SorobanNetworkConfig refConfig; - { - LedgerTxn ltx(app->getLedgerTxnRoot()); - refConfig = app->getLedgerManager().getSorobanNetworkConfig(ltx); - } SECTION("success with default limits") { resources.footprint.readOnly.back() = contractDataKey( @@ -2712,8 +2706,9 @@ TEST_CASE("soroban transaction validation", "[tx][envelope][soroban]") resources.footprint.readOnly.back() = contractDataKey( SCAddress{}, makeSymbol("abcdefghijklmnopqrstuvwxyz012345"), ContractDataDurability::PERSISTENT, DATA_ENTRY); - refConfig.maxContractDataKeySizeBytes() = 64; - app->getLedgerManager().setSorobanNetworkConfig(refConfig); + modifySorobanNetworkConfig(*app, [](SorobanNetworkConfig& cfg) { + cfg.mMaxContractDataKeySizeBytes = 64; + }); auto tx = sorobanTransactionFrameFromOps(app->getNetworkID(), root, {op}, {}, resources, 3'500'000, 100'000); @@ -2726,8 +2721,9 @@ TEST_CASE("soroban transaction validation", "[tx][envelope][soroban]") resources.footprint.readWrite.back() = contractDataKey( SCAddress{}, makeSymbol("abcdefghijklmnopqrstuvwxyz012345"), ContractDataDurability::PERSISTENT, DATA_ENTRY); - refConfig.maxContractDataKeySizeBytes() = 64; - app->getLedgerManager().setSorobanNetworkConfig(refConfig); + modifySorobanNetworkConfig(*app, [](SorobanNetworkConfig& cfg) { + cfg.mMaxContractDataKeySizeBytes = 64; + }); auto tx = sorobanTransactionFrameFromOps(app->getNetworkID(), root, {op}, {}, resources, 3'500'000, 100'000);