Skip to content

Commit

Permalink
soroban upgrades for simulation tests and fix runHistoricalSnapshotTest
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasBrady committed Aug 30, 2024
1 parent 052c40b commit d4bf49a
Show file tree
Hide file tree
Showing 12 changed files with 437 additions and 135 deletions.
4 changes: 3 additions & 1 deletion src/bucket/test/BucketIndexTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ class BucketIndexTest
runHistoricalSnapshotTest()
{
uint32_t ledger = 0;
auto canonicalEntry = LedgerTestUtils::generateValidLedgerEntry();
auto canonicalEntry =
LedgerTestUtils::generateValidLedgerEntryWithExclusions(
{LedgerEntryType::CONFIG_SETTING});
canonicalEntry.lastModifiedLedgerSeq = 0;

do
Expand Down
8 changes: 8 additions & 0 deletions src/herder/TransactionQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ class SorobanTransactionQueue : public TransactionQueue
}

size_t getMaxQueueSizeOps() const override;
#ifdef BUILD_TESTS
void
clearBroadcastCarryover()
{
mBroadcastOpCarryover.clear();
mBroadcastOpCarryover.resize(1, Resource::makeEmptySoroban());
}
#endif

private:
virtual std::pair<Resource, std::optional<Resource>>
Expand Down
4 changes: 2 additions & 2 deletions src/herder/Upgrades.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class ConfigUpgradeSetFrame
static ConfigUpgradeSetFrameConstPtr
makeFromKey(AbstractLedgerTxn& ltx, ConfigUpgradeSetKey const& key);

static LedgerKey getLedgerKey(ConfigUpgradeSetKey const& upgradeKey);

ConfigUpgradeSet const& toXDR() const;

ConfigUpgradeSetKey const& getKey() const;
Expand All @@ -182,8 +184,6 @@ class ConfigUpgradeSetFrame
ConfigUpgradeSetKey const& key,
uint32_t ledgerVersion);

static LedgerKey getLedgerKey(ConfigUpgradeSetKey const& upgradeKey);

bool isValidXDR(ConfigUpgradeSet const& upgradeSetXDR,
ConfigUpgradeSetKey const& key) const;

Expand Down
117 changes: 54 additions & 63 deletions src/herder/test/HerderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3213,24 +3213,22 @@ TEST_CASE("soroban txs each parameter surge priced", "[soroban][herder]")
});
simulation->startAllNodes();
auto nodes = simulation->getNodes();
for (auto& node : nodes)
{
overrideSorobanNetworkConfigForTest(*node);
modifySorobanNetworkConfig(
*node, [&tweakSorobanConfig](SorobanNetworkConfig& cfg) {
auto mx = std::numeric_limits<uint32_t>::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;
tweakSorobanConfig(cfg);
});
}
upgradeSorobanNetworkConfig(
[&tweakSorobanConfig](SorobanNetworkConfig& cfg) {
setSorobanNetworkConfigForTest(cfg);
auto mx = std::numeric_limits<uint32_t>::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;
tweakSorobanConfig(cfg);
},
simulation);
auto& loadGen = nodes[0]->getLoadGenerator();

// Generate some accounts
Expand Down Expand Up @@ -3513,20 +3511,19 @@ TEST_CASE("overlay parallel processing")
uint32_t desiredTxRate = 1;
uint32_t ledgerWideLimit = static_cast<uint32>(
desiredTxRate * Herder::EXP_LEDGER_TIMESPAN_SECONDS.count() * 2);
uint32_t const numAccounts = 100;
for (auto& node : nodes)
{
overrideSorobanNetworkConfigForTest(*node);
modifySorobanNetworkConfig(*node, [&](SorobanNetworkConfig& cfg) {
upgradeSorobanNetworkConfig(
[&](SorobanNetworkConfig& cfg) {
setSorobanNetworkConfigForTest(cfg);
cfg.mLedgerMaxTxCount = ledgerWideLimit;
});
}
},
simulation);
auto& loadGen = nodes[0]->getLoadGenerator();

