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

fix: fix winning proofs #4629

Merged
merged 3 commits into from
Aug 9, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion scripts/tests/api_compare/filter-list
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion scripts/tests/api_compare/filter-list-offline
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/fil_cns/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -28,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};
Expand Down Expand Up @@ -391,6 +393,7 @@ fn verify_winning_post_proof<DB: Blockstore>(
&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(
Expand All @@ -411,7 +414,9 @@ fn to_fil_public_replica_infos(
.map::<Result<(SectorId, PublicReplicaInfo), String>, _>(|sector_info: &SectorInfo| {
let commr = cid_to_replica_commitment_v1(&sector_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);
Expand Down
70 changes: 70 additions & 0 deletions src/lotus_json/extended_sector_info.rs
Original file line number Diff line number Diff line change
@@ -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<RegisteredSealProof>")]
#[serde(with = "crate::lotus_json")]
seal_proof: RegisteredSealProof,
sector_number: u64,
#[schemars(with = "LotusJson<Option<Cid>>")]
#[serde(with = "crate::lotus_json")]
sector_key: Option<Cid>,
#[schemars(with = "LotusJson<Cid>")]
#[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,
}
}
}
1 change: 1 addition & 0 deletions src/lotus_json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions src/lotus_json/po_st_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -30,15 +30,15 @@ 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!"),
),
)]
}

fn into_lotus_json(self) -> Self::LotusJson {
let PoStProofV3 {
let PoStProofV4 {
post_proof,
proof_bytes,
} = self.into();
Expand All @@ -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,
})
Expand Down
8 changes: 4 additions & 4 deletions src/lotus_json/registered_po_st_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand All @@ -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),
LesnyRumcajs marked this conversation as resolved.
Show resolved Hide resolved
)]
}

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))
}
}
8 changes: 4 additions & 4 deletions src/lotus_json/registered_seal_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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))
}
}
4 changes: 2 additions & 2 deletions src/lotus_json/sector_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ impl HasLotusJson for SectorInfo {
}
}),
Self::new(
fvm_shared3::sector::RegisteredSealProof::StackedDRG2KiBV1,
fvm_shared4::sector::RegisteredSealProof::StackedDRG2KiBV1,
0,
::cid::Cid::default(),
),
)]
}

fn into_lotus_json(self) -> Self::LotusJson {
let fvm_shared3::sector::SectorInfo {
let fvm_shared4::sector::SectorInfo {
proof,
sector_number,
sealed_cid,
Expand Down
8 changes: 5 additions & 3 deletions src/rpc/methods/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -870,7 +871,7 @@ impl RpcMethod<3> for StateMinerInitialPledgeCollateral {
)?;
let initial_pledge: TokenAmount = reward_state
.initial_pledge_for_power(
&sector_weigth,
&sector_weight,
pledge_collateral,
power_smoothed,
&circ_supply.fil_circulating.into(),
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/rpc/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -503,8 +503,8 @@ pub struct MiningBaseInfo {
#[schemars(with = "LotusJson<StoragePower>")]
pub network_power: StoragePower,
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<Vec<SectorInfo>>")]
pub sectors: Vec<SectorInfo>,
#[schemars(with = "LotusJson<Vec<ExtendedSectorInfo>>")]
pub sectors: Vec<ExtendedSectorInfo>,
#[serde(with = "crate::lotus_json")]
#[schemars(with = "LotusJson<Address>")]
pub worker_key: Address,
Expand Down
Loading
Loading