diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d83d19d0d8..875d3cee99 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: test-64bits: runs-on: ubuntu-latest container: - image: rust:1.88 + image: rust:1.89 steps: - uses: actions/checkout@v4 - uses: Swatinem/rust-cache@v2 @@ -39,7 +39,7 @@ jobs: test-32bits: runs-on: ubuntu-latest container: - image: rust:1.88 + image: rust:1.89 steps: - run: apt-get update && apt install -y libc6-dev-i386 - uses: actions/checkout@v4 @@ -50,7 +50,7 @@ jobs: wasm-node-check: runs-on: ubuntu-latest container: - image: rust:1.88 + image: rust:1.89 steps: - uses: actions/checkout@v4 - run: rustup target add wasm32-unknown-unknown @@ -67,7 +67,7 @@ jobs: check-features: runs-on: ubuntu-latest container: - image: rust:1.88 + image: rust:1.89 steps: - uses: actions/checkout@v4 - uses: Swatinem/rust-cache@v2 @@ -101,7 +101,7 @@ jobs: check-no-std: runs-on: ubuntu-latest container: - image: rust:1.88 + image: rust:1.89 steps: - uses: actions/checkout@v4 - run: rustup target add thumbv7m-none-eabi @@ -113,7 +113,7 @@ jobs: check-rustdoc-links: runs-on: ubuntu-latest container: - image: rust:1.88 + image: rust:1.89 steps: - uses: actions/checkout@v4 - uses: Swatinem/rust-cache@v2 @@ -122,7 +122,7 @@ jobs: fmt: runs-on: ubuntu-latest container: - image: rust:1.88 + image: rust:1.89 steps: # Checks `rustfmt` formatting - uses: actions/checkout@v4 @@ -136,7 +136,7 @@ jobs: clippy: runs-on: ubuntu-latest container: - image: rust:1.88 + image: rust:1.89 steps: - uses: actions/checkout@v4 # Since build artifacts are specific to a nightly version, we pin the specific nightly @@ -177,7 +177,7 @@ jobs: wasm-node-versions-match: runs-on: ubuntu-latest container: - image: rust:1.88 + image: rust:1.89 steps: - uses: actions/checkout@v4 - run: apt-get update && apt install -y jq diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1d0b86fb86..a8f3850bbe 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -56,7 +56,7 @@ jobs: build-js-doc: runs-on: ubuntu-latest container: - image: rust:1.88 + image: rust:1.89 steps: - uses: actions/checkout@v4 with: @@ -83,7 +83,7 @@ jobs: build-rust-doc: runs-on: ubuntu-latest container: - image: rust:1.88 + image: rust:1.89 steps: - uses: actions/checkout@v4 with: @@ -104,7 +104,7 @@ jobs: build-tests-coverage: runs-on: ubuntu-latest container: - image: rust:1.88 + image: rust:1.89 steps: - run: apt update && apt install -y jq - run: rustup component add llvm-tools-preview @@ -174,7 +174,7 @@ jobs: npm-publish: runs-on: ubuntu-latest container: - image: rust:1.88 + image: rust:1.89 steps: - uses: actions/checkout@v4 - run: rustup target add wasm32-unknown-unknown @@ -245,7 +245,7 @@ jobs: crates-io-publish: runs-on: ubuntu-latest container: - image: rust:1.88 + image: rust:1.89 steps: - uses: actions/checkout@v4 - run: cargo publish --dry-run --locked diff --git a/.github/workflows/periodic-cargo-update.yml b/.github/workflows/periodic-cargo-update.yml index bdef8151d2..15b3baa277 100644 --- a/.github/workflows/periodic-cargo-update.yml +++ b/.github/workflows/periodic-cargo-update.yml @@ -9,7 +9,7 @@ jobs: cargo-update: runs-on: ubuntu-latest container: - image: rust:1.88 + image: rust:1.89 steps: - uses: actions/checkout@v4 # Note: `cargo update --workspace` doesn't seem to have any effect. diff --git a/full-node/src/consensus_service.rs b/full-node/src/consensus_service.rs index 1109601dd7..f5c814bd11 100644 --- a/full-node/src/consensus_service.rs +++ b/full-node/src/consensus_service.rs @@ -114,10 +114,6 @@ pub struct Config { pub slot_duration_author_ratio: u16, } -/// Identifier for a blocks request to be performed. -#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] -pub struct BlocksRequestId(usize); - /// Summary of the state of the [`ConsensusService`]. #[derive(Debug, Clone)] pub struct SyncState { diff --git a/full-node/src/json_rpc_service/chain_head_subscriptions.rs b/full-node/src/json_rpc_service/chain_head_subscriptions.rs index 7eb9fd3638..5098adb647 100644 --- a/full-node/src/json_rpc_service/chain_head_subscriptions.rs +++ b/full-node/src/json_rpc_service/chain_head_subscriptions.rs @@ -305,7 +305,7 @@ pub async fn spawn_chain_head_subscription_task(config: Config) -> String { return_value } -fn convert_runtime_spec(runtime: &executor::CoreVersion) -> methods::MaybeRuntimeSpec { +fn convert_runtime_spec(runtime: &'_ executor::CoreVersion) -> methods::MaybeRuntimeSpec<'_> { let runtime = runtime.decode(); methods::MaybeRuntimeSpec::Valid { spec: methods::RuntimeSpec { diff --git a/full-node/src/json_rpc_service/requests_handler.rs b/full-node/src/json_rpc_service/requests_handler.rs index f3c68d49df..75aeb3338d 100644 --- a/full-node/src/json_rpc_service/requests_handler.rs +++ b/full-node/src/json_rpc_service/requests_handler.rs @@ -832,7 +832,7 @@ pub fn spawn_requests_handler(config: Config) { })); } -fn convert_runtime_version(runtime_spec: &executor::CoreVersion) -> methods::RuntimeVersion { +fn convert_runtime_version(runtime_spec: &'_ executor::CoreVersion) -> methods::RuntimeVersion<'_> { let runtime_spec = runtime_spec.decode(); methods::RuntimeVersion { spec_name: runtime_spec.spec_name.into(), diff --git a/lib/src/chain/blocks_tree.rs b/lib/src/chain/blocks_tree.rs index de860fb077..62d5366fd9 100644 --- a/lib/src/chain/blocks_tree.rs +++ b/lib/src/chain/blocks_tree.rs @@ -246,7 +246,7 @@ impl NonFinalizedTree { /// Returns the header of all known non-finalized blocks in the chain without any specific /// order. - pub fn iter_unordered(&self) -> impl Iterator { + pub fn iter_unordered(&'_ self) -> impl Iterator> { self.blocks .iter_unordered() .map(move |(_, b)| header::decode(&b.header, self.block_number_bytes).unwrap()) @@ -256,7 +256,7 @@ impl NonFinalizedTree { /// /// The returned items are guaranteed to be in an order in which the parents are found before /// their children. - pub fn iter_ancestry_order(&self) -> impl Iterator { + pub fn iter_ancestry_order(&'_ self) -> impl Iterator> { self.blocks .iter_ancestry_order() .map(move |(_, b)| header::decode(&b.header, self.block_number_bytes).unwrap()) @@ -281,7 +281,7 @@ impl NonFinalizedTree { /// Builds a [`chain_information::ChainInformationRef`] struct that might later be used to /// build a new [`NonFinalizedTree`]. - pub fn as_chain_information(&self) -> chain_information::ValidChainInformationRef { + pub fn as_chain_information(&'_ self) -> chain_information::ValidChainInformationRef<'_> { let attempt = chain_information::ChainInformationRef { finalized_block_header: header::decode( &self.finalized_block_header, @@ -376,7 +376,7 @@ impl NonFinalizedTree { } /// Returns consensus information about the current best block of the chain. - pub fn best_block_consensus(&self) -> chain_information::ChainInformationConsensusRef { + pub fn best_block_consensus(&'_ self) -> chain_information::ChainInformationConsensusRef<'_> { match ( &self.finalized_consensus, self.blocks_by_best_score diff --git a/lib/src/chain/blocks_tree/finality.rs b/lib/src/chain/blocks_tree/finality.rs index ed6228a4f7..362f176a51 100644 --- a/lib/src/chain/blocks_tree/finality.rs +++ b/lib/src/chain/blocks_tree/finality.rs @@ -71,11 +71,11 @@ impl NonFinalizedTree { /// verification is nonetheless deterministic. // TODO: expand the documentation about how blocks with authorities changes have to be finalized before any further block can be finalized pub fn verify_justification( - &mut self, + &'_ mut self, consensus_engine_id: [u8; 4], scale_encoded_justification: &[u8], randomness_seed: [u8; 32], - ) -> Result, JustificationVerifyError> { + ) -> Result, JustificationVerifyError> { match (&self.finality, &consensus_engine_id) { (Finality::Grandpa { .. }, b"FRNK") => { // Turn justification into a strongly-typed struct. @@ -121,10 +121,10 @@ impl NonFinalizedTree { /// A randomness seed must be provided and will be used during the verification. Note that the /// verification is nonetheless deterministic. pub fn verify_grandpa_commit_message( - &mut self, + &'_ mut self, scale_encoded_commit: &[u8], randomness_seed: [u8; 32], - ) -> Result, CommitVerifyError> { + ) -> Result, CommitVerifyError> { // The code below would panic if the chain doesn't use Grandpa. if !matches!(self.finality, Finality::Grandpa { .. }) { return Err(CommitVerifyError::NotGrandpa); @@ -202,9 +202,9 @@ impl NonFinalizedTree { /// If necessary, the current best block will be updated to be a descendant of the /// newly-finalized block. pub fn set_finalized_block( - &mut self, + &'_ mut self, block_hash: &[u8; 32], - ) -> Result, SetFinalizedError> { + ) -> Result, SetFinalizedError> { let block_index = match self.blocks_by_hash.get(block_hash) { Some(idx) => *idx, None => return Err(SetFinalizedError::UnknownBlock), @@ -311,9 +311,9 @@ impl NonFinalizedTree { /// Panics if `block_index_to_finalize` isn't a valid node in the tree. /// fn set_finalized_block_inner( - &mut self, + &'_ mut self, block_index_to_finalize: fork_tree::NodeIndex, - ) -> SetFinalizedBlockIter { + ) -> SetFinalizedBlockIter<'_, T> { let new_finalized_block = self.blocks.get_mut(block_index_to_finalize).unwrap(); // Update `self.finality`. diff --git a/lib/src/chain/chain_information.rs b/lib/src/chain/chain_information.rs index da6a494da7..ba0d638ebf 100644 --- a/lib/src/chain/chain_information.rs +++ b/lib/src/chain/chain_information.rs @@ -61,7 +61,7 @@ impl From for ChainInformation { impl ValidChainInformation { /// Gives access to the information. - pub fn as_ref(&self) -> ChainInformationRef { + pub fn as_ref(&'_ self) -> ChainInformationRef<'_> { From::from(&self.inner) } } diff --git a/lib/src/chain/fork_tree.rs b/lib/src/chain/fork_tree.rs index 400d8c6968..5edf22e4b1 100644 --- a/lib/src/chain/fork_tree.rs +++ b/lib/src/chain/fork_tree.rs @@ -259,7 +259,7 @@ impl ForkTree { /// /// Panics if the [`NodeIndex`] is invalid. /// - pub fn prune_ancestors(&mut self, node_index: NodeIndex) -> PruneAncestorsIter { + pub fn prune_ancestors(&'_ mut self, node_index: NodeIndex) -> PruneAncestorsIter<'_, T> { self.prune_ancestors_inner(node_index, false) } @@ -274,15 +274,15 @@ impl ForkTree { /// /// Panics if the [`NodeIndex`] is invalid. /// - pub fn prune_uncles(&mut self, node_index: NodeIndex) -> PruneAncestorsIter { + pub fn prune_uncles(&'_ mut self, node_index: NodeIndex) -> PruneAncestorsIter<'_, T> { self.prune_ancestors_inner(node_index, true) } fn prune_ancestors_inner( - &mut self, + &'_ mut self, node_index: NodeIndex, uncles_only: bool, - ) -> PruneAncestorsIter { + ) -> PruneAncestorsIter<'_, T> { let iter = self.first_root.unwrap(); // `first_root` is updated ahead of the removal of the nodes. The update strategy is as diff --git a/lib/src/chain_spec.rs b/lib/src/chain_spec.rs index 661e7a9180..c966c73e7e 100644 --- a/lib/src/chain_spec.rs +++ b/lib/src/chain_spec.rs @@ -249,7 +249,7 @@ impl ChainSpec { /// /// Bootnode addresses that have failed to be parsed are returned as well in the form of /// a [`Bootnode::UnrecognizedFormat`]. - pub fn boot_nodes(&self) -> impl ExactSizeIterator { + pub fn boot_nodes(&'_ self) -> impl ExactSizeIterator> { // Note that we intentionally don't expose types found in the `libp2p` module in order to // not tie the code that parses chain specifications to the libp2p code. self.client_spec.boot_nodes.iter().map(|unparsed| { @@ -311,7 +311,7 @@ impl ChainSpec { } /// Gives access to what is known about the storage of the genesis block of the chain. - pub fn genesis_storage(&self) -> GenesisStorage { + pub fn genesis_storage(&'_ self) -> GenesisStorage<'_> { match &self.client_spec.genesis { structs::Genesis::Raw(raw) => GenesisStorage::Items(GenesisStorageItems { raw }), structs::Genesis::StateRootHash(hash) => GenesisStorage::TrieRootHash(&hash.0), diff --git a/lib/src/executor/host.rs b/lib/src/executor/host.rs index 1124159cb9..6a4aef68a7 100644 --- a/lib/src/executor/host.rs +++ b/lib/src/executor/host.rs @@ -3554,7 +3554,7 @@ enum LogEmitInner { impl LogEmit { /// Returns the data that the runtime would like to print. - pub fn info(&self) -> LogEmitInfo { + pub fn info(&'_ self) -> LogEmitInfo<'_> { match self.log_entry { LogEmitInner::Num(n) => LogEmitInfo::Num(n), LogEmitInner::Utf8 { str_ptr, str_size } => LogEmitInfo::Utf8(LogEmitInfoStr { diff --git a/lib/src/executor/host/runtime_version.rs b/lib/src/executor/host/runtime_version.rs index fbbc7c7ed5..38a0e1b67d 100644 --- a/lib/src/executor/host/runtime_version.rs +++ b/lib/src/executor/host/runtime_version.rs @@ -89,8 +89,8 @@ pub struct EmbeddedRuntimeVersionApis<'a> { /// /// This function does not attempt to decode the content of the custom sections. pub fn find_encoded_embedded_runtime_version_apis( - binary_wasm_module: &[u8], -) -> Result { + binary_wasm_module: &'_ [u8], +) -> Result, FindEncodedEmbeddedRuntimeVersionApisError> { let mut parser = nom::combinator::all_consuming(nom::combinator::complete(nom::sequence::preceded( ( @@ -194,7 +194,7 @@ impl CoreVersion { Ok(CoreVersion(input)) } - pub fn decode(&self) -> CoreVersionRef { + pub fn decode(&'_ self) -> CoreVersionRef<'_> { decode(&self.0).unwrap() } } @@ -438,7 +438,7 @@ pub struct CoreVersionApi { pub version: u32, } -fn decode(scale_encoded: &[u8]) -> Result { +fn decode(scale_encoded: &'_ [u8]) -> Result, ()> { // See https://spec.polkadot.network/#defn-rt-core-version let result: nom::IResult<_, _> = nom::Parser::parse( &mut nom::combinator::all_consuming(nom::combinator::complete(nom::combinator::map( @@ -542,7 +542,7 @@ struct WasmSection<'a> { } /// Parses a Wasm section. If it is a custom section, returns its name and content. -fn wasm_section(bytes: &[u8]) -> nom::IResult<&[u8], Option> { +fn wasm_section(bytes: &'_ [u8]) -> nom::IResult<&'_ [u8], Option>> { nom::Parser::parse( &mut nom::branch::alt(( nom::combinator::map( diff --git a/lib/src/executor/host/zstd.rs b/lib/src/executor/host/zstd.rs index 0308a9510b..25eb4df0e1 100644 --- a/lib/src/executor/host/zstd.rs +++ b/lib/src/executor/host/zstd.rs @@ -29,9 +29,9 @@ pub(super) const ZSTD_PREFIX: [u8; 8] = [82, 188, 83, 118, 70, 219, 142, 5]; /// /// The output data shall not be larger than `max_allowed`, to avoid potential zip bombs. pub(super) fn zstd_decode_if_necessary( - data: &[u8], + data: &'_ [u8], max_allowed: usize, -) -> Result, Error> { +) -> Result, Error> { if data.starts_with(&ZSTD_PREFIX) { Ok(Cow::Owned(zstd_decode( &data[ZSTD_PREFIX.len()..], diff --git a/lib/src/executor/runtime_call.rs b/lib/src/executor/runtime_call.rs index 3aedbdd6d1..77703e0af7 100644 --- a/lib/src/executor/runtime_call.rs +++ b/lib/src/executor/runtime_call.rs @@ -252,8 +252,8 @@ impl StorageChanges { /// Returns `Some` if and only if [`Config::calculate_trie_changes`] was `true` or if the /// [`StorageChanges`] was created using [`StorageChanges::empty`]. pub fn trie_changes_iter_ordered( - &self, - ) -> Option, &[Nibble], TrieChange)>> { + &'_ self, + ) -> Option, &'_ [Nibble], TrieChange<'_>)>> { if !self.calculate_trie_changes { return None; } @@ -1268,7 +1268,7 @@ pub struct LogEmit { impl LogEmit { /// Returns the data that the runtime would like to print. - pub fn info(&self) -> LogEmitInfo { + pub fn info(&'_ self) -> LogEmitInfo<'_> { match &self.inner.vm { host::HostVm::LogEmit(req) => req.info(), // We only create a `LogEmit` if the inner state is `LogEmit`. diff --git a/lib/src/finality/decode.rs b/lib/src/finality/decode.rs index c5eee1025f..ecf6bc7ef8 100644 --- a/lib/src/finality/decode.rs +++ b/lib/src/finality/decode.rs @@ -22,9 +22,9 @@ use core::fmt; /// Attempt to decode the given SCALE-encoded justification. pub fn decode_grandpa_justification( - scale_encoded: &[u8], + scale_encoded: &'_ [u8], block_number_bytes: usize, -) -> Result { +) -> Result, JustificationDecodeError> { match nom::Parser::parse( &mut nom::combinator::complete(nom::combinator::all_consuming::< _, @@ -46,9 +46,9 @@ pub fn decode_grandpa_justification( /// Contrary to [`decode_grandpa_justification`], doesn't return an error if the slice is too long /// but returns the remainder. pub fn decode_partial_grandpa_justification( - scale_encoded: &[u8], + scale_encoded: &'_ [u8], block_number_bytes: usize, -) -> Result<(GrandpaJustificationRef, &[u8]), JustificationDecodeError> { +) -> Result<(GrandpaJustificationRef<'_>, &'_ [u8]), JustificationDecodeError> { match nom::Parser::parse( &mut nom::combinator::complete(grandpa_justification::>( block_number_bytes, @@ -87,9 +87,9 @@ pub struct GrandpaJustification { /// Attempt to decode the given SCALE-encoded Grandpa commit. pub fn decode_grandpa_commit( - scale_encoded: &[u8], + scale_encoded: &'_ [u8], block_number_bytes: usize, -) -> Result { +) -> Result, CommitDecodeError<'_>> { match nom::Parser::parse( &mut nom::combinator::all_consuming(commit_message(block_number_bytes)), scale_encoded, @@ -104,9 +104,9 @@ pub fn decode_grandpa_commit( /// Contrary to [`decode_grandpa_commit`], doesn't return an error if the slice is too long, but /// returns the remainder. pub fn decode_partial_grandpa_commit( - scale_encoded: &[u8], + scale_encoded: &'_ [u8], block_number_bytes: usize, -) -> Result<(CommitMessageRef, &[u8]), CommitDecodeError> { +) -> Result<(CommitMessageRef<'_>, &'_ [u8]), CommitDecodeError<'_>> { match nom::Parser::parse(&mut commit_message(block_number_bytes), scale_encoded) { Ok((remainder, commit)) => Ok((commit, remainder)), Err(err) => Err(CommitDecodeError(err)), @@ -289,9 +289,9 @@ impl PrecommitRef<'_> { /// /// Returns the rest of the data alongside with the decoded struct. pub fn decode_partial( - scale_encoded: &[u8], + scale_encoded: &'_ [u8], block_number_bytes: usize, - ) -> Result<(PrecommitRef, &[u8]), JustificationDecodeError> { + ) -> Result<(PrecommitRef<'_>, &'_ [u8]), JustificationDecodeError> { match nom::Parser::parse( &mut precommit::>(block_number_bytes), scale_encoded, diff --git a/lib/src/header.rs b/lib/src/header.rs index 2bc79ee1ba..aa7c9fb380 100644 --- a/lib/src/header.rs +++ b/lib/src/header.rs @@ -127,7 +127,7 @@ pub fn extrinsics_root(transactions: &[impl AsRef<[u8]>]) -> [u8; 32] { } /// Attempt to decode the given SCALE-encoded header. -pub fn decode(scale_encoded: &[u8], block_number_bytes: usize) -> Result { +pub fn decode(scale_encoded: &'_ [u8], block_number_bytes: usize) -> Result, Error> { let (header, remainder) = decode_partial(scale_encoded, block_number_bytes)?; if !remainder.is_empty() { return Err(Error::TooLong); @@ -141,9 +141,9 @@ pub fn decode(scale_encoded: &[u8], block_number_bytes: usize) -> Result Result<(HeaderRef, &[u8]), Error> { +) -> Result<(HeaderRef<'_>, &'_ [u8]), Error> { if scale_encoded.len() < 32 + 1 { return Err(Error::TooShort); } @@ -901,7 +901,7 @@ pub struct Digest { impl Digest { /// Returns an iterator to the log items in this digest. - pub fn logs(&self) -> LogsIter { + pub fn logs(&'_ self) -> LogsIter<'_> { DigestRef::from(self).logs() } @@ -916,7 +916,7 @@ impl Digest { } /// Returns the Babe pre-runtime digest item, if any. - pub fn babe_pre_runtime(&self) -> Option { + pub fn babe_pre_runtime(&'_ self) -> Option> { DigestRef::from(self).babe_pre_runtime() } @@ -924,7 +924,9 @@ impl Digest { /// /// It is guaranteed that a configuration change is present only if an epoch change is /// present too. - pub fn babe_epoch_information(&self) -> Option<(BabeNextEpochRef, Option)> { + pub fn babe_epoch_information( + &'_ self, + ) -> Option<(BabeNextEpochRef<'_>, Option)> { DigestRef::from(self).babe_epoch_information() } @@ -1334,9 +1336,9 @@ impl<'a> From> for DigestItem { /// Decodes a single digest log item. On success, returns the item and the data that remains /// after the item. fn decode_item( - mut slice: &[u8], + mut slice: &'_ [u8], block_number_bytes: usize, -) -> Result<(DigestItemRef, &[u8]), Error> { +) -> Result<(DigestItemRef<'_>, &'_ [u8]), Error> { let index = *slice.first().ok_or(Error::TooShort)?; slice = &slice[1..]; diff --git a/lib/src/json_rpc/methods.rs b/lib/src/json_rpc/methods.rs index d44df7d362..cbb93f7587 100644 --- a/lib/src/json_rpc/methods.rs +++ b/lib/src/json_rpc/methods.rs @@ -36,8 +36,8 @@ use hashbrown::HashMap; /// On success, returns a JSON-encoded identifier for that request that must be passed back when /// emitting the response. pub fn parse_jsonrpc_client_to_server( - message: &str, -) -> Result<(&str, MethodCall), ParseClientToServerError> { + message: &'_ str, +) -> Result<(&'_ str, MethodCall<'_>), ParseClientToServerError<'_>> { let call_def = parse::parse_request(message).map_err(ParseClientToServerError::JsonRpcParse)?; // No notification is supported by this server. If the `id` field is missing in the request, @@ -82,7 +82,9 @@ pub enum ParseClientToServerError<'a> { } /// Parses a JSON notification. -pub fn parse_notification(message: &str) -> Result { +pub fn parse_notification( + message: &'_ str, +) -> Result, ParseNotificationError<'_>> { let call_def = parse::parse_request(message).map_err(ParseNotificationError::JsonRpcParse)?; let call = ServerToClient::from_defs(call_def.method, call_def.params_json) .map_err(ParseNotificationError::Method)?; diff --git a/lib/src/json_rpc/parse.rs b/lib/src/json_rpc/parse.rs index f02a65a2a7..97a7563fed 100644 --- a/lib/src/json_rpc/parse.rs +++ b/lib/src/json_rpc/parse.rs @@ -20,7 +20,7 @@ use alloc::{borrow::Cow, string::String}; /// Parses a JSON-encoded RPC method call or notification. -pub fn parse_request(request_json: &str) -> Result { +pub fn parse_request(request_json: &'_ str) -> Result, ParseError> { let serde_request: SerdeRequest = serde_json::from_str(request_json).map_err(ParseError)?; if let Some(id) = &serde_request.id { @@ -47,7 +47,7 @@ pub fn parse_request(request_json: &str) -> Result { } /// Parses a JSON-encoded RPC response. -pub fn parse_response(response_json: &str) -> Result { +pub fn parse_response(response_json: &'_ str) -> Result, ParseError> { let error = match serde_json::from_str::(response_json) { Err(err) => err, Ok(SerdeSuccess { diff --git a/lib/src/json_rpc/service/client_main_task.rs b/lib/src/json_rpc/service/client_main_task.rs index 929cf38124..2dfed0e1e6 100644 --- a/lib/src/json_rpc/service/client_main_task.rs +++ b/lib/src/json_rpc/service/client_main_task.rs @@ -997,7 +997,7 @@ impl RequestProcess { /// /// The request is guaranteed to not be related to subscriptions in any way. // TODO: with stronger typing users wouldn't have to worry about the type of request - pub fn request(&self) -> methods::MethodCall { + pub fn request(&'_ self) -> methods::MethodCall<'_> { methods::parse_jsonrpc_client_to_server(&self.request) .unwrap() .1 @@ -1124,7 +1124,7 @@ impl SubscriptionStartProcess { /// /// The request is guaranteed to be a request that starts a subscription. // TODO: with stronger typing users wouldn't have to worry about the type of request - pub fn request(&self) -> methods::MethodCall { + pub fn request(&'_ self) -> methods::MethodCall<'_> { methods::parse_jsonrpc_client_to_server(&self.request) .unwrap() .1 diff --git a/lib/src/libp2p/with_buffers.rs b/lib/src/libp2p/with_buffers.rs index c6b62bcc13..b14d4e9a1e 100644 --- a/lib/src/libp2p/with_buffers.rs +++ b/lib/src/libp2p/with_buffers.rs @@ -108,9 +108,9 @@ where /// > **Note**: The parameter requires `Self` to be pinned for consistency with /// > [`WithBuffers::wait_read_write_again`]. pub fn read_write_access( - self: Pin<&mut Self>, + self: Pin<&'_ mut Self>, now: TNow, - ) -> Result, &io::Error> { + ) -> Result, &'_ io::Error> { let this = self.project(); debug_assert!( diff --git a/lib/src/network/basic_peering_strategy.rs b/lib/src/network/basic_peering_strategy.rs index 0244589d8f..9f45c8a708 100644 --- a/lib/src/network/basic_peering_strategy.rs +++ b/lib/src/network/basic_peering_strategy.rs @@ -611,10 +611,10 @@ where /// > **Note**: This function is a shortcut for calling /// > [`BasicPeeringStrategy::unassign_slot_and_ban`] for all existing chains. pub fn unassign_slots_and_ban( - &mut self, + &'_ mut self, peer_id: &PeerId, when_unban: TInstant, - ) -> UnassignSlotsAndBanIter { + ) -> UnassignSlotsAndBanIter<'_, TChainId, TInstant> { let Some(&peer_id_index) = self.peer_ids_indices.get(peer_id) else { return UnassignSlotsAndBanIter { chains: &self.chains, diff --git a/lib/src/network/codec.rs b/lib/src/network/codec.rs index 51fe27a4b6..df1d358ecd 100644 --- a/lib/src/network/codec.rs +++ b/lib/src/network/codec.rs @@ -175,7 +175,7 @@ pub fn encode_protocol_name_string(protocol: ProtocolName) -> String { /// Decodes a protocol name into its components. /// /// Returns an error if the protocol name isn't recognized. -pub fn decode_protocol_name(name: &str) -> Result { +pub fn decode_protocol_name(name: &'_ str) -> Result, ()> { nom::Parser::parse( &mut nom::combinator::all_consuming(nom::branch::alt(( nom::combinator::map(nom::bytes::complete::tag("/ipfs/id/1.0.0"), |_| { @@ -264,8 +264,8 @@ fn protocol_ty(name: &str) -> nom::IResult<&str, ProtocolTy> { fn protocol_ty_to_real_protocol( ty: ProtocolTy, genesis_hash: [u8; 32], - fork_id: Option<&str>, -) -> ProtocolName { + fork_id: Option<&'_ str>, +) -> ProtocolName<'_> { match ty { ProtocolTy::BlockAnnounces => ProtocolName::BlockAnnounces { genesis_hash, diff --git a/lib/src/network/codec/block_announces.rs b/lib/src/network/codec/block_announces.rs index 45291e2ca7..f2a303c1ac 100644 --- a/lib/src/network/codec/block_announces.rs +++ b/lib/src/network/codec/block_announces.rs @@ -103,9 +103,9 @@ pub fn encode_block_announce(announce: BlockAnnounceRef) -> impl Iterator Result { +) -> Result, DecodeBlockAnnounceError> { let result: Result<_, nom::error::Error<_>> = nom::Parser::parse( &mut nom::combinator::all_consuming(nom::combinator::complete(nom::combinator::map( ( @@ -169,8 +169,8 @@ pub fn encode_block_announces_handshake( /// Decodes a SCALE-encoded block announces handshake. pub fn decode_block_announces_handshake( expected_block_number_bytes: usize, - handshake: &[u8], -) -> Result { + handshake: &'_ [u8], +) -> Result, BlockAnnouncesHandshakeDecodeError> { let result: Result<_, nom::error::Error<_>> = nom::Parser::parse( &mut nom::combinator::all_consuming(nom::combinator::complete(nom::combinator::map( ( diff --git a/lib/src/network/codec/grandpa.rs b/lib/src/network/codec/grandpa.rs index 720814141e..32551a1127 100644 --- a/lib/src/network/codec/grandpa.rs +++ b/lib/src/network/codec/grandpa.rs @@ -148,9 +148,9 @@ pub struct PrevoteRef<'a> { /// Attempt to decode the given SCALE-encoded Grandpa notification. pub fn decode_grandpa_notification( - scale_encoded: &[u8], + scale_encoded: &'_ [u8], block_number_bytes: usize, -) -> Result { +) -> Result, DecodeGrandpaNotificationError> { match nom::Parser::parse( &mut nom::combinator::all_consuming::<_, nom::error::Error<&[u8]>, _>( nom::combinator::complete(grandpa_notification(block_number_bytes)), diff --git a/lib/src/network/codec/grandpa_warp_sync.rs b/lib/src/network/codec/grandpa_warp_sync.rs index 89d8dacb6a..b3a9d2b2f3 100644 --- a/lib/src/network/codec/grandpa_warp_sync.rs +++ b/lib/src/network/codec/grandpa_warp_sync.rs @@ -76,9 +76,9 @@ pub struct DecodeGrandpaWarpSyncResponseError; /// Decodes a SCALE-encoded GrandPa warp sync response. pub fn decode_grandpa_warp_sync_response( - encoded: &[u8], + encoded: &'_ [u8], block_number_bytes: usize, -) -> Result { +) -> Result, DecodeGrandpaWarpSyncResponseError> { nom::Parser::parse( &mut nom::combinator::all_consuming::<_, (&[u8], nom::error::ErrorKind), _>( nom::combinator::map( diff --git a/lib/src/network/service.rs b/lib/src/network/service.rs index b085bd16e4..9b16f4987b 100644 --- a/lib/src/network/service.rs +++ b/lib/src/network/service.rs @@ -4558,7 +4558,7 @@ pub struct EncodedBlockAnnounce { impl EncodedBlockAnnounce { /// Returns the decoded version of the announcement. - pub fn decode(&self) -> codec::BlockAnnounceRef { + pub fn decode(&'_ self) -> codec::BlockAnnounceRef<'_> { codec::decode_block_announce(&self.message, self.block_number_bytes).unwrap() } } @@ -4602,7 +4602,7 @@ impl EncodedGrandpaWarpSyncResponse { } /// Returns the decoded version of the warp sync message. - pub fn decode(&self) -> codec::GrandpaWarpSyncResponse { + pub fn decode(&'_ self) -> codec::GrandpaWarpSyncResponse<'_> { match codec::decode_grandpa_warp_sync_response(&self.message, self.block_number_bytes) { Ok(msg) => msg, _ => unreachable!(), @@ -4656,7 +4656,7 @@ pub struct EncodedBlockAnnounceHandshake { impl EncodedBlockAnnounceHandshake { /// Returns the decoded version of the handshake. - pub fn decode(&self) -> codec::BlockAnnouncesHandshakeRef { + pub fn decode(&'_ self) -> codec::BlockAnnouncesHandshakeRef<'_> { codec::decode_block_announces_handshake(self.block_number_bytes, &self.handshake).unwrap() } } @@ -4707,7 +4707,7 @@ impl EncodedGrandpaCommitMessage { } /// Returns the decoded version of the commit message. - pub fn decode(&self) -> codec::CommitMessageRef { + pub fn decode(&'_ self) -> codec::CommitMessageRef<'_> { match codec::decode_grandpa_notification(&self.message, self.block_number_bytes) { Ok(codec::GrandpaNotificationRef::Commit(msg)) => msg, _ => unreachable!(), diff --git a/lib/src/sync/all.rs b/lib/src/sync/all.rs index b7de3c9d7e..4d429507a7 100644 --- a/lib/src/sync/all.rs +++ b/lib/src/sync/all.rs @@ -235,7 +235,7 @@ impl AllSync { /// Builds a [`chain_information::ChainInformationRef`] struct corresponding to the current /// latest finalized block. Can later be used to reconstruct a chain. - pub fn as_chain_information(&self) -> chain_information::ValidChainInformationRef { + pub fn as_chain_information(&'_ self) -> chain_information::ValidChainInformationRef<'_> { let Some(all_forks) = &self.all_forks else { unreachable!() }; @@ -244,7 +244,7 @@ impl AllSync { } /// Returns the current status of the syncing. - pub fn status(&self) -> Status { + pub fn status(&'_ self) -> Status<'_, TSrc> { // TODO: Status::Sync /*match &self.inner { @@ -344,13 +344,13 @@ impl AllSync { } /// Returns consensus information about the current best block of the chain. - pub fn best_block_consensus(&self) -> chain_information::ChainInformationConsensusRef { + pub fn best_block_consensus(&'_ self) -> chain_information::ChainInformationConsensusRef<'_> { todo!() // TODO: } /// Returns the header of all known non-finalized blocks in the chain without any specific /// order. - pub fn non_finalized_blocks_unordered(&self) -> impl Iterator { + pub fn non_finalized_blocks_unordered(&'_ self) -> impl Iterator> { let Some(all_forks) = &self.all_forks else { unreachable!() }; @@ -362,7 +362,9 @@ impl AllSync { /// /// The returned items are guaranteed to be in an order in which the parents are found before /// their children. - pub fn non_finalized_blocks_ancestry_order(&self) -> impl Iterator { + pub fn non_finalized_blocks_ancestry_order( + &'_ self, + ) -> impl Iterator> { let Some(all_forks) = &self.all_forks else { unreachable!() }; @@ -396,10 +398,10 @@ impl AllSync { /// This function call doesn't modify anything but returns an object that allows actually /// inserting the source. pub fn prepare_add_source( - &mut self, + &'_ mut self, best_block_number: u64, best_block_hash: [u8; 32], - ) -> AddSource { + ) -> AddSource<'_, TRq, TSrc, TBl> { match self .all_forks .as_mut() @@ -1068,11 +1070,11 @@ impl AllSync { /// Panics if the [`SourceId`] is invalid. /// pub fn block_announce( - &mut self, + &'_ mut self, source_id: SourceId, announced_scale_encoded_header: Vec, is_best: bool, - ) -> BlockAnnounceOutcome { + ) -> BlockAnnounceOutcome<'_, TRq, TSrc, TBl> { let Some(&SourceMapping { all_forks: inner_source_id, .. diff --git a/lib/src/sync/all_forks.rs b/lib/src/sync/all_forks.rs index 3de4647629..cda0984fe7 100644 --- a/lib/src/sync/all_forks.rs +++ b/lib/src/sync/all_forks.rs @@ -441,7 +441,7 @@ impl AllForksSync { /// Builds a [`chain_information::ChainInformationRef`] struct corresponding to the current /// latest finalized block. Can later be used to reconstruct a chain. - pub fn as_chain_information(&self) -> chain_information::ValidChainInformationRef { + pub fn as_chain_information(&'_ self) -> chain_information::ValidChainInformationRef<'_> { self.chain.as_chain_information() } @@ -486,7 +486,7 @@ impl AllForksSync { /// Returns the header of all known non-finalized blocks in the chain without any specific /// order. - pub fn non_finalized_blocks_unordered(&self) -> impl Iterator { + pub fn non_finalized_blocks_unordered(&'_ self) -> impl Iterator> { self.chain.iter_unordered() } @@ -494,7 +494,9 @@ impl AllForksSync { /// /// The returned items are guaranteed to be in an order in which the parents are found before /// their children. - pub fn non_finalized_blocks_ancestry_order(&self) -> impl Iterator { + pub fn non_finalized_blocks_ancestry_order( + &'_ self, + ) -> impl Iterator> { self.chain.iter_ancestry_order() } @@ -504,10 +506,10 @@ impl AllForksSync { /// block referenced by `best_block_number` and `best_block_hash`. It returns an enum that /// allows performing the actual insertion. pub fn prepare_add_source( - &mut self, + &'_ mut self, best_block_number: u64, best_block_hash: [u8; 32], - ) -> AddSource { + ) -> AddSource<'_, TBl, TRq, TSrc> { if best_block_number <= self.chain.finalized_block_height() { return AddSource::OldBestBlock(AddSourceOldBlock { inner: self, @@ -768,9 +770,9 @@ impl AllForksSync { /// Panics if the [`RequestId`] is invalid. /// pub fn finish_request( - &mut self, + &'_ mut self, request_id: RequestId, - ) -> (TRq, FinishRequest) { + ) -> (TRq, FinishRequest<'_, TBl, TRq, TSrc>) { // Sets the `occupation` of `source_id` back to `AllSync`. let ( pending_blocks::RequestParams { @@ -807,11 +809,11 @@ impl AllForksSync { /// Panics if `source_id` is invalid. /// pub fn block_announce( - &mut self, + &'_ mut self, source_id: SourceId, announced_scale_encoded_header: Vec, is_best: bool, - ) -> BlockAnnounceOutcome { + ) -> BlockAnnounceOutcome<'_, TBl, TRq, TSrc> { let announced_header = match header::decode( &announced_scale_encoded_header, self.chain.block_number_bytes(), diff --git a/lib/src/sync/para.rs b/lib/src/sync/para.rs index 2196d46af6..24480f5148 100644 --- a/lib/src/sync/para.rs +++ b/lib/src/sync/para.rs @@ -74,9 +74,9 @@ impl OccupiedCoreAssumption { /// Attempt to decode the return value of the `ParachainHost_persisted_validation_data` runtime /// call. pub fn decode_persisted_validation_data_return_value( - scale_encoded: &[u8], + scale_encoded: &'_ [u8], block_number_bytes: usize, -) -> Result, Error> { +) -> Result>, Error> { let res: Result<_, nom::Err>> = nom::Parser::parse( &mut nom::combinator::all_consuming(crate::util::nom_option_decode( persisted_validation_data(block_number_bytes), diff --git a/lib/src/sync/warp_sync.rs b/lib/src/sync/warp_sync.rs index e40a1fdbbb..2dcea3b69b 100644 --- a/lib/src/sync/warp_sync.rs +++ b/lib/src/sync/warp_sync.rs @@ -542,7 +542,7 @@ impl WarpSync { } /// Returns the chain information that is considered verified. - pub fn as_chain_information(&self) -> ValidChainInformationRef { + pub fn as_chain_information(&'_ self) -> ValidChainInformationRef<'_> { // Note: after verifying a warp sync fragment, we are certain that the header targeted by // this fragment is indeed part of the chain. However, this is not enough in order to // produce a full chain information struct. Such struct can only be produced after the @@ -590,7 +590,7 @@ impl WarpSync { } /// Returns the current status of the warp syncing. - pub fn status(&self) -> Status { + pub fn status(&'_ self) -> Status<'_, TSrc> { match &self.runtime_download { RuntimeDownload::NotStarted { .. } => { let finalized_block_hash = self.warped_header_hash; diff --git a/lib/src/trie/proof_decode.rs b/lib/src/trie/proof_decode.rs index 502ec192d9..c47ea419c5 100644 --- a/lib/src/trie/proof_decode.rs +++ b/lib/src/trie/proof_decode.rs @@ -600,8 +600,8 @@ impl> DecodedTrieProof { // TODO: ordering between trie roots unspecified // TODO: consider not returning a Vec pub fn iter_runtime_context_ordered( - &self, - ) -> impl Iterator>, StorageValue)> { + &'_ self, + ) -> impl Iterator>, StorageValue<'_>)> { self.iter_ordered().filter_map( |( EntryKey { diff --git a/lib/src/trie/trie_node.rs b/lib/src/trie/trie_node.rs index f9342e576a..58e90f6b18 100644 --- a/lib/src/trie/trie_node.rs +++ b/lib/src/trie/trie_node.rs @@ -314,7 +314,9 @@ impl fmt::Debug for MerkleValueOutput { /// Decodes a node value found in a proof into its components. /// /// This can decode nodes no matter their version or hash algorithm. -pub fn decode(mut node_value: &[u8]) -> Result, Error> { +pub fn decode( + mut node_value: &'_ [u8], +) -> Result, &'_ [u8]>, Error> { if node_value.is_empty() { return Err(Error::Empty); } diff --git a/lib/src/trie/trie_structure.rs b/lib/src/trie/trie_structure.rs index 967453c4ac..e50cacf3cd 100644 --- a/lib/src/trie/trie_structure.rs +++ b/lib/src/trie/trie_structure.rs @@ -194,7 +194,7 @@ impl TrieStructure { /// assert!(trie.root_node().is_some()); /// assert!(trie.root_node().unwrap().parent().is_none()); /// ``` - pub fn root_node(&mut self) -> Option> { + pub fn root_node(&'_ mut self) -> Option> { Some(self.node_by_index_inner(self.root_index?).unwrap()) } @@ -258,7 +258,7 @@ impl TrieStructure { /// _ => unreachable!(), /// }; /// ``` - pub fn node(&mut self, key: TKIter) -> Entry + pub fn node(&'_ mut self, key: TKIter) -> Entry<'_, TUd, TKIter> where TKIter: Iterator + Clone, { @@ -312,9 +312,9 @@ impl TrieStructure { /// This method is a shortcut for calling [`TrieStructure::node`] followed with /// [`Entry::into_occupied`]. pub fn existing_node( - &mut self, + &'_ mut self, key: impl Iterator + Clone, - ) -> Option> { + ) -> Option> { if let ExistingNodeInnerResult::Found { node_index, has_storage_value, @@ -393,9 +393,9 @@ impl TrieStructure { /// Returns the closest ancestors to the nodes that have been removed, or `None` if that /// closest ancestor is not a descendant of the new trie root. pub fn remove_prefix( - &mut self, + &'_ mut self, prefix: impl Iterator + Clone, - ) -> Option> { + ) -> Option> { // `ancestor` is the node that doesn't have the prefix but is the common ancestor of all // the nodes to remove. let (ancestor_index, ancestor_child_nibble) = match self.existing_node_inner(prefix.clone()) @@ -1026,12 +1026,12 @@ impl TrieStructure { /// let mut node = trie.node_by_index(node_index).unwrap(); /// assert_eq!(*node.user_data(), 12); /// ``` - pub fn node_by_index(&mut self, node_index: NodeIndex) -> Option> { + pub fn node_by_index(&'_ mut self, node_index: NodeIndex) -> Option> { self.node_by_index_inner(node_index.0) } /// Internal function. Returns the [`NodeAccess`] of the node at the given index. - fn node_by_index_inner(&mut self, node_index: usize) -> Option> { + fn node_by_index_inner(&'_ mut self, node_index: usize) -> Option> { if self.nodes.get(node_index)?.has_storage_value { Some(NodeAccess::Storage(StorageNodeAccess { trie: self, @@ -1247,7 +1247,7 @@ impl<'a, TUd> NodeAccess<'a, TUd> { } /// Returns the parent of this node, or `None` if this is the root node. - pub fn parent(&mut self) -> Option> { + pub fn parent(&'_ mut self) -> Option> { match self { NodeAccess::Storage(n) => n.parent(), NodeAccess::Branch(n) => n.parent(), @@ -1268,7 +1268,7 @@ impl<'a, TUd> NodeAccess<'a, TUd> { } /// Returns the child of this node at the given index. - pub fn child(&mut self, index: Nibble) -> Option> { + pub fn child(&'_ mut self, index: Nibble) -> Option> { match self { NodeAccess::Storage(n) => n.child(index), NodeAccess::Branch(n) => n.child(index), @@ -1376,7 +1376,7 @@ impl<'a, TUd> StorageNodeAccess<'a, TUd> { } /// Returns the parent of this node, or `None` if this is the root node. - pub fn parent(&mut self) -> Option> { + pub fn parent(&'_ mut self) -> Option> { let parent_idx = self.trie.nodes.get(self.node_index).unwrap().parent?.0; Some(self.trie.node_by_index_inner(parent_idx).unwrap()) } @@ -1415,7 +1415,7 @@ impl<'a, TUd> StorageNodeAccess<'a, TUd> { } /// Returns the child of this node at the given index. - pub fn child(&mut self, index: Nibble) -> Option> { + pub fn child(&'_ mut self, index: Nibble) -> Option> { let child_idx = self.trie.nodes.get(self.node_index).unwrap().children[usize::from(u8::from(index))]?; Some(self.trie.node_by_index_inner(child_idx).unwrap()) @@ -1751,7 +1751,7 @@ impl<'a, TUd> BranchNodeAccess<'a, TUd> { } /// Returns the parent of this node, or `None` if this is the root node. - pub fn parent(&mut self) -> Option> { + pub fn parent(&'_ mut self) -> Option> { let parent_idx = self.trie.nodes.get(self.node_index).unwrap().parent?.0; Some(self.trie.node_by_index_inner(parent_idx).unwrap()) } @@ -1790,7 +1790,7 @@ impl<'a, TUd> BranchNodeAccess<'a, TUd> { } /// Returns the child of this node at the given index. - pub fn child(&mut self, index: Nibble) -> Option> { + pub fn child(&'_ mut self, index: Nibble) -> Option> { let child_idx = self.trie.nodes.get(self.node_index).unwrap().children[usize::from(u8::from(index))]?; Some(self.trie.node_by_index_inner(child_idx).unwrap()) diff --git a/light-base/src/json_rpc_service/background.rs b/light-base/src/json_rpc_service/background.rs index ad6d61ddf3..878dda7c87 100644 --- a/light-base/src/json_rpc_service/background.rs +++ b/light-base/src/json_rpc_service/background.rs @@ -5741,8 +5741,8 @@ pub(super) async fn run( } fn convert_runtime_version_legacy( - runtime_spec: &smoldot::executor::CoreVersion, -) -> methods::RuntimeVersion { + runtime_spec: &'_ smoldot::executor::CoreVersion, +) -> methods::RuntimeVersion<'_> { let runtime_spec = runtime_spec.decode(); methods::RuntimeVersion { spec_name: runtime_spec.spec_name.into(), @@ -5759,7 +5759,9 @@ fn convert_runtime_version_legacy( } } -fn convert_runtime_version(runtime_spec: &smoldot::executor::CoreVersion) -> methods::RuntimeSpec { +fn convert_runtime_version( + runtime_spec: &'_ smoldot::executor::CoreVersion, +) -> methods::RuntimeSpec<'_> { let runtime_spec = runtime_spec.decode(); methods::RuntimeSpec { spec_name: runtime_spec.spec_name.into(), diff --git a/light-base/src/platform.rs b/light-base/src/platform.rs index 924015a635..a3835ff00e 100644 --- a/light-base/src/platform.rs +++ b/light-base/src/platform.rs @@ -168,11 +168,11 @@ pub trait PlatformRef: UnwindSafe + Clone + Send + Sync + 'static { /// Value returned when a JSON-RPC client requests the name of the client, or when a peer /// performs an identification request. Reasonable value is `env!("CARGO_PKG_NAME")`. - fn client_name(&self) -> Cow; + fn client_name(&'_ self) -> Cow<'_, str>; /// Value returned when a JSON-RPC client requests the version of the client, or when a peer /// performs an identification request. Reasonable value is `env!("CARGO_PKG_VERSION")`. - fn client_version(&self) -> Cow; + fn client_version(&'_ self) -> Cow<'_, str>; /// Returns `true` if [`PlatformRef::connect_stream`] or [`PlatformRef::connect_multistream`] /// accepts a connection of the corresponding type. diff --git a/light-base/src/platform/address_parse.rs b/light-base/src/platform/address_parse.rs index fe74e833eb..c9eeae2d66 100644 --- a/light-base/src/platform/address_parse.rs +++ b/light-base/src/platform/address_parse.rs @@ -38,7 +38,9 @@ impl<'a> From<&'a AddressOrMultiStreamAddress<'a>> for ConnectionType { } /// Parses a [`Multiaddr`] into an [`Address`] or [`MultiStreamAddress`]. -pub fn multiaddr_to_address(multiaddr: &Multiaddr) -> Result { +pub fn multiaddr_to_address( + multiaddr: &'_ Multiaddr, +) -> Result, Error> { let mut iter = multiaddr.iter().fuse(); let proto1 = iter.next().ok_or(Error::UnknownCombination)?; diff --git a/light-base/src/platform/default.rs b/light-base/src/platform/default.rs index 3f2fd46c19..a650300fa7 100644 --- a/light-base/src/platform/default.rs +++ b/light-base/src/platform/default.rs @@ -198,11 +198,11 @@ impl PlatformRef for Arc { ) } - fn client_name(&self) -> Cow { + fn client_name(&'_ self) -> Cow<'_, str> { Cow::Borrowed(&self.client_name) } - fn client_version(&self) -> Cow { + fn client_version(&'_ self) -> Cow<'_, str> { Cow::Borrowed(&self.client_version) } diff --git a/light-base/src/platform/with_prefix.rs b/light-base/src/platform/with_prefix.rs index e44fa3d3bb..ed4d4c0aa7 100644 --- a/light-base/src/platform/with_prefix.rs +++ b/light-base/src/platform/with_prefix.rs @@ -89,11 +89,11 @@ impl PlatformRef for WithPrefix { ) } - fn client_name(&self) -> Cow { + fn client_name(&'_ self) -> Cow<'_, str> { self.inner.client_name() } - fn client_version(&self) -> Cow { + fn client_version(&'_ self) -> Cow<'_, str> { self.inner.client_version() } diff --git a/light-base/src/sync_service.rs b/light-base/src/sync_service.rs index 9d72085634..9d03b2079d 100644 --- a/light-base/src/sync_service.rs +++ b/light-base/src/sync_service.rs @@ -123,10 +123,6 @@ pub struct ConfigParachain { pub para_id: u32, } -/// Identifier for a blocks request to be performed. -#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)] -pub struct BlocksRequestId(usize); - pub struct SyncService { /// Sender of messages towards the background task. to_background: async_channel::Sender, diff --git a/wasm-node/rust/src/bindings.rs b/wasm-node/rust/src/bindings.rs index 0e1b28b2d6..1f9cc09691 100644 --- a/wasm-node/rust/src/bindings.rs +++ b/wasm-node/rust/src/bindings.rs @@ -603,7 +603,7 @@ pub(crate) fn get_buffer(buffer_index: u32) -> Box<[u8]> { let len = usize::try_from(buffer_size(buffer_index)).unwrap(); let mut buffer = Box::<[u8]>::new_uninit_slice(len); - buffer_copy(buffer_index, buffer.as_mut_ptr() as usize as u32); + buffer_copy(buffer_index, buffer.as_mut_ptr().addr() as u32); buffer.assume_init() } } diff --git a/wasm-node/rust/src/init.rs b/wasm-node/rust/src/init.rs index ef381e1e19..bd17ba10cf 100644 --- a/wasm-node/rust/src/init.rs +++ b/wasm-node/rust/src/init.rs @@ -128,7 +128,7 @@ fn panic(info: &core::panic::PanicInfo) -> ! { unsafe { bindings::panic( - u32::try_from(message.as_bytes().as_ptr() as usize).unwrap(), + u32::try_from(message.as_bytes().as_ptr().addr()).unwrap(), u32::try_from(message.as_bytes().len()).unwrap(), ); diff --git a/wasm-node/rust/src/lib.rs b/wasm-node/rust/src/lib.rs index 97a92427b3..18ad32b4e9 100644 --- a/wasm-node/rust/src/lib.rs +++ b/wasm-node/rust/src/lib.rs @@ -105,7 +105,7 @@ fn add_chain( let error = "Wasm node is running low on memory and will prevent any new chain from being added"; bindings::chain_initialized( outer_chain_id_u32, - u32::try_from(error.as_bytes().as_ptr() as usize).unwrap(), + u32::try_from(error.as_bytes().as_ptr().addr()).unwrap(), u32::try_from(error.as_bytes().len()).unwrap(), ); return; @@ -142,7 +142,7 @@ fn add_chain( let error = error.to_string(); bindings::chain_initialized( outer_chain_id_u32, - u32::try_from(error.as_bytes().as_ptr() as usize).unwrap(), + u32::try_from(error.as_bytes().as_ptr().addr()).unwrap(), u32::try_from(error.as_bytes().len()).unwrap(), ); return; diff --git a/wasm-node/rust/src/platform.rs b/wasm-node/rust/src/platform.rs index 8c32105c2b..5536ca75fb 100644 --- a/wasm-node/rust/src/platform.rs +++ b/wasm-node/rust/src/platform.rs @@ -98,7 +98,7 @@ impl smoldot_light::platform::PlatformRef for PlatformRef { fn fill_random_bytes(&self, buffer: &mut [u8]) { unsafe { bindings::random_get( - u32::try_from(buffer.as_mut_ptr() as usize).unwrap(), + u32::try_from(buffer.as_mut_ptr().addr()).unwrap(), u32::try_from(buffer.len()).unwrap(), ) } @@ -126,7 +126,7 @@ impl smoldot_light::platform::PlatformRef for PlatformRef { fn poll(self: pin::Pin<&mut Self>, cx: &mut task::Context) -> task::Poll { let this = self.project(); bindings::current_task_entered( - u32::try_from(this.name.as_bytes().as_ptr() as usize).unwrap(), + u32::try_from(this.name.as_bytes().as_ptr().addr()).unwrap(), u32::try_from(this.name.as_bytes().len()).unwrap(), ); @@ -221,9 +221,9 @@ impl smoldot_light::platform::PlatformRef for PlatformRef { if key_values.peek().is_none() { bindings::log( log_level, - u32::try_from(log_target.as_bytes().as_ptr() as usize).unwrap(), + u32::try_from(log_target.as_bytes().as_ptr().addr()).unwrap(), u32::try_from(log_target.as_bytes().len()).unwrap(), - u32::try_from(message.as_bytes().as_ptr() as usize).unwrap(), + u32::try_from(message.as_bytes().as_ptr().addr()).unwrap(), u32::try_from(message.as_bytes().len()).unwrap(), ) } else { @@ -242,19 +242,19 @@ impl smoldot_light::platform::PlatformRef for PlatformRef { bindings::log( log_level, - u32::try_from(log_target.as_bytes().as_ptr() as usize).unwrap(), + u32::try_from(log_target.as_bytes().as_ptr().addr()).unwrap(), u32::try_from(log_target.as_bytes().len()).unwrap(), - u32::try_from(message_build.as_bytes().as_ptr() as usize).unwrap(), + u32::try_from(message_build.as_bytes().as_ptr().addr()).unwrap(), u32::try_from(message_build.as_bytes().len()).unwrap(), ) } } - fn client_name(&self) -> Cow { + fn client_name(&'_ self) -> Cow<'_, str> { env!("CARGO_PKG_NAME").into() } - fn client_version(&self) -> Cow { + fn client_version(&'_ self) -> Cow<'_, str> { env!("CARGO_PKG_VERSION").into() } @@ -358,7 +358,7 @@ impl smoldot_light::platform::PlatformRef for PlatformRef { bindings::connection_new( connection_id, - u32::try_from(encoded_address.as_ptr() as usize).unwrap(), + u32::try_from(encoded_address.as_ptr().addr()).unwrap(), u32::try_from(encoded_address.len()).unwrap(), ); @@ -428,7 +428,7 @@ impl smoldot_light::platform::PlatformRef for PlatformRef { bindings::connection_new( connection_id, - u32::try_from(encoded_address.as_ptr() as usize).unwrap(), + u32::try_from(encoded_address.as_ptr().addr()).unwrap(), u32::try_from(encoded_address.len()).unwrap(), ); @@ -742,7 +742,7 @@ impl<'a> Drop for ReadWriteAccess<'a> { for buffer in &self.read_write.write_buffers { io_vectors.push(bindings::StreamSendIoVector { - ptr: u32::try_from(buffer.as_ptr() as usize).unwrap(), + ptr: u32::try_from(buffer.as_ptr().addr()).unwrap(), len: u32::try_from(buffer.len()).unwrap(), }); total_length += buffer.len(); @@ -757,7 +757,7 @@ impl<'a> Drop for ReadWriteAccess<'a> { bindings::stream_send( self.stream.connection_id, self.stream.stream_id.unwrap_or(0), - u32::try_from(io_vectors.as_ptr() as usize).unwrap(), + u32::try_from(io_vectors.as_ptr().addr()).unwrap(), u32::try_from(io_vectors.len()).unwrap(), );