Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7,620 changes: 4,043 additions & 3,577 deletions Cargo.lock

Large diffs are not rendered by default.

252 changes: 128 additions & 124 deletions Cargo.toml

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ avail-core = { workspace = true, default-features = false }

# Substrate related
codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
# parking_lot= { workspace = true }
parking_lot= { workspace = true, optional = true }
scale-info = { workspace = true, default-features = false }
sp-core = { workspace = true, default-features = false, features = ["serde"] }
sp-std = { workspace = true, default-features = false }
Expand Down Expand Up @@ -41,8 +43,9 @@ std = [
"binary-merkle-tree/std",
"codec/std",
"frame-support/std",
"sp-authority-discovery/std",
"parking_lot",
"sp-api/std",
"sp-authority-discovery/std",
"sp-core/std",
"sp-runtime-interface/std",
"sp-runtime/std",
Expand Down
5 changes: 2 additions & 3 deletions base/src/header_extension/builder_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use codec::{Decode, Encode};
use derive_more::Constructor;
use sp_core::H256;
use sp_runtime::OpaqueExtrinsic;
use sp_runtime_interface::pass_by::PassByCodec;
use sp_std::{iter::repeat, vec::Vec};

#[derive(Constructor, Debug, Encode, Decode, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -38,7 +37,7 @@ pub struct ExtractedTxData {
pub bridge_data: Option<BridgedData>,
}

