Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
client/mmr: replace async_std with tokio
  • Loading branch information
acatangiu committed Dec 2, 2022
commit 958ebbdcc5c5e63217ff2e39cf44e3923bf4f9e1
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion client/merkle-mountain-range/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ sc-offchain = { version = "4.0.0-dev", path = "../offchain" }
sp-runtime = { version = "7.0.0", path = "../../primitives/runtime" }

[dev-dependencies]
async-std = { version = "1.11.0", default-features = false }
parking_lot = "0.12.1"
sc-block-builder = { version = "0.10.0-dev", path = "../block-builder" }
sp-tracing = { version = "6.0.0", path = "../../primitives/tracing" }
Expand Down
8 changes: 4 additions & 4 deletions client/merkle-mountain-range/src/aux_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub(crate) mod tests {
let a2 = client.import_block(&BlockId::Number(1), b"a2", Some(1)).await;
let a3 = client.import_block(&BlockId::Number(2), b"a3", Some(2)).await;
client.finalize_block(a3.hash(), Some(3));
async_std::task::sleep(Duration::from_millis(200)).await;
tokio::time::sleep(Duration::from_millis(200)).await;
// a1, a2, a3 were canonicalized
client.assert_canonicalized(&[&a1, &a2, &a3]);
},
Expand All @@ -143,7 +143,7 @@ pub(crate) mod tests {
let a5 = client.import_block(&BlockId::Number(4), b"a5", Some(4)).await;
let a6 = client.import_block(&BlockId::Number(5), b"a6", Some(5)).await;
client.finalize_block(a6.hash(), Some(6));
async_std::task::sleep(Duration::from_millis(200)).await;
tokio::time::sleep(Duration::from_millis(200)).await;

// a4, a5, a6 were canonicalized
client.assert_canonicalized(&[&a4, &a5, &a6]);
Expand Down Expand Up @@ -171,7 +171,7 @@ pub(crate) mod tests {
blocks.push(client.import_block(&BlockId::Number(1), b"a2", Some(1)).await);
blocks.push(client.import_block(&BlockId::Number(2), b"a3", Some(2)).await);
client.finalize_block(blocks.last().unwrap().hash(), Some(3));
async_std::task::sleep(Duration::from_millis(200)).await;
tokio::time::sleep(Duration::from_millis(200)).await;
// a1, a2, a3 were canonicalized
let slice: Vec<&MmrBlock> = blocks.iter().collect();
client.assert_canonicalized(&slice);
Expand Down Expand Up @@ -212,7 +212,7 @@ pub(crate) mod tests {
let a5 = client.import_block(&BlockId::Number(4), b"a5", Some(4)).await;
let a6 = client.import_block(&BlockId::Number(5), b"a6", Some(5)).await;
client.finalize_block(a6.hash(), Some(6));
async_std::task::sleep(Duration::from_millis(200)).await;
tokio::time::sleep(Duration::from_millis(200)).await;

let block_1_to_3 = blocks.lock();
let slice: Vec<&MmrBlock> = block_1_to_3.iter().collect();
Expand Down
6 changes: 3 additions & 3 deletions client/merkle-mountain-range/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ mod tests {
let a2 = client.import_block(&BlockId::Hash(a1.hash()), b"a2", Some(1)).await;

client.finalize_block(a1.hash(), Some(1));
async_std::task::sleep(Duration::from_millis(200)).await;
tokio::time::sleep(Duration::from_millis(200)).await;
// expected finalized heads: a1
client.assert_canonicalized(&[&a1]);
client.assert_not_pruned(&[&a2]);
Expand All @@ -247,7 +247,7 @@ mod tests {
let a6 = client.import_block(&BlockId::Hash(a5.hash()), b"a6", Some(2)).await;

client.finalize_block(a5.hash(), Some(2));
async_std::task::sleep(Duration::from_millis(200)).await;
tokio::time::sleep(Duration::from_millis(200)).await;
// expected finalized heads: a4, a5
client.assert_canonicalized(&[&a4, &a5]);
client.assert_not_pruned(&[&a6]);
Expand All @@ -266,7 +266,7 @@ mod tests {
// Simulate the case where the runtime says that there are 2 mmr_blocks when in fact
// there is only 1.
client.finalize_block(a1.hash(), Some(2));
async_std::task::sleep(Duration::from_millis(200)).await;
tokio::time::sleep(Duration::from_millis(200)).await;
// expected finalized heads: -
client.assert_not_canonicalized(&[&a1]);
});
Expand Down
6 changes: 3 additions & 3 deletions client/merkle-mountain-range/src/offchain_mmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,15 @@ mod tests {
let d5 = client.import_block(&BlockId::Hash(d4.hash()), b"d5", Some(4)).await;

client.finalize_block(a3.hash(), Some(3));
async_std::task::sleep(Duration::from_millis(200)).await;
tokio::time::sleep(Duration::from_millis(200)).await;
// expected finalized heads: a1, a2, a3
client.assert_canonicalized(&[&a1, &a2, &a3]);
// expected stale heads: c1
// expected pruned heads because of temp key collision: b1
client.assert_pruned(&[&c1, &b1]);

client.finalize_block(d5.hash(), None);
async_std::task::sleep(Duration::from_millis(200)).await;
tokio::time::sleep(Duration::from_millis(200)).await;
// expected finalized heads: d4, d5,
client.assert_canonicalized(&[&d4, &d5]);
// expected stale heads: b1, b2, b3, a4
Expand Down Expand Up @@ -353,7 +353,7 @@ mod tests {
let a4 = client.import_block(&BlockId::Hash(a3.hash()), b"a4", Some(3)).await;

client.finalize_block(a4.hash(), Some(4));
async_std::task::sleep(Duration::from_millis(200)).await;
tokio::time::sleep(Duration::from_millis(200)).await;
// expected finalized heads: a1, a2 _and_ a3, a4.
client.assert_canonicalized(&[&a1, &a2, &a3, &a4]);
},
Expand Down
40 changes: 18 additions & 22 deletions client/merkle-mountain-range/src/test_utils.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 crate::MmrGadget;
use futures::{executor::LocalPool, task::LocalSpawn, FutureExt};
use parking_lot::Mutex;
use sc_block_builder::BlockBuilderProvider;
use sc_client_api::{
Expand All @@ -44,6 +43,7 @@ use substrate_test_runtime_client::{
Backend, BlockBuilderExt, Client, ClientBlockImportExt, ClientExt, DefaultTestClientBuilderExt,
TestClientBuilder, TestClientBuilderExt,
};
use tokio::runtime::Runtime;

type MmrHash = H256;

Expand Down Expand Up @@ -336,30 +336,26 @@ pub(crate) fn run_test_with_mmr_gadget_pre_post_using_client<F, G, RetF, RetG>(
RetF: Future<Output = ()>,
RetG: Future<Output = ()>,
{
let mut pool = LocalPool::new();

let client_clone = client.clone();
pool.run_until(async move { pre_gadget(client_clone).await });
let runtime = Runtime::new().unwrap();
runtime.block_on(async move { pre_gadget(client_clone).await });

let client_clone = client.clone();
pool.spawner()
.spawn_local_obj(
async move {
let backend = client_clone.backend.clone();
MmrGadget::start(
client_clone.clone(),
backend,
MockRuntimeApi::INDEXING_PREFIX.to_vec(),
)
.await
}
.boxed_local()
.into(),
)
.unwrap();

pool.run_until(async move {
async_std::task::sleep(Duration::from_millis(200)).await;
runtime.spawn(
async move {
let backend = client_clone.backend.clone();
MmrGadget::start(
client_clone.clone(),
backend,
MockRuntimeApi::INDEXING_PREFIX.to_vec(),
)
.await
}, /* .boxed_local()
* .into(), */
);

runtime.block_on(async move {
tokio::time::sleep(Duration::from_millis(200)).await;

post_gadget(client).await
});
Expand Down