Skip to content

Commit

Permalink
Merge branch 'main' into cli/restore-preamble
Browse files Browse the repository at this point in the history
  • Loading branch information
tsachiherman authored Aug 24, 2023
2 parents 812b65a + 28478ef commit 9af4cd6
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 31 deletions.
1 change: 1 addition & 0 deletions cmd/crates/soroban-spec-json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub fn generate_from_wasm(wasm: &[u8]) -> Result<String, FromWasmError> {
Ok(json)
}

/// # Panics
pub fn generate(spec: &[ScSpecEntry]) -> String {
let collected: Vec<_> = spec.iter().map(Entry::from).collect();
serde_json::to_string_pretty(&collected).expect("serialization of the spec entries should not have any failure cases as all keys are strings and the serialize implementations are derived")
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ fn build_custom_cmd(name: &str, spec: &Spec) -> Result<clap::Command, Error> {
let long_doc: &'static str = Box::leak(arg_file_help(doc).into_boxed_str());

cmd = cmd.about(Some(doc)).long_about(long_doc);
for (name, type_) in inputs_map.iter() {
for (name, type_) in inputs_map {
let mut arg = clap::Arg::new(name);
let file_arg_name = fmt_arg_file_name(name);
let mut file_arg = clap::Arg::new(&file_arg_name);
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn short() -> String {
pub fn long() -> String {
let env = soroban_env_host::VERSION;
let xdr = soroban_env_host::VERSION.xdr;
vec![
[
short(),
format!("soroban-env {} ({})", env.pkg, env.rev),
format!("soroban-env interface version {}", meta::INTERFACE_VERSION),
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/log/event.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use soroban_env_host::events::HostEvent;

pub fn events(events: &[HostEvent]) {
for event in events.iter() {
for event in events {
tracing::info!(log = event.to_string());
}
}
6 changes: 4 additions & 2 deletions cmd/soroban-cli/src/rpc/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ pub fn sign_soroban_authorizations(
let SorobanAuthorizationEntry {
credentials: SorobanCredentials::Address(ref mut credentials),
..
} = auth else {
} = auth
else {
// Doesn't need special signing
return Ok(auth);
};
Expand Down Expand Up @@ -187,7 +188,8 @@ pub fn sign_soroban_authorization_entry(
let SorobanAuthorizationEntry {
credentials: SorobanCredentials::Address(ref mut credentials),
..
} = auth else {
} = auth
else {
// Doesn't need special signing
return Ok(auth);
};
Expand Down
6 changes: 3 additions & 3 deletions cmd/soroban-cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn add_contract_code_to_ledger_entries(
}),
ext: LedgerEntryExt::V0,
};
for (k, e) in entries.iter_mut() {
for (k, e) in &mut *entries {
if **k == code_key {
**e = code_entry;
return Ok(hash);
Expand Down Expand Up @@ -125,7 +125,7 @@ pub fn add_contract_to_ledger_entries(
}),
ext: LedgerEntryExt::V0,
};
for (k, e) in entries.iter_mut() {
for (k, e) in &mut *entries {
if **k == contract_key {
**e = contract_entry;
return;
Expand All @@ -138,7 +138,7 @@ pub fn bump_ledger_entry_expirations<S: BuildHasher>(
entries: &mut [(Box<LedgerKey>, Box<LedgerEntry>)],
lookup: &HashMap<LedgerKey, u32, S>,
) {
for (k, e) in entries.iter_mut() {
for (k, e) in &mut *entries {
if let Some(min_expiration) = lookup.get(k.as_ref()) {
if let LedgerEntryData::ContractData(entry) = &mut e.data {
entry.expiration_ledger_seq = *min_expiration;
Expand Down
7 changes: 5 additions & 2 deletions cmd/soroban-rpc/internal/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,20 @@ func NewJSONRPCHandler(cfg *config.Config, params HandlerParams) Handler {
Namespace: params.Daemon.MetricsNamespace(), Subsystem: "network", Name: "global_request_execution_duration_threshold_limit",
Help: "The metric measures the count of requests that surpassed the limit threshold for execution time",
})
durationLimitedBridge := network.MakeHTTPRequestDurationLimiter(
var handler http.Handler = network.MakeHTTPRequestDurationLimiter(
queueLimitedBridge,
cfg.RequestExecutionWarningThreshold,
cfg.MaxRequestExecutionDuration,
globalQueueRequestExecutionDurationWarningCounter,
globalQueueRequestExecutionDurationLimitCounter,
params.Logger)

// Limit request sizes to 10MB
handler = http.MaxBytesHandler(handler, 1024*1024*10)

return Handler{
bridge: bridge,
logger: params.Logger,
Handler: durationLimitedBridge,
Handler: handler,
}
}
13 changes: 6 additions & 7 deletions cmd/soroban-rpc/lib/preflight/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ fn get_fee_configurations(
ledger_storage.get_configuration_setting(ConfigSettingId::ContractComputeV0)?
else {
bail!("unexpected config setting entry for ComputeV0 key");

};

let ConfigSettingEntry::ContractLedgerCostV0(ledger_cost) =
Expand Down Expand Up @@ -195,9 +194,9 @@ fn get_fee_configurations(

let ConfigSettingEntry::StateExpiration(state_expiration) =
ledger_storage.get_configuration_setting(ConfigSettingId::StateExpiration)?
else {
bail!("unexpected config setting entry for StateExpiration key");
};
else {
bail!("unexpected config setting entry for StateExpiration key");
};

let write_fee_configuration = WriteFeeConfiguration {
bucket_list_target_size_bytes: ledger_cost.bucket_list_target_size_bytes,
Expand Down Expand Up @@ -395,9 +394,9 @@ pub(crate) fn compute_restore_footprint_transaction_data_and_min_fee(
) -> Result<(SorobanTransactionData, i64)> {
let ConfigSettingEntry::StateExpiration(state_expiration) =
ledger_storage.get_configuration_setting(ConfigSettingId::StateExpiration)?
else {
bail!("unexpected config setting entry for StateExpiration key");
};
else {
bail!("unexpected config setting entry for StateExpiration key");
};
let rent_changes = compute_restore_footprint_rent_changes(
&footprint,
ledger_storage,
Expand Down
10 changes: 5 additions & 5 deletions cmd/soroban-rpc/lib/preflight/src/ledger_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ impl LedgerStorage {
let setting_id = ConfigSettingId::StateExpiration;
let ConfigSettingEntry::StateExpiration(state_expiration) =
ledger_storage.get_configuration_setting(setting_id)?
else {
return Err(
Error::UnexpectedConfigLedgerEntry { setting_id: setting_id.name().to_string() }
);
};
else {
return Err(Error::UnexpectedConfigLedgerEntry {
setting_id: setting_id.name().to_string(),
});
};
// Now that we have the state expiration config, we can build the tracker
ledger_storage.restore_tracker = Some(EntryRestoreTracker {
current_ledger_seq: current_ledger_sequence,
Expand Down
18 changes: 9 additions & 9 deletions cmd/soroban-rpc/lib/preflight/src/preflight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,21 @@ fn host_events_to_diagnostic_events(events: &Events) -> Vec<DiagnosticEvent> {
fn get_budget_from_network_config_params(ledger_storage: &LedgerStorage) -> Result<Budget> {
let ConfigSettingEntry::ContractComputeV0(compute) =
ledger_storage.get_configuration_setting(ConfigSettingId::ContractComputeV0)?
else {
bail!("unexpected config setting entry for ComputeV0 key");
};
else {
bail!("unexpected config setting entry for ComputeV0 key");
};

let ConfigSettingEntry::ContractCostParamsCpuInstructions(cost_params_cpu) = ledger_storage
.get_configuration_setting(ConfigSettingId::ContractCostParamsCpuInstructions)?
else {
bail!("unexpected config setting entry for CostParamsCpuInstructions key");
};
else {
bail!("unexpected config setting entry for CostParamsCpuInstructions key");
};

let ConfigSettingEntry::ContractCostParamsMemoryBytes(cost_params_memory) =
ledger_storage.get_configuration_setting(ConfigSettingId::ContractCostParamsMemoryBytes)?
else {
bail!("unexpected config setting entry for CostParamsMemoryBytes key");
};
else {
bail!("unexpected config setting entry for CostParamsMemoryBytes key");
};

let budget = Budget::try_from_configs(
compute.tx_max_instructions as u64,
Expand Down

0 comments on commit 9af4cd6

Please sign in to comment.