#[derive(Debug, Default, PassByCodec, Encode, Decode)]
#[derive(Debug, Default, Encode, Decode)]
pub struct HeaderExtensionBuilderData {
pub data_submissions: Vec<SubmittedData>,
pub bridge_messages: Vec<BridgedData>,
Expand Down Expand Up @@ -238,7 +237,7 @@ where
T: AsRef<[u8]>,
{
let leaves = leaf_iter.collect::<Vec<_>>();
let mp = merkle_proof::<Keccak256, _, T>(leaves, leaf_idx);
let mp = merkle_proof::<Keccak256, _, T>(leaves, leaf_idx as u32);
// NOTE: As we are using refrences for the leaves, like `&'a [u8]`, we need to
// convert them to `Vec<u8>`.
MerkleProof {
Expand Down
68 changes: 26 additions & 42 deletions base/src/mem_tmp_storage.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use codec::{Decode, Encode};
use sp_runtime_interface::runtime_interface;
use sp_runtime_interface::{
pass_by::{AllocateAndReturnByCodec, PassFatPointerAndRead},
runtime_interface,
};
use sp_std::{collections::btree_map::BTreeMap, vec::Vec};

/// A simple key-value storage in memory.
Expand All @@ -20,7 +23,7 @@ impl MemoryTemporaryStorage {
/// Encodes and inserts `value` into the memory temporal storage under `key`.
pub fn insert<T: Encode + Decode>(key: Vec<u8>, value: T) -> Option<T> {
let raw_value = value.encode();
hosted_mem_tmp_storage::insert(key, raw_value)
hosted_mem_tmp_storage::insert(&key, raw_value)
.and_then(|raw| T::decode(&mut raw.as_slice()).ok())
}

Expand Down Expand Up @@ -60,10 +63,10 @@ impl MemoryTemporaryStorage {
////// Native Code
//////

#[cfg(feature = "std")]
#[cfg(not(substrate_runtime))]
pub(crate) mod native {
use super::*;
use sp_std::sync::RwLock;
use parking_lot::RwLock;

pub static MEM_TMP_STORAGE: RwLock<StorageMap> = RwLock::new(StorageMap::new());
}
Expand All @@ -76,58 +79,39 @@ pub(crate) mod native {
/// - [ ] Improve error handling of poisoned sync: Panic?
#[runtime_interface]
pub trait HostedMemTmpStorage {
/// Insert auxiliary data into key-value storage.
fn insert(key: Vec<u8>, value: Vec<u8>) -> Option<Vec<u8>> {
let Ok(mut guard) = native::MEM_TMP_STORAGE.write() else {
log_poisoned_sync();
return None;
};

guard.insert(key, value)
fn insert(
key: PassFatPointerAndRead<&[u8]>,
value: PassFatPointerAndRead<Vec<u8>>,
) -> AllocateAndReturnByCodec<Option<Vec<u8>>> {
let mut guard = native::MEM_TMP_STORAGE.write();
guard.insert(key.to_vec(), value)
}

/// Returns the value under `key` from the memory temporal storage.
fn get(key: &[u8]) -> Option<Vec<u8>> {
let Ok(guard) = native::MEM_TMP_STORAGE.read() else {
log_poisoned_sync();
return None;
};

guard.get(key).cloned()
fn get(key: PassFatPointerAndRead<&[u8]>) -> AllocateAndReturnByCodec<Option<Vec<u8>>> {
let guard = native::MEM_TMP_STORAGE.read();
guard.get(&*key).cloned()
}

fn take(key: &[u8]) -> Option<Vec<u8>> {
let Ok(mut guard) = native::MEM_TMP_STORAGE.write() else {
log_poisoned_sync();
return None;
};

guard.remove(key)
fn take(key: PassFatPointerAndRead<&[u8]>) -> AllocateAndReturnByCodec<Option<Vec<u8>>> {
let mut guard = native::MEM_TMP_STORAGE.write();
guard.remove(&*key)
}

/// Clears the memory temporal storage.
fn clear() {
let Ok(mut guard) = native::MEM_TMP_STORAGE.write() else {
log_poisoned_sync();
return;
};

let mut guard = native::MEM_TMP_STORAGE.write();
guard.clear();
}

/// Returns the content of the memory temporal storage as a list of key-value pairs.
/// NOTE: Conversion to plain list is needed due to `ByPass` constraints.
fn storage() -> Vec<(Vec<u8>, Vec<u8>)> {
let Ok(guard) = native::MEM_TMP_STORAGE.read() else {
log_poisoned_sync();
return Vec::default();
};

fn storage() -> AllocateAndReturnByCodec<Vec<(Vec<u8>, Vec<u8>)>> {
let guard = native::MEM_TMP_STORAGE.read();
guard.iter().map(|(k, v)| (k.clone(), v.clone())).collect()
}
}

#[cfg(feature = "std")]
fn log_poisoned_sync() {
log::error!("Memory Temporal Storage with a poisoned sync");
}
// #[cfg(not(substrate_runtime))]
// fn log_poisoned_sync() {
// log::error!("Memory Temporal Storage with a poisoned sync");
// }
6 changes: 3 additions & 3 deletions base/src/testing_env.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use avail_core::app_extrinsic::AppExtrinsic;
use sp_std::vec::Vec;
// use avail_core::app_extrinsic::AppExtrinsic;
// use sp_std::vec::Vec;

pub static mut ENABLE_TEST_EXTENSION_FAILURE: bool = false;
pub static mut ENABLE_TEST_GRID_FAILURE: bool = false;
pub static mut ENABLE_TEST_COMMITMENT_FAILURE: bool = false;
pub static mut TEST_POPULATE_GRID: Option<Vec<AppExtrinsic>> = None;
// pub static mut TEST_POPULATE_GRID: Option<Vec<AppExtrinsic>> = None;
50 changes: 27 additions & 23 deletions blob/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ da-commitment = { workspace = true, default-features = false }
sp-core = { workspace = true, default-features = false }
sp-runtime = { workspace = true, default-features = false }
sp-api = { workspace = true, default-features = false }
sp-io = { workspace = true, default-features = false }
sp-std = { workspace = true, default-features = false }
sc-network = { workspace = true, default-features = false }
sc-network-gossip = { workspace = true, default-features = false }
Expand Down Expand Up @@ -67,32 +68,35 @@ divan = { version = "0.1" }
avail-rust = { package = "avail-rust-client", version = "0.4.0", default-features = false, features = ["native", "reqwest", "next"] }

[features]
default = ["std"]
default = [ "std" ]
std = [
"avail-core/std",
"kate/std",
"kate-recovery/std",
"frame-benchmarking/std",
"da-runtime/std",
"da-control/std",
"codec/std",
"scale-info/std",
"serde/std",
"frame-system/std",
"avail-base/std",
"da-commitment/std",
"sp-core/std",
"sp-runtime/std",
"sp-api/std",
"sp-std/std",
"sc-executor/std",
"sp-transaction-pool/std",
"sp-authority-discovery/std",
"futures/std",
"log/std",
"once_cell/std",
"avail-base/std",
"avail-core/std",
"codec/std",
"da-commitment/std",
"da-control/std",
"da-runtime/std",
"frame-benchmarking/std",
"frame-system/std",
"futures/std",
"kate-recovery/std",
"kate/std",
"log/std",
"once_cell/std",
"sc-executor/std",
"scale-info/std",
"serde/std",
"sp-api/std",
"sp-authority-discovery/std",
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"sp-transaction-pool/std",
]

runtime-benchmarks = []

[[bench]]
name = "submit_data"
harness = false
12 changes: 6 additions & 6 deletions blob/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ use da_control::BlobRuntimeParameters;
use da_runtime::apis::BlobApi;
use futures::channel::oneshot;
use sc_client_api::HeaderBackend;
use sc_network::service::traits::NetworkService as NetworkServiceT;
use sc_network::{
config::{IncomingRequest, OutgoingResponse},
IfDisconnected, NetworkPeers, NetworkRequest, NetworkService, NetworkStateInfo, ObservedRole,
PeerId,
IfDisconnected, NetworkPeers, NetworkRequest, NetworkStateInfo, ObservedRole, PeerId,
};
use sp_api::ProvideRuntimeApi;
use sp_core::H256;
Expand Down Expand Up @@ -543,14 +543,14 @@ where
log::error!(target: LOG_TARGET,
"Invalid response in send blob request, expected BlobResponse");
BlobReputationChange::MalformedResponse
.report(&blob_handle.network, &target_peer);
.report::<Block>(&blob_handle.network, &target_peer);
break;
},
Err(err) => {
log::error!(target: LOG_TARGET,
"Failed to decode Blob response ({} bytes): {:?}", data.len(), err);
BlobReputationChange::MalformedResponse
.report(&blob_handle.network, &target_peer);
.report::<Block>(&blob_handle.network, &target_peer);
break;
},
}
Expand Down Expand Up @@ -596,7 +596,7 @@ where
pub fn handle_incoming_blob_request<Block: BlockT>(
request: IncomingRequest,
blob_database: &dyn StorageApiT,
network: &Arc<NetworkService<Block, Block::Hash>>,
network: &Arc<dyn NetworkServiceT>,
) where
Block: BlockT,
{
Expand Down Expand Up @@ -884,7 +884,7 @@ async fn handle_blob_stored_notification<Block>(
pub async fn send_blob_query_request<Block>(
hash: BlobHash,
target_peer: PeerId,
network: &Arc<NetworkService<Block, Block::Hash>>,
network: &Arc<dyn NetworkServiceT>,
) -> Result<Option<Blob>>
where
Block: BlockT,
Expand Down
Loading