mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 00:31:07 +00:00
chore(deps): Update smoldot to the latest version (#1400)
* Update smoldot to 0.17 and smoldot-light to 0.15
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Update cargo lock
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* lightclient: Add generic platform for AddedChain
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* debug: Finalized heads
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* lightclient: Use generic TPlat for chainSuccess
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* lightclient: Trim response for logs
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Backup
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* tests/lightclient: Switch to localnode for testing
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* cargo: Point smoldot to crates.io
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Solve merge conflicts
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Add subxt macro for tests
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* lightclient/wasm: Impl log of the PlatformRef
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Use git dep
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Revert "tests/lightclient: Switch to localnode for testing" + max log
size
This reverts commit 74dd9d7cff.
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* tests: Comment chainspec
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* lightclient/wasm: Import IpAddr from core::net
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* tests: Enable all tests again
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* tests/wasm: Update cargo lock
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* tests: Add trace logs to easily reproduce problems
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* cargo: Use released smoldot version
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* lightclient: Use chainspec and optionally make use of unstable backend
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* lightclient: Fix clippy
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* lightclient: Better trimming for log messages
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* lightclient: Remove max log size
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* lightclient: Use both backends for testing
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
* Update Cargo.toml
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
* Update Cargo.toml
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
* Update testing/integration-tests/src/light_client/mod.rs
* Update testing/integration-tests/src/light_client/mod.rs
---------
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
This commit is contained in:
@@ -108,7 +108,7 @@ impl BackgroundTaskHandle {
|
||||
/// coming to/from Smoldot.
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub struct BackgroundTask<TPlatform: PlatformRef, TChain> {
|
||||
channels: BackgroundTaskChannels,
|
||||
channels: BackgroundTaskChannels<TPlatform>,
|
||||
data: BackgroundTaskData<TPlatform, TChain>,
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ impl<TPlatform: PlatformRef, TChain> BackgroundTask<TPlatform, TChain> {
|
||||
pub(crate) fn new(
|
||||
client: SharedClient<TPlatform, TChain>,
|
||||
chain_id: smoldot_light::ChainId,
|
||||
from_back: smoldot_light::JsonRpcResponses,
|
||||
from_back: smoldot_light::JsonRpcResponses<TPlatform>,
|
||||
) -> (BackgroundTask<TPlatform, TChain>, BackgroundTaskHandle) {
|
||||
let (tx, rx) = mpsc::unbounded_channel();
|
||||
|
||||
@@ -176,10 +176,11 @@ impl<TPlatform: PlatformRef, TChain> BackgroundTask<TPlatform, TChain> {
|
||||
tracing::trace!(target: LOG_TARGET, "Smoldot RPC responses channel closed");
|
||||
break;
|
||||
};
|
||||
|
||||
tracing::trace!(
|
||||
target: LOG_TARGET,
|
||||
"Received smoldot RPC chain {:?} result {:?}",
|
||||
chain_id, back_message
|
||||
"Received smoldot RPC chain {chain_id:?} result {}",
|
||||
trim_message(&back_message),
|
||||
);
|
||||
|
||||
data.handle_rpc_response(back_message);
|
||||
@@ -191,11 +192,11 @@ impl<TPlatform: PlatformRef, TChain> BackgroundTask<TPlatform, TChain> {
|
||||
}
|
||||
}
|
||||
|
||||
struct BackgroundTaskChannels {
|
||||
struct BackgroundTaskChannels<TPlatform: PlatformRef> {
|
||||
/// Messages sent into this background task from the front end.
|
||||
from_front: UnboundedReceiverStream<Message>,
|
||||
/// Messages sent into the background task from Smoldot.
|
||||
from_back: smoldot_light::JsonRpcResponses,
|
||||
from_back: smoldot_light::JsonRpcResponses<TPlatform>,
|
||||
}
|
||||
|
||||
struct BackgroundTaskData<TPlatform: PlatformRef, TChain> {
|
||||
@@ -242,6 +243,18 @@ struct ActiveSubscription {
|
||||
unsubscribe_method: String,
|
||||
}
|
||||
|
||||
fn trim_message(s: &str) -> &str {
|
||||
const MAX_SIZE: usize = 512;
|
||||
if s.len() < MAX_SIZE {
|
||||
return s;
|
||||
}
|
||||
|
||||
match s.char_indices().nth(MAX_SIZE) {
|
||||
None => s,
|
||||
Some((idx, _)) => &s[..idx],
|
||||
}
|
||||
}
|
||||
|
||||
impl<TPlatform: PlatformRef, TChain> BackgroundTaskData<TPlatform, TChain> {
|
||||
/// Fetch and increment the request ID.
|
||||
fn next_id(&mut self) -> usize {
|
||||
@@ -359,7 +372,7 @@ impl<TPlatform: PlatformRef, TChain> BackgroundTaskData<TPlatform, TChain> {
|
||||
/// Parse the response received from the light client and sent it to the appropriate user.
|
||||
fn handle_rpc_response(&mut self, response: String) {
|
||||
let chain_id = self.chain_id;
|
||||
tracing::trace!(target: LOG_TARGET, "Received from smoldot response='{response}' chain={chain_id:?}");
|
||||
tracing::trace!(target: LOG_TARGET, "Received from smoldot response='{}' chain={chain_id:?}", trim_message(&response));
|
||||
|
||||
match RpcResponse::from_str(&response) {
|
||||
Ok(RpcResponse::Method { id, result }) => {
|
||||
|
||||
@@ -185,7 +185,7 @@ impl LightClientRpc {
|
||||
pub(crate) fn new_raw<TPlat, TChain>(
|
||||
client: impl Into<SharedClient<TPlat, TChain>>,
|
||||
chain_id: smoldot_light::ChainId,
|
||||
rpc_responses: smoldot_light::JsonRpcResponses,
|
||||
rpc_responses: smoldot_light::JsonRpcResponses<TPlat>,
|
||||
) -> Self
|
||||
where
|
||||
TPlat: smoldot_light::platform::PlatformRef + Send + 'static,
|
||||
|
||||
@@ -4,12 +4,16 @@
|
||||
|
||||
use super::wasm_socket::WasmSocket;
|
||||
|
||||
use core::time::Duration;
|
||||
use core::{
|
||||
fmt::{self, Write as _},
|
||||
net::IpAddr,
|
||||
time::Duration,
|
||||
};
|
||||
use futures::prelude::*;
|
||||
use smoldot::libp2p::with_buffers;
|
||||
use smoldot_light::platform::{
|
||||
Address, ConnectionType, IpAddr, MultiStreamAddress, MultiStreamWebRtcConnection, PlatformRef,
|
||||
SubstreamDirection,
|
||||
Address, ConnectionType, LogLevel, MultiStreamAddress, MultiStreamWebRtcConnection,
|
||||
PlatformRef, SubstreamDirection,
|
||||
};
|
||||
|
||||
use std::{io, net::SocketAddr, pin::Pin};
|
||||
@@ -187,4 +191,33 @@ impl PlatformRef for SubxtPlatform {
|
||||
super::wasm_helpers::sleep(duration).await;
|
||||
}))
|
||||
}
|
||||
|
||||
fn log<'a>(
|
||||
&self,
|
||||
log_level: LogLevel,
|
||||
log_target: &'a str,
|
||||
message: &'a str,
|
||||
key_values: impl Iterator<Item = (&'a str, &'a dyn fmt::Display)>,
|
||||
) {
|
||||
let mut message_build = String::with_capacity(128);
|
||||
message_build.push_str(message);
|
||||
let mut first = true;
|
||||
for (key, value) in key_values {
|
||||
if first {
|
||||
let _ = write!(message_build, "; ");
|
||||
first = false;
|
||||
} else {
|
||||
let _ = write!(message_build, ", ");
|
||||
}
|
||||
let _ = write!(message_build, "{}={}", key, value);
|
||||
}
|
||||
|
||||
match log_level {
|
||||
LogLevel::Error => tracing::error!("target={} {}", log_target, message_build),
|
||||
LogLevel::Warn => tracing::warn!("target={} {}", log_target, message_build),
|
||||
LogLevel::Info => tracing::info!("target={} {}", log_target, message_build),
|
||||
LogLevel::Debug => tracing::debug!("target={} {}", log_target, message_build),
|
||||
LogLevel::Trace => tracing::trace!("target={} {}", log_target, message_build),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ impl<TPlat: sl::platform::PlatformRef, TChain> SharedClient<TPlat, TChain> {
|
||||
pub(crate) fn add_chain(
|
||||
&self,
|
||||
config: sl::AddChainConfig<'_, TChain, impl Iterator<Item = sl::ChainId>>,
|
||||
) -> Result<sl::AddChainSuccess, sl::AddChainError> {
|
||||
) -> Result<sl::AddChainSuccess<TPlat>, sl::AddChainError> {
|
||||
self.client
|
||||
.lock()
|
||||
.expect("mutex should not be poisoned")
|
||||
|
||||
Reference in New Issue
Block a user