From 9aa2ae0733f2ed8c1b4cd0679aac0c92948d6497 Mon Sep 17 00:00:00 2001 From: hanabi1224 Date: Fri, 3 May 2024 07:37:01 +0800 Subject: [PATCH] chore: bump rust toolchain version to 1.78.0 --- rust-toolchain.toml | 2 +- src/beacon/signatures/public_key_impls.rs | 2 +- src/blocks/chain4u.rs | 12 +- src/chain/weight.rs | 18 +-- src/chain_sync/consensus.rs | 132 ---------------------- src/cli/humantoken.rs | 4 +- src/cli/subcommands/mpool_cmd.rs | 2 +- src/cli_shared/cli/mod.rs | 2 +- src/db/car/forest.rs | 3 - src/ipld/mod.rs | 1 - src/ipld/selector/mod.rs | 1 - src/ipld/selector/walk.rs | 28 ----- src/message_pool/msgpool/msg_pool.rs | 27 +---- src/message_pool/msgpool/provider.rs | 6 - src/message_pool/msgpool/test_provider.rs | 13 --- src/shim/address.rs | 25 ++-- src/utils/reqwest_resume/mod.rs | 11 -- 17 files changed, 29 insertions(+), 260 deletions(-) delete mode 100644 src/ipld/selector/walk.rs diff --git a/rust-toolchain.toml b/rust-toolchain.toml index b3f7ba4dfa15..8415153f47ed 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.77.0" +channel = "1.78.0" components = ["clippy", "llvm-tools-preview", "rustfmt"] diff --git a/src/beacon/signatures/public_key_impls.rs b/src/beacon/signatures/public_key_impls.rs index 702f9a0faa03..3f8967c5b5b9 100644 --- a/src/beacon/signatures/public_key_impls.rs +++ b/src/beacon/signatures/public_key_impls.rs @@ -9,7 +9,7 @@ impl PublicKeyOnG2 { } pub fn verify(&self, message: impl AsRef<[u8]>, signature: &SignatureOnG1) -> bool { - verify_messages_unchained(self, &[message.as_ref()], &[&signature]) + verify_messages_unchained(self, &[message.as_ref()], &[signature]) } pub fn verify_batch(&self, messages: &[&[u8]], signatures: &[&SignatureOnG1]) -> bool { diff --git a/src/blocks/chain4u.rs b/src/blocks/chain4u.rs index 3cd8f18ab2fb..20673176e6f2 100644 --- a/src/blocks/chain4u.rs +++ b/src/blocks/chain4u.rs @@ -167,10 +167,10 @@ impl Chain4U { inner: Default::default(), } } - pub fn get(&self, ident: &Q) -> Option + pub fn get(&self, ident: &Q) -> Option where String: Borrow, - Q: Hash + Eq, + Q: Hash + Eq + ?Sized, { self.inner.lock().ident2header.get(ident).cloned() } @@ -395,15 +395,11 @@ impl KeyedDiGraph { { petgraph::algo::is_cyclic_directed(&self.graph) } - fn neighbors_directed( - &self, - node: &Q, - dir: petgraph::Direction, - ) -> impl Iterator + fn neighbors_directed(&self, node: &Q, dir: petgraph::Direction) -> impl Iterator where Ix: petgraph::graph::IndexType, N: Borrow + Hash + Eq, - Q: Hash + Eq, + Q: Hash + Eq + ?Sized, { self.node2ix .get_by_left(node) diff --git a/src/chain/weight.rs b/src/chain/weight.rs index 1e8b76dbf1ee..46efea7fa6f4 100644 --- a/src/chain/weight.rs +++ b/src/chain/weight.rs @@ -1,20 +1,4 @@ // Copyright 2019-2024 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -use crate::blocks::Tipset; -use fvm_ipld_blockstore::Blockstore; -use num::BigInt; -use std::sync::Arc; - -pub type Weight = BigInt; - -/// The `Scale` trait abstracts away the logic of assigning a weight to a chain, -/// which can be consensus specific. For example it can depend on the stake and -/// power of validators, or it can be as simple as the height of the blocks in -/// a `Nakamoto` style consensus. -pub trait Scale { - /// Calculate the weight of a tipset. - fn weight(db: &Arc, ts: &Tipset) -> Result - where - DB: Blockstore; -} +pub type Weight = num::BigInt; diff --git a/src/chain_sync/consensus.rs b/src/chain_sync/consensus.rs index 7fa7b5551704..6a4779131133 100644 --- a/src/chain_sync/consensus.rs +++ b/src/chain_sync/consensus.rs @@ -1,50 +1,8 @@ // Copyright 2019-2024 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -use std::{ - borrow::Cow, - fmt::{Debug, Display}, - sync::Arc, -}; - -use crate::blocks::{Block, Tipset}; -use crate::chain::Scale; -use crate::message::SignedMessage; -use crate::message_pool::MessagePool; -use crate::state_manager::StateManager; -use async_trait::async_trait; use futures::{stream::FuturesUnordered, StreamExt}; -use fvm_ipld_blockstore::Blockstore; use nunny::Vec as NonEmpty; -use tokio::task::JoinSet; - -/// The `Consensus` trait encapsulates consensus specific rules of validation -/// and block creation. Behind the scenes they can farm out the total ordering -/// of transactions to an arbitrary consensus engine, but in the end they -/// package the transactions into Filecoin compatible blocks. -/// -/// Not all fields will be made use of, however, so the validation of these -/// blocks at least partially have to be trusted to the `Consensus` component. -/// -/// Common rules for message ordering will be followed, and can be validated -/// outside by the host system during chain synchronization. -#[async_trait] -pub trait Consensus: Scale + Debug + Send + Sync + Unpin + 'static { - type Error: Debug + Display + Send + Sync; - - /// Perform block validation asynchronously and return all encountered - /// errors if failed. - /// - /// Being asynchronous gives the method a chance to construct a pipeline of - /// validations, i.e. do some common ones before branching out. - async fn validate_block( - &self, - state_manager: Arc>, - block: Arc, - ) -> Result<(), NonEmpty> - where - DB: Blockstore + Sync + Send + 'static; -} /// Helper function to collect errors from async validations. pub async fn collect_errs( @@ -63,93 +21,3 @@ pub async fn collect_errs( Err(_) => Ok(()), } } - -/// The `Proposer` trait expresses the ability to "mine", or in more general, -/// to propose blocks to the network according to the rules of the consensus -/// protocol. -/// -/// It is separate from the `Consensus` trait because it is only expected to -/// be called once, then left to run in the background and try to publish -/// blocks to the network which may or may not be adopted. -/// -/// It exists mostly as a way for us to describe what kind of dependencies -/// mining processes are expected to take. -#[async_trait] -pub trait Proposer { - /// Start proposing blocks in the background and never return, unless - /// something went horribly wrong. Broadly, they should select messages - /// from the `mempool`, come up with a total ordering for them, then create - /// blocks and publish them to the network. - /// - /// To establish total ordering, the proposer might have to communicate - /// with other peers using custom P2P messages, however that is its own - /// concern, the dependencies to implement a suitable network later must - /// come from somewhere else, because they are not common across all - /// consensus variants. - /// - /// The method returns a vector of handles so that it can start unspecified - /// number of background tasks, which can all be canceled by the main thread - /// if the application needs to exit. The method is async so that it can - /// use async operations to initialize itself, during which it might - /// encounter some errors. - async fn spawn( - self, - // NOTE: We will need access to the `ChainStore` as well, or, ideally - // a wrapper over it that only allows us to do what we need to, but - // for example not reset the Genesis. But since the `StateManager` - // already exposes the `ChainStore` as is, and this is how it's - // accessed during validation for example, I think we can defer - // these for later refactoring and just use the same pattern. - state_manager: Arc>, - mpool: Arc, - services: &mut JoinSet>, - ) -> anyhow::Result<()> - where - DB: Blockstore + Sync + Send + 'static, - MP: MessagePoolApi + Sync + Send + 'static; -} - -/// The `MessagePoolApi` is the window of consensus to the contents of the -/// `MessagePool`. -/// -/// It exists to narrow down the possible operations that a consensus engine can -/// do with the `MessagePool` to only those that it should reasonably exercise, -/// which are mostly read-only queries to get transactions which can be expected -/// to be put in the next block, based on their account nonce values and the -/// current state. -/// -/// The `MessagePool` is still expected to monitor the chain growth and remove -/// messages which were included in blocks on its own. -pub trait MessagePoolApi { - /// Select the set of suitable signed messages based on a tipset we are - /// about to build the next block on. - /// - /// The result is a `Cow` in case the source can avoid cloning messages and - /// just return a reference. They will be sent to the data store for - /// storage, but a reference is enough for that. - fn select_signed( - &self, - state_manager: &StateManager, - base: &Tipset, - ) -> anyhow::Result>> - where - DB: Blockstore; -} - -impl

