Skip to content

Commit

Permalink
Increase memory budget to 50MB (#737)
Browse files Browse the repository at this point in the history
* Increase memory budget to 50MB; impl display

* fixup! Increase memory budget to 50MB; impl display
  • Loading branch information
jayz22 authored Mar 22, 2023
1 parent 7dde7cb commit 75b2169
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions soroban-env-host/src/budget.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
cell::{RefCell, RefMut},
fmt::Debug,
fmt::{Debug, Display},
rc::Rc,
};

Expand Down Expand Up @@ -260,6 +260,7 @@ pub(crate) struct BudgetImpl {

impl Debug for BudgetImpl {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "{:=<70}", "")?;
writeln!(
f,
"Cpu limit: {}; used: {}",
Expand All @@ -270,27 +271,28 @@ impl Debug for BudgetImpl {
"Mem limit: {}; used: {}",
self.mem_bytes.limit, self.mem_bytes.total_count
)?;

// TODO: align them nicely
writeln!(f, "CostType\tinput\tcpu_insns\tmem_bytes")?;
writeln!(f, "{:=<70}", "")?;
writeln!(
f,
"{:<25}{:<15}{:<15}{:<15}",
"CostType", "input", "cpu_insns", "mem_bytes"
)?;
for ct in CostType::variants() {
let i = *ct as usize;
writeln!(
f,
"{:?}\t{}\t{}\t{}",
ct, self.inputs[i], self.cpu_insns.counts[i], self.mem_bytes.counts[i]
"{:<25}{:<15}{:<15}{:<15}",
format!("{:?}", ct),
self.inputs[i],
self.cpu_insns.counts[i],
self.mem_bytes.counts[i]
)?;
}
writeln!(f, "{:=<70}", "")?;
Ok(())
}
}

#[test]
fn test_print() {
let budget = Budget::default();
println!("{:?}", budget)
}

#[derive(Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Budget(pub(crate) Rc<RefCell<BudgetImpl>>);

Expand All @@ -300,6 +302,12 @@ impl Debug for Budget {
}
}

impl Display for Budget {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
<Self as Debug>::fmt(&self, f)
}
}

pub trait AsBudget {
fn as_budget(&self) -> &Budget;
}
Expand Down Expand Up @@ -532,7 +540,7 @@ impl Default for BudgetImpl {
// TODO: Set proper limits once all the machinary (including in SDK tests) is in place and models are calibrated.
// For now we set a generous but finite limit for DOS prevention.
b.cpu_insns.reset(40_000_000); // 100x the estimation above which corresponds to 10ms
b.mem_bytes.reset(0xa0_0000); // 10MB of memory
b.mem_bytes.reset(0x320_0000); // 50MB of memory
b
}
}

0 comments on commit 75b2169

Please sign in to comment.