From 245d0ef9980dc6861a75dbb9073b0c8a76703ad5 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Mon, 28 Aug 2023 17:14:19 -0700 Subject: [PATCH 1/3] Add TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE setting --- src/ledger/NetworkConfig.cpp | 91 +++++++++++++++++++++++++++++------- src/main/Config.cpp | 8 ++++ src/main/Config.h | 3 ++ 3 files changed, 84 insertions(+), 18 deletions(-) diff --git a/src/ledger/NetworkConfig.cpp b/src/ledger/NetworkConfig.cpp index 9096814c9e..a27f986ed3 100644 --- a/src/ledger/NetworkConfig.cpp +++ b/src/ledger/NetworkConfig.cpp @@ -31,40 +31,53 @@ createConfigSettingEntry(ConfigSettingEntry const& configSetting, } ConfigSettingEntry -initialMaxContractSizeEntry() +initialMaxContractSizeEntry(Config const& cfg) { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES); entry.contractMaxSizeBytes() = InitialSorobanNetworkConfig::MAX_CONTRACT_SIZE; + if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) + { + entry.contractMaxSizeBytes() *= 32; + } + return entry; } ConfigSettingEntry -initialMaxContractDataKeySizeEntry() +initialMaxContractDataKeySizeEntry(Config const& cfg) { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_DATA_KEY_SIZE_BYTES); entry.contractDataKeySizeBytes() = InitialSorobanNetworkConfig::MAX_CONTRACT_DATA_KEY_SIZE_BYTES; + if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) + { + entry.contractDataKeySizeBytes() *= 10; + } return entry; } ConfigSettingEntry -initialMaxContractDataEntrySizeEntry() +initialMaxContractDataEntrySizeEntry(Config const& cfg) { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES); entry.contractDataEntrySizeBytes() = InitialSorobanNetworkConfig::MAX_CONTRACT_DATA_ENTRY_SIZE_BYTES; + if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) + { + entry.contractDataEntrySizeBytes() *= 10; + } return entry; } ConfigSettingEntry -initialContractComputeSettingsEntry() +initialContractComputeSettingsEntry(Config const& cfg) { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_COMPUTE_V0); auto& e = entry.contractCompute(); @@ -77,11 +90,18 @@ initialContractComputeSettingsEntry() InitialSorobanNetworkConfig::FEE_RATE_PER_INSTRUCTIONS_INCREMENT; e.txMemoryLimit = InitialSorobanNetworkConfig::MEMORY_LIMIT; + if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) + { + e.ledgerMaxInstructions *= 50; + e.txMaxInstructions *= 50; + e.txMemoryLimit *= 10; + } + return entry; } ConfigSettingEntry -initialContractLedgerAccessSettingsEntry() +initialContractLedgerAccessSettingsEntry(Config const& cfg) { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_LEDGER_COST_V0); auto& e = entry.contractLedgerCost(); @@ -114,6 +134,18 @@ initialContractLedgerAccessSettingsEntry() e.bucketListWriteFeeGrowthFactor = InitialSorobanNetworkConfig::BUCKET_LIST_WRITE_FEE_GROWTH_FACTOR; + if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) + { + e.ledgerMaxReadLedgerEntries *= 10; + e.ledgerMaxReadBytes *= 10; + e.ledgerMaxWriteLedgerEntries *= 10; + e.ledgerMaxWriteBytes *= 10; + e.txMaxReadLedgerEntries *= 10; + e.txMaxReadBytes *= 10; + e.txMaxWriteLedgerEntries *= 10; + e.txMaxWriteBytes *= 10; + } + return entry; } @@ -129,7 +161,7 @@ initialContractHistoricalDataSettingsEntry() } ConfigSettingEntry -initialContractEventsSettingsEntry() +initialContractEventsSettingsEntry(Config const& cfg) { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_EVENTS_V0); auto& e = entry.contractEvents(); @@ -139,11 +171,15 @@ initialContractEventsSettingsEntry() e.feeContractEvents1KB = InitialSorobanNetworkConfig::FEE_CONTRACT_EVENTS_SIZE_1KB; + if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) + { + e.txMaxContractEventsSizeBytes *= 20; + } return entry; } ConfigSettingEntry -initialContractBandwidthSettingsEntry() +initialContractBandwidthSettingsEntry(Config const& cfg) { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_BANDWIDTH_V0); auto& e = entry.contractBandwidth(); @@ -154,15 +190,27 @@ initialContractBandwidthSettingsEntry() e.feeTxSize1KB = InitialSorobanNetworkConfig::FEE_TRANSACTION_SIZE_1KB; + if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) + { + e.ledgerMaxTxsSizeBytes *= 5; + e.txMaxSizeBytes *= 5; + } + return entry; } ConfigSettingEntry -initialContractExecutionLanesSettingsEntry() +initialContractExecutionLanesSettingsEntry(Config const& cfg) { ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_EXECUTION_LANES); auto& e = entry.contractExecutionLanes(); e.ledgerMaxTxCount = InitialSorobanNetworkConfig::LEDGER_MAX_TX_COUNT; + + if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) + { + e.ledgerMaxTxCount *= 5; + } + return entry; } @@ -309,6 +357,11 @@ initialStateExpirationSettings(Config const& cfg) InitialSorobanNetworkConfig::PERSISTENT_RENT_RATE_DENOMINATOR; entry.stateExpirationSettings().tempRentRateDenominator = InitialSorobanNetworkConfig::TEMP_RENT_RATE_DENOMINATOR; + + if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) + { + entry.stateExpirationSettings().maxEntryExpiration = 6307200; // 1 year + } return entry; } @@ -590,19 +643,21 @@ SorobanNetworkConfig::createLedgerEntriesForV20(AbstractLedgerTxn& ltx, Application& app) { #ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION - createConfigSettingEntry(initialMaxContractSizeEntry(), ltx); - createConfigSettingEntry(initialMaxContractDataKeySizeEntry(), ltx); - createConfigSettingEntry(initialMaxContractDataEntrySizeEntry(), ltx); - createConfigSettingEntry(initialContractComputeSettingsEntry(), ltx); - createConfigSettingEntry(initialContractLedgerAccessSettingsEntry(), ltx); + auto const& cfg = app.getConfig(); + createConfigSettingEntry(initialMaxContractSizeEntry(cfg), ltx); + createConfigSettingEntry(initialMaxContractDataKeySizeEntry(cfg), ltx); + createConfigSettingEntry(initialMaxContractDataEntrySizeEntry(cfg), ltx); + createConfigSettingEntry(initialContractComputeSettingsEntry(cfg), ltx); + createConfigSettingEntry(initialContractLedgerAccessSettingsEntry(cfg), + ltx); createConfigSettingEntry(initialContractHistoricalDataSettingsEntry(), ltx); - createConfigSettingEntry(initialContractEventsSettingsEntry(), ltx); - createConfigSettingEntry(initialContractBandwidthSettingsEntry(), ltx); - createConfigSettingEntry(initialContractExecutionLanesSettingsEntry(), ltx); + createConfigSettingEntry(initialContractEventsSettingsEntry(cfg), ltx); + createConfigSettingEntry(initialContractBandwidthSettingsEntry(cfg), ltx); + createConfigSettingEntry(initialContractExecutionLanesSettingsEntry(cfg), + ltx); createConfigSettingEntry(initialCpuCostParamsEntry(), ltx); createConfigSettingEntry(initialMemCostParamsEntry(), ltx); - createConfigSettingEntry(initialStateExpirationSettings(app.getConfig()), - ltx); + createConfigSettingEntry(initialStateExpirationSettings(cfg), ltx); createConfigSettingEntry(initialBucketListSizeWindow(app), ltx); createConfigSettingEntry(initialEvictionIterator(), ltx); #endif diff --git a/src/main/Config.cpp b/src/main/Config.cpp index bbd6f8efbd..1513159ba7 100644 --- a/src/main/Config.cpp +++ b/src/main/Config.cpp @@ -264,6 +264,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 = 0; + TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE = false; #endif #ifdef BUILD_TESTS @@ -1473,6 +1474,13 @@ Config::processConfig(std::shared_ptr t) "Overriding MINIMUM_PERSISTENT_ENTRY_LIFETIME to {}", TESTING_MINIMUM_PERSISTENT_ENTRY_LIFETIME); } + else if (item.first == "TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE") + { + TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE = readBool(item); + + LOG_WARNING(DEFAULT_LOG, "Overriding Soroban limits with " + "TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE"); + } #endif else if (item.first == "ARTIFICIALLY_SLEEP_MAIN_THREAD_FOR_TESTING") { diff --git a/src/main/Config.h b/src/main/Config.h index 48d7b481bc..afb3d0ca10 100644 --- a/src/main/Config.h +++ b/src/main/Config.h @@ -576,6 +576,9 @@ class Config : public std::enable_shared_from_this // Override the initial hardcoded MINIMUM_PERSISTENT_ENTRY_LIFETIME // for testing. uint32_t TESTING_MINIMUM_PERSISTENT_ENTRY_LIFETIME; + + //TODO: add comment + bool TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE; #endif #ifdef BUILD_TESTS From 16d4645d1d281852cfba781a26d4958b70c19958 Mon Sep 17 00:00:00 2001 From: Siddharth Suresh Date: Tue, 29 Aug 2023 08:24:11 -0700 Subject: [PATCH 2/3] Update comments --- src/main/Config.cpp | 8 ++++++-- src/main/Config.h | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/Config.cpp b/src/main/Config.cpp index 1513159ba7..de5a0cfe42 100644 --- a/src/main/Config.cpp +++ b/src/main/Config.cpp @@ -1478,8 +1478,12 @@ Config::processConfig(std::shared_ptr t) { TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE = readBool(item); - LOG_WARNING(DEFAULT_LOG, "Overriding Soroban limits with " - "TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE"); + if (TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) + { + LOG_WARNING(DEFAULT_LOG, + "Overriding Soroban limits with " + "TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE"); + } } #endif else if (item.first == "ARTIFICIALLY_SLEEP_MAIN_THREAD_FOR_TESTING") diff --git a/src/main/Config.h b/src/main/Config.h index afb3d0ca10..2852815e6b 100644 --- a/src/main/Config.h +++ b/src/main/Config.h @@ -577,7 +577,7 @@ class Config : public std::enable_shared_from_this // for testing. uint32_t TESTING_MINIMUM_PERSISTENT_ENTRY_LIFETIME; - //TODO: add comment + // Increase all initial max limits to higher values for testing bool TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE; #endif From 9e4e31149e2db4bc83f3ea01b71e41391821e091 Mon Sep 17 00:00:00 2001 From: Jay Geng Date: Tue, 29 Aug 2023 12:48:55 -0400 Subject: [PATCH 3/3] Create and use `TestOverrideSorobanNetworkConfig` --- src/ledger/NetworkConfig.cpp | 55 +++++++++++++++++++++------------- src/ledger/NetworkConfig.h | 57 +++++++++++++++++++++++++++++++++++- 2 files changed, 91 insertions(+), 21 deletions(-) diff --git a/src/ledger/NetworkConfig.cpp b/src/ledger/NetworkConfig.cpp index a27f986ed3..18bb8ebd1b 100644 --- a/src/ledger/NetworkConfig.cpp +++ b/src/ledger/NetworkConfig.cpp @@ -37,10 +37,10 @@ initialMaxContractSizeEntry(Config const& cfg) entry.contractMaxSizeBytes() = InitialSorobanNetworkConfig::MAX_CONTRACT_SIZE; - if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) { - entry.contractMaxSizeBytes() *= 32; + entry.contractMaxSizeBytes() = + TestOverrideSorobanNetworkConfig::MAX_CONTRACT_SIZE; } return entry; @@ -55,7 +55,8 @@ initialMaxContractDataKeySizeEntry(Config const& cfg) InitialSorobanNetworkConfig::MAX_CONTRACT_DATA_KEY_SIZE_BYTES; if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) { - entry.contractDataKeySizeBytes() *= 10; + entry.contractDataKeySizeBytes() = + TestOverrideSorobanNetworkConfig::MAX_CONTRACT_DATA_KEY_SIZE_BYTES; } return entry; @@ -70,7 +71,8 @@ initialMaxContractDataEntrySizeEntry(Config const& cfg) InitialSorobanNetworkConfig::MAX_CONTRACT_DATA_ENTRY_SIZE_BYTES; if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) { - entry.contractDataEntrySizeBytes() *= 10; + entry.contractDataEntrySizeBytes() = TestOverrideSorobanNetworkConfig:: + MAX_CONTRACT_DATA_ENTRY_SIZE_BYTES; } return entry; @@ -92,9 +94,11 @@ initialContractComputeSettingsEntry(Config const& cfg) if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) { - e.ledgerMaxInstructions *= 50; - e.txMaxInstructions *= 50; - e.txMemoryLimit *= 10; + e.ledgerMaxInstructions = + TestOverrideSorobanNetworkConfig::LEDGER_MAX_INSTRUCTIONS; + e.txMaxInstructions = + TestOverrideSorobanNetworkConfig::TX_MAX_INSTRUCTIONS; + e.txMemoryLimit = TestOverrideSorobanNetworkConfig::MEMORY_LIMIT; } return entry; @@ -136,14 +140,21 @@ initialContractLedgerAccessSettingsEntry(Config const& cfg) if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) { - e.ledgerMaxReadLedgerEntries *= 10; - e.ledgerMaxReadBytes *= 10; - e.ledgerMaxWriteLedgerEntries *= 10; - e.ledgerMaxWriteBytes *= 10; - e.txMaxReadLedgerEntries *= 10; - e.txMaxReadBytes *= 10; - e.txMaxWriteLedgerEntries *= 10; - e.txMaxWriteBytes *= 10; + e.ledgerMaxReadLedgerEntries = + TestOverrideSorobanNetworkConfig::LEDGER_MAX_READ_LEDGER_ENTRIES; + e.ledgerMaxReadBytes = + TestOverrideSorobanNetworkConfig::LEDGER_MAX_READ_BYTES; + e.ledgerMaxWriteLedgerEntries = + TestOverrideSorobanNetworkConfig::LEDGER_MAX_WRITE_LEDGER_ENTRIES; + e.ledgerMaxWriteBytes = + TestOverrideSorobanNetworkConfig::LEDGER_MAX_WRITE_BYTES; + e.txMaxReadLedgerEntries = + TestOverrideSorobanNetworkConfig::TX_MAX_READ_LEDGER_ENTRIES; + e.txMaxReadBytes = TestOverrideSorobanNetworkConfig::TX_MAX_READ_BYTES; + e.txMaxWriteLedgerEntries = + TestOverrideSorobanNetworkConfig::TX_MAX_WRITE_LEDGER_ENTRIES; + e.txMaxWriteBytes = + TestOverrideSorobanNetworkConfig::TX_MAX_WRITE_BYTES; } return entry; @@ -173,7 +184,8 @@ initialContractEventsSettingsEntry(Config const& cfg) if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) { - e.txMaxContractEventsSizeBytes *= 20; + e.txMaxContractEventsSizeBytes = + TestOverrideSorobanNetworkConfig::TX_MAX_CONTRACT_EVENTS_SIZE_BYTES; } return entry; } @@ -192,8 +204,9 @@ initialContractBandwidthSettingsEntry(Config const& cfg) if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) { - e.ledgerMaxTxsSizeBytes *= 5; - e.txMaxSizeBytes *= 5; + e.ledgerMaxTxsSizeBytes = TestOverrideSorobanNetworkConfig:: + LEDGER_MAX_TRANSACTION_SIZES_BYTES; + e.txMaxSizeBytes = TestOverrideSorobanNetworkConfig::TX_MAX_SIZE_BYTES; } return entry; @@ -208,7 +221,8 @@ initialContractExecutionLanesSettingsEntry(Config const& cfg) if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) { - e.ledgerMaxTxCount *= 5; + e.ledgerMaxTxCount = + TestOverrideSorobanNetworkConfig::LEDGER_MAX_TX_COUNT; } return entry; @@ -360,7 +374,8 @@ initialStateExpirationSettings(Config const& cfg) if (cfg.TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE) { - entry.stateExpirationSettings().maxEntryExpiration = 6307200; // 1 year + entry.stateExpirationSettings().maxEntryExpiration = + TestOverrideSorobanNetworkConfig::MAXIMUM_ENTRY_LIFETIME; } return entry; } diff --git a/src/ledger/NetworkConfig.h b/src/ledger/NetworkConfig.h index 2be0a69609..85bf200dec 100644 --- a/src/ledger/NetworkConfig.h +++ b/src/ledger/NetworkConfig.h @@ -110,7 +110,7 @@ struct InitialSorobanNetworkConfig static constexpr uint32_t TX_MAX_SIZE_BYTES = MinimumSorobanNetworkConfig::TX_MAX_SIZE_BYTES; static constexpr uint32_t LEDGER_MAX_TRANSACTION_SIZES_BYTES = - MinimumSorobanNetworkConfig::TX_MAX_SIZE_BYTES; + TX_MAX_SIZE_BYTES; static constexpr int64_t FEE_TRANSACTION_SIZE_1KB = 2'000; // Contract events settings @@ -143,6 +143,61 @@ struct InitialSorobanNetworkConfig static constexpr uint32_t LEDGER_MAX_TX_COUNT = 1; }; +// Defines the subset of the `InitialSorobanNetworkConfig` to be overridden for +// testing, enabled by `Config::TESTING_SOROBAN_HIGH_LIMIT_OVERRIDE`. +struct TestOverrideSorobanNetworkConfig +{ + // Contract size settings + static constexpr uint32_t MAX_CONTRACT_SIZE = + InitialSorobanNetworkConfig::MAX_CONTRACT_SIZE * 32; + + // Contract data settings + static constexpr uint32_t MAX_CONTRACT_DATA_KEY_SIZE_BYTES = + InitialSorobanNetworkConfig::MAX_CONTRACT_DATA_KEY_SIZE_BYTES * 10; + static constexpr uint32_t MAX_CONTRACT_DATA_ENTRY_SIZE_BYTES = + InitialSorobanNetworkConfig::MAX_CONTRACT_DATA_ENTRY_SIZE_BYTES * 10; + + // Compute settings + static constexpr int64_t TX_MAX_INSTRUCTIONS = + InitialSorobanNetworkConfig::TX_MAX_INSTRUCTIONS * 50; + static constexpr int64_t LEDGER_MAX_INSTRUCTIONS = TX_MAX_INSTRUCTIONS; + static constexpr uint32_t MEMORY_LIMIT = + InitialSorobanNetworkConfig::MEMORY_LIMIT * 10; + + // Ledger access settings + static constexpr uint32_t TX_MAX_READ_LEDGER_ENTRIES = + InitialSorobanNetworkConfig::TX_MAX_READ_LEDGER_ENTRIES * 10; + static constexpr uint32_t TX_MAX_READ_BYTES = + InitialSorobanNetworkConfig::TX_MAX_READ_BYTES * 10; + static constexpr uint32_t TX_MAX_WRITE_LEDGER_ENTRIES = + InitialSorobanNetworkConfig::TX_MAX_WRITE_LEDGER_ENTRIES * 10; + static constexpr uint32_t TX_MAX_WRITE_BYTES = + InitialSorobanNetworkConfig::TX_MAX_WRITE_BYTES * 10; + static constexpr uint32_t LEDGER_MAX_READ_LEDGER_ENTRIES = + 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 = + TX_MAX_WRITE_LEDGER_ENTRIES; + static constexpr uint32_t LEDGER_MAX_WRITE_BYTES = TX_MAX_WRITE_BYTES; + + // Bandwidth settings + static constexpr uint32_t TX_MAX_SIZE_BYTES = + InitialSorobanNetworkConfig::TX_MAX_SIZE_BYTES * 5; + static constexpr uint32_t LEDGER_MAX_TRANSACTION_SIZES_BYTES = + TX_MAX_SIZE_BYTES; + + // Contract events settings + static constexpr uint32_t TX_MAX_CONTRACT_EVENTS_SIZE_BYTES = + InitialSorobanNetworkConfig::TX_MAX_CONTRACT_EVENTS_SIZE_BYTES * 20; + + // State expiration settings + static constexpr uint32_t MAXIMUM_ENTRY_LIFETIME = 6307200; // 1 year + + // General execution settings + static constexpr uint32_t LEDGER_MAX_TX_COUNT = + InitialSorobanNetworkConfig::LEDGER_MAX_TX_COUNT * 5; +}; + // Wrapper for the contract-related network configuration. class SorobanNetworkConfig {