Skip to content

Commit

Permalink
lightclient(fix): Ensure lightclient chainSpec is at least one block …
Browse files Browse the repository at this point in the history
…old (#1372)

* testing(fix): Ensure lightclient chainSpec is at least one block old

Signed-off-by: Alexandru Vasile <[email protected]>

* Revert "testing(fix): Ensure lightclient chainSpec is at least one block old"

This reverts commit 0eafcb2.

* lightclient(fix): Ensure lightclient chainSpec is at least one block old

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Link smoldot issue

Signed-off-by: Alexandru Vasile <[email protected]>

* subxt: Use tokio under lightclient feature flag

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Do not sleep on errors to fetch the chainSpec

Signed-off-by: Alexandru Vasile <[email protected]>

* artifacts: Remove test file

Signed-off-by: Alexandru Vasile <[email protected]>

* lightclient: Subscribe to two finalized blocks

Signed-off-by: Alexandru Vasile <[email protected]>

* subxt: Revert cargo toml

Signed-off-by: Alexandru Vasile <[email protected]>

---------

Signed-off-by: Alexandru Vasile <[email protected]>
  • Loading branch information
lexnv authored Jan 17, 2024
1 parent ab6b6ae commit 92a9e77
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions subxt/src/client/light_client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,36 @@ async fn build_client_from_rpc<T: Config>(
/// Fetch the chain spec from the URL.
#[cfg(feature = "jsonrpsee")]
async fn fetch_url(url: impl AsRef<str>) -> Result<serde_json::Value, Error> {
use jsonrpsee::core::client::ClientT;
use jsonrpsee::core::client::{ClientT, SubscriptionClientT};
use jsonrpsee::rpc_params;
use serde_json::value::RawValue;

let client = jsonrpsee_helpers::client(url.as_ref()).await?;

client
let result = client
.request("sync_state_genSyncSpec", jsonrpsee::rpc_params![true])
.await
.map_err(|err| Error::Rpc(crate::error::RpcError::ClientError(Box::new(err))))
.map_err(|err| Error::Rpc(crate::error::RpcError::ClientError(Box::new(err))))?;

// Subscribe to the finalized heads of the chain.
let mut subscription = SubscriptionClientT::subscribe::<Box<RawValue>, _>(
&client,
"chain_subscribeFinalizedHeads",
rpc_params![],
"chain_unsubscribeFinalizedHeads",
)
.await
.map_err(|err| Error::Rpc(crate::error::RpcError::ClientError(Box::new(err))))?;

// We must ensure that the finalized block of the chain is not the block included
// in the chainSpec.
// This is a temporary workaround for: https://github.com/smol-dot/smoldot/issues/1562.
// The first finalized block that is received might by the finalized block could be the one
// included in the chainSpec. Decoding the chainSpec for this purpose is too complex.
let _ = subscription.next().await;
let _ = subscription.next().await;

Ok(result)
}

cfg_jsonrpsee_native! {
Expand Down

0 comments on commit 92a9e77

Please sign in to comment.