Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add max tx count for Soroban network settings #3767

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 48 additions & 9 deletions src/ledger/NetworkConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ initialContractComputeSettingsEntry(Config const& cfg)
ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_COMPUTE_V0);
auto& e = entry.contractCompute();

if (cfg.TESTING_LEDGER_MAX_INSTRUCTIONS && cfg.USE_CONFIG_FOR_GENESIS)
if (cfg.USE_CONFIG_FOR_GENESIS)
{
e.ledgerMaxInstructions = cfg.TESTING_LEDGER_MAX_INSTRUCTIONS;
}
Expand All @@ -84,8 +84,7 @@ initialContractLedgerAccessSettingsEntry(Config const& cfg)
ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_LEDGER_COST_V0);
auto& e = entry.contractLedgerCost();

if (cfg.TESTING_LEDGER_MAX_READ_LEDGER_ENTRIES &&
cfg.USE_CONFIG_FOR_GENESIS)
if (cfg.USE_CONFIG_FOR_GENESIS)
{
e.ledgerMaxReadLedgerEntries =
cfg.TESTING_LEDGER_MAX_READ_LEDGER_ENTRIES;
Expand All @@ -95,7 +94,7 @@ initialContractLedgerAccessSettingsEntry(Config const& cfg)
e.ledgerMaxReadLedgerEntries =
InitialSorobanNetworkConfig::LEDGER_MAX_READ_LEDGER_ENTRIES;
}
if (cfg.TESTING_LEDGER_MAX_READ_BYTES && cfg.USE_CONFIG_FOR_GENESIS)
if (cfg.USE_CONFIG_FOR_GENESIS)
{
e.ledgerMaxReadBytes = cfg.TESTING_LEDGER_MAX_READ_BYTES;
}
Expand All @@ -104,8 +103,7 @@ initialContractLedgerAccessSettingsEntry(Config const& cfg)
e.ledgerMaxReadBytes =
InitialSorobanNetworkConfig::LEDGER_MAX_READ_BYTES;
}
if (cfg.TESTING_LEDGER_MAX_WRITE_LEDGER_ENTRIES &&
cfg.USE_CONFIG_FOR_GENESIS)
if (cfg.USE_CONFIG_FOR_GENESIS)
{
e.ledgerMaxWriteLedgerEntries =
cfg.TESTING_LEDGER_MAX_WRITE_LEDGER_ENTRIES;
Expand All @@ -115,7 +113,7 @@ initialContractLedgerAccessSettingsEntry(Config const& cfg)
e.ledgerMaxWriteLedgerEntries =
InitialSorobanNetworkConfig::LEDGER_MAX_WRITE_LEDGER_ENTRIES;
}
if (cfg.TESTING_LEDGER_MAX_WRITE_BYTES && cfg.USE_CONFIG_FOR_GENESIS)
if (cfg.USE_CONFIG_FOR_GENESIS)
{
e.ledgerMaxWriteBytes = cfg.TESTING_LEDGER_MAX_WRITE_BYTES;
}
Expand Down Expand Up @@ -176,8 +174,7 @@ initialContractBandwidthSettingsEntry(Config const& cfg)
ConfigSettingEntry entry(CONFIG_SETTING_CONTRACT_BANDWIDTH_V0);
auto& e = entry.contractBandwidth();

if (cfg.TESTING_LEDGER_MAX_PROPAGATE_SIZE_BYTES &&
cfg.USE_CONFIG_FOR_GENESIS)
if (cfg.USE_CONFIG_FOR_GENESIS)
{
e.ledgerMaxPropagateSizeBytes =
cfg.TESTING_LEDGER_MAX_PROPAGATE_SIZE_BYTES;
Expand All @@ -193,6 +190,24 @@ initialContractBandwidthSettingsEntry(Config const& cfg)
return entry;
}

ConfigSettingEntry
initialContractExecutionLanesSettingsEntry(Config const& cfg)
{
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;
}

return entry;
}

ConfigSettingEntry
initialCpuCostParamsEntry(Config const& cfg)
{
Expand Down Expand Up @@ -393,6 +408,8 @@ SorobanNetworkConfig::createLedgerEntriesForV20(AbstractLedgerTxn& ltx,
ltx);
createConfigSettingEntry(initialContractMetaDataSettingsEntry(cfg), ltx);
createConfigSettingEntry(initialContractBandwidthSettingsEntry(cfg), ltx);
createConfigSettingEntry(initialContractExecutionLanesSettingsEntry(cfg),
ltx);
createConfigSettingEntry(initialCpuCostParamsEntry(cfg), ltx);
createConfigSettingEntry(initialMemCostParamsEntry(cfg), ltx);
createConfigSettingEntry(initialStateExpirationSettings(), ltx);
Expand Down Expand Up @@ -424,6 +441,7 @@ SorobanNetworkConfig::loadFromLedger(AbstractLedgerTxn& ltxRoot)
loadCpuCostParams(ltx);
loadMemCostParams(ltx);
loadStateExpirationSettings(ltx);
loadExecutionLanesSettings(ltx);
}

