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

Misc fixes/improvements for tx generator. #4529

Merged
merged 4 commits into from
Nov 5, 2024
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
9 changes: 5 additions & 4 deletions src/herder/test/HerderTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4147,14 +4147,15 @@ herderExternalizesValuesWithProtocol(uint32_t version)

TEST_CASE("herder externalizes values", "[herder]")
{
SECTION("v19")
SECTION("prev protocol")
{
herderExternalizesValuesWithProtocol(19);
herderExternalizesValuesWithProtocol(
Config::CURRENT_LEDGER_PROTOCOL_VERSION - 1);
}
SECTION("soroban")
SECTION("curr protocol")
{
herderExternalizesValuesWithProtocol(
static_cast<uint32_t>(SOROBAN_PROTOCOL_VERSION));
Config::CURRENT_LEDGER_PROTOCOL_VERSION);
}
}

Expand Down
122 changes: 122 additions & 0 deletions src/ledger/NetworkConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,10 @@ SorobanNetworkConfig::initializeGenesisLedgerForTesting(
ltx.loadHeader().current().ledgerVersion =
static_cast<uint32_t>(SOROBAN_PROTOCOL_VERSION);
SorobanNetworkConfig::createLedgerEntriesForV20(ltx, app);
// Protocol 20 released with somewhat incorrect costs and has been
// re-calibrated short after the release. We catch up here to the more
// correct costs that exist on the network.
updateRecalibratedCostTypesForV20(ltx);
ltx.loadHeader().current().ledgerVersion = genesisLedgerProtocol;
}

Expand Down Expand Up @@ -1927,6 +1931,124 @@ SorobanNetworkConfig::evictionIterator()
{
return mEvictionIterator;
}

void
SorobanNetworkConfig::updateRecalibratedCostTypesForV20(
dmkozh marked this conversation as resolved.
Show resolved Hide resolved
AbstractLedgerTxn& ltxRoot)
{
LedgerTxn ltx(ltxRoot);

LedgerKey key(CONFIG_SETTING);
key.configSetting().configSettingID =
ConfigSettingID::CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS;

auto& cpuParams = ltx.load(key)
.current()
.data.configSetting()
.contractCostParamsCpuInsns();

for (size_t val = 0; val < cpuParams.size(); ++val)
{
switch (val)
{
case DispatchHostFunction:
cpuParams[val] = ContractCostParamEntry{ExtensionPoint{0}, 295, 0};
break;
case VisitObject:
cpuParams[val] = ContractCostParamEntry{ExtensionPoint{0}, 60, 0};
break;
case ValSer:
cpuParams[val] = ContractCostParamEntry{ExtensionPoint{0}, 221, 26};
break;
case ValDeser:
cpuParams[val] =
ContractCostParamEntry{ExtensionPoint{0}, 331, 4369};
break;
case ComputeSha256Hash:
cpuParams[val] =
ContractCostParamEntry{ExtensionPoint{0}, 3636, 7013};
break;
case ComputeEd25519PubKey:
cpuParams[val] =
ContractCostParamEntry{ExtensionPoint{0}, 40256, 0};
break;
case VerifyEd25519Sig:
cpuParams[val] =
ContractCostParamEntry{ExtensionPoint{0}, 377551, 4059};
break;
case VmInstantiation:
cpuParams[val] =
ContractCostParamEntry{ExtensionPoint{0}, 417482, 45712};
break;
case VmCachedInstantiation:
cpuParams[val] =
ContractCostParamEntry{ExtensionPoint{0}, 417482, 45712};
break;
case InvokeVmFunction:
cpuParams[val] = ContractCostParamEntry{ExtensionPoint{0}, 1945, 0};
break;
case ComputeKeccak256Hash:
cpuParams[val] =
ContractCostParamEntry{ExtensionPoint{0}, 6481, 5943};
break;
case DecodeEcdsaCurve256Sig:
cpuParams[val] = ContractCostParamEntry{ExtensionPoint{0}, 711, 0};
break;
case RecoverEcdsaSecp256k1Key:
cpuParams[val] =
ContractCostParamEntry{ExtensionPoint{0}, 2314804, 0};
break;
case Int256AddSub:
cpuParams[val] = ContractCostParamEntry{ExtensionPoint{0}, 4176, 0};
break;
case Int256Mul:
cpuParams[val] = ContractCostParamEntry{ExtensionPoint{0}, 4716, 0};
break;
case Int256Div:
cpuParams[val] = ContractCostParamEntry{ExtensionPoint{0}, 4680, 0};
break;
case Int256Pow:
cpuParams[val] = ContractCostParamEntry{ExtensionPoint{0}, 4256, 0};
break;
case Int256Shift:
cpuParams[val] = ContractCostParamEntry{ExtensionPoint{0}, 884, 0};
break;
case ChaCha20DrawBytes:
cpuParams[val] =
ContractCostParamEntry{ExtensionPoint{0}, 1059, 502};
break;
default:
break;
}
}

LedgerKey memKey(CONFIG_SETTING);
memKey.configSetting().configSettingID =
ConfigSettingID::CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES;

auto& memParams = ltx.load(memKey)
.current()
.data.configSetting()
.contractCostParamsMemBytes();
for (size_t val = 0; val < memParams.size(); ++val)
{
switch (val)
{
case VmInstantiation:
memParams[val] =
ContractCostParamEntry{ExtensionPoint{0}, 132773, 4903};
break;
case VmCachedInstantiation:
memParams[val] =
ContractCostParamEntry{ExtensionPoint{0}, 132773, 4903};
break;
default:
break;
}
}

ltx.commit();
}
#endif

