Skip to content

Commit

Permalink
Fix compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
jasl committed Sep 9, 2022
1 parent 236b257 commit 28a0656
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 82 deletions.
19 changes: 3 additions & 16 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/phactory/src/light_validation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ where
#[derive(Debug)]
pub enum Error {
// InvalidStorageProof,
StorageRootMismatch,
// StorageRootMismatch,
StorageValueUnavailable,
// InvalidValidatorSetProof,
ValidatorSetMismatch,
Expand All @@ -237,7 +237,7 @@ pub enum Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::StorageRootMismatch => write!(f, "storage root mismatch"),
// Error::StorageRootMismatch => write!(f, "storage root mismatch"),
Error::StorageValueUnavailable => write!(f, "storage value unavailable"),
Error::ValidatorSetMismatch => write!(f, "validator set mismatch"),
Error::InvalidAncestryProof => write!(f, "invalid ancestry proof"),
Expand Down
10 changes: 5 additions & 5 deletions crates/phactory/src/light_validation/storage_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use anyhow::Result;
use hash_db::{HashDB, Hasher, EMPTY_PREFIX};
use sp_trie::{trie_types::TrieDB, MemoryDB, Trie};
use sp_trie::trie_types::TrieDBBuilder;

use super::Error;

Expand Down Expand Up @@ -49,22 +50,21 @@ where
}
let checker = StorageProofChecker { root, db };
// Return error if trie would be invalid.
let _ = checker.trie()?;
let _ = checker.trie();
Ok(checker)
}

/// Reads a value from the available subset of storage. If the value cannot be read due to an
/// incomplete or otherwise invalid proof, this returns an error.
pub fn read_value(&self, key: &[u8]) -> Result<Option<Vec<u8>>> {
self.trie()?
self.trie()
.get(key)
.map(|value| value.map(|value| value.to_vec()))
.map_err(|_| anyhow::Error::msg(Error::StorageValueUnavailable))
}

fn trie(&self) -> Result<TrieDB<H>> {
TrieDB::new(&self.db, &self.root)
.map_err(|_| anyhow::Error::msg(Error::StorageRootMismatch))
fn trie(&self) -> TrieDB<H> {
TrieDBBuilder::new(&self.db, &self.root).build()
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/phactory/src/system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub use phactory_api::prpc::{GatekeeperRole, GatekeeperStatus};
use phala_crypto::{
ecdh::EcdhKey,
key_share,
sr25519::{Persistence, Signing, KDF},
sr25519::{Persistence, KDF},
};
use phala_mq::{
traits::MessageChannel, BadOrigin, ContractId, MessageDispatcher, MessageOrigin,
Expand Down
2 changes: 1 addition & 1 deletion crates/phala-trie-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "

serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }
hash-db = "0.15.2"
trie-db = "0.23.1"
trie-db = "0.24.0"
im = { version = "15", features = ["serde"] }
parity-util-mem = "0.11.0"

Expand Down
24 changes: 16 additions & 8 deletions crates/phala-trie-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ use alloc::vec::Vec;
use parity_scale_codec::Codec;
use sp_core::storage::ChildInfo;
use sp_core::Hasher;
use sp_state_machine::{Backend, TrieBackend};
use sp_trie::{trie_types::TrieDBMutV0 as TrieDBMut, TrieMut};
use sp_state_machine::{Backend, TrieBackend, TrieBackendBuilder};
use sp_trie::{
TrieMut,
trie_types::{
TrieDBMutBuilderV0 as TrieDBMutBuilder,
},
};

pub use memdb::GenericMemoryDB as MemoryDB;

Expand All @@ -40,7 +45,7 @@ where
H::Out: Codec,
{
fn default() -> Self {
Self(TrieBackend::new(Default::default(), Default::default()))
Self(TrieBackendBuilder::new(Default::default(), Default::default()).build())
}
}

Expand All @@ -53,14 +58,14 @@ where
let mut root = Default::default();
let mut mdb = Default::default();
{
let mut trie_db = TrieDBMut::new(&mut mdb, &mut root);
let mut trie_db = TrieDBMutBuilder::new(&mut mdb, &mut root).build();
for (key, value) in pairs {
if trie_db.insert(key.as_ref(), value.as_ref()).is_err() {
panic!("Insert item into trie DB should not fail");
}
}
}
TrieBackend::new(mdb, root)
TrieBackendBuilder::new(mdb, root).build()
}

#[cfg(feature = "serde")]
Expand Down Expand Up @@ -88,7 +93,7 @@ where
let (root, kvs): (H::Out, im::HashMap<_, (Vec<u8>, i32)>) =
Deserialize::deserialize(deserializer)?;
let mdb = MemoryDB::from_inner(kvs);
let backend = TrieBackend::new(mdb, root);
let backend = TrieBackendBuilder::new(mdb, root).build();
Ok(backend)
}

