Skip to content

Commit

Permalink
rework "sorobaninfo" to use names from xdr when using "basic"
Browse files Browse the repository at this point in the history
  • Loading branch information
MonsieurNicolas committed Feb 27, 2024
1 parent 07b920a commit aa0d36d
Showing 1 changed file with 20 additions and 105 deletions.
125 changes: 20 additions & 105 deletions src/main/CommandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,124 +752,39 @@ CommandHandler::sorobanInfo(std::string const& params, std::string& retStr)
return;
}

std::set<uint32_t> excluded;
auto format =
parseOptionalParamOrDefault<std::string>(retMap, "format", "basic");
if (format == "basic")
{
Json::Value res;
auto const& conf = lm.getSorobanNetworkConfig();

// Contract size
res["max_contract_size"] = conf.maxContractSizeBytes();

// Contract data
res["max_contract_data_key_size"] =
conf.maxContractDataKeySizeBytes();
res["max_contract_data_entry_size"] =
conf.maxContractDataEntrySizeBytes();

// Compute settings
res["tx"]["max_instructions"] =
static_cast<Json::Int64>(conf.txMaxInstructions());
res["ledger"]["max_instructions"] =
static_cast<Json::Int64>(conf.ledgerMaxInstructions());
res["fee_rate_per_instructions_increment"] =
static_cast<Json::Int64>(
conf.feeRatePerInstructionsIncrement());
res["tx"]["memory_limit"] = conf.txMemoryLimit();

// Ledger access settings
res["ledger"]["max_read_ledger_entries"] =
conf.ledgerMaxReadLedgerEntries();
res["ledger"]["max_read_bytes"] = conf.ledgerMaxReadBytes();
res["ledger"]["max_write_ledger_entries"] =
conf.ledgerMaxWriteLedgerEntries();
res["ledger"]["max_write_bytes"] = conf.ledgerMaxWriteBytes();
res["tx"]["max_read_ledger_entries"] =
conf.txMaxReadLedgerEntries();
res["tx"]["max_read_bytes"] = conf.txMaxReadBytes();
res["tx"]["max_write_ledger_entries"] =
conf.txMaxWriteLedgerEntries();
res["tx"]["max_write_bytes"] = conf.txMaxWriteBytes();

// Fees
res["fee_read_ledger_entry"] =
static_cast<Json::Int64>(conf.feeReadLedgerEntry());
res["fee_write_ledger_entry"] =
static_cast<Json::Int64>(conf.feeWriteLedgerEntry());
res["fee_read_1kb"] = static_cast<Json::Int64>(conf.feeRead1KB());
res["fee_write_1kb"] = static_cast<Json::Int64>(conf.feeWrite1KB());
res["fee_historical_1kb"] =
static_cast<Json::Int64>(conf.feeHistorical1KB());

// Contract events settings
res["tx"]["max_contract_events_size_bytes"] =
conf.txMaxContractEventsSizeBytes();
res["fee_contract_events_size_1kb"] =
static_cast<Json::Int64>(conf.feeContractEventsSize1KB());

// Bandwidth related data settings
res["ledger"]["max_tx_size_bytes"] =
conf.ledgerMaxTransactionSizesBytes();
res["tx"]["max_size_bytes"] = conf.txMaxSizeBytes();
res["fee_transaction_size_1kb"] =
static_cast<Json::Int64>(conf.feeTransactionSize1KB());

// General execution ledger settings
res["ledger"]["max_tx_count"] = conf.ledgerMaxTxCount();

// State archival settings
auto& archivalInfo = res["state_archival"];
auto const& stateArchivalSettings = conf.stateArchivalSettings();
archivalInfo["max_entry_ttl"] = stateArchivalSettings.maxEntryTTL;
archivalInfo["min_temporary_ttl"] =
stateArchivalSettings.minTemporaryTTL;
archivalInfo["min_persistent_ttl"] =
stateArchivalSettings.minPersistentTTL;

archivalInfo["persistent_rent_rate_denominator"] =
static_cast<Json::Int64>(
stateArchivalSettings.persistentRentRateDenominator);
archivalInfo["temp_rent_rate_denominator"] =
static_cast<Json::Int64>(
stateArchivalSettings.tempRentRateDenominator);

archivalInfo["max_entries_to_archive"] =
stateArchivalSettings.maxEntriesToArchive;
archivalInfo["bucketlist_size_window_sample_size"] =
stateArchivalSettings.bucketListSizeWindowSampleSize;

archivalInfo["eviction_scan_size"] = static_cast<Json::UInt64>(
stateArchivalSettings.evictionScanSize);
archivalInfo["starting_eviction_scan_level"] =
stateArchivalSettings.startingEvictionScanLevel;
archivalInfo["bucket_list_size_snapshot_period"] =
stateArchivalSettings.bucketListSizeWindowSampleSize;

// non-configurable settings
archivalInfo["average_bucket_list_size"] =
static_cast<Json::UInt64>(conf.getAverageBucketListSize());
retStr = res.toStyledString();
excluded.insert(
{CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS,
CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES,
CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW,
CONFIG_SETTING_EVICTION_ITERATOR});
}
else if (format == "detailed")
{
LedgerTxn ltx(mApp.getLedgerTxnRoot(),
/* shouldUpdateLastModified */ false,
TransactionMode::READ_ONLY_WITHOUT_SQL_TXN);
xdr::xvector<ConfigSettingEntry> entries;
for (auto c : xdr::xdr_traits<ConfigSettingID>::enum_values())
}
else
{
retStr = "Invalid format option";
return;
}
LedgerTxn ltx(mApp.getLedgerTxnRoot(),
/* shouldUpdateLastModified */ false,
TransactionMode::READ_ONLY_WITHOUT_SQL_TXN);
xdr::xvector<ConfigSettingEntry> entries;
for (auto c : xdr::xdr_traits<ConfigSettingID>::enum_values())
{
if (excluded.find(c) == excluded.end())
{
auto entry =
ltx.load(configSettingKey(static_cast<ConfigSettingID>(c)));
entries.emplace_back(entry.current().data.configSetting());
}

retStr = xdr_to_string(entries, "ConfigSettingsEntries");
}
else
{
retStr = "Invalid format option";
}
retStr = xdr_to_string(entries, "ConfigSettingsEntries");
}
else
{
Expand Down

0 comments on commit aa0d36d

Please sign in to comment.