Skip to content

Commit

Permalink
Create and use TestOverrideSorobanNetworkConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
jayz22 committed Aug 29, 2023
1 parent 16d4645 commit 9e4e311
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 21 deletions.
55 changes: 35 additions & 20 deletions src/ledger/NetworkConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
57 changes: 56 additions & 1 deletion src/ledger/NetworkConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down

9 comments on commit 9e4e311

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from sisuresh
at jayz22@9e4e311

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging jayz22/stellar-core/so = 9e4e311 into auto

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jayz22/stellar-core/so = 9e4e311 merged ok, testing candidate = 5a9f7c5b

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from sisuresh
at jayz22@9e4e311

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging jayz22/stellar-core/so = 9e4e311 into auto

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jayz22/stellar-core/so = 9e4e311 merged ok, testing candidate = bf43636

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = bf43636

Please sign in to comment.