// Generate some accounts
auto& loadGenDone =
nodes[0]->getMetrics().NewMeter({"loadgen", "run", "complete"}, "run");
auto currLoadGenCount = loadGenDone.count();
uint32_t const numAccounts = 100;
loadGen.generateLoad(
GeneratedLoadConfig::createAccountsLoad(numAccounts, desiredTxRate));
simulation->crankUntil(
Expand Down Expand Up @@ -3583,13 +3580,13 @@ TEST_CASE("soroban txs accepted by the network",
uint32_t ledgerWideLimit = static_cast<uint32>(
desiredTxRate * Herder::EXP_LEDGER_TIMESPAN_SECONDS.count() * 2);
uint32_t const numAccounts = 100;
for (auto& node : nodes)
{
overrideSorobanNetworkConfigForTest(*node);
modifySorobanNetworkConfig(*node, [&](SorobanNetworkConfig& cfg) {
upgradeSorobanNetworkConfig(
[&](SorobanNetworkConfig& cfg) {
setSorobanNetworkConfigForTest(cfg);
cfg.mLedgerMaxTxCount = ledgerWideLimit;
});
}
},
simulation);

auto& loadGen = nodes[0]->getLoadGenerator();
auto& txsSucceeded =
nodes[0]->getMetrics().NewCounter({"ledger", "apply", "success"});
Expand All @@ -3610,6 +3607,7 @@ TEST_CASE("soroban txs accepted by the network",
[&]() { return loadGenDone.count() > currLoadGenCount; },
10 * Herder::EXP_LEDGER_TIMESPAN_SECONDS, false);

uint64_t lastSorobanSucceeded = sorobanTxsSucceeded.count();
uint64_t lastSucceeded = txsSucceeded.count();
REQUIRE(lastSucceeded > 0);
REQUIRE(txsFailed.count() == 0);
Expand Down Expand Up @@ -3749,8 +3747,9 @@ TEST_CASE("soroban txs accepted by the network",
REQUIRE(secondLoadGenFailed.count() == 0);
// Check all classic txs got applied
REQUIRE(txsSucceeded.count() - lastSucceeded -
sorobanTxsSucceeded.count() ==
classicTxCount);
sorobanTxsSucceeded.count() +
lastSorobanSucceeded /* to prevent double counting */
== classicTxCount);
REQUIRE(txsFailed.count() == sorobanTxsFailed.count());
}
}
Expand Down Expand Up @@ -3862,16 +3861,15 @@ herderExternalizesValuesWithProtocol(uint32_t version)
REQUIRE(getC()->getHerder().getState() ==
Herder::State::HERDER_BOOTING_STATE);

simulation->startAllNodes();
if (protocolVersionStartsFrom(version, SOROBAN_PROTOCOL_VERSION))
{
for (auto const& node : simulation->getNodes())
{
modifySorobanNetworkConfig(*node, [&](SorobanNetworkConfig& cfg) {
upgradeSorobanNetworkConfig(
[&](SorobanNetworkConfig& cfg) {
cfg.mStateArchivalSettings.bucketListWindowSamplePeriod = 1;
});
}
},
simulation);
}
simulation->startAllNodes();

// After SCP is restored, Herder is tracking
REQUIRE(getC()->getHerder().getState() ==
Expand Down Expand Up @@ -3933,7 +3931,7 @@ herderExternalizesValuesWithProtocol(uint32_t version)
return currentALedger();
};

uint32_t currentLedger = 1;
uint32_t currentLedger = currentBLedger();
REQUIRE(currentALedger() == currentLedger);
REQUIRE(currentCLedger() == currentLedger);

Expand Down Expand Up @@ -4192,12 +4190,6 @@ herderExternalizesValuesWithProtocol(uint32_t version)
simulation->removeNode(validatorCKey.getPublicKey());
configC.MAX_SLOTS_TO_REMEMBER += 5;
auto newC = simulation->addNode(validatorCKey, qset, &configC, false);
if (protocolVersionStartsFrom(version, SOROBAN_PROTOCOL_VERSION))
{
modifySorobanNetworkConfig(*newC, [&](SorobanNetworkConfig& cfg) {
cfg.mStateArchivalSettings.bucketListWindowSamplePeriod = 1;
});
}
newC->start();
HerderImpl& newHerderC = *static_cast<HerderImpl*>(&newC->getHerder());

