Skip to content

Commit a605f30

Browse files
committed
chore: deprecate storage default state
1 parent 986f5f6 commit a605f30

10 files changed

Lines changed: 225 additions & 18 deletions

File tree

executor/common/src/calldata/de.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ impl<'de> serde::Deserializer<'de> for Value {
725725
{
726726
match self {
727727
Value::Array(v) => visit_array(v, visitor),
728+
Value::Bytes(v) => visitor.visit_byte_buf(v),
728729
_ => Err(self.invalid_type(&visitor)),
729730
}
730731
}

executor/src/host/message.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ impl SlotID {
6161
ret.0.copy_from_slice(digest.finalize().as_slice());
6262
ret
6363
}
64+
65+
pub fn from_bytes(data: [u8; 32]) -> Self {
66+
SlotID(data)
67+
}
6468
}
6569

6670
impl From<[u8; 32]> for SlotID {

executor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub async fn run_with_impl(
9696
wasi::genlayer_sdk::StorageHostHolder(
9797
supervisor.host.clone(),
9898
wasi::genlayer_sdk::ReadToken {
99-
mode: public_abi::StorageType::Default,
99+
mode: public_abi::StorageType::LatestNonFinal,
100100
account: entry_data.message.contract_address,
101101
},
102102
),

executor/src/rt/vm/storage.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@ impl PageID {
1212
pub fn to_bytes(&self) -> [u8; 36] {
1313
let mut res = [0u8; 36];
1414
res[..32].copy_from_slice(&self.0.raw());
15-
res[32..].copy_from_slice(&self.1.to_le_bytes());
15+
res[32..].copy_from_slice(&self.1.to_be_bytes());
1616
res
1717
}
18+
19+
pub fn from_bytes(data: [u8; 36]) -> Self {
20+
let mut slot_bytes = [0u8; 32];
21+
slot_bytes.copy_from_slice(&data[..32]);
22+
let slot_id = SlotID::from_bytes(slot_bytes);
23+
let mut index_bytes = [0u8; 4];
24+
index_bytes.copy_from_slice(&data[32..]);
25+
let index = u32::from_be_bytes(index_bytes);
26+
Self(slot_id, index)
27+
}
1828
}
1929

2030
#[derive(Debug, Clone, serde::Serialize)]
@@ -369,3 +379,30 @@ impl<HS: HostStorageLocking + Send + Sync> Storage<HS> {
369379
Ok(res)
370380
}
371381
}
382+
383+
#[cfg(test)]
384+
mod tests {
385+
use super::*;
386+
387+
#[test]
388+
fn pages_sorted_correctly_1_byte() {
389+
let left = PageID(SlotID::from_bytes([1u8; 32]), 5);
390+
let right = PageID(SlotID::from_bytes([1u8; 32]), 10);
391+
assert!(left < right);
392+
assert!(left.to_bytes() < right.to_bytes());
393+
394+
assert!(right > left);
395+
assert!(right.to_bytes() > left.to_bytes());
396+
}
397+
398+
#[test]
399+
fn pages_sorted_correctly_2_byte() {
400+
let left = PageID(SlotID::from_bytes([1u8; 32]), 5);
401+
let right = PageID(SlotID::from_bytes([1u8; 32]), 1024);
402+
assert!(left < right);
403+
assert!(left.to_bytes() < right.to_bytes());
404+
405+
assert!(right > left);
406+
assert!(right.to_bytes() > left.to_bytes());
407+
}
408+
}

executor/tests/.gitignore

Whitespace-only changes.

0 commit comments

Comments
 (0)