MessagePoolApi for MessagePool

-where - P: crate::message_pool::Provider + Send + Sync + 'static, -{ - fn select_signed( - &self, - _: &StateManager, - base: &Tipset, - ) -> anyhow::Result>> - where - DB: Blockstore, - { - self.select_messages_for_block(base) - .map_err(|e| e.into()) - .map(|v| v.into_iter().map(Cow::Owned).collect()) - } -} diff --git a/src/cli/humantoken.rs b/src/cli/humantoken.rs index 28d59df8647f..4ce951c1c6d1 100644 --- a/src/cli/humantoken.rs +++ b/src/cli/humantoken.rs @@ -219,9 +219,9 @@ mod parse { } /// Take a float from the front of `input` - fn bigdecimal<'a, E: ParseError<&'a str>>(input: &'a str) -> IResult<&str, BigDecimal, E> + fn bigdecimal<'a, E>(input: &'a str) -> IResult<&str, BigDecimal, E> where - E: FromExternalError<&'a str, ParseBigDecimalError>, + E: ParseError<&'a str> + FromExternalError<&'a str, ParseBigDecimalError>, { map_res(recognize_float, str::parse)(input) } diff --git a/src/cli/subcommands/mpool_cmd.rs b/src/cli/subcommands/mpool_cmd.rs index f6832febfdcf..26b9954cfb94 100644 --- a/src/cli/subcommands/mpool_cmd.rs +++ b/src/cli/subcommands/mpool_cmd.rs @@ -134,7 +134,7 @@ fn compute_stats( let actor_sequence = *actor_sequences.get(&address).expect("get must succeed"); let mut curr_sequence = actor_sequence; - while bucket.get(&curr_sequence).is_some() { + while bucket.contains_key(&curr_sequence) { curr_sequence += 1; } diff --git a/src/cli_shared/cli/mod.rs b/src/cli_shared/cli/mod.rs index 0cc6d85729e8..8cd0df5de28a 100644 --- a/src/cli_shared/cli/mod.rs +++ b/src/cli_shared/cli/mod.rs @@ -194,7 +194,7 @@ impl CliOpts { } if let Some(addresses) = &self.p2p_listen_address { - cfg.network.listening_multiaddrs = addresses.clone(); + cfg.network.listening_multiaddrs.clone_from(addresses); } if self.import_snapshot.is_some() && self.import_chain.is_some() { diff --git a/src/db/car/forest.rs b/src/db/car/forest.rs index e0eadad4dda1..bb5f2829f287 100644 --- a/src/db/car/forest.rs +++ b/src/db/car/forest.rs @@ -83,9 +83,6 @@ pub const DEFAULT_FOREST_CAR_FRAME_SIZE: usize = 8000_usize.next_power_of_two(); pub const DEFAULT_FOREST_CAR_COMPRESSION_LEVEL: u16 = zstd::DEFAULT_COMPRESSION_LEVEL as _; const ZSTD_SKIP_FRAME_LEN: u64 = 8; -pub trait ReaderGen: Fn() -> io::Result + Send + Sync + 'static {} -impl io::Result + Send + Sync + 'static> ReaderGen for X {} - pub struct ForestCar { // Multiple `ForestCar` structures may share the same cache. The cache key is used to identify // the origin of a cached z-frame. diff --git a/src/ipld/mod.rs b/src/ipld/mod.rs index b5a7f24b9454..f626912d17f9 100644 --- a/src/ipld/mod.rs +++ b/src/ipld/mod.rs @@ -4,7 +4,6 @@ pub mod selector; pub mod util; -pub use libipld::Path; pub use libipld_core::ipld::Ipld; pub use util::*; diff --git a/src/ipld/selector/mod.rs b/src/ipld/selector/mod.rs index b744da1dc594..3545a09bd997 100644 --- a/src/ipld/selector/mod.rs +++ b/src/ipld/selector/mod.rs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: Apache-2.0, MIT mod empty_map; -mod walk; use std::ops::SubAssign; use indexmap::IndexMap; diff --git a/src/ipld/selector/walk.rs b/src/ipld/selector/walk.rs deleted file mode 100644 index 33d845ba1f30..000000000000 --- a/src/ipld/selector/walk.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2019-2024 ChainSafe Systems -// SPDX-License-Identifier: Apache-2.0, MIT - -use async_trait::async_trait; -use cid::Cid; - -use super::super::{Ipld, Path}; - -#[async_trait] -pub trait LinkResolver { - /// Resolves a Cid link into it's respective IPLD node, if it exists. - async fn load_link(&mut self, link: &Cid) -> Result, String>; -} - -#[async_trait] -impl LinkResolver for () { - async fn load_link(&mut self, _link: &Cid) -> Result, String> { - Err("load_link not implemented on the LinkResolver for default implementation".into()) - } -} - -/// Contains information about the last block that was traversed in walking of -/// the IPLD graph. -#[derive(Debug, PartialEq, Eq, Clone)] -pub struct LastBlockInfo { - pub path: Path, - pub link: Cid, -} diff --git a/src/message_pool/msgpool/msg_pool.rs b/src/message_pool/msgpool/msg_pool.rs index 8ee971bb0170..03ad9329d816 100644 --- a/src/message_pool/msgpool/msg_pool.rs +++ b/src/message_pool/msgpool/msg_pool.rs @@ -40,8 +40,8 @@ use crate::message_pool::{ errors::Error, head_change, metrics, msgpool::{ - recover_sig, republish_pending_messages, select_messages_for_block, - BASE_FEE_LOWER_BOUND_FACTOR_CONSERVATIVE, RBF_DENOM, RBF_NUM, + recover_sig, republish_pending_messages, BASE_FEE_LOWER_BOUND_FACTOR_CONSERVATIVE, + RBF_DENOM, RBF_NUM, }, provider::Provider, utils::get_base_fee_lower_bound, @@ -139,7 +139,7 @@ impl MsgSet { if self.msgs.remove(&sequence).is_none() { if applied && sequence >= self.next_sequence { self.next_sequence = sequence + 1; - while self.msgs.get(&self.next_sequence).is_some() { + while self.msgs.contains_key(&self.next_sequence) { self.next_sequence += 1; } } @@ -442,27 +442,6 @@ where self.config = cfg; Ok(()) } - - /// Select messages that can be included in a block built on a given base - /// tipset. - pub fn select_messages_for_block(&self, base: &Tipset) -> Result, Error> { - // Take a snapshot of the pending messages. - let pending: HashMap> = { - let pending = self.pending.read(); - pending - .iter() - .filter_map(|(actor, mset)| { - if mset.msgs.is_empty() { - None - } else { - Some((*actor, mset.msgs.clone())) - } - }) - .collect() - }; - - select_messages_for_block(self.api.as_ref(), self.chain_config.as_ref(), base, pending) - } } impl MessagePool diff --git a/src/message_pool/msgpool/provider.rs b/src/message_pool/msgpool/provider.rs index a159129258c0..307cb1ff1108 100644 --- a/src/message_pool/msgpool/provider.rs +++ b/src/message_pool/msgpool/provider.rs @@ -46,8 +46,6 @@ pub trait Provider { &self, h: &CachingBlockHeader, ) -> Result<(Vec, Vec), Error>; - /// Return all messages for a tipset - fn messages_for_tipset(&self, h: &Tipset) -> Result, Error>; /// Return a tipset given the tipset keys from the `ChainStore` fn load_tipset(&self, tsk: &TipsetKey) -> Result, Error>; /// Computes the base fee @@ -117,10 +115,6 @@ where crate::chain::block_messages(self.sm.blockstore(), h).map_err(|err| err.into()) } - fn messages_for_tipset(&self, h: &Tipset) -> Result, Error> { - Ok(self.sm.chain_store().messages_for_tipset(h)?) - } - fn load_tipset(&self, tsk: &TipsetKey) -> Result, Error> { Ok(self .sm diff --git a/src/message_pool/msgpool/test_provider.rs b/src/message_pool/msgpool/test_provider.rs index 3ba1d2b57f8c..c0ee0930d864 100644 --- a/src/message_pool/msgpool/test_provider.rs +++ b/src/message_pool/msgpool/test_provider.rs @@ -188,19 +188,6 @@ impl Provider for TestApi { } } - fn messages_for_tipset(&self, h: &Tipset) -> Result, Error> { - let (us, s) = self.messages_for_block(h.block_headers().first())?; - let mut msgs = Vec::with_capacity(us.len() + s.len()); - - for msg in us { - msgs.push(ChainMessage::Unsigned(msg)); - } - for smsg in s { - msgs.push(ChainMessage::Signed(smsg)); - } - Ok(msgs) - } - fn load_tipset(&self, tsk: &TipsetKey) -> Result, Error> { let inner = self.inner.lock(); for ts in &inner.tipsets { diff --git a/src/shim/address.rs b/src/shim/address.rs index ad33cb6489c6..6d4107f5ba6d 100644 --- a/src/shim/address.rs +++ b/src/shim/address.rs @@ -79,19 +79,24 @@ impl CurrentNetwork { } } +#[cfg(test)] struct NetworkGuard(Network); -impl NetworkGuard { - #[cfg(test)] - fn new(new_network: Network) -> Self { - let previous_network = CurrentNetwork::get(); - CurrentNetwork::set(new_network); - NetworkGuard(previous_network) +#[cfg(test)] +mod network_guard_impl { + use super::*; + + impl NetworkGuard { + pub fn new(new_network: Network) -> Self { + let previous_network = CurrentNetwork::get(); + CurrentNetwork::set(new_network); + NetworkGuard(previous_network) + } } -} -impl Drop for NetworkGuard { - fn drop(&mut self) { - CurrentNetwork::set(self.0); + impl Drop for NetworkGuard { + fn drop(&mut self) { + CurrentNetwork::set(self.0); + } } } diff --git a/src/utils/reqwest_resume/mod.rs b/src/utils/reqwest_resume/mod.rs index 82e1ec8fa960..73289aad2715 100644 --- a/src/utils/reqwest_resume/mod.rs +++ b/src/utils/reqwest_resume/mod.rs @@ -20,17 +20,6 @@ use std::{ }; use tokio::time::sleep; -/// Extension to [`reqwest::Client`] that provides a method to convert it -pub trait ClientExt { - /// Convert a [`reqwest::Client`] into a [`reqwest_resume::Client`](Client) - fn resumable(self) -> Client; -} -impl ClientExt for reqwest::Client { - fn resumable(self) -> Client { - Client(self) - } -} - /// A `Client` to make Requests with. /// /// See [`reqwest::Client`].