Skip to content

Commit

Permalink
chore(deps): Update smoldot to the latest version (#1400)
Browse files Browse the repository at this point in the history
* 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 74dd9d7.

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>
  • Loading branch information
lexnv and niklasad1 committed Sep 9, 2024
1 parent 246865d commit 1cf206f
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 85 deletions.
127 changes: 63 additions & 64 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 @@ -120,8 +120,8 @@ sc-executor = "0.40.0"
sc-executor-common = "0.35.0"

# Light client support:
smoldot = { version = "0.16.0", default-features = false }
smoldot-light = { version = "0.14.0", default-features = false }
smoldot = { version = "0.18.0", default-features = false }
smoldot-light = { version = "0.16.2", default-features = false }
tokio-stream = "0.1.15"
futures-util = "0.3.30"
rand = "0.8.5"
Expand Down
27 changes: 20 additions & 7 deletions lightclient/src/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}

Expand All @@ -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();

Expand Down Expand Up @@ -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);
Expand All @@ -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> {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 }) => {
Expand Down
2 changes: 1 addition & 1 deletion lightclient/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 1cf206f

Please sign in to comment.