bool
Expand Down
9 changes: 9 additions & 0 deletions src/ledger/NetworkConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,15 @@ class SorobanNetworkConfig
#ifdef BUILD_TESTS
StateArchivalSettings& stateArchivalSettings();
EvictionIterator& evictionIterator();
// Update the protocol 20 cost types to match the real network
// configuration.
// Protocol 20 cost types were imprecise and were re-calibrated shortly
// after the release. This should be called when initializing the test with
// protocol 20+.
// Future recalibrations should be accounted for in a similar way in order
// to have more accurage modelled CPU and memory costs in tests and
// especially the benchmarks.
static void updateRecalibratedCostTypesForV20(AbstractLedgerTxn& ltx);
#endif
bool operator==(SorobanNetworkConfig const& other) const;

Expand Down
24 changes: 23 additions & 1 deletion src/ledger/SorobanMetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,23 @@ SorobanMetrics::SorobanMetrics(medida::MetricsRegistry& metrics)
{"soroban", "config", "bucket-list-target-size-byte"}))
, mConfigFeeWrite1KB(
metrics.NewCounter({"soroban", "config", "fee-write-1kb"}))
, mLedgerHostFnCpuInsnsRatio(metrics.NewHistogram(
{"soroban", "host-fn-op", "ledger-cpu-insns-ratio"}))
, mLedgerHostFnCpuInsnsRatioExclVm(metrics.NewHistogram(
{"soroban", "host-fn-op", "ledger-cpu-insns-ratio-excl-vm"}))
{
}

void
SorobanMetrics::accumulateModelledCpuInsns(uint64_t insnsCount,
uint64_t insnsExclVmCount,
uint64_t hostFnExecTimeNsecs)
{
mLedgerInsnsCount += insnsCount;
mLedgerInsnsExclVmCount += insnsExclVmCount;
mLedgerHostFnExecTimeNsecs += hostFnExecTimeNsecs;
}

void
SorobanMetrics::accumulateLedgerTxCount(uint64_t txCount)
{
Expand Down Expand Up @@ -177,6 +191,11 @@ SorobanMetrics::publishAndResetLedgerWideMetrics()
mLedgerReadLedgerByte.Update(mCounterLedgerReadByte);
mLedgerWriteEntry.Update(mCounterLedgerWriteEntry);
mLedgerWriteLedgerByte.Update(mCounterLedgerWriteByte);
mLedgerHostFnCpuInsnsRatio.Update(mLedgerHostFnExecTimeNsecs * 1000000 /
std::max(mLedgerInsnsCount, uint64_t(1)));
mLedgerHostFnCpuInsnsRatioExclVm.Update(
mLedgerHostFnExecTimeNsecs * 1000000 /
std::max(mLedgerInsnsExclVmCount, uint64_t(1)));

mCounterLedgerTxCount = 0;
mCounterLedgerCpuInsn = 0;
Expand All @@ -185,5 +204,8 @@ SorobanMetrics::publishAndResetLedgerWideMetrics()
mCounterLedgerReadByte = 0;
mCounterLedgerWriteEntry = 0;
mCounterLedgerWriteByte = 0;
mLedgerHostFnExecTimeNsecs = 0;
mLedgerInsnsCount = 0;
mLedgerInsnsExclVmCount = 0;
}
}
}
9 changes: 9 additions & 0 deletions src/ledger/SorobanMetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class SorobanMetrics
uint64_t mCounterLedgerWriteEntry{0};
uint64_t mCounterLedgerWriteByte{0};

uint64_t mLedgerInsnsCount{0};
uint64_t mLedgerInsnsExclVmCount{0};
uint64_t mLedgerHostFnExecTimeNsecs{0};