void
Expand Down Expand Up @@ -577,6 +595,20 @@ SorobanNetworkConfig::loadMemCostParams(AbstractLedgerTxn& ltx)
#endif
}

void
SorobanNetworkConfig::loadExecutionLanesSettings(AbstractLedgerTxn& ltx)
{
#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION
LedgerKey key(CONFIG_SETTING);
key.configSetting().configSettingID =
ConfigSettingID::CONFIG_SETTING_CONTRACT_EXECUTION_LANES;
auto le = ltx.loadWithoutRecord(key).current();
auto const& configSetting =
le.data.configSetting().contractExecutionLanes();
mLedgerMaxTxCount = configSetting.ledgerMaxTxCount;
#endif
}

uint32_t
SorobanNetworkConfig::maxContractSizeBytes() const
{
Expand Down Expand Up @@ -769,6 +801,13 @@ SorobanNetworkConfig::feePropagateData1KB() const
return mFeePropagateData1KB;
}

// General execution lanes settings for contracts
uint32_t
SorobanNetworkConfig::ledgerMaxTxCount() const
{
return mLedgerMaxTxCount;
}

#ifdef BUILD_TESTS
uint32_t&
SorobanNetworkConfig::maxContractDataKeySizeBytes()
Expand Down
8 changes: 8 additions & 0 deletions src/ledger/NetworkConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ struct InitialSorobanNetworkConfig
static constexpr uint32_t MINIMUM_TEMP_ENTRY_LIFETIME = 16;

static constexpr uint32_t AUTO_BUMP_NUM_LEDGERS = 10;

// General execution settings
static constexpr uint32_t LEDGER_MAX_TX_COUNT = 10;
};

// Wrapper for the contract-related network configuration.
Expand Down Expand Up @@ -169,6 +172,9 @@ class SorobanNetworkConfig
// Fee for propagating 1KB of data
int64_t feePropagateData1KB() const;

// General execution ledger settings
uint32_t ledgerMaxTxCount() const;

#ifdef BUILD_TESTS
uint32_t& maxContractDataKeySizeBytes();
uint32_t& maxContractDataEntrySizeBytes();
Expand Down Expand Up @@ -199,6 +205,7 @@ class SorobanNetworkConfig
void loadCpuCostParams(AbstractLedgerTxn& ltx);
void loadMemCostParams(AbstractLedgerTxn& ltx);
void loadStateExpirationSettings(AbstractLedgerTxn& ltx);
void loadExecutionLanesSettings(AbstractLedgerTxn& ltx);

uint32_t mMaxContractSizeBytes{};
uint32_t mMaxContractDataKeySizeBytes{};
Expand All @@ -215,6 +222,7 @@ class SorobanNetworkConfig
uint32_t mLedgerMaxReadBytes{};
uint32_t mLedgerMaxWriteLedgerEntries{};
uint32_t mLedgerMaxWriteBytes{};
uint32_t mLedgerMaxTxCount{};
uint32_t mTxMaxReadLedgerEntries{};
uint32_t mTxMaxReadBytes{};
uint32_t mTxMaxWriteLedgerEntries{};
Expand Down
6 changes: 3 additions & 3 deletions src/ledger/test/LedgerCloseMetaStreamTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ TEST_CASE_VERSIONS("meta stream contains reasonable meta", "[ledgerclosemeta]")
VirtualClock clock;
cfg.METADATA_OUTPUT_STREAM = metaPath;
// TODO: later when network configs per ledger are settled, regenerate
// meta and remove the 6 lines below
// meta and remove the 7 lines below
cfg.TESTING_LEDGER_MAX_SOROBAN_TX_COUNT = 1;
cfg.TESTING_LEDGER_MAX_PROPAGATE_SIZE_BYTES = 1;
cfg.TESTING_LEDGER_MAX_INSTRUCTIONS = 1;
cfg.TESTING_LEDGER_MAX_READ_LEDGER_ENTRIES = 1;
Expand All @@ -474,8 +475,7 @@ TEST_CASE_VERSIONS("meta stream contains reasonable meta", "[ledgerclosemeta]")
auto cur1 = issuer.asset("CUR1");

// Ledger #5 sets up a trustline which has to happen before we can
// use
// it.
// use it.
acc1.changeTrust(cur1, 100);

// Ledger #6 uses closeLedger so emits interesting meta.
Expand Down
1 change: 1 addition & 0 deletions src/main/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ Config::Config() : NODE_SEED(SecretKey::random())
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;

HTTP_PORT = DEFAULT_PEER_PORT + 1;
PUBLIC_HTTP_PORT = false;
Expand Down
2 changes: 2 additions & 0 deletions src/main/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ class Config : public std::enable_shared_from_this<Config>
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;

unsigned short HTTP_PORT; // what port to listen for commands
bool PUBLIC_HTTP_PORT; // if you accept commands from not localhost
int HTTP_MAX_CLIENT; // maximum number of http clients, i.e backlog
Expand Down
Loading