Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump rust toolchain version to 1.78.0 #4284

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.77.0"
channel = "1.78.0"
components = ["clippy", "llvm-tools-preview", "rustfmt"]
2 changes: 1 addition & 1 deletion src/beacon/signatures/public_key_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 4 additions & 8 deletions src/blocks/chain4u.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ impl<T> Chain4U<T> {
inner: Default::default(),
}
}
pub fn get<Q: ?Sized>(&self, ident: &Q) -> Option<RawBlockHeader>
pub fn get<Q>(&self, ident: &Q) -> Option<RawBlockHeader>
where
String: Borrow<Q>,
Q: Hash + Eq,
Q: Hash + Eq + ?Sized,
{
self.inner.lock().ident2header.get(ident).cloned()
}
Expand Down Expand Up @@ -395,15 +395,11 @@ impl<N, E, Ix> KeyedDiGraph<N, E, Ix> {
{
petgraph::algo::is_cyclic_directed(&self.graph)
}
fn neighbors_directed<Q: ?Sized>(
&self,
node: &Q,
dir: petgraph::Direction,
) -> impl Iterator<Item = &N>
fn neighbors_directed<Q>(&self, node: &Q, dir: petgraph::Direction) -> impl Iterator<Item = &N>
where
Ix: petgraph::graph::IndexType,
N: Borrow<Q> + Hash + Eq,
Q: Hash + Eq,
Q: Hash + Eq + ?Sized,
{
self.node2ix
.get_by_left(node)
Expand Down
18 changes: 1 addition & 17 deletions src/chain/weight.rs
Original file line number Diff line number Diff line change
@@ -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>(db: &Arc<DB>, ts: &Tipset) -> Result<Weight, anyhow::Error>
where
DB: Blockstore;
}
pub type Weight = num::BigInt;
132 changes: 0 additions & 132 deletions src/chain_sync/consensus.rs
Original file line number Diff line number Diff line change
@@ -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<DB>(
&self,
state_manager: Arc<StateManager<DB>>,
block: Arc<Block>,
) -> Result<(), NonEmpty<Self::Error>>
where
DB: Blockstore + Sync + Send + 'static;
}

/// Helper function to collect errors from async validations.
pub async fn collect_errs<E>(
Expand All @@ -63,93 +21,3 @@ pub async fn collect_errs<E>(
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<DB, MP>(
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<StateManager<DB>>,
mpool: Arc<MP>,
services: &mut JoinSet<anyhow::Result<()>>,
) -> 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<DB>(
&self,
state_manager: &StateManager<DB>,
base: &Tipset,
) -> anyhow::Result<Vec<Cow<SignedMessage>>>
where
DB: Blockstore;
}

impl<P> MessagePoolApi for MessagePool<P>
where
P: crate::message_pool::Provider + Send + Sync + 'static,
{
fn select_signed<DB>(
&self,
_: &StateManager<DB>,
base: &Tipset,
) -> anyhow::Result<Vec<Cow<SignedMessage>>>
where
DB: Blockstore,
{
self.select_messages_for_block(base)
.map_err(|e| e.into())
.map(|v| v.into_iter().map(Cow::Owned).collect())
}
}
4 changes: 2 additions & 2 deletions src/cli/humantoken.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/subcommands/mpool_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/cli_shared/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
3 changes: 0 additions & 3 deletions src/db/car/forest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<V>: Fn() -> io::Result<V> + Send + Sync + 'static {}
impl<ReaderT, X: Fn() -> io::Result<ReaderT> + Send + Sync + 'static> ReaderGen<ReaderT> for X {}

pub struct ForestCar<ReaderT> {
// Multiple `ForestCar` structures may share the same cache. The cache key is used to identify
// the origin of a cached z-frame.
Expand Down
1 change: 0 additions & 1 deletion src/ipld/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
pub mod selector;
pub mod util;

pub use libipld::Path;
pub use libipld_core::ipld::Ipld;
pub use util::*;

Expand Down
1 change: 0 additions & 1 deletion src/ipld/selector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0, MIT

mod empty_map;
mod walk;
use std::ops::SubAssign;

use indexmap::IndexMap;
Expand Down
28 changes: 0 additions & 28 deletions src/ipld/selector/walk.rs

This file was deleted.

27 changes: 3 additions & 24 deletions src/message_pool/msgpool/msg_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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<Vec<SignedMessage>, Error> {
// Take a snapshot of the pending messages.
let pending: HashMap<Address, HashMap<u64, SignedMessage>> = {
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<T> MessagePool<T>
Expand Down
6 changes: 0 additions & 6 deletions src/message_pool/msgpool/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ pub trait Provider {
&self,
h: &CachingBlockHeader,
) -> Result<(Vec<Message>, Vec<SignedMessage>), Error>;
/// Return all messages for a tipset
fn messages_for_tipset(&self, h: &Tipset) -> Result<Vec<ChainMessage>, Error>;
/// Return a tipset given the tipset keys from the `ChainStore`
fn load_tipset(&self, tsk: &TipsetKey) -> Result<Arc<Tipset>, Error>;
/// Computes the base fee
Expand Down Expand Up @@ -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<Vec<ChainMessage>, Error> {
Ok(self.sm.chain_store().messages_for_tipset(h)?)
}

fn load_tipset(&self, tsk: &TipsetKey) -> Result<Arc<Tipset>, Error> {
Ok(self
.sm
Expand Down
13 changes: 0 additions & 13 deletions src/message_pool/msgpool/test_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,6 @@ impl Provider for TestApi {
}
}

fn messages_for_tipset(&self, h: &Tipset) -> Result<Vec<ChainMessage>, 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<Arc<Tipset>, Error> {
let inner = self.inner.lock();
for ts in &inner.tipsets {
Expand Down
Loading
Loading