Skip to content
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
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ license = "MIT OR Apache-2.0"
description = "Rust Filecoin implementation."
exclude = [".config", ".github", ".maintain", "documentation", "scripts", "interop-tests", "go.work*"]

[lints]
workspace = true

[lib]
name = "forest"

Expand Down Expand Up @@ -358,6 +361,10 @@ required-features = ["benchmark-private"]
# See https://docs.rs/about/metadata
rustdoc-args = ["--document-private-items"]

[workspace.lints.clippy]
ref_option = "deny"
ref_option_ref = "deny"

[workspace]
members = ["interop-tests"]
resolver = "3"
3 changes: 3 additions & 0 deletions interop-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ license = "MIT OR Apache-2.0"
description = "Interop tests for Forest."
publish = false

[lints]
workspace = true

[dependencies]

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions src/chain/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ async fn test_export_inner(version: FilecoinSnapshotVersion) -> anyhow::Result<(

match version {
FilecoinSnapshotVersion::V1 => {
assert_eq!(car.metadata(), &None);
assert_eq!(car.metadata(), None);
}
FilecoinSnapshotVersion::V2 => {
assert_eq!(
car.metadata(),
&Some(FilecoinSnapshotMetadata {
Some(&FilecoinSnapshotMetadata {
version,
head_tipset_key: head_key_cids,
f3_data: None,
Expand Down
23 changes: 13 additions & 10 deletions src/cli/subcommands/mpool_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ pub enum MpoolCommands {
fn filter_messages(
messages: Vec<SignedMessage>,
local_addrs: Option<HashSet<Address>>,
to: &Option<StrictAddress>,
from: &Option<StrictAddress>,
to: Option<&StrictAddress>,
from: Option<&StrictAddress>,
) -> anyhow::Result<Vec<SignedMessage>> {
use crate::message::Message;

Expand All @@ -61,8 +61,10 @@ fn filter_messages(
.as_ref()
.map(|addrs| addrs.contains(&msg.from()))
.unwrap_or(true)
&& to.map(|addr| msg.to() == addr.into()).unwrap_or(true)
&& from.map(|addr| msg.from() == addr.into()).unwrap_or(true)
&& to.map(|addr| msg.to() == (*addr).into()).unwrap_or(true)
&& from
.map(|addr| msg.from() == (*addr).into())
.unwrap_or(true)
})
.collect();

Expand Down Expand Up @@ -218,7 +220,8 @@ impl MpoolCommands {
None
};

let filtered_messages = filter_messages(messages, local_addrs, &to, &from)?;
let filtered_messages =
filter_messages(messages, local_addrs, to.as_ref(), from.as_ref())?;

for msg in filtered_messages {
if cids {
Expand Down Expand Up @@ -250,7 +253,7 @@ impl MpoolCommands {
None
};

let messages: Vec<Message> = filter_messages(messages, local_addrs, &None, &None)?
let messages: Vec<Message> = filter_messages(messages, local_addrs, None, None)?
.into_iter()
.map(|it| it.message)
.collect();
Expand Down Expand Up @@ -304,7 +307,7 @@ mod tests {
let smsg_json_vec = smsg_vec.clone().into_iter().collect_vec();

// No filtering is set up
let smsg_filtered: Vec<SignedMessage> = filter_messages(smsg_json_vec, None, &None, &None)
let smsg_filtered: Vec<SignedMessage> = filter_messages(smsg_json_vec, None, None, None)
.unwrap()
.into_iter()
.collect();
Expand Down Expand Up @@ -346,7 +349,7 @@ mod tests {

// Filter local addresses
let smsg_filtered: Vec<SignedMessage> =
filter_messages(smsg_json_vec, Some(local_addrs), &None, &None)
filter_messages(smsg_json_vec, Some(local_addrs), None, None)
.unwrap()
.into_iter()
.collect();
Expand Down Expand Up @@ -379,7 +382,7 @@ mod tests {

// Filtering messages from sender2
let smsg_filtered: Vec<SignedMessage> =
filter_messages(smsg_json_vec, None, &None, &Some(sender2.into()))
filter_messages(smsg_json_vec, None, None, Some(&sender2.into()))
.unwrap()
.into_iter()
.collect();
Expand Down Expand Up @@ -412,7 +415,7 @@ mod tests {

// Filtering messages to target2
let smsg_filtered: Vec<SignedMessage> =
filter_messages(smsg_json_vec, None, &Some(target2.into()), &None)
filter_messages(smsg_json_vec, None, Some(&target2.into()), None)
.unwrap()
.into_iter()
.collect();
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/db_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ pub async fn import_chain_as_forest_car(

let forest_car = ForestCar::try_from(forest_car_db_path.as_path())?;

if let Some(f3_cid) = forest_car.metadata().as_ref().and_then(|m| m.f3_data) {
if let Some(f3_cid) = forest_car.metadata().and_then(|m| m.f3_data) {
if crate::f3::get_f3_sidecar_params(chain_config)
.initial_power_table
.is_none()
Expand Down
2 changes: 1 addition & 1 deletion src/db/car/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<ReaderT: RandomAccessFileReader> AnyCar<ReaderT> {
))
}

pub fn metadata(&self) -> &Option<FilecoinSnapshotMetadata> {
pub fn metadata(&self) -> Option<&FilecoinSnapshotMetadata> {
match self {
AnyCar::Forest(forest) => forest.metadata(),
AnyCar::Plain(plain) => plain.metadata(),
Expand Down
24 changes: 13 additions & 11 deletions src/db/car/forest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,20 @@ impl<ReaderT: super::RandomAccessFileReader> ForestCar<ReaderT> {
})
}

pub fn metadata(&self) -> &Option<FilecoinSnapshotMetadata> {
self.metadata.get_or_init(|| {
if self.header.roots.len() == super::V2_SNAPSHOT_ROOT_COUNT {
let maybe_metadata_cid = self.header.roots.first();
if let Ok(Some(metadata)) =
self.get_cbor::<FilecoinSnapshotMetadata>(maybe_metadata_cid)
{
return Some(metadata);
pub fn metadata(&self) -> Option<&FilecoinSnapshotMetadata> {
self.metadata
.get_or_init(|| {
if self.header.roots.len() == super::V2_SNAPSHOT_ROOT_COUNT {
let maybe_metadata_cid = self.header.roots.first();
if let Ok(Some(metadata)) =
self.get_cbor::<FilecoinSnapshotMetadata>(maybe_metadata_cid)
{
return Some(metadata);
}
}
}
None
})
None
})
.as_ref()
}

pub fn is_valid(reader: &ReaderT) -> bool {
Expand Down
24 changes: 13 additions & 11 deletions src/db/car/plain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,20 @@ impl<ReaderT: super::RandomAccessFileReader> PlainCar<ReaderT> {
}
}

pub fn metadata(&self) -> &Option<FilecoinSnapshotMetadata> {
self.metadata.get_or_init(|| {
if self.header_v1.roots.len() == super::V2_SNAPSHOT_ROOT_COUNT {
let maybe_metadata_cid = self.header_v1.roots.first();
if let Ok(Some(metadata)) =
self.get_cbor::<FilecoinSnapshotMetadata>(maybe_metadata_cid)
{
return Some(metadata);
pub fn metadata(&self) -> Option<&FilecoinSnapshotMetadata> {
self.metadata
.get_or_init(|| {
if self.header_v1.roots.len() == super::V2_SNAPSHOT_ROOT_COUNT {
let maybe_metadata_cid = self.header_v1.roots.first();
if let Ok(Some(metadata)) =
self.get_cbor::<FilecoinSnapshotMetadata>(maybe_metadata_cid)
{
return Some(metadata);
}
}
}
None
})
None
})
.as_ref()
}

pub fn head_tipset_key(&self) -> &NonEmpty<Cid> {
Expand Down
4 changes: 2 additions & 2 deletions src/eth/eip_1559_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl EthEip1559TxArgs {
.append(&format_bigint(&self.max_priority_fee_per_gas)?)
.append(&format_bigint(&self.max_fee_per_gas)?)
.append(&format_u64(self.gas_limit))
.append(&format_address(&self.to))
.append(&format_address(self.to.as_ref()))
.append(&format_bigint(&self.value)?)
.append(&self.input)
.append_list(access_list);
Expand Down Expand Up @@ -156,7 +156,7 @@ impl EthEip1559TxArgs {
self.chain_id,
eth_chain_id
);
let method_info = get_filecoin_method_info(&self.to, &self.input)?;
let method_info = get_filecoin_method_info(self.to.as_ref(), &self.input)?;
Ok(Message {
version: 0,
from,
Expand Down
4 changes: 2 additions & 2 deletions src/eth/eip_155_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl EthLegacyEip155TxArgs {
.append(&format_u64(self.nonce))
.append(&format_bigint(&self.gas_price)?)
.append(&format_u64(self.gas_limit))
.append(&format_address(&self.to))
.append(&format_address(self.to.as_ref()))
.append(&format_bigint(&self.value)?)
.append(&self.input);
Ok(stream)
Expand Down Expand Up @@ -240,7 +240,7 @@ impl EthLegacyEip155TxArgs {
validate_eip155_chain_id(eth_chain_id, &self.v).is_ok(),
"Failed to validate EIP155 chain Id"
);
let method_info = get_filecoin_method_info(&self.to, &self.input)?;
let method_info = get_filecoin_method_info(self.to.as_ref(), &self.input)?;
Ok(Message {
version: 0,
from,
Expand Down
4 changes: 2 additions & 2 deletions src/eth/homestead_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl EthLegacyHomesteadTxArgs {
.append(&format_u64(self.nonce))
.append(&format_bigint(&self.gas_price)?)
.append(&format_u64(self.gas_limit))
.append(&format_address(&self.to))
.append(&format_address(self.to.as_ref()))
.append(&format_bigint(&self.value)?)
.append(&self.input);
Ok(stream)
Expand Down Expand Up @@ -195,7 +195,7 @@ impl EthLegacyHomesteadTxArgs {

/// Constructs an unsigned message using legacy homestead transaction args
pub fn get_unsigned_message(&self, from: Address) -> anyhow::Result<Message> {
let method_info = get_filecoin_method_info(&self.to, &self.input)?;
let method_info = get_filecoin_method_info(self.to.as_ref(), &self.input)?;
Ok(Message {
version: 0,
from,
Expand Down
4 changes: 2 additions & 2 deletions src/eth/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ pub fn format_bigint(value: &BigInt) -> anyhow::Result<Bytes> {
})
}

pub fn format_address(value: &Option<EthAddress>) -> Bytes {
pub fn format_address(value: Option<&EthAddress>) -> Bytes {
if let Some(addr) = value {
addr.0.as_bytes().to_vec().into()
} else {
Expand Down Expand Up @@ -470,7 +470,7 @@ pub struct MethodInfo {

/// Retrieves method info
pub fn get_filecoin_method_info(
recipient: &Option<EthAddress>,
recipient: Option<&EthAddress>,
input: &[u8],
) -> anyhow::Result<MethodInfo> {
let params = if !input.is_empty() {
Expand Down
10 changes: 5 additions & 5 deletions src/ipld/tests/selector_explore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ struct TestVector {

// Just needed because cannot deserialize the current selector position in
// recursive selectors
fn test_equal(s1: &Option<Selector>, s2: &Option<Selector>) -> bool {
fn test_equal(s1: Option<&Selector>, s2: Option<&Selector>) -> bool {
use Selector::*;
if let (
&Some(ExploreRecursive {
Some(ExploreRecursive {
current: _,
sequence: s1,
limit: l1,
stop_at: st1,
}),
&Some(ExploreRecursive {
Some(ExploreRecursive {
current: _,
sequence: s2,
limit: l2,
stop_at: st2,
}),
) = (&s1, &s2)
) = (s1, s2)
{
s1 == s2 && l1 == l2 && st1 == st2
} else {
Expand All @@ -60,7 +60,7 @@ fn selector_explore_tests() {
for tv in vectors {
let result = process_vector(tv.initial_selector, tv.explore);
assert!(
test_equal(&result, &tv.result_selector),
test_equal(result.as_ref(), tv.result_selector.as_ref()),
"({}) Failed:\nExpected: {:?}\nFound: {:?}",
tv.description
.unwrap_or_else(|| "Unnamed test case".to_owned()),
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/methods/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ pub enum ChainGetTipSetV2 {}
impl ChainGetTipSetV2 {
pub async fn get_tipset_by_anchor(
ctx: &Ctx<impl Blockstore + Send + Sync + 'static>,
anchor: &Option<TipsetAnchor>,
anchor: Option<&TipsetAnchor>,
) -> anyhow::Result<Tipset> {
if let Some(anchor) = anchor {
match (&anchor.key.0, &anchor.tag) {
Expand Down Expand Up @@ -1162,7 +1162,7 @@ impl ChainGetTipSetV2 {
}
// Get tipset by height.
if let Some(height) = &selector.height {
let anchor = Self::get_tipset_by_anchor(ctx, &height.anchor).await?;
let anchor = Self::get_tipset_by_anchor(ctx, height.anchor.as_ref()).await?;
let ts = ctx.chain_index().tipset_by_height(
height.at,
anchor,
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/methods/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3790,7 +3790,7 @@ async fn trace_filter(
for block_trace in block_traces {
if block_trace
.trace
.match_filter_criteria(&filter.from_address, &filter.to_address)?
.match_filter_criteria(filter.from_address.as_ref(), filter.to_address.as_ref())?
{
trace_counter += 1;
if let Some(after) = filter.after
Expand Down
14 changes: 3 additions & 11 deletions src/rpc/methods/eth/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl EthEventHandler {

fn install_filter(
&self,
filter_manager: &Option<Arc<dyn FilterManager>>,
filter_manager: Option<&dyn FilterManager>,
) -> Result<FilterID, Error> {
if let Some(manager) = filter_manager {
let filter = manager.install().context("Installation error")?;
Expand All @@ -194,20 +194,12 @@ impl EthEventHandler {

// Installs an eth block filter
pub fn eth_new_block_filter(&self) -> Result<FilterID, Error> {
let filter_manager: Option<Arc<dyn FilterManager>> = self
.tipset_filter_manager
.as_ref()
.map(|fm| Arc::clone(fm) as Arc<dyn FilterManager>);
self.install_filter(&filter_manager)
self.install_filter(self.tipset_filter_manager.as_deref().map(|fm| fm as _))
}

// Installs an eth pending transaction filter
pub fn eth_new_pending_transaction_filter(&self) -> Result<FilterID, Error> {
let filter_manager: Option<Arc<dyn FilterManager>> = self
.mempool_filter_manager
.as_ref()
.map(|fm| Arc::clone(fm) as Arc<dyn FilterManager>);
self.install_filter(&filter_manager)
self.install_filter(self.mempool_filter_manager.as_deref().map(|fm| fm as _))
}

fn uninstall_filter(&self, filter: Arc<dyn Filter>) -> Result<(), Error> {
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/methods/eth/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,8 @@ lotus_json_with_self!(EthTraceFilterCriteria);
impl EthTrace {
pub fn match_filter_criteria(
&self,
from_decoded_addresses: &Option<EthAddressList>,
to_decoded_addresses: &Option<EthAddressList>,
from_decoded_addresses: Option<&EthAddressList>,
to_decoded_addresses: Option<&EthAddressList>,
) -> Result<bool> {
let (trace_to, trace_from) = match &self.action {
TraceAction::Call(action) => (action.to, action.from),
Expand Down
Loading
Loading