Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): Update smoldot to the latest version #1400

Merged
merged 38 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
bf3c7f3
Update smoldot to 0.17 and smoldot-light to 0.15
lexnv Jan 26, 2024
1231920
Update cargo lock
lexnv Jan 26, 2024
ab0f67f
lightclient: Add generic platform for AddedChain
lexnv Jan 26, 2024
b948044
Merge remote-tracking branch 'origin/master' into lexnv/update-smoldot
lexnv Jan 30, 2024
f14bf9a
debug: Finalized heads
lexnv Jan 30, 2024
644626f
Merge remote-tracking branch 'origin/master' into lexnv/update-smoldot
lexnv Apr 3, 2024
b91742a
lightclient: Use generic TPlat for chainSuccess
lexnv Apr 3, 2024
75ace42
lightclient: Trim response for logs
lexnv Apr 3, 2024
c8020c9
Backup
lexnv Apr 8, 2024
6c9088e
Merge remote-tracking branch 'origin/master' into lexnv/update-smoldot
lexnv Apr 9, 2024
74dd9d7
tests/lightclient: Switch to localnode for testing
lexnv Apr 9, 2024
1c96d5e
cargo: Point smoldot to crates.io
lexnv Apr 9, 2024
03c629a
Merge remote-tracking branch 'origin/master' into lexnv/update-smoldot
lexnv Apr 9, 2024
1de5a06
Solve merge conflicts
lexnv Apr 9, 2024
c74e4ad
Add subxt macro for tests
lexnv Apr 9, 2024
b517adf
lightclient/wasm: Impl log of the PlatformRef
lexnv Apr 9, 2024
67ca3ec
Use git dep
lexnv Apr 15, 2024
c776229
Merge remote-tracking branch 'origin/master' into lexnv/update-smoldot
lexnv Jun 25, 2024
c4fe110
Revert "tests/lightclient: Switch to localnode for testing" + max log
lexnv Jun 25, 2024
6cca6f9
tests: Comment chainspec
lexnv Jun 25, 2024
2e7bacd
lightclient/wasm: Import IpAddr from core::net
lexnv Jun 26, 2024
c587309
Merge remote-tracking branch 'origin/master' into lexnv/update-smoldot
lexnv Jun 26, 2024
a6d7055
tests: Enable all tests again
lexnv Jun 26, 2024
3412cb6
tests/wasm: Update cargo lock
lexnv Jun 26, 2024
b6bdd06
tests: Add trace logs to easily reproduce problems
lexnv Jun 26, 2024
2779faf
cargo: Use released smoldot version
lexnv Jun 26, 2024
4612da3
Merge remote-tracking branch 'origin/master' into lexnv/update-smoldot
lexnv Sep 3, 2024
648b4f9
lightclient: Use chainspec and optionally make use of unstable backend
lexnv Sep 3, 2024
3b81de0
lightclient: Fix clippy
lexnv Sep 3, 2024
b69cba7
lightclient: Better trimming for log messages
lexnv Sep 6, 2024
f222db1
lightclient: Remove max log size
lexnv Sep 6, 2024
1a02662
lightclient: Use both backends for testing
lexnv Sep 6, 2024
f3c6179
Update Cargo.toml
lexnv Sep 6, 2024
8b34dcd
Update Cargo.toml
lexnv Sep 6, 2024
30c81b8
Merge remote-tracking branch 'origin/master' into lexnv/update-smoldot
lexnv Sep 6, 2024
7a41bf7
Merge branch 'master' into lexnv/update-smoldot
niklasad1 Sep 6, 2024
0b611f5
Update testing/integration-tests/src/light_client/mod.rs
niklasad1 Sep 6, 2024
43bd4db
Update testing/integration-tests/src/light_client/mod.rs
niklasad1 Sep 6, 2024
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
36 changes: 28 additions & 8 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ scale-typegen = "0.1.1"
strip-ansi-escapes = "0.2.0"