Expand All @@ -4208,7 +4200,6 @@ herderExternalizesValuesWithProtocol(uint32_t version)
SECTION("tracking")
{
receiveLedger(destinationLedger, newHerderC);

checkHerder(*newC, newHerderC,
Herder::State::HERDER_TRACKING_NETWORK_STATE,
currentlyTracking);
Expand Down Expand Up @@ -4641,8 +4632,8 @@ 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.NODE_IS_VALIDATOR = false;
cfg.FORCE_SCP = false;
cfg.NODE_IS_VALIDATOR = true;
cfg.FORCE_SCP = true;
cfg.FLOOD_TX_PERIOD_MS = 100;
cfg.FLOOD_OP_RATE_PER_LEDGER = 2.0;
cfg.FLOOD_SOROBAN_TX_PERIOD_MS = 50;
Expand All @@ -4654,32 +4645,30 @@ TEST_CASE("do not flood too many soroban transactions",
auto otherKey = SecretKey::fromSeed(sha256("other"));

SCPQuorumSet qset;
qset.threshold = 1;
qset.threshold = 2;
qset.validators.push_back(mainKey.getPublicKey());
qset.validators.push_back(otherKey.getPublicKey());

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);

upgradeSorobanNetworkConfig(
[&](SorobanNetworkConfig& cfg) {
setSorobanNetworkConfigForTest(cfg);
// Update read entries to allow flooding at most 1 tx per broadcast
// interval.
cfg.mLedgerMaxReadLedgerEntries = 40;
cfg.mLedgerMaxReadBytes = cfg.mTxMaxReadBytes;
},
simulation);

auto const& cfg = app->getConfig();
auto& lm = app->getLedgerManager();
auto& herder = static_cast<HerderImpl&>(app->getHerder());
Expand Down Expand Up @@ -4769,6 +4758,8 @@ TEST_CASE("do not flood too many soroban transactions",
{
// no broadcast right away
REQUIRE(numBroadcast == 0);
tq.clearBroadcastCarryover();

// wait for a bit more than a broadcast period
// rate per period is 100 ms
auto broadcastPeriod =
Expand Down
71 changes: 71 additions & 0 deletions src/ledger/NetworkConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,22 @@ SorobanNetworkConfig::bucketListTargetSizeBytes() const
return mBucketListTargetSizeBytes;
}

int64_t
SorobanNetworkConfig::writeFee1KBBucketListLow() const
{
return mWriteFee1KBBucketListLow;
}
int64_t
SorobanNetworkConfig::writeFee1KBBucketListHigh() const
{
return mWriteFee1KBBucketListHigh;
}
uint32_t
SorobanNetworkConfig::bucketListWriteFeeGrowthFactor() const
{
return mBucketListWriteFeeGrowthFactor;
}

// Historical data (pushed to core archives) settings for contracts.
int64_t
SorobanNetworkConfig::feeHistorical1KB() const
Expand Down Expand Up @@ -1712,4 +1728,59 @@ SorobanNetworkConfig::computeWriteFee(uint32_t configMaxProtocol,
mFeeWrite1KB = rust_bridge::compute_write_fee_per_1kb(
configMaxProtocol, protocolVersion, mAverageBucketListSize, feeConfig);
}

bool
SorobanNetworkConfig::operator==(SorobanNetworkConfig const& other) const
{
return mMaxContractSizeBytes == other.maxContractSizeBytes() &&
mMaxContractDataKeySizeBytes ==
other.maxContractDataKeySizeBytes() &&
mMaxContractDataEntrySizeBytes ==
other.maxContractDataEntrySizeBytes() &&

mLedgerMaxInstructions == other.ledgerMaxInstructions() &&
mTxMaxInstructions == other.txMaxInstructions() &&
mFeeRatePerInstructionsIncrement ==
other.feeRatePerInstructionsIncrement() &&
mTxMemoryLimit == other.txMemoryLimit() &&

mLedgerMaxReadLedgerEntries == other.ledgerMaxReadLedgerEntries() &&
mLedgerMaxReadBytes == other.ledgerMaxReadBytes() &&
mLedgerMaxWriteLedgerEntries ==
other.ledgerMaxWriteLedgerEntries() &&
mLedgerMaxWriteBytes == other.ledgerMaxWriteBytes() &&
mLedgerMaxTxCount == other.ledgerMaxTxCount() &&

mTxMaxReadLedgerEntries == other.txMaxReadLedgerEntries() &&
mTxMaxReadBytes == other.txMaxReadBytes() &&
mTxMaxWriteLedgerEntries == other.txMaxWriteLedgerEntries() &&
mTxMaxWriteBytes == other.txMaxWriteBytes() &&
mFeeReadLedgerEntry == other.feeReadLedgerEntry() &&
mFeeWriteLedgerEntry == other.feeWriteLedgerEntry() &&
mFeeRead1KB == other.feeRead1KB() &&
mBucketListTargetSizeBytes == other.bucketListTargetSizeBytes() &&

mWriteFee1KBBucketListLow == other.writeFee1KBBucketListLow() &&
mWriteFee1KBBucketListHigh == other.writeFee1KBBucketListHigh() &&
mBucketListWriteFeeGrowthFactor ==
other.bucketListWriteFeeGrowthFactor() &&

mFeeHistorical1KB == other.feeHistorical1KB() &&

mTxMaxContractEventsSizeBytes ==
other.txMaxContractEventsSizeBytes() &&
mFeeContractEvents1KB == other.feeContractEventsSize1KB() &&

mLedgerMaxTransactionsSizeBytes ==
other.ledgerMaxTransactionSizesBytes() &&
mTxMaxSizeBytes == other.txMaxSizeBytes() &&
mFeeTransactionSize1KB == other.feeTransactionSize1KB() &&

mCpuCostParams == other.cpuCostParams() &&
mMemCostParams == other.memCostParams() &&

mStateArchivalSettings == other.stateArchivalSettings() &&
mEvictionIterator == other.evictionIterator();
}

} // namespace stellar
4 changes: 4 additions & 0 deletions src/ledger/NetworkConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ class SorobanNetworkConfig
int64_t feeWrite1KB() const;
// Bucket list target size (in bytes)
int64_t bucketListTargetSizeBytes() const;
int64_t writeFee1KBBucketListLow() const;
int64_t writeFee1KBBucketListHigh() const;
uint32_t bucketListWriteFeeGrowthFactor() const;

// Historical data (pushed to core archives) settings for contracts.
// Fee for storing 1KB in archives
Expand Down Expand Up @@ -328,6 +331,7 @@ class SorobanNetworkConfig
StateArchivalSettings& stateArchivalSettings();
EvictionIterator& evictionIterator();
#endif
bool operator==(SorobanNetworkConfig const& other) const;

private:
void loadMaxContractSize(AbstractLedgerTxn& ltx);
Expand Down
Loading

0 comments on commit d4bf49a

Please sign in to comment.