Expand All @@ -102,7 +107,7 @@ where
let mdb = trie
.backend_storage()
.clone();
TrieBackend::new(mdb, *root)
TrieBackendBuilder::new(mdb, *root).build()
}

impl<H: Hasher> TrieStorage<H>
Expand Down Expand Up @@ -148,7 +153,10 @@ where
pub fn apply_changes(&mut self, root: H::Out, transaction: MemoryDB<H>) {
let mut storage = core::mem::take(self).0.into_storage();
storage.consolidate(transaction);
let _ = core::mem::replace(&mut self.0, TrieBackend::new(storage, root));
let _ = core::mem::replace(
&mut self.0,
TrieBackendBuilder::new(storage, root).build()
);
}

pub fn purge(&mut self) {}
Expand Down
16 changes: 10 additions & 6 deletions crates/pink/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ frame_support::construct_runtime! {
parameter_types! {
pub const BlockHashCount: u32 = 250;
pub RuntimeBlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(2 * WEIGHT_PER_SECOND);
frame_system::limits::BlockWeights::simple_max(WEIGHT_PER_SECOND.saturating_mul(2));
pub static ExistentialDeposit: u64 = 0;
}

Expand Down Expand Up @@ -96,7 +96,7 @@ parameter_types! {
pub const SurchargeReward: u64 = 500_000;
pub const MaxValueSize: u32 = 16_384;
pub const DeletionQueueDepth: u32 = 1024;
pub const DeletionWeightLimit: Weight = 500_000_000_000;
pub const DeletionWeightLimit: Weight = Weight::from_ref_time(500_000_000_000);
pub const MaxCodeLen: u32 = 2 * 1024 * 1024;
pub const RelaxedMaxCodeLen: u32 = 2 * 1024 * 1024;
pub const TransactionByteFee: u64 = 0;
Expand All @@ -107,7 +107,7 @@ parameter_types! {

impl Convert<Weight, Balance> for PinkRuntime {
fn convert(w: Weight) -> Balance {
w as _
w.ref_time() as _
}
}

Expand Down Expand Up @@ -243,7 +243,7 @@ mod tests {
#[test]
pub fn crypto_hashes_test() {
pub const ALICE: AccountId32 = AccountId32::new([1u8; 32]);
const GAS_LIMIT: Weight = 1_000_000_000_000_000;
const GAS_LIMIT: Weight = Weight::from_ref_time(1_000_000_000_000_000);

let (wasm, code_hash) =
compile_wat::<PinkRuntime>(include_bytes!("../tests/fixtures/crypto_hashes.wat"))
Expand Down Expand Up @@ -296,12 +296,16 @@ mod tests {

pub mod exec {
use sp_runtime::traits::BlakeTwo256;
use sp_state_machine::{Backend, Ext, OverlayedChanges, StorageTransactionCache};
use sp_state_machine::{
backend::AsTrieBackend,
Ext, OverlayedChanges, StorageTransactionCache,
};

pub type InMemoryBackend = sp_state_machine::InMemoryBackend<BlakeTwo256>;

pub fn execute_with<R>(f: impl FnOnce() -> R) -> R {
let state = InMemoryBackend::default();
let backend = state.as_trie_backend().unwrap();
let backend = state.as_trie_backend();

let mut overlay = OverlayedChanges::default();
overlay.start_transaction();
Expand Down
13 changes: 7 additions & 6 deletions crates/pink/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use phala_trie_storage::{deserialize_trie_backend, serialize_trie_backend, Memor
use serde::{Deserialize, Serialize};
use sp_runtime::DispatchError;
use sp_state_machine::{Backend as StorageBackend, Ext, OverlayedChanges, StorageTransactionCache};
use sp_state_machine::backend::AsTrieBackend;

mod backend;

Expand All @@ -15,10 +16,10 @@ pub type InMemoryBackend = phala_trie_storage::InMemoryBackend<Hashing>;
pub fn new_in_memory_backend() -> InMemoryBackend {
let db = MemoryDB::default();
// V1 is same as V0 for an empty trie.
sp_state_machine::TrieBackend::new(
sp_state_machine::TrieBackendBuilder::new(
db,
sp_trie::empty_trie_root::<sp_state_machine::LayoutV1<Hashing>>(),
)
).build()
}

pub trait CommitTransaction: StorageBackend<Hashing> {
Expand All @@ -29,7 +30,7 @@ impl CommitTransaction for InMemoryBackend {
fn commit_transaction(&mut self, root: Hash, transaction: Self::Transaction) {
let mut storage = sp_std::mem::replace(self, new_in_memory_backend()).into_storage();
storage.consolidate(transaction);
*self = sp_state_machine::TrieBackend::new(storage, root);
*self = sp_state_machine::TrieBackendBuilder::new(storage, root).build();
}
}

Expand Down Expand Up @@ -60,15 +61,15 @@ where

impl<Backend> Storage<Backend>
where
Backend: StorageBackend<Hashing> + CommitTransaction,
Backend: StorageBackend<Hashing> + CommitTransaction + AsTrieBackend<Hashing>,
{
pub fn execute_with<R>(
&mut self,
rollback: bool,
callbacks: Option<BoxedEventCallbacks>,
f: impl FnOnce() -> R,
) -> (R, ExecSideEffects) {
let backend = self.backend.as_trie_backend().expect("No trie backend?");
let backend = self.backend.as_trie_backend();

let mut overlay = OverlayedChanges::default();
overlay.start_transaction();
Expand Down Expand Up @@ -160,7 +161,7 @@ impl Serialize for Storage<InMemoryBackend> {
where
S: serde::Serializer,
{
let trie = self.backend.as_trie_backend().unwrap();
let trie = self.backend.as_trie_backend();
serialize_trie_backend(trie, serializer)
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/pink/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ pub type Balance = u128;
pub type BlockNumber = u32;
pub type Index = u64;

pub const ENOUGH: Balance = Balance::MAX / 2;
pub const ENOUGH: Balance = Balance::MAX.saturating_div(2);

pub const QUERY_GAS_LIMIT: Weight = Weight::MAX / 2;
pub const QUERY_GAS_LIMIT: Weight = Weight::MAX.saturating_div(2);

// No much test there. They are the values enough to run the examples
pub const COMMAND_GAS_LIMIT: Weight = 5000000000000;
pub const INSTANTIATE_GAS_LIMIT: Weight = 10000000000000;
pub const COMMAND_GAS_LIMIT: Weight = Weight::from_ref_time(5000000000000u64);
pub const INSTANTIATE_GAS_LIMIT: Weight = Weight::from_ref_time(10000000000000u64);
5 changes: 3 additions & 2 deletions standalone/node/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use nix::{
unistd::Pid,
};
use node_primitives::Block;
use remote_externalities::rpc_api;
use remote_externalities::rpc_api::RpcService;
use std::{
io::{BufRead, BufReader, Read},
ops::{Deref, DerefMut},
Expand Down Expand Up @@ -71,9 +71,10 @@ pub async fn wait_n_finalized_blocks(
pub async fn wait_n_finalized_blocks_from(n: usize, url: &str) {
let mut built_blocks = std::collections::HashSet::new();
let mut interval = tokio::time::interval(Duration::from_secs(2));
let rpc_service = RpcService::new(url, false).await.unwrap();

loop {
if let Ok(block) = rpc_api::get_finalized_head::<Block, _>(url.to_string()).await {
if let Ok(block) = rpc_service.get_finalized_head::<Block>().await {
built_blocks.insert(block);
if built_blocks.len() > n {
break
Expand Down
1 change: 0 additions & 1 deletion standalone/node/tests/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use assert_cmd::cargo::cargo_bin;
use platforms::*;
use regex::Regex;
use std::process::Command;

Expand Down
17 changes: 2 additions & 15 deletions standalone/prouter/Cargo.lock

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

Loading

0 comments on commit 28a0656

Please sign in to comment.