Skip to content

Commit

Permalink
chore: potentially valid
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Mar 15, 2023
1 parent f6dcac4 commit 058b2e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion soroban-env-host/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ impl Host {
}
}

pub(crate) fn to_host_obj<'a>(&self, ob: &ScValObjRef<'a>) -> Result<Object, HostError> {
pub(crate) fn to_host_obj(&self, ob: &ScValObjRef) -> Result<Object, HostError> {
self.charge_budget(CostType::ValXdrConv, 1)?;
let val: &ScVal = (*ob).into();
match val {
Expand Down
25 changes: 8 additions & 17 deletions soroban-env-host/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,13 @@ impl Footprint {
) -> Result<(), HostError> {
if let Some(existing) = self.0.get::<Rc<LedgerKey>>(key, budget)? {
match (existing, ty.clone()) {
(AccessType::ReadOnly, AccessType::ReadOnly) => Ok(()),
(AccessType::ReadOnly, AccessType::ReadWrite) => {
// The only interesting case is an upgrade
// from previously-read-only to read-write.
self.0 = self.0.insert(Rc::clone(key), ty, budget)?;
Ok(())
}
(AccessType::ReadWrite, AccessType::ReadOnly) => Ok(()),
(AccessType::ReadWrite, AccessType::ReadWrite) => Ok(()),
_ => Ok(()),
}
} else {
self.0 = self.0.insert(Rc::clone(key), ty, budget)?;
Expand All @@ -100,31 +98,24 @@ impl Footprint {
) -> Result<(), HostError> {
if let Some(existing) = self.0.get::<Rc<LedgerKey>>(key, budget)? {
match (existing, ty) {
(AccessType::ReadOnly, AccessType::ReadOnly) => Ok(()),
(AccessType::ReadOnly, AccessType::ReadWrite) => {
Err(ScHostStorageErrorCode::ReadwriteAccessToReadonlyEntry.into())
}
(AccessType::ReadWrite, AccessType::ReadOnly) => Ok(()),
(AccessType::ReadWrite, AccessType::ReadWrite) => Ok(()),
_ => Ok(()),
}
} else {
Err(ScHostStorageErrorCode::AccessToUnknownEntry.into())
}
}
}

#[derive(Clone)]
#[derive(Clone, Default)]
pub enum FootprintMode {
Recording(Rc<dyn SnapshotSource>),
#[default]
Enforcing,
}

impl Default for FootprintMode {
fn default() -> Self {
FootprintMode::Enforcing
}
}

/// A special-purpose map from [LedgerKey]s to [LedgerEntry]s. Represents a
/// transactional batch of contract IO from and to durable storage, while
/// partitioning that IO between concurrently executing groups of contracts
Expand Down Expand Up @@ -204,7 +195,7 @@ impl Storage {
match self.map.get::<Rc<LedgerKey>>(key, budget)? {
None => Err(ScHostStorageErrorCode::MissingKeyInGet.into()),
Some(None) => Err(ScHostStorageErrorCode::GetOnDeletedKey.into()),
Some(Some(val)) => Ok(Rc::clone(&val)),
Some(Some(val)) => Ok(Rc::clone(val)),
}
}

Expand All @@ -225,7 +216,7 @@ impl Storage {
};
self.map = self
.map
.insert(Rc::clone(key), val.map(|v| Rc::clone(v)), budget)?;
.insert(Rc::clone(key), val.map(Rc::clone), budget)?;
Ok(())
}

Expand Down Expand Up @@ -312,7 +303,7 @@ mod test_footprint {
key: ScVal::I32(0),
}));
fp.record_access(&key, AccessType::ReadOnly, &budget)?;
assert_eq!(fp.0.contains_key::<LedgerKey>(&key, &budget)?, true);
assert!(fp.0.contains_key::<LedgerKey>(&key, &budget)?);
assert_eq!(
fp.0.get::<LedgerKey>(&key, &budget)?,
Some(&AccessType::ReadOnly)
Expand Down Expand Up @@ -405,7 +396,7 @@ pub(crate) mod test_storage {
impl SnapshotSource for MockSnapshotSource {
fn get(&self, key: &Rc<LedgerKey>) -> Result<Rc<LedgerEntry>, HostError> {
if let Some(val) = self.0.get(key) {
Ok(Rc::clone(&val))
Ok(Rc::clone(val))
} else {
Err(ScUnknownErrorCode::General.into())
}
Expand Down

0 comments on commit 058b2e5

Please sign in to comment.