From 03a59395a92f7abd1b094be592022d17df3bdd56 Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Thu, 8 Aug 2024 13:00:31 +0200 Subject: [PATCH 1/3] fix: fix winning proofs --- src/fil_cns/validation.rs | 5 +- src/lotus_json/po_st_proof.rs | 8 +- src/lotus_json/registered_po_st_proof.rs | 8 +- src/lotus_json/registered_seal_proof.rs | 8 +- src/lotus_json/sector_info.rs | 4 +- src/rpc/methods/state.rs | 8 +- src/shim/sector.rs | 224 +++++++++++++---------- src/state_manager/utils.rs | 4 +- 8 files changed, 151 insertions(+), 118 deletions(-) diff --git a/src/fil_cns/validation.rs b/src/fil_cns/validation.rs index 24a6f878e4c9..ffc54b2020ca 100644 --- a/src/fil_cns/validation.rs +++ b/src/fil_cns/validation.rs @@ -13,6 +13,7 @@ use crate::shim::actors::PowerActorStateLoad as _; use crate::shim::crypto::{ cid_to_replica_commitment_v1, verify_bls_sig, TICKET_RANDOMNESS_LOOKBACK, }; +use crate::shim::sector::RegisteredSealProof; use crate::shim::{ address::Address, randomness::Randomness, @@ -411,7 +412,9 @@ fn to_fil_public_replica_infos( .map::, _>(|sector_info: &SectorInfo| { let commr = cid_to_replica_commitment_v1(§or_info.sealed_cid)?; let proof = match typ { - ProofType::Winning => sector_info.proof.registered_winning_post_proof()?, + ProofType::Winning => RegisteredSealProof::from(sector_info.proof) + .registered_winning_post_proof() + .map_err(|e| e.to_string())?, // ProofType::Window => sector_info.proof.registered_window_post_proof()?, }; let replica = PublicReplicaInfo::new(proof.try_into()?, commr); diff --git a/src/lotus_json/po_st_proof.rs b/src/lotus_json/po_st_proof.rs index 17dfc9314c01..314f9d58b1fa 100644 --- a/src/lotus_json/po_st_proof.rs +++ b/src/lotus_json/po_st_proof.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0, MIT use crate::shim::sector::{PoStProof, RegisteredPoStProof}; -use fvm_shared3::sector::PoStProof as PoStProofV3; +use fvm_shared4::sector::PoStProof as PoStProofV4; use super::*; @@ -30,7 +30,7 @@ impl HasLotusJson for PoStProof { }), PoStProof::new( crate::shim::sector::RegisteredPoStProof::from( - crate::shim::sector::RegisteredPoStProofV3::StackedDRGWinning2KiBV1, + crate::shim::sector::RegisteredPoStProofV4::StackedDRGWinning2KiBV1, ), Vec::from_iter(*b"hello world!"), ), @@ -38,7 +38,7 @@ impl HasLotusJson for PoStProof { } fn into_lotus_json(self) -> Self::LotusJson { - let PoStProofV3 { + let PoStProofV4 { post_proof, proof_bytes, } = self.into(); @@ -53,7 +53,7 @@ impl HasLotusJson for PoStProof { po_st_proof, proof_bytes, } = lotus_json; - Self::from(PoStProofV3 { + Self::from(PoStProofV4 { post_proof: po_st_proof.into(), proof_bytes, }) diff --git a/src/lotus_json/registered_po_st_proof.rs b/src/lotus_json/registered_po_st_proof.rs index f507eece4ca4..838749674faa 100644 --- a/src/lotus_json/registered_po_st_proof.rs +++ b/src/lotus_json/registered_po_st_proof.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0, MIT use crate::shim::sector::RegisteredPoStProof; -use fvm_shared3::sector::RegisteredPoStProof as RegisteredPoStProofV3; +use fvm_shared4::sector::RegisteredPoStProof as RegisteredPoStProofV4; use super::*; @@ -13,15 +13,15 @@ impl HasLotusJson for RegisteredPoStProof { fn snapshots() -> Vec<(serde_json::Value, Self)> { vec![( json!(0), - RegisteredPoStProof::from(RegisteredPoStProofV3::StackedDRGWinning2KiBV1), + RegisteredPoStProof::from(RegisteredPoStProofV4::StackedDRGWinning2KiBV1), )] } fn into_lotus_json(self) -> Self::LotusJson { - i64::from(RegisteredPoStProofV3::from(self)) + i64::from(RegisteredPoStProofV4::from(self)) } fn from_lotus_json(i: Self::LotusJson) -> Self { - Self::from(RegisteredPoStProofV3::from(i)) + Self::from(RegisteredPoStProofV4::from(i)) } } diff --git a/src/lotus_json/registered_seal_proof.rs b/src/lotus_json/registered_seal_proof.rs index ecebc901abf2..da0dd8b95a8e 100644 --- a/src/lotus_json/registered_seal_proof.rs +++ b/src/lotus_json/registered_seal_proof.rs @@ -3,7 +3,7 @@ use super::*; use crate::shim::sector::RegisteredSealProof; -use fvm_shared3::sector::RegisteredSealProof as RegisteredSealProofV3; +use fvm_shared4::sector::RegisteredSealProof as RegisteredSealProofV4; impl HasLotusJson for RegisteredSealProof { type LotusJson = i64; @@ -12,15 +12,15 @@ impl HasLotusJson for RegisteredSealProof { fn snapshots() -> Vec<(serde_json::Value, Self)> { vec![( json!(0), - Self::from(RegisteredSealProofV3::StackedDRG2KiBV1), + Self::from(RegisteredSealProofV4::StackedDRG2KiBV1), )] } fn into_lotus_json(self) -> Self::LotusJson { - i64::from(RegisteredSealProofV3::from(self)) + i64::from(RegisteredSealProofV4::from(self)) } fn from_lotus_json(i: Self::LotusJson) -> Self { - Self::from(RegisteredSealProofV3::from(i)) + Self::from(RegisteredSealProofV4::from(i)) } } diff --git a/src/lotus_json/sector_info.rs b/src/lotus_json/sector_info.rs index 5cda943d6083..32bd48fe472c 100644 --- a/src/lotus_json/sector_info.rs +++ b/src/lotus_json/sector_info.rs @@ -32,7 +32,7 @@ impl HasLotusJson for SectorInfo { } }), Self::new( - fvm_shared3::sector::RegisteredSealProof::StackedDRG2KiBV1, + fvm_shared4::sector::RegisteredSealProof::StackedDRG2KiBV1, 0, ::cid::Cid::default(), ), @@ -40,7 +40,7 @@ impl HasLotusJson for SectorInfo { } fn into_lotus_json(self) -> Self::LotusJson { - let fvm_shared3::sector::SectorInfo { + let fvm_shared4::sector::SectorInfo { proof, sector_number, sealed_cid, diff --git a/src/rpc/methods/state.rs b/src/rpc/methods/state.rs index de6b4a2546f2..ca24583fc2fc 100644 --- a/src/rpc/methods/state.rs +++ b/src/rpc/methods/state.rs @@ -26,7 +26,7 @@ use crate::shim::actors::{ use crate::shim::address::Payload; use crate::shim::message::Message; use crate::shim::piece::PaddedPieceSize; -use crate::shim::sector::SectorNumber; +use crate::shim::sector::{SectorNumber, SectorSize}; use crate::shim::state_tree::{ActorID, StateTree}; use crate::shim::{ address::Address, clock::ChainEpoch, deal::DealID, econ::TokenAmount, executor::Receipt, @@ -855,7 +855,8 @@ impl RpcMethod<3> for StateMinerInitialPledgeCollateral { pci.expiration, )?; let duration = pci.expiration - ts.epoch(); - let sector_weigth = qa_power_for_weight(sector_size, duration, &w, &vw); + let sector_weight = + qa_power_for_weight(SectorSize::from(sector_size).into(), duration, &w, &vw); let power_state: power::State = ctx.state_manager.get_actor_state(&ts)?; let power_smoothed = power_state.total_power_smoothed(); @@ -870,7 +871,7 @@ impl RpcMethod<3> for StateMinerInitialPledgeCollateral { )?; let initial_pledge: TokenAmount = reward_state .initial_pledge_for_power( - §or_weigth, + §or_weight, pledge_collateral, power_smoothed, &circ_supply.fil_circulating.into(), @@ -913,6 +914,7 @@ impl RpcMethod<3> for StateMinerPreCommitDepositForPower { pci.expiration, )?; let duration = pci.expiration - ts.epoch(); + let sector_size = SectorSize::from(sector_size).into(); let sector_weight = if ctx.state_manager.get_network_version(ts.epoch()) < NetworkVersion::V16 { qa_power_for_weight(sector_size, duration, &w, &vw) diff --git a/src/shim/sector.rs b/src/shim/sector.rs index 794c99f17c16..39fc75f409bf 100644 --- a/src/shim/sector.rs +++ b/src/shim/sector.rs @@ -1,20 +1,22 @@ // Copyright 2019-2024 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -pub use fvm_shared3::sector::StoragePower; -pub use fvm_shared3::sector::{ - RegisteredPoStProof as RegisteredPoStProofV3, RegisteredSealProof as RegisteredSealProofV3, -}; -pub use fvm_shared4::sector::RegisteredSealProof as RegisteredSealProofV4; - use crate::shim::version::NetworkVersion; +use anyhow::bail; use fvm_ipld_encoding::repr::{Deserialize_repr, Serialize_repr}; use fvm_shared2::sector::{ - RegisteredPoStProof as RegisteredPoStProofV2, RegisteredSealProof as RegisteredSealProofV2, - SectorInfo as SectorInfoV2, SectorSize as SectorSizeV2, + PoStProof as PoStProofV2, RegisteredPoStProof as RegisteredPoStProofV2, + RegisteredSealProof as RegisteredSealProofV2, SectorInfo as SectorInfoV2, + SectorSize as SectorSizeV2, }; -use fvm_shared3::sector::{ - PoStProof as PoStProofV3, SectorInfo as SectorInfoV3, SectorSize as SectorSizeV3, +pub use fvm_shared3::sector::{ + RegisteredPoStProof as RegisteredPoStProofV3, RegisteredSealProof as RegisteredSealProofV3, + SectorSize as SectorSizeV3, StoragePower, +}; +pub use fvm_shared4::sector::{ + PoStProof as PoStProofV4, RegisteredPoStProof as RegisteredPoStProofV4, + RegisteredSealProof as RegisteredSealProofV4, SectorInfo as SectorInfoV4, + SectorSize as SectorSizeV4, }; use num_derive::FromPrimitive; use serde::{Deserialize, Serialize}; @@ -40,30 +42,57 @@ pub type SectorNumber = fvm_shared3::sector::SectorNumber; /// assert_eq!(fvm3_proof, *proof_shim); /// assert_eq!(fvm2_proof, proof_shim.into()); /// ``` -#[derive( - serde::Serialize, - serde::Deserialize, - Clone, - Copy, - derive_more::From, - derive_more::Into, - Eq, - PartialEq, - Debug, -)] -pub struct RegisteredSealProof(RegisteredSealProofV3); +#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Eq, PartialEq, Debug)] +pub struct RegisteredSealProof(RegisteredSealProofV4); impl RegisteredSealProof { pub fn from_sector_size(size: SectorSize, network_version: NetworkVersion) -> Self { - RegisteredSealProof(RegisteredSealProofV3::from_sector_size( + RegisteredSealProof(RegisteredSealProofV4::from_sector_size( size.into(), network_version.into(), )) } + + pub fn registered_winning_post_proof(self) -> anyhow::Result { + use fvm_shared4::sector::RegisteredPoStProof as PoStProof; + use fvm_shared4::sector::RegisteredSealProof as SealProof; + match self.0 { + SealProof::StackedDRG64GiBV1 + | SealProof::StackedDRG64GiBV1P1 + | SealProof::StackedDRG64GiBV1P1_Feat_SyntheticPoRep + | SealProof::StackedDRG64GiBV1P2_Feat_NiPoRep => { + Ok(PoStProof::StackedDRGWinning64GiBV1) + } + SealProof::StackedDRG32GiBV1 + | SealProof::StackedDRG32GiBV1P1 + | SealProof::StackedDRG32GiBV1P1_Feat_SyntheticPoRep + | SealProof::StackedDRG32GiBV1P2_Feat_NiPoRep => { + Ok(PoStProof::StackedDRGWinning32GiBV1) + } + SealProof::StackedDRG2KiBV1 + | SealProof::StackedDRG2KiBV1P1 + | SealProof::StackedDRG2KiBV1P1_Feat_SyntheticPoRep + | SealProof::StackedDRG2KiBV1P2_Feat_NiPoRep => Ok(PoStProof::StackedDRGWinning2KiBV1), + SealProof::StackedDRG8MiBV1 + | SealProof::StackedDRG8MiBV1P1 + | SealProof::StackedDRG8MiBV1P1_Feat_SyntheticPoRep + | SealProof::StackedDRG8MiBV1P2_Feat_NiPoRep => Ok(PoStProof::StackedDRGWinning8MiBV1), + SealProof::StackedDRG512MiBV1 + | SealProof::StackedDRG512MiBV1P1 + | SealProof::StackedDRG512MiBV1P1_Feat_SyntheticPoRep + | SealProof::StackedDRG512MiBV1P2_Feat_NiPoRep => { + Ok(PoStProof::StackedDRGWinning512MiBV1) + } + SealProof::Invalid(_) => bail!( + "Unsupported mapping from {:?} to PoSt-winning RegisteredProof", + self + ), + } + } } impl Deref for RegisteredSealProof { - type Target = RegisteredSealProofV3; + type Target = RegisteredSealProofV4; fn deref(&self) -> &Self::Target { &self.0 } @@ -72,7 +101,7 @@ impl Deref for RegisteredSealProof { impl From for RegisteredSealProof { fn from(value: RegisteredSealProofV2) -> RegisteredSealProof { let num_id: i64 = value.into(); - RegisteredSealProof(RegisteredSealProofV3::from(num_id)) + RegisteredSealProof(RegisteredSealProofV4::from(num_id)) } } @@ -83,10 +112,17 @@ impl From for RegisteredSealProofV2 { } } +impl From for RegisteredSealProof { + fn from(value: RegisteredSealProofV3) -> RegisteredSealProof { + let num_id: i64 = value.into(); + RegisteredSealProof(RegisteredSealProofV4::from(num_id)) + } +} + impl From for RegisteredSealProof { fn from(value: RegisteredSealProofV4) -> RegisteredSealProof { let num_id: i64 = value.into(); - RegisteredSealProof(RegisteredSealProofV3::from(num_id)) + RegisteredSealProof(RegisteredSealProofV4::from(num_id)) } } @@ -109,12 +145,12 @@ impl quickcheck::Arbitrary for RegisteredSealProof { #[derive( Eq, PartialEq, Debug, Clone, derive_more::From, derive_more::Into, Serialize, Deserialize, )] -pub struct SectorInfo(SectorInfoV3); +pub struct SectorInfo(SectorInfoV4); #[cfg(test)] impl quickcheck::Arbitrary for SectorInfo { fn arbitrary(g: &mut quickcheck::Gen) -> Self { - Self(SectorInfoV3 { + Self(SectorInfoV4 { proof: RegisteredSealProof::arbitrary(g).into(), sector_number: u64::arbitrary(g), sealed_cid: cid::Cid::arbitrary(g), @@ -124,11 +160,11 @@ impl quickcheck::Arbitrary for SectorInfo { impl SectorInfo { pub fn new( - proof: RegisteredSealProofV3, + proof: RegisteredSealProofV4, sector_number: SectorNumber, sealed_cid: cid::Cid, ) -> Self { - SectorInfo(SectorInfoV3 { + SectorInfo(SectorInfoV4 { proof, sector_number, sealed_cid, @@ -137,7 +173,7 @@ impl SectorInfo { } impl Deref for SectorInfo { - type Target = SectorInfoV3; + type Target = SectorInfoV4; fn deref(&self) -> &Self::Target { &self.0 } @@ -153,28 +189,18 @@ impl From for SectorInfoV2 { } } -#[derive( - serde::Serialize, - serde::Deserialize, - Clone, - Debug, - PartialEq, - derive_more::From, - derive_more::Into, -)] -pub struct RegisteredPoStProof(RegisteredPoStProofV3); +#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, derive_more::Into)] +pub struct RegisteredPoStProof(RegisteredPoStProofV4); #[cfg(test)] impl quickcheck::Arbitrary for RegisteredPoStProof { fn arbitrary(g: &mut quickcheck::Gen) -> Self { - // RegisteredPoStProofV3: ::arbitrary::Arbitrary - // RegisteredPoStProofV3: !::quickcheck::Arbitrary - Self(RegisteredPoStProofV3::from(i64::arbitrary(g))) + Self(RegisteredPoStProofV4::from(i64::arbitrary(g))) } } impl Deref for RegisteredPoStProof { - type Target = RegisteredPoStProofV3; + type Target = RegisteredPoStProofV4; fn deref(&self) -> &Self::Target { &self.0 } @@ -190,14 +216,27 @@ impl TryFrom for fil_actors_shared::filecoin_proofs_api::Re impl From for RegisteredPoStProof { fn from(value: i64) -> Self { - RegisteredPoStProof(RegisteredPoStProofV3::from(value)) + RegisteredPoStProof(RegisteredPoStProofV4::from(value)) } } impl From for RegisteredPoStProof { fn from(value: RegisteredPoStProofV2) -> RegisteredPoStProof { let num_id: i64 = value.into(); - RegisteredPoStProof(RegisteredPoStProofV3::from(num_id)) + RegisteredPoStProof(RegisteredPoStProofV4::from(num_id)) + } +} + +impl From for RegisteredPoStProof { + fn from(value: RegisteredPoStProofV3) -> RegisteredPoStProof { + let num_id: i64 = value.into(); + RegisteredPoStProof(RegisteredPoStProofV4::from(num_id)) + } +} + +impl From for RegisteredPoStProof { + fn from(value: RegisteredPoStProofV4) -> RegisteredPoStProof { + RegisteredPoStProof(value) } } @@ -213,53 +252,36 @@ pub enum SectorSize { _64GiB = 2 * (32 << 30), } -impl From for SectorSize { - fn from(value: SectorSizeV3) -> Self { - match value { - SectorSizeV3::_2KiB => SectorSize::_2KiB, - SectorSizeV3::_8MiB => SectorSize::_8MiB, - SectorSizeV3::_512MiB => SectorSize::_512MiB, - SectorSizeV3::_32GiB => SectorSize::_32GiB, - SectorSizeV3::_64GiB => SectorSize::_64GiB, - } - } -} - -impl From for SectorSize { - fn from(value: SectorSizeV2) -> SectorSize { - match value { - SectorSizeV2::_2KiB => SectorSize::_2KiB, - SectorSizeV2::_8MiB => SectorSize::_8MiB, - SectorSizeV2::_512MiB => SectorSize::_512MiB, - SectorSizeV2::_32GiB => SectorSize::_32GiB, - SectorSizeV2::_64GiB => SectorSize::_64GiB, - } - } -} - -impl From for SectorSizeV2 { - fn from(value: SectorSize) -> SectorSizeV2 { - match value { - SectorSize::_2KiB => SectorSizeV2::_2KiB, - SectorSize::_8MiB => SectorSizeV2::_8MiB, - SectorSize::_512MiB => SectorSizeV2::_512MiB, - SectorSize::_32GiB => SectorSizeV2::_32GiB, - SectorSize::_64GiB => SectorSizeV2::_64GiB, - } - } +macro_rules! sector_size_conversion { + ($($internal:ty),+) => { + $( + impl From<$internal> for SectorSize { + fn from(value: $internal) -> Self { + match value { + <$internal>::_2KiB => SectorSize::_2KiB, + <$internal>::_8MiB => SectorSize::_8MiB, + <$internal>::_512MiB => SectorSize::_512MiB, + <$internal>::_32GiB => SectorSize::_32GiB, + <$internal>::_64GiB => SectorSize::_64GiB, + } + } + } + impl From for $internal { + fn from(value: SectorSize) -> $internal { + match value { + SectorSize::_2KiB => <$internal>::_2KiB, + SectorSize::_8MiB => <$internal>::_8MiB, + SectorSize::_512MiB => <$internal>::_512MiB, + SectorSize::_32GiB => <$internal>::_32GiB, + SectorSize::_64GiB => <$internal>::_64GiB, + } + } + } + )+ + }; } -impl From for SectorSizeV3 { - fn from(value: SectorSize) -> SectorSizeV3 { - match value { - SectorSize::_2KiB => SectorSizeV3::_2KiB, - SectorSize::_8MiB => SectorSizeV3::_8MiB, - SectorSize::_512MiB => SectorSizeV3::_512MiB, - SectorSize::_32GiB => SectorSizeV3::_32GiB, - SectorSize::_64GiB => SectorSizeV3::_64GiB, - } - } -} +sector_size_conversion!(SectorSizeV2, SectorSizeV3, SectorSizeV4); #[derive( serde::Serialize, @@ -272,12 +294,11 @@ impl From for SectorSizeV3 { Eq, )] #[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))] -pub struct PoStProof(PoStProofV3); +pub struct PoStProof(PoStProofV4); impl Hash for PoStProof { fn hash(&self, state: &mut H) { - // TODO(forest): https://github.com/ChainSafe/forest/issues/3852 - let PoStProofV3 { + let PoStProofV4 { post_proof, proof_bytes, } = &self.0; @@ -288,7 +309,7 @@ impl Hash for PoStProof { impl PoStProof { pub fn new(reg_post_proof: RegisteredPoStProof, proof_bytes: Vec) -> Self { - PoStProof(PoStProofV3 { + PoStProof(PoStProofV4 { post_proof: *reg_post_proof, proof_bytes, }) @@ -296,13 +317,22 @@ impl PoStProof { } impl Deref for PoStProof { - type Target = PoStProofV3; + type Target = PoStProofV4; fn deref(&self) -> &Self::Target { &self.0 } } +impl From for PoStProof { + fn from(value: PoStProofV2) -> PoStProof { + PoStProof(PoStProofV4 { + post_proof: *RegisteredPoStProof::from(value.post_proof), + proof_bytes: value.proof_bytes, + }) + } +} + pub fn convert_window_post_proof_v1_to_v1p1( rpp: RegisteredPoStProofV3, ) -> anyhow::Result { diff --git a/src/state_manager/utils.rs b/src/state_manager/utils.rs index bc9a6b1024a0..41bebc710c60 100644 --- a/src/state_manager/utils.rs +++ b/src/state_manager/utils.rs @@ -77,9 +77,7 @@ where let info = mas.info(store)?; let spt = RegisteredSealProof::from_sector_size(info.sector_size().into(), nv); - let wpt = spt - .registered_winning_post_proof() - .map_err(|e| anyhow::anyhow!("{}", e))?; + let wpt = spt.registered_winning_post_proof()?; let m_id = miner_address.id()?; From 996e29e86cd31dc100aeca57a13bc59cc0cf2f50 Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Thu, 8 Aug 2024 14:41:40 +0200 Subject: [PATCH 2/3] Reapply "fix: fix incorrect `MinerGetBaseInfo` (#4617)" (#4627) This reverts commit b8d5f3bb5ee59ac81f06c0a1852ad8a8f0ffe64d. --- CHANGELOG.md | 3 + scripts/tests/api_compare/filter-list | 1 - scripts/tests/api_compare/filter-list-offline | 1 - src/fil_cns/validation.rs | 2 + src/lotus_json/extended_sector_info.rs | 70 +++++++++++++++++++ src/lotus_json/mod.rs | 1 + src/rpc/types/mod.rs | 6 +- src/shim/sector.rs | 32 ++++++++- src/state_manager/utils.rs | 11 ++- 9 files changed, 118 insertions(+), 9 deletions(-) create mode 100644 src/lotus_json/extended_sector_info.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 455178f5bef3..1fe9f122ee99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -67,6 +67,9 @@ deserialisation in `Filecoin.EthGetBlockByNumber` and `Filecoin.EthGetBlockByHash` RPC methods. +- [#4610](https://github.com/ChainSafe/forest/issues/4610) Fixed incorrect + structure in the `Filecoin.MinerGetBaseInfo` RPC method. + ## Forest 0.19.2 "Eagle" Non-mandatory release that includes a fix for the Prometheus-incompatible diff --git a/scripts/tests/api_compare/filter-list b/scripts/tests/api_compare/filter-list index 22c0d94ad0ae..0649721eea2c 100644 --- a/scripts/tests/api_compare/filter-list +++ b/scripts/tests/api_compare/filter-list @@ -1,6 +1,5 @@ # This list contains potentially broken methods (or tests) that are ignored. # They should be considered bugged, and not used until the root cause is resolved. -!Filecoin.MinerGetBaseInfo # Internal Server Error on Lotus: https://github.com/ChainSafe/forest/actions/runs/8619017774/job/23623141130?pr=4170 !Filecoin.MpoolGetNonce # CustomCheckFailed in Forest: https://github.com/ChainSafe/forest/actions/runs/9593268587/job/26453560366 diff --git a/scripts/tests/api_compare/filter-list-offline b/scripts/tests/api_compare/filter-list-offline index 3096f480e667..f7f62934fa96 100644 --- a/scripts/tests/api_compare/filter-list-offline +++ b/scripts/tests/api_compare/filter-list-offline @@ -1,6 +1,5 @@ # This list contains potentially broken methods (or tests) that are ignored. # They should be considered bugged, and not used until the root cause is resolved. -!Filecoin.MinerGetBaseInfo # Internal Server Error on Lotus: https://github.com/ChainSafe/forest/actions/runs/8619314467/job/23624081698 !Filecoin.MpoolGetNonce !Filecoin.EthSyncing diff --git a/src/fil_cns/validation.rs b/src/fil_cns/validation.rs index ffc54b2020ca..31918a3e1a2f 100644 --- a/src/fil_cns/validation.rs +++ b/src/fil_cns/validation.rs @@ -29,6 +29,7 @@ use fil_actors_shared::v10::runtime::DomainSeparationTag; use futures::stream::FuturesUnordered; use fvm_ipld_blockstore::Blockstore; use fvm_ipld_encoding::{bytes_32, to_vec}; +use itertools::Itertools; use nunny::Vec as NonEmpty; use crate::fil_cns::{metrics, FilecoinConsensusError}; @@ -392,6 +393,7 @@ fn verify_winning_post_proof( &header.miner_address, Randomness::new(rand.to_vec()), ) + .map(|sectors| sectors.iter().map(Into::into).collect_vec()) .map_err(|e| FilecoinConsensusError::WinningPoStValidation(e.to_string()))?; verify_winning_post( diff --git a/src/lotus_json/extended_sector_info.rs b/src/lotus_json/extended_sector_info.rs new file mode 100644 index 000000000000..45466578af9c --- /dev/null +++ b/src/lotus_json/extended_sector_info.rs @@ -0,0 +1,70 @@ +// Copyright 2019-2024 ChainSafe Systems +// SPDX-License-Identifier: Apache-2.0, MIT + +use super::*; +use crate::shim::sector::{ExtendedSectorInfo, RegisteredSealProof}; +use ::cid::Cid; + +#[derive(Serialize, Deserialize, JsonSchema)] +#[serde(rename_all = "PascalCase")] +#[schemars(rename = "ExtendedSectorInfo")] +pub struct ExtendedSectorInfoLotusJson { + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + seal_proof: RegisteredSealProof, + sector_number: u64, + #[schemars(with = "LotusJson>")] + #[serde(with = "crate::lotus_json")] + sector_key: Option, + #[schemars(with = "LotusJson")] + #[serde(with = "crate::lotus_json")] + sealed_c_i_d: Cid, +} + +impl HasLotusJson for ExtendedSectorInfo { + type LotusJson = ExtendedSectorInfoLotusJson; + + #[cfg(test)] + fn snapshots() -> Vec<(serde_json::Value, Self)> { + vec![( + json!({ + "SealProof": 0, + "SectorNumber": 0, + "SectorKey": null, + "SealedCID": { + "/": "baeaaaaa" + } + }), + Self { + proof: fvm_shared3::sector::RegisteredSealProof::StackedDRG2KiBV1.into(), + sector_number: 0, + sector_key: None, + sealed_cid: ::cid::Cid::default(), + }, + )] + } + + fn into_lotus_json(self) -> Self::LotusJson { + Self::LotusJson { + seal_proof: self.proof, + sector_number: self.sector_number, + sector_key: self.sector_key, + sealed_c_i_d: self.sealed_cid, + } + } + + fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { + let Self::LotusJson { + seal_proof, + sector_number, + sector_key, + sealed_c_i_d, + } = lotus_json; + Self { + proof: seal_proof, + sector_number, + sector_key, + sealed_cid: sealed_c_i_d, + } + } +} diff --git a/src/lotus_json/mod.rs b/src/lotus_json/mod.rs index 0107ee666d56..373be63e8a25 100644 --- a/src/lotus_json/mod.rs +++ b/src/lotus_json/mod.rs @@ -196,6 +196,7 @@ decl_and_test!( block_header for crate::blocks::CachingBlockHeader, cid for ::cid::Cid, election_proof for crate::blocks::ElectionProof, + extended_sector_info for crate::shim::sector::ExtendedSectorInfo, gossip_block for crate::blocks::GossipBlock, key_info for crate::key_management::KeyInfo, message for crate::shim::message::Message, diff --git a/src/rpc/types/mod.rs b/src/rpc/types/mod.rs index 1a080f6a305c..123fac4ecb73 100644 --- a/src/rpc/types/mod.rs +++ b/src/rpc/types/mod.rs @@ -25,7 +25,7 @@ use crate::shim::{ executor::Receipt, fvm_shared_latest::MethodNum, message::Message, - sector::{RegisteredSealProof, SectorInfo, SectorNumber, StoragePower}, + sector::{ExtendedSectorInfo, RegisteredSealProof, SectorNumber, StoragePower}, }; use cid::Cid; use fil_actor_interface::market::AllocationID; @@ -503,8 +503,8 @@ pub struct MiningBaseInfo { #[schemars(with = "LotusJson")] pub network_power: StoragePower, #[serde(with = "crate::lotus_json")] - #[schemars(with = "LotusJson>")] - pub sectors: Vec, + #[schemars(with = "LotusJson>")] + pub sectors: Vec, #[serde(with = "crate::lotus_json")] #[schemars(with = "LotusJson
")] pub worker_key: Address, diff --git a/src/shim/sector.rs b/src/shim/sector.rs index 39fc75f409bf..d08ebe77a9c8 100644 --- a/src/shim/sector.rs +++ b/src/shim/sector.rs @@ -3,6 +3,7 @@ use crate::shim::version::NetworkVersion; use anyhow::bail; +use cid::Cid; use fvm_ipld_encoding::repr::{Deserialize_repr, Serialize_repr}; use fvm_shared2::sector::{ PoStProof as PoStProofV2, RegisteredPoStProof as RegisteredPoStProofV2, @@ -23,7 +24,7 @@ use serde::{Deserialize, Serialize}; use std::hash::{Hash, Hasher}; use std::ops::Deref; -pub type SectorNumber = fvm_shared3::sector::SectorNumber; +pub type SectorNumber = fvm_shared4::sector::SectorNumber; /// Represents a shim over `RegisteredSealProof` from `fvm_shared` with /// convenience methods to convert to an older version of the type @@ -189,6 +190,35 @@ impl From for SectorInfoV2 { } } +/// Information about a sector necessary for PoSt verification +#[derive( + Eq, PartialEq, Debug, Clone, derive_more::From, derive_more::Into, Serialize, Deserialize, +)] +pub struct ExtendedSectorInfo { + pub proof: RegisteredSealProof, + pub sector_number: SectorNumber, + pub sector_key: Option, + pub sealed_cid: Cid, +} + +impl From<&ExtendedSectorInfo> for SectorInfo { + fn from(value: &ExtendedSectorInfo) -> SectorInfo { + SectorInfo::new(value.proof.into(), value.sector_number, value.sealed_cid) + } +} + +#[cfg(test)] +impl quickcheck::Arbitrary for ExtendedSectorInfo { + fn arbitrary(g: &mut quickcheck::Gen) -> Self { + Self { + proof: RegisteredSealProof::arbitrary(g), + sector_number: u64::arbitrary(g), + sector_key: Option::::arbitrary(g), + sealed_cid: cid::Cid::arbitrary(g), + } + } +} + #[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, derive_more::Into)] pub struct RegisteredPoStProof(RegisteredPoStProofV4); diff --git a/src/state_manager/utils.rs b/src/state_manager/utils.rs index 41bebc710c60..c27d2e7dd7e6 100644 --- a/src/state_manager/utils.rs +++ b/src/state_manager/utils.rs @@ -5,7 +5,7 @@ use crate::shim::{ actors::{is_account_actor, is_ethaccount_actor, is_placeholder_actor}, address::{Address, Payload}, randomness::Randomness, - sector::{RegisteredPoStProof, RegisteredSealProof, SectorInfo}, + sector::{ExtendedSectorInfo, RegisteredPoStProof, RegisteredSealProof}, state_tree::ActorState, version::NetworkVersion, }; @@ -33,7 +33,7 @@ where nv: NetworkVersion, miner_address: &Address, rand: Randomness, - ) -> Result, anyhow::Error> { + ) -> Result, anyhow::Error> { let store = self.blockstore(); let actor = self @@ -100,7 +100,12 @@ where let out = sectors .into_iter() - .map(|s_info| SectorInfo::new(*spt, s_info.sector_number, s_info.sealed_cid)) + .map(|s_info| ExtendedSectorInfo { + proof: s_info.seal_proof.into(), + sector_number: s_info.sector_number, + sector_key: s_info.sector_key_cid, + sealed_cid: s_info.sealed_cid, + }) .collect(); Ok(out) From 30fc68e364a373a33f6513c93b8a861b46c4464f Mon Sep 17 00:00:00 2001 From: Hubert Bugaj Date: Thu, 8 Aug 2024 14:59:46 +0200 Subject: [PATCH 3/3] fix doctests; more macro --- src/shim/sector.rs | 60 +++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/shim/sector.rs b/src/shim/sector.rs index d08ebe77a9c8..65fe84454f27 100644 --- a/src/shim/sector.rs +++ b/src/shim/sector.rs @@ -38,9 +38,13 @@ pub type SectorNumber = fvm_shared4::sector::SectorNumber; /// // Create a correspndoning FVM3 RegisteredSealProof /// let fvm3_proof = fvm_shared3::sector::RegisteredSealProof::StackedDRG2KiBV1; /// +/// // Create a correspndoning FVM4 RegisteredSealProof +/// let fvm4_proof = fvm_shared4::sector::RegisteredSealProof::StackedDRG2KiBV1; +/// /// // Create a shim out of fvm2 proof, ensure conversions are correct /// let proof_shim = RegisteredSealProof::from(fvm2_proof); -/// assert_eq!(fvm3_proof, *proof_shim); +/// assert_eq!(fvm4_proof, *proof_shim); +/// assert_eq!(fvm3_proof, proof_shim.into()); /// assert_eq!(fvm2_proof, proof_shim.into()); /// ``` #[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Eq, PartialEq, Debug)] @@ -99,40 +103,36 @@ impl Deref for RegisteredSealProof { } } -impl From for RegisteredSealProof { - fn from(value: RegisteredSealProofV2) -> RegisteredSealProof { - let num_id: i64 = value.into(); - RegisteredSealProof(RegisteredSealProofV4::from(num_id)) - } -} - -impl From for RegisteredSealProofV2 { - fn from(value: RegisteredSealProof) -> RegisteredSealProofV2 { - let num_id: i64 = value.0.into(); - RegisteredSealProofV2::from(num_id) - } -} - -impl From for RegisteredSealProof { - fn from(value: RegisteredSealProofV3) -> RegisteredSealProof { - let num_id: i64 = value.into(); - RegisteredSealProof(RegisteredSealProofV4::from(num_id)) +impl From for RegisteredSealProof { + fn from(value: i64) -> Self { + RegisteredSealProof(RegisteredSealProofV4::from(value)) } } -impl From for RegisteredSealProof { - fn from(value: RegisteredSealProofV4) -> RegisteredSealProof { - let num_id: i64 = value.into(); - RegisteredSealProof(RegisteredSealProofV4::from(num_id)) - } +macro_rules! registered_seal_proof_conversion { + ($($internal:ty),+) => { + $( + impl From<$internal> for RegisteredSealProof { + fn from(value: $internal) -> Self { + let num_id: i64 = value.into(); + RegisteredSealProof::from(num_id) + } + } + impl From for $internal { + fn from(value: RegisteredSealProof) -> $internal { + let num_id: i64 = value.0.into(); + <$internal>::from(num_id) + } + } + )+ + }; } -impl From for RegisteredSealProofV4 { - fn from(value: RegisteredSealProof) -> RegisteredSealProofV4 { - let num_id: i64 = value.0.into(); - RegisteredSealProofV4::from(num_id) - } -} +registered_seal_proof_conversion!( + RegisteredSealProofV2, + RegisteredSealProofV3, + RegisteredSealProofV4 +); #[cfg(test)] impl quickcheck::Arbitrary for RegisteredSealProof {