Skip to content

Commit

Permalink
update smoldot (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci authored Jan 3, 2024
1 parent a5dac94 commit fd1d5de
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "vendor/smoldot"]
path = vendor/smoldot
url = https://github.com/ermalkaleci/smoldot.git
url = https://github.com/smol-dot/smoldot.git
22 changes: 16 additions & 6 deletions executor/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 2 additions & 9 deletions executor/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ pub fn decode_proof(
let entries = decoded
.iter_ordered()
.filter(|(key, entry)| {
if key.key.is_empty() {
return false;
}
if !key.trie_root_hash.eq(&trie_root_hash.0) {
return false;
}
Expand All @@ -33,9 +30,7 @@ pub fn decode_proof(
)
})
.map(|(key, entry)| {
let key = HexString(
nibbles_to_bytes_suffix_extend(key.key.iter().cloned()).collect::<Vec<_>>(),
);
let key = HexString(nibbles_to_bytes_suffix_extend(key.key).collect::<Vec<_>>());
match entry.trie_node_info.storage_value {
StorageValue::Known { value, .. } => (key, HexString(value.to_vec())),
_ => unreachable!(),
Expand Down Expand Up @@ -75,9 +70,7 @@ pub fn create_proof(
for (entry_key, value) in decoded.iter_ordered() {
let decoded_value = trie_node::decode(value.node_value).unwrap();

if let trie_structure::Entry::Vacant(vacant) =
trie.node(entry_key.key.iter().map(|x| x.to_owned()))
{
if let trie_structure::Entry::Vacant(vacant) = trie.node(entry_key.key) {
if let trie_node::StorageValue::Unhashed(value) = decoded_value.storage_value {
vacant.insert_storage_value().insert(value.to_vec(), vec![]);
}
Expand Down
23 changes: 11 additions & 12 deletions executor/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use serde::{Deserialize, Serialize};
use serde_wasm_bindgen::{from_value, to_value};
use smoldot::{
executor::{
host::{Config, HeapPages, HostVmPrototype},
runtime_host::{self, OffchainContext, RuntimeHostVm},
host::{Config, HeapPages, HostVmPrototype, LogEmitInfo},
runtime_call::{self, OffchainContext, RuntimeCall},
storage_diff::TrieDiff,
CoreVersionRef,
},
Expand All @@ -14,7 +14,6 @@ use smoldot::{
calculate_root::{root_merkle_value, RootMerkleValueCalculation},
nibbles_to_bytes_suffix_extend, HashFunction, TrieEntryVersion,
},
verify::body_only::LogEmitInfo,
};
use std::collections::BTreeMap;
use wasm_bindgen::prelude::*;
Expand Down Expand Up @@ -134,7 +133,7 @@ pub async fn run_task(task: TaskCall, js: crate::JsCallback) -> Result<TaskRespo
let mut runtime_logs: Vec<LogInfo> = vec![];

for (call, params) in task.calls {
let mut vm = runtime_host::run(runtime_host::Config {
let mut vm = runtime_call::run(runtime_call::Config {
virtual_machine: vm_proto.clone(),
function_to_call: call.as_str(),
parameter: params.into_iter().map(|x| x.0),
Expand All @@ -148,11 +147,11 @@ pub async fn run_task(task: TaskCall, js: crate::JsCallback) -> Result<TaskRespo

let res = loop {
vm = match vm {
RuntimeHostVm::Finished(res) => {
RuntimeCall::Finished(res) => {
break res;
}

RuntimeHostVm::StorageGet(req) => {
RuntimeCall::StorageGet(req) => {
let key = if let Some(child) = req.child_trie() {
HexString(prefixed_child_key(
child.as_ref().iter().copied(),
Expand Down Expand Up @@ -184,13 +183,13 @@ pub async fn run_task(task: TaskCall, js: crate::JsCallback) -> Result<TaskRespo
}
}

RuntimeHostVm::ClosestDescendantMerkleValue(req) => {
RuntimeCall::ClosestDescendantMerkleValue(req) => {
let value = js.get_state_root().await?;
let value = from_value::<HexString>(value).map(|x| x.0)?;
req.inject_merkle_value(Some(value.as_ref()))
}

RuntimeHostVm::NextKey(req) => {
RuntimeCall::NextKey(req) => {
if req.branch_nodes() {
// root_calculation, skip
req.inject_key(None::<Vec<_>>.map(|x| x.into_iter()))
Expand Down Expand Up @@ -222,7 +221,7 @@ pub async fn run_task(task: TaskCall, js: crate::JsCallback) -> Result<TaskRespo
}
}

RuntimeHostVm::SignatureVerification(req) => {
RuntimeCall::SignatureVerification(req) => {
let bypass =
task.mock_signature_host && is_magic_signature(req.signature().as_ref());
if bypass {
Expand All @@ -232,15 +231,15 @@ pub async fn run_task(task: TaskCall, js: crate::JsCallback) -> Result<TaskRespo
}
}

RuntimeHostVm::OffchainStorageSet(req) => {
RuntimeCall::OffchainStorageSet(req) => {
offchain_storage_changes.insert(
req.key().as_ref().to_vec(),
req.value().map(|x| x.as_ref().to_vec()),
);
req.resume()
}

RuntimeHostVm::Offchain(ctx) => match ctx {
RuntimeCall::Offchain(ctx) => match ctx {
OffchainContext::StorageGet(req) => {
let key = HexString(req.key().as_ref().to_vec());
let key = to_value(&key)?;
Expand Down Expand Up @@ -292,7 +291,7 @@ pub async fn run_task(task: TaskCall, js: crate::JsCallback) -> Result<TaskRespo
}
},

RuntimeHostVm::LogEmit(req) => {
RuntimeCall::LogEmit(req) => {
{
match req.info() {
LogEmitInfo::Num(v) => {
Expand Down
2 changes: 1 addition & 1 deletion vendor/smoldot
Submodule smoldot updated 136 files

0 comments on commit fd1d5de

Please sign in to comment.