public:
// ledger-wide metrics
medida::Histogram& mLedgerTxCount;
Expand All @@ -41,6 +45,8 @@ class SorobanMetrics
medida::Histogram& mLedgerReadLedgerByte;
medida::Histogram& mLedgerWriteEntry;
medida::Histogram& mLedgerWriteLedgerByte;
medida::Histogram& mLedgerHostFnCpuInsnsRatio;
medida::Histogram& mLedgerHostFnCpuInsnsRatioExclVm;

// tx-wide metrics
medida::Histogram& mTxSizeByte;
Expand Down Expand Up @@ -106,6 +112,9 @@ class SorobanMetrics

SorobanMetrics(medida::MetricsRegistry& metrics);

void accumulateModelledCpuInsns(uint64_t insnsCount,
uint64_t insnsExclVmCount,
uint64_t execTimeNsecs);
void accumulateLedgerTxCount(uint64_t txCount);
void accumulateLedgerCpuInsn(uint64_t cpuInsn);
void accumulateLedgerTxsSizeByte(uint64_t txsSizeByte);
Expand Down
35 changes: 34 additions & 1 deletion src/main/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1884,6 +1884,10 @@ runApplyLoad(CommandLineArgs const& args)
[&] {
auto config = configOption.getConfig();
config.RUN_STANDALONE = true;
config.USE_CONFIG_FOR_GENESIS = true;
config.TESTING_UPGRADE_MAX_TX_SET_SIZE = 1000;
config.LEDGER_PROTOCOL_VERSION =
Config::CURRENT_LEDGER_PROTOCOL_VERSION;

VirtualClock clock(VirtualClock::REAL_TIME);
auto appPtr = Application::create(clock, config);
Expand Down Expand Up @@ -1911,7 +1915,16 @@ runApplyLoad(CommandLineArgs const& args)
"invoke-time-fsecs-cpu-insn-ratio-excl-vm"});
cpuInsRatioExclVm.Clear();

for (size_t i = 0; i < 20; ++i)
auto& ledgerCpuInsRatio = app.getMetrics().NewHistogram(
{"soroban", "host-fn-op", "ledger-cpu-insns-ratio"});
ledgerCpuInsRatio.Clear();

auto& ledgerCpuInsRatioExclVm = app.getMetrics().NewHistogram(
{"soroban", "host-fn-op",
"ledger-cpu-insns-ratio-excl-vm"});
ledgerCpuInsRatioExclVm.Clear();

for (size_t i = 0; i < 100; ++i)
{
al.benchmark();
}
Expand All @@ -1922,6 +1935,8 @@ runApplyLoad(CommandLineArgs const& args)
ledgerClose.min());
CLOG_INFO(Perf, "Mean ledger close: {} milliseconds",
ledgerClose.mean());
CLOG_INFO(Perf, "stddev ledger close: {} milliseconds",
ledgerClose.std_dev());

CLOG_INFO(Perf, "Max CPU ins ratio: {}",
cpuInsRatio.max() / 1000000);
Expand All @@ -1932,6 +1947,24 @@ runApplyLoad(CommandLineArgs const& args)
cpuInsRatioExclVm.max() / 1000000);
CLOG_INFO(Perf, "Mean CPU ins ratio excl VM: {}",
cpuInsRatioExclVm.mean() / 1000000);
CLOG_INFO(Perf, "stddev CPU ins ratio excl VM: {}",
cpuInsRatioExclVm.std_dev() / 1000000);

CLOG_INFO(Perf, "Ledger Max CPU ins ratio: {}",
ledgerCpuInsRatio.max() / 1000000);
CLOG_INFO(Perf, "Ledger Mean CPU ins ratio: {}",
ledgerCpuInsRatio.mean() / 1000000);
CLOG_INFO(Perf, "Ledger stddev CPU ins ratio: {}",
ledgerCpuInsRatio.std_dev() / 1000000);

CLOG_INFO(Perf, "Ledger Max CPU ins ratio excl VM: {}",
ledgerCpuInsRatioExclVm.max() / 1000000);
CLOG_INFO(Perf, "Ledger Mean CPU ins ratio excl VM: {}",
ledgerCpuInsRatioExclVm.mean() / 1000000);
CLOG_INFO(
Perf,
"Ledger stddev CPU ins ratio excl VM: {} milliseconds",
ledgerCpuInsRatioExclVm.std_dev() / 1000000);

CLOG_INFO(Perf, "Tx count utilization {}%",
al.getTxCountUtilization().mean() / 1000.0);
Expand Down
Loading
Loading