# Light client support:
smoldot = { version = "0.16.0", default-features = false }
smoldot-light = { version = "0.14.0", default-features = false }
smoldot = { version = "0.17.0", default-features = false }
smoldot-light = { version = "0.15.0", default-features = false }
tokio-stream = "0.1.14"
futures-util = "0.3.30"
rand = "0.8.5"
Expand Down
4 changes: 2 additions & 2 deletions lightclient/src/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,10 @@ impl<TPlatform: PlatformRef, TChain> BackgroundTask<TPlatform, TChain> {
/// Perform the main background task:
/// - receiving requests from subxt RPC method / subscriptions
/// - provides the results from the light client back to users.
pub async fn start_task(
pub async fn start_task<TPlat: smoldot_light::platform::PlatformRef>(
&mut self,
from_subxt: mpsc::UnboundedReceiver<FromSubxt>,
from_node: Vec<AddedChain>,
from_node: Vec<AddedChain<TPlat>>,
) {
let from_subxt_event = tokio_stream::wrappers::UnboundedReceiverStream::new(from_subxt);

Expand Down
6 changes: 3 additions & 3 deletions lightclient/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl LightClientRpc {
/// https://docs.rs/wasm-bindgen-futures/latest/wasm_bindgen_futures/fn.future_to_promise.html.
pub fn new_from_client<TPlat>(
client: smoldot_light::Client<TPlat>,
chains: impl IntoIterator<Item = AddedChain>,
chains: impl IntoIterator<Item = AddedChain<TPlat>>,
) -> RawLightClientRpc
where
TPlat: smoldot_light::platform::PlatformRef + Clone,
Expand Down Expand Up @@ -204,9 +204,9 @@ impl LightClientRpc {
}

/// The added chain of the light-client.
pub struct AddedChain {
pub struct AddedChain<TPlat: smoldot_light::platform::PlatformRef> {
/// The id of the chain.
pub chain_id: smoldot_light::ChainId,
/// Producer of RPC responses for the chain.
pub rpc_responses: smoldot_light::JsonRpcResponses,
pub rpc_responses: smoldot_light::JsonRpcResponses<TPlat>,
}
17 changes: 7 additions & 10 deletions subxt/src/client/light_client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,27 +186,27 @@ impl<T: Config> LightClientBuilder<T> {
}

/// Raw builder for [`RawLightClient`].
pub struct RawLightClientBuilder {
chains: Vec<AddedChain>,
pub struct RawLightClientBuilder<TPlatform: smoldot::PlatformRef> {
chains: Vec<AddedChain<TPlatform>>,
}

impl Default for RawLightClientBuilder {
impl<TPlatform: smoldot::PlatformRef> Default for RawLightClientBuilder<TPlatform> {
fn default() -> Self {
Self { chains: Vec::new() }
}
}

impl RawLightClientBuilder {
impl<TPlatform: smoldot::PlatformRef> RawLightClientBuilder<TPlatform> {
/// Create a new [`RawLightClientBuilder`].
pub fn new() -> RawLightClientBuilder {
pub fn new() -> RawLightClientBuilder<TPlatform> {
RawLightClientBuilder::default()
}

/// Adds a new chain to the list of chains synchronized by the light client.
pub fn add_chain(
mut self,
chain_id: smoldot::ChainId,
rpc_responses: smoldot::JsonRpcResponses,
rpc_responses: smoldot::JsonRpcResponses<TPlatform>,
) -> Self {
self.chains.push(AddedChain {
chain_id,
Expand All @@ -219,10 +219,7 @@ impl RawLightClientBuilder {
///
/// The provided `chain_id` is the chain with which the current instance of light client will interact.
/// To target a different chain call the [`LightClient::target_chain`] method.
pub async fn build<TPlatform: smoldot::PlatformRef>(
self,
client: smoldot::Client<TPlatform>,
) -> Result<RawLightClient, Error> {
pub async fn build(self, client: smoldot::Client<TPlatform>) -> Result<RawLightClient, Error> {
// The raw subxt light client that spawns the smoldot background task.
let raw_rpc: subxt_lightclient::RawLightClientRpc =
subxt_lightclient::LightClientRpc::new_from_client(client, self.chains.into_iter());
Expand Down
2 changes: 1 addition & 1 deletion subxt/src/client/light_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl RawLightClient {
/// # Note
///
/// If you are unsure, please use [`LightClient::builder`] instead.
pub fn builder() -> RawLightClientBuilder {
pub fn builder<TPlatform: smoldot::PlatformRef>() -> RawLightClientBuilder<TPlatform> {
RawLightClientBuilder::default()
}

Expand Down
62 changes: 57 additions & 5 deletions testing/integration-tests/src/light_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,52 +39,85 @@ type Client = LightClient<PolkadotConfig>;

// Check that we can subscribe to non-finalized blocks.
async fn non_finalized_headers_subscription(api: &Client) -> Result<(), subxt::Error> {
let now = std::time::Instant::now();

println!("In non_finalized_headers_subscription");
let mut sub = api.blocks().subscribe_best().await?;

let _block = sub.next().await.unwrap()?;
println!("First block took {:?}", now.elapsed());

let _block = sub.next().await.unwrap()?;
println!("Second block took {:?}", now.elapsed());

let _block = sub.next().await.unwrap()?;
println!("Third block took {:?}\n", now.elapsed());

Ok(())
}

// Check that we can subscribe to finalized blocks.
async fn finalized_headers_subscription(api: &Client) -> Result<(), subxt::Error> {
let now = std::time::Instant::now();

println!("In finalized_headers_subscription");

let mut sub = api.blocks().subscribe_finalized().await?;
let header = sub.next().await.unwrap()?;
println!("First block took {:?}", now.elapsed());

let finalized_hash = api
.backend()
.latest_finalized_block_ref()
.await
.unwrap()
.hash();

println!(
"Finalized hash: {:?} took {:?}",
finalized_hash,
now.elapsed()
);

assert_eq!(header.hash(), finalized_hash);
println!("Check progress {:?}", now.elapsed());

let _block = sub.next().await.unwrap()?;
println!("Second block took {:?}", now.elapsed());
let _block = sub.next().await.unwrap()?;
println!("Third block took {:?}", now.elapsed());
let _block = sub.next().await.unwrap()?;
println!("Fourth block took {:?}\n", now.elapsed());

Ok(())
}

// Check that we can subscribe to non-finalized blocks.
async fn runtime_api_call(api: &Client) -> Result<(), subxt::Error> {
let now = std::time::Instant::now();
println!("In runtime_api_call");

let mut sub = api.blocks().subscribe_best().await?;

let block = sub.next().await.unwrap()?;
println!("First block took {:?}", now.elapsed());
let rt = block.runtime_api().await?;

// get metadata via state_call. if it decodes ok, it's probably all good.
let _ = rt
.call_raw::<(Compact<u32>, Metadata)>("Metadata_metadata", None)
.await?;

println!("Made runtime API call in {:?}\n", now.elapsed());

Ok(())
}

// Lookup for the `Timestamp::now` plain storage entry.
async fn storage_plain_lookup(api: &Client) -> Result<(), subxt::Error> {
let now = std::time::Instant::now();
println!("In storage_plain_lookup");

let addr = node_runtime::storage().timestamp().now();
let entry = api
.storage()
Expand All @@ -93,42 +126,61 @@ async fn storage_plain_lookup(api: &Client) -> Result<(), subxt::Error> {
.fetch_or_default(&addr)
.await?;

println!("Storage lookup took {:?}\n", now.elapsed());

assert!(entry > 0);

Ok(())
}

// Make a dynamic constant query for `System::BlockLenght`.
async fn dynamic_constant_query(api: &Client) -> Result<(), subxt::Error> {
let now = std::time::Instant::now();
println!("In dynamic_constant_query");

let constant_query = subxt::dynamic::constant("System", "BlockLength");
let _value = api.constants().at(&constant_query)?;

println!("Dynamic constant query took {:?}\n", now.elapsed());

Ok(())
}

// Fetch a few all events from the latest block and decode them dynamically.
async fn dynamic_events(api: &Client) -> Result<(), subxt::Error> {
let now = std::time::Instant::now();
println!("In dynamic_events");

let events = api.events().at_latest().await?;

for event in events.iter() {
let _event = event?;

println!("Event decoding took {:?}", now.elapsed());
}

println!("Dynamic events took {:?}\n", now.elapsed());

Ok(())
}

#[tokio::test]
async fn light_client_testing() -> Result<(), subxt::Error> {
tracing_subscriber::fmt::init();

let now = std::time::Instant::now();
let api: LightClient<PolkadotConfig> = LightClientBuilder::new()
.build_from_url("wss://rpc.polkadot.io:443")
.await?;

non_finalized_headers_subscription(&api).await?;
println!("Light client initialization took {:?}\n", now.elapsed());

// non_finalized_headers_subscription(&api).await?;
finalized_headers_subscription(&api).await?;
runtime_api_call(&api).await?;
storage_plain_lookup(&api).await?;
dynamic_constant_query(&api).await?;
dynamic_events(&api).await?;
// runtime_api_call(&api).await?;
// storage_plain_lookup(&api).await?;
// dynamic_constant_query(&api).await?;
// dynamic_events(&api).await?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these still be commented out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I've added a few debug logs in f14bf9a.
This is to help reproduce the issue from smoldot faster smol-dot/smoldot#1638.

I suggest putting this PR on pending until another smoldot version is published on crates io :D

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a plan :)


Ok(())
}
Loading