From 3b4af7fde41ec0fdaafa04787553613577fbc3bc Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Mon, 14 Dec 2020 00:21:00 -0500 Subject: [PATCH 01/18] fix chain randomness and fix readobj --- node/rpc/src/chain_api.rs | 32 +++++++++++++++++++++++++++----- node/rpc/src/lib.rs | 11 ++++++++--- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/node/rpc/src/chain_api.rs b/node/rpc/src/chain_api.rs index 1174f080d957..7cfe65331dca 100644 --- a/node/rpc/src/chain_api.rs +++ b/node/rpc/src/chain_api.rs @@ -83,7 +83,7 @@ where pub(crate) async fn chain_read_obj( data: Data>, Params(params): Params<(CidJson,)>, -) -> Result, JsonRpcError> +) -> Result where DB: BlockStore + Send + Sync + 'static, KS: KeyStore + Send + Sync + 'static, @@ -95,7 +95,7 @@ where .blockstore() .get_bytes(&obj_cid)? .ok_or("can't find object with that cid")?; - Ok(ret) + Ok(base64::encode(ret)) } pub(crate) async fn chain_has_obj( @@ -259,9 +259,9 @@ where Ok(TipsetJson(ts)) } -pub(crate) async fn chain_get_randomness( +pub(crate) async fn chain_get_randomness_from_tickets( data: Data>, - Params(params): Params<(TipsetKeys, i64, ChainEpoch, Vec)>, + Params(params): Params<(TipsetKeys, i64, ChainEpoch, String)>, ) -> Result<[u8; 32], JsonRpcError> where DB: BlockStore + Send + Sync + 'static, @@ -276,7 +276,29 @@ where &tsk, DomainSeparationTag::from_i64(pers).ok_or("invalid DomainSeparationTag")?, epoch, - &entropy, + &base64::decode(entropy)?, + ) + .await?) +} + +pub(crate) async fn chain_get_randomness_from_beacon( + data: Data>, + Params(params): Params<(TipsetKeys, i64, ChainEpoch, String)>, +) -> Result<[u8; 32], JsonRpcError> +where + DB: BlockStore + Send + Sync + 'static, + KS: KeyStore + Send + Sync + 'static, + B: Beacon + Send + Sync + 'static, +{ + let (tsk, pers, epoch, entropy) = params; + Ok(data + .state_manager + .chain_store() + .get_beacon_randomness( + &tsk, + DomainSeparationTag::from_i64(pers).ok_or("invalid DomainSeparationTag")?, + epoch, + &base64::decode(entropy)?, ) .await?) } diff --git a/node/rpc/src/lib.rs b/node/rpc/src/lib.rs index dd4eaa611f8d..3a710d4a61b3 100644 --- a/node/rpc/src/lib.rs +++ b/node/rpc/src/lib.rs @@ -100,7 +100,7 @@ where chain_api::chain_get_message::, false, ) - .with_method("Filecoin.ChainGetObj", chain_read_obj::, false) + .with_method("Filecoin.ChainReadObj", chain_read_obj::, false) .with_method("Filecoin.ChainHasObj", chain_has_obj::, false) .with_method( "Filecoin.ChainGetBlockMessages", @@ -128,8 +128,13 @@ where false, ) .with_method( - "Filecoin.GetRandomness", - chain_get_randomness::, + "Filecoin.GetRandomnessFromTickets", + chain_get_randomness_from_tickets::, + false, + ) + .with_method( + "Filecoin.GetRandomnessFromBeacon", + chain_get_randomness_from_beacon::, false, ) .with_method( From 0929a79914c7c238c506726e4e88403e67b5523e Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Mon, 14 Dec 2020 00:30:51 -0500 Subject: [PATCH 02/18] fix method names --- node/rpc/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node/rpc/src/lib.rs b/node/rpc/src/lib.rs index 3a710d4a61b3..31e89cc4ad7f 100644 --- a/node/rpc/src/lib.rs +++ b/node/rpc/src/lib.rs @@ -128,12 +128,12 @@ where false, ) .with_method( - "Filecoin.GetRandomnessFromTickets", + "Filecoin.ChainGetRandomnessFromTicket", chain_get_randomness_from_tickets::, false, ) .with_method( - "Filecoin.GetRandomnessFromBeacon", + "Filecoin.ChainGetRandomnessFromBeacon", chain_get_randomness_from_beacon::, false, ) From 1c49d33007f93ed906a769f3118eb942621b4cf0 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Mon, 14 Dec 2020 00:41:27 -0500 Subject: [PATCH 03/18] ok fix for real... --- node/rpc/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/rpc/src/lib.rs b/node/rpc/src/lib.rs index 31e89cc4ad7f..ec944829e573 100644 --- a/node/rpc/src/lib.rs +++ b/node/rpc/src/lib.rs @@ -128,7 +128,7 @@ where false, ) .with_method( - "Filecoin.ChainGetRandomnessFromTicket", + "Filecoin.ChainGetRandomnessFromTickets", chain_get_randomness_from_tickets::, false, ) From d0bf29921ffb9270ec65c6c7552127d3ad269c09 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Mon, 14 Dec 2020 02:05:54 -0500 Subject: [PATCH 04/18] fix ticket param --- node/rpc/src/chain_api.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node/rpc/src/chain_api.rs b/node/rpc/src/chain_api.rs index 7cfe65331dca..df90f27581f3 100644 --- a/node/rpc/src/chain_api.rs +++ b/node/rpc/src/chain_api.rs @@ -261,14 +261,14 @@ where pub(crate) async fn chain_get_randomness_from_tickets( data: Data>, - Params(params): Params<(TipsetKeys, i64, ChainEpoch, String)>, + Params(params): Params<(TipsetKeysJson, i64, ChainEpoch, String)>, ) -> Result<[u8; 32], JsonRpcError> where DB: BlockStore + Send + Sync + 'static, KS: KeyStore + Send + Sync + 'static, B: Beacon + Send + Sync + 'static, { - let (tsk, pers, epoch, entropy) = params; + let (TipsetKeysJson(tsk), pers, epoch, entropy) = params; Ok(data .state_manager .chain_store() From 676228a8ff97cbbecd5b3f5d79022ca8d587c86f Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Mon, 14 Dec 2020 02:43:42 -0500 Subject: [PATCH 05/18] fix network version --- node/rpc/src/lib.rs | 6 +++++- node/rpc/src/state_api.rs | 29 +++++++++++------------------ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/node/rpc/src/lib.rs b/node/rpc/src/lib.rs index ec944829e573..7613dcff9393 100644 --- a/node/rpc/src/lib.rs +++ b/node/rpc/src/lib.rs @@ -300,7 +300,11 @@ where miner_create_block::, false, ) - .with_method("Filecoin.NetworkVersion", state_get_network_version, false) + .with_method( + "Filecoin.StateNetworkVersion", + state_get_network_version::, + false, + ) // Gas API .with_method( "Filecoin.GasEstimateGasLimit", diff --git a/node/rpc/src/state_api.rs b/node/rpc/src/state_api.rs index ae4eb3251ccf..e63b2bc2309a 100644 --- a/node/rpc/src/state_api.rs +++ b/node/rpc/src/state_api.rs @@ -27,10 +27,8 @@ use fil_types::json::SectorInfoJson; use fil_types::sector::post::json::PoStProofJson; use fil_types::{ deadlines::DeadlineInfo, - use_newest_network, verifier::{FullVerifier, ProofVerifier}, - NetworkVersion, PoStProof, SectorNumber, SectorSize, NEWEST_NETWORK_VERSION, - UPGRADE_BREEZE_HEIGHT, UPGRADE_SMOKE_HEIGHT, + NetworkVersion, PoStProof, SectorNumber, SectorSize, }; use ipld::{json::IpldJson, Ipld}; use ipld_amt::Amt; @@ -400,22 +398,17 @@ pub(crate) async fn state_replay< }) } -pub(crate) async fn state_get_network_version( - Params(params): Params, +pub(crate) async fn state_get_network_version< + DB: BlockStore + Send + Sync + 'static, + KS: KeyStore + Send + Sync + 'static, + B: Beacon + Send + Sync + 'static, +>( + data: Data>, + Params(params): Params<(TipsetKeysJson,)>, ) -> Result { - let height = params; - if use_newest_network() { - return Ok(NEWEST_NETWORK_VERSION); - } - if height <= UPGRADE_BREEZE_HEIGHT { - return Ok(NEWEST_NETWORK_VERSION); - } - - if height <= UPGRADE_SMOKE_HEIGHT { - return Ok(NetworkVersion::V0); - } - - Ok(NEWEST_NETWORK_VERSION) + let (TipsetKeysJson(tsk),) = params; + let ts = data.chain_store.tipset_from_keys(&tsk).await?; + Ok(data.state_manager.get_network_version(ts.epoch())) } /// returns the indicated actor's nonce and balance. From 8b91e782fef4f54297b785ab1ecdabe86aea81a3 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Mon, 14 Dec 2020 03:42:01 -0500 Subject: [PATCH 06/18] gotta figure out the filter estimate stuff --- node/rpc/Cargo.toml | 3 ++ node/rpc/src/state_api.rs | 90 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) diff --git a/node/rpc/Cargo.toml b/node/rpc/Cargo.toml index 1773f1672960..aaf708048b26 100644 --- a/node/rpc/Cargo.toml +++ b/node/rpc/Cargo.toml @@ -7,6 +7,9 @@ edition = "2018" [dependencies] ipld_amt = { path = "../../ipld/amt/" } actor = { package = "actor_interface", path = "../../vm/actor_interface" } +forest_actor = { path = "../../vm/actor" } +forest_actor_v0 = { package = "forest_actor", version = "0.1" } + bls-signatures = "0.6.1" async-std = { version = "1.6.3", features = ["attributes"] } serde = { version = "1.0.101", default-features = false, features = ["derive"] } diff --git a/node/rpc/src/state_api.rs b/node/rpc/src/state_api.rs index e63b2bc2309a..62b7e0b41acb 100644 --- a/node/rpc/src/state_api.rs +++ b/node/rpc/src/state_api.rs @@ -4,7 +4,9 @@ use crate::RpcState; use actor::{ market::{self, DealProposal, DealState}, - miner::{self, MinerInfo, SectorOnChainInfo}, + miner::{self, MinerInfo, SectorOnChainInfo, SectorPreCommitInfo}, + power::{self}, + reward::{self}, }; use address::{json::AddressJson, Address}; use async_std::task; @@ -795,6 +797,92 @@ pub(crate) async fn state_miner_sector_allocated< Ok(allocated_sectors) } +pub(crate) async fn state_miner_pre_commit_deposit_for_power< + DB: BlockStore + Send + Sync + 'static, + KS: KeyStore + Send + Sync + 'static, + B: Beacon + Send + Sync + 'static, + V: ProofVerifier + Send + Sync + 'static, +>( + data: Data>, + Params(params): Params<(AddressJson, SectorPreCommitInfo, TipsetKeysJson)>, +) -> Result { + let (AddressJson(maddr), pci, TipsetKeysJson(tsk)) = params; + let ts = data.chain_store.tipset_from_keys(&tsk).await?; + let (state, _) = data.state_manager.tipset_state::(&ts).await?; + let state = StateTree::new_from_root(data.chain_store.db.as_ref(), &state)?; + let ssize = pci.seal_proof.sector_size()?; + + let actor = state + .get_actor(market::ADDRESS)? + .ok_or("couldnt load market actor")?; + let (w, vw) = match market::State::load(data.state_manager.blockstore(), &actor)? { + market::State::V0(s) => forest_actor_v0::market::validate_deals_for_activation( + &s, + data.state_manager.blockstore(), + &pci.deal_ids, + &maddr, + pci.expiration, + ts.epoch(), + ), + market::State::V2(s) => forest_actor::market::validate_deals_for_activation( + &s, + data.state_manager.blockstore(), + &pci.deal_ids, + &maddr, + pci.expiration, + ts.epoch(), + ), + }?; + let duration = pci.expiration - ts.epoch(); + let sector_weight = forest_actor::miner::qa_power_for_weight(ssize, duration, &w, &vw); + + let actor = state + .get_actor(power::ADDRESS)? + .ok_or("couldnt load market actor")?; + let deposit = match power::State::load(data.state_manager.blockstore(), &actor)? { + power::State::V0(s) => { + let power_smoothed = s.this_epoch_qa_power_smoothed; + let reward_actor = state + .get_actor(reward::ADDRESS)? + .ok_or("couldnt load market actor")?; + match reward::State::load(data.state_manager.blockstore(), &reward_actor)? { + reward::State::V0(rs) => forest_actor_v0::miner::pre_commit_deposit_for_power( + &rs.this_epoch_reward_smoothed, + &power_smoothed, + §or_weight, + ), + reward::State::V2(rs) => forest_actor::miner::pre_commit_deposit_for_power( + &rs.this_epoch_reward_smoothed, + &power_smoothed, + §or_weight, + ), + } + } + power::State::V2(s) => { + let power_smoothed = s.this_epoch_qa_power_smoothed; + let reward_actor = state + .get_actor(reward::ADDRESS)? + .ok_or("couldnt load market actor")?; + match reward::State::load(data.state_manager.blockstore(), &reward_actor)? { + reward::State::V0(rs) => forest_actor_v0::miner::pre_commit_deposit_for_power( + &rs.this_epoch_reward_smoothed, + &power_smoothed, + §or_weight, + ), + reward::State::V2(rs) => forest_actor::miner::pre_commit_deposit_for_power( + &rs.this_epoch_reward_smoothed, + &power_smoothed, + §or_weight, + ), + } + } + }; + + // return types.BigDiv(types.BigMul(deposit, initialPledgeNum), initialPledgeDen), nil + let ret = (deposit * 110) / 100; + Ok(ret.to_string()) +} + /// returns a state tree given a tipset async fn state_for_ts( state_manager: &Arc>, From 0d52a919b3a090fd3e2c5487540510dadff22df8 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Mon, 14 Dec 2020 12:58:40 -0500 Subject: [PATCH 07/18] added some methods to actor interface --- node/rpc/src/lib.rs | 5 +++ node/rpc/src/state_api.rs | 46 ++++---------------- vm/actor/src/builtin/miner/policy.rs | 5 ++- vm/actor/src/builtin/power/policy.rs | 2 +- vm/actor_interface/src/builtin/market/mod.rs | 35 ++++++++++++++- vm/actor_interface/src/builtin/miner/mod.rs | 4 +- vm/actor_interface/src/builtin/mod.rs | 25 +++++++++++ vm/actor_interface/src/builtin/reward/mod.rs | 28 +++++++++++- 8 files changed, 106 insertions(+), 44 deletions(-) diff --git a/node/rpc/src/lib.rs b/node/rpc/src/lib.rs index 7613dcff9393..d9afb7ead894 100644 --- a/node/rpc/src/lib.rs +++ b/node/rpc/src/lib.rs @@ -248,6 +248,11 @@ where state_miner_partitions::, false, ) + .with_method( + "Filecoin.StateMinerPreCommitDepositForPower", + state_miner_pre_commit_deposit_for_power::, + false, + ) .with_method("Filecoin.StateReplay", state_replay::, false) .with_method( "Filecoin.StateGetActor", diff --git a/node/rpc/src/state_api.rs b/node/rpc/src/state_api.rs index 62b7e0b41acb..64cd5cd2540b 100644 --- a/node/rpc/src/state_api.rs +++ b/node/rpc/src/state_api.rs @@ -815,24 +815,14 @@ pub(crate) async fn state_miner_pre_commit_deposit_for_power< let actor = state .get_actor(market::ADDRESS)? .ok_or("couldnt load market actor")?; - let (w, vw) = match market::State::load(data.state_manager.blockstore(), &actor)? { - market::State::V0(s) => forest_actor_v0::market::validate_deals_for_activation( - &s, + let (w, vw) = market::State::load(data.state_manager.blockstore(), &actor)? + .validate_deals_for_activation( data.state_manager.blockstore(), &pci.deal_ids, &maddr, pci.expiration, ts.epoch(), - ), - market::State::V2(s) => forest_actor::market::validate_deals_for_activation( - &s, - data.state_manager.blockstore(), - &pci.deal_ids, - &maddr, - pci.expiration, - ts.epoch(), - ), - }?; + )?; let duration = pci.expiration - ts.epoch(); let sector_weight = forest_actor::miner::qa_power_for_weight(ssize, duration, &w, &vw); @@ -845,41 +835,21 @@ pub(crate) async fn state_miner_pre_commit_deposit_for_power< let reward_actor = state .get_actor(reward::ADDRESS)? .ok_or("couldnt load market actor")?; - match reward::State::load(data.state_manager.blockstore(), &reward_actor)? { - reward::State::V0(rs) => forest_actor_v0::miner::pre_commit_deposit_for_power( - &rs.this_epoch_reward_smoothed, - &power_smoothed, - §or_weight, - ), - reward::State::V2(rs) => forest_actor::miner::pre_commit_deposit_for_power( - &rs.this_epoch_reward_smoothed, - &power_smoothed, - §or_weight, - ), - } + reward::State::load(data.state_manager.blockstore(), &reward_actor)? + .pre_commit_deposit_for_power(power_smoothed.into(), §or_weight) } power::State::V2(s) => { let power_smoothed = s.this_epoch_qa_power_smoothed; let reward_actor = state .get_actor(reward::ADDRESS)? .ok_or("couldnt load market actor")?; - match reward::State::load(data.state_manager.blockstore(), &reward_actor)? { - reward::State::V0(rs) => forest_actor_v0::miner::pre_commit_deposit_for_power( - &rs.this_epoch_reward_smoothed, - &power_smoothed, - §or_weight, - ), - reward::State::V2(rs) => forest_actor::miner::pre_commit_deposit_for_power( - &rs.this_epoch_reward_smoothed, - &power_smoothed, - §or_weight, - ), - } + reward::State::load(data.state_manager.blockstore(), &reward_actor)? + .pre_commit_deposit_for_power(power_smoothed.into(), §or_weight) } }; // return types.BigDiv(types.BigMul(deposit, initialPledgeNum), initialPledgeDen), nil - let ret = (deposit * 110) / 100; + let ret: BigInt = (deposit * 110) / 100; Ok(ret.to_string()) } diff --git a/vm/actor/src/builtin/miner/policy.rs b/vm/actor/src/builtin/miner/policy.rs index 030f681b87b2..e0beb8f897d1 100644 --- a/vm/actor/src/builtin/miner/policy.rs +++ b/vm/actor/src/builtin/miner/policy.rs @@ -58,7 +58,10 @@ pub const SEALED_CID_PREFIX: cid::Prefix = cid::Prefix { /// List of proof types which can be used when creating new miner actors pub fn check_supported_proof_types(proof: RegisteredSealProof) -> bool { use RegisteredSealProof::*; - matches!(proof, StackedDRG32GiBV1 | StackedDRG64GiBV1) + matches!( + proof, + StackedDRG2KiBV1 | StackedDRG32GiBV1 | StackedDRG64GiBV1 + ) } /// Maximum duration to allow for the sealing process for seal algorithms. /// Dependent on algorithm and sector size diff --git a/vm/actor/src/builtin/power/policy.rs b/vm/actor/src/builtin/power/policy.rs index c24b0d0e8e5c..351376b11c2b 100644 --- a/vm/actor/src/builtin/power/policy.rs +++ b/vm/actor/src/builtin/power/policy.rs @@ -18,5 +18,5 @@ pub const MAX_MINER_PROVE_COMMITS_PER_EPOCH: u64 = 200; lazy_static! { // TODO: Might need to be able to override later on based on network params /// Minimum power of an individual miner to meet the threshold for leader election. - pub static ref CONSENSUS_MINER_MIN_POWER: StoragePower = StoragePower::from_i64(10 << 40).unwrap(); // placeholder + pub static ref CONSENSUS_MINER_MIN_POWER: StoragePower = StoragePower::from_i64(2048).unwrap(); // placeholder } diff --git a/vm/actor_interface/src/builtin/market/mod.rs b/vm/actor_interface/src/builtin/market/mod.rs index 5aa135233a95..2495b2634fee 100644 --- a/vm/actor_interface/src/builtin/market/mod.rs +++ b/vm/actor_interface/src/builtin/market/mod.rs @@ -6,7 +6,7 @@ use cid::Cid; use clock::ChainEpoch; use fil_types::PaddedPieceSize; use ipld_blockstore::BlockStore; -use num_bigint::bigint_ser; +use num_bigint::{bigint_ser, BigInt}; use serde::Serialize; use std::error::Error; use vm::{ActorState, TokenAmount}; @@ -125,6 +125,39 @@ impl State { State::V2(st) => st.total_locked(), } } + + /// Validates a collection of deal dealProposals for activation, and returns their combined weight, + /// split into regular deal weight and verified deal weight. + pub fn validate_deals_for_activation( + &self, + store: &BS, + deal_ids: &[u64], + miner_addr: &Address, + sector_expiry: ChainEpoch, + curr_epoch: ChainEpoch, + ) -> Result<(BigInt, BigInt), Box> + where + BS: BlockStore, + { + match self { + State::V0(st) => actorv0::market::validate_deals_for_activation( + &st, + store, + deal_ids, + miner_addr, + sector_expiry, + curr_epoch, + ), + State::V2(st) => actorv2::market::validate_deals_for_activation( + &st, + store, + deal_ids, + miner_addr, + sector_expiry, + curr_epoch, + ), + } + } } pub enum BalanceTable<'a, BS> { diff --git a/vm/actor_interface/src/builtin/miner/mod.rs b/vm/actor_interface/src/builtin/miner/mod.rs index 4ef94739bc86..d2abb5d5a320 100644 --- a/vm/actor_interface/src/builtin/miner/mod.rs +++ b/vm/actor_interface/src/builtin/miner/mod.rs @@ -10,7 +10,7 @@ use forest_bitfield::BitField; use ipld_blockstore::BlockStore; use libp2p::PeerId; use num_bigint::{bigint_ser, BigInt}; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::borrow::Cow; use std::error::Error; use vm::{ActorState, DealID, TokenAmount}; @@ -441,7 +441,7 @@ impl From for SectorPreCommitOnChain } } -#[derive(Serialize)] +#[derive(Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct SectorPreCommitInfo { pub seal_proof: RegisteredSealProof, diff --git a/vm/actor_interface/src/builtin/mod.rs b/vm/actor_interface/src/builtin/mod.rs index d06a1aa9ec6a..eb36b7b68def 100644 --- a/vm/actor_interface/src/builtin/mod.rs +++ b/vm/actor_interface/src/builtin/mod.rs @@ -12,6 +12,7 @@ pub mod reward; pub mod system; use cid::Cid; +use num_bigint::BigInt; pub const EPOCH_DURATION_SECONDS: clock::ChainEpoch = actorv0::EPOCH_DURATION_SECONDS; pub const EPOCHS_IN_DAY: clock::ChainEpoch = actorv0::EPOCHS_IN_DAY; @@ -36,3 +37,27 @@ pub fn is_account_actor(code: &Cid) -> bool { pub fn is_singleton_actor(code: &Cid) -> bool { actorv0::is_singleton_actor(code) || actorv2::is_singleton_actor(code) } + +#[derive(Default, Clone, Debug, PartialEq)] +pub struct FilterEstimate { + pub position: BigInt, + pub velocity: BigInt, +} + +impl From for FilterEstimate { + fn from(filter_est: actorv0::util::smooth::FilterEstimate) -> Self { + Self { + position: filter_est.position, + velocity: filter_est.velocity, + } + } +} + +impl From for FilterEstimate { + fn from(filter_est: actorv2::util::smooth::FilterEstimate) -> Self { + Self { + position: filter_est.position, + velocity: filter_est.velocity, + } + } +} diff --git a/vm/actor_interface/src/builtin/reward/mod.rs b/vm/actor_interface/src/builtin/reward/mod.rs index 1c278e2f3d4b..d978f8115754 100644 --- a/vm/actor_interface/src/builtin/reward/mod.rs +++ b/vm/actor_interface/src/builtin/reward/mod.rs @@ -1,11 +1,12 @@ // Copyright 2020 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT +use crate::FilterEstimate; use fil_types::StoragePower; use ipld_blockstore::BlockStore; use serde::Serialize; use std::error::Error; -use vm::ActorState; +use vm::{ActorState, TokenAmount}; /// Reward actor address. pub static ADDRESS: &actorv2::REWARD_ACTOR_ADDR = &actorv2::REWARD_ACTOR_ADDR; @@ -48,4 +49,29 @@ impl State { State::V2(st) => st.into_total_storage_power_reward(), } } + + pub fn pre_commit_deposit_for_power( + &self, + network_qa_power: FilterEstimate, + sector_weight: &StoragePower, + ) -> TokenAmount { + match self { + State::V0(st) => actorv0::miner::pre_commit_deposit_for_power( + &st.this_epoch_reward_smoothed, + &actorv0::util::smooth::FilterEstimate { + position: network_qa_power.position, + velocity: network_qa_power.velocity, + }, + sector_weight, + ), + State::V2(st) => actorv2::miner::pre_commit_deposit_for_power( + &st.this_epoch_reward_smoothed, + &actorv2::util::smooth::FilterEstimate { + position: network_qa_power.position, + velocity: network_qa_power.velocity, + }, + sector_weight, + ), + } + } } From 9a51158a540f0b5a771efa722a4bcba5716bc716 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Mon, 14 Dec 2020 15:02:30 -0500 Subject: [PATCH 08/18] fix sectorprecommitinfo json --- vm/actor_interface/src/builtin/miner/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vm/actor_interface/src/builtin/miner/mod.rs b/vm/actor_interface/src/builtin/miner/mod.rs index d2abb5d5a320..aea10a29b01e 100644 --- a/vm/actor_interface/src/builtin/miner/mod.rs +++ b/vm/actor_interface/src/builtin/miner/mod.rs @@ -447,9 +447,10 @@ pub struct SectorPreCommitInfo { pub seal_proof: RegisteredSealProof, pub sector_number: SectorNumber, /// CommR - #[serde(with = "cid::json")] + #[serde(with = "cid::json", rename="SealedCID")] pub sealed_cid: Cid, pub seal_rand_epoch: ChainEpoch, + #[serde(rename = "DealIDs")] pub deal_ids: Vec, pub expiration: ChainEpoch, /// Whether to replace a "committed capacity" no-deal sector (requires non-empty DealIDs) From da9c8016c306640d6f9ebb1728cfad1df3e5a255 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Tue, 15 Dec 2020 00:11:06 -0500 Subject: [PATCH 09/18] fix merge compile errors --- node/rpc/src/state_api.rs | 2 +- vm/actor_interface/src/builtin/market/mod.rs | 5 +++-- vm/actor_interface/src/builtin/miner/mod.rs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/node/rpc/src/state_api.rs b/node/rpc/src/state_api.rs index 64cd5cd2540b..158c59361855 100644 --- a/node/rpc/src/state_api.rs +++ b/node/rpc/src/state_api.rs @@ -816,7 +816,7 @@ pub(crate) async fn state_miner_pre_commit_deposit_for_power< .get_actor(market::ADDRESS)? .ok_or("couldnt load market actor")?; let (w, vw) = market::State::load(data.state_manager.blockstore(), &actor)? - .validate_deals_for_activation( + .verify_deals_for_activation( data.state_manager.blockstore(), &pci.deal_ids, &maddr, diff --git a/vm/actor_interface/src/builtin/market/mod.rs b/vm/actor_interface/src/builtin/market/mod.rs index 2495b2634fee..cd20044b2655 100644 --- a/vm/actor_interface/src/builtin/market/mod.rs +++ b/vm/actor_interface/src/builtin/market/mod.rs @@ -128,7 +128,7 @@ impl State { /// Validates a collection of deal dealProposals for activation, and returns their combined weight, /// split into regular deal weight and verified deal weight. - pub fn validate_deals_for_activation( + pub fn verify_deals_for_activation( &self, store: &BS, deal_ids: &[u64], @@ -155,7 +155,8 @@ impl State { miner_addr, sector_expiry, curr_epoch, - ), + ) + .map(|(deal_st, verified_st, _)| (deal_st, verified_st)), } } } diff --git a/vm/actor_interface/src/builtin/miner/mod.rs b/vm/actor_interface/src/builtin/miner/mod.rs index aea10a29b01e..d9cab5b0f3fc 100644 --- a/vm/actor_interface/src/builtin/miner/mod.rs +++ b/vm/actor_interface/src/builtin/miner/mod.rs @@ -447,7 +447,7 @@ pub struct SectorPreCommitInfo { pub seal_proof: RegisteredSealProof, pub sector_number: SectorNumber, /// CommR - #[serde(with = "cid::json", rename="SealedCID")] + #[serde(with = "cid::json", rename = "SealedCID")] pub sealed_cid: Cid, pub seal_rand_epoch: ChainEpoch, #[serde(rename = "DealIDs")] From 8775e390e7e776414bc470e42710263afe6e98be Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Tue, 15 Dec 2020 13:02:06 -0500 Subject: [PATCH 10/18] go through actor interface --- node/rpc/Cargo.toml | 3 --- node/rpc/src/state_api.rs | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/node/rpc/Cargo.toml b/node/rpc/Cargo.toml index aaf708048b26..1773f1672960 100644 --- a/node/rpc/Cargo.toml +++ b/node/rpc/Cargo.toml @@ -7,9 +7,6 @@ edition = "2018" [dependencies] ipld_amt = { path = "../../ipld/amt/" } actor = { package = "actor_interface", path = "../../vm/actor_interface" } -forest_actor = { path = "../../vm/actor" } -forest_actor_v0 = { package = "forest_actor", version = "0.1" } - bls-signatures = "0.6.1" async-std = { version = "1.6.3", features = ["attributes"] } serde = { version = "1.0.101", default-features = false, features = ["derive"] } diff --git a/node/rpc/src/state_api.rs b/node/rpc/src/state_api.rs index 158c59361855..641ed15674db 100644 --- a/node/rpc/src/state_api.rs +++ b/node/rpc/src/state_api.rs @@ -824,7 +824,7 @@ pub(crate) async fn state_miner_pre_commit_deposit_for_power< ts.epoch(), )?; let duration = pci.expiration - ts.epoch(); - let sector_weight = forest_actor::miner::qa_power_for_weight(ssize, duration, &w, &vw); + let sector_weight = actor::actorv2::miner::qa_power_for_weight(ssize, duration, &w, &vw); let actor = state .get_actor(power::ADDRESS)? From 289006c853590e40dd004c711155a1e16702a000 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Wed, 16 Dec 2020 20:08:16 -0500 Subject: [PATCH 11/18] fix get beacon params --- node/rpc/src/chain_api.rs | 2 +- node/rpc/src/mpool_api.rs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/node/rpc/src/chain_api.rs b/node/rpc/src/chain_api.rs index df90f27581f3..a2ef48ea85cf 100644 --- a/node/rpc/src/chain_api.rs +++ b/node/rpc/src/chain_api.rs @@ -283,7 +283,7 @@ where pub(crate) async fn chain_get_randomness_from_beacon( data: Data>, - Params(params): Params<(TipsetKeys, i64, ChainEpoch, String)>, + Params(params): Params<(TipsetKeysJson, i64, ChainEpoch, String)>, ) -> Result<[u8; 32], JsonRpcError> where DB: BlockStore + Send + Sync + 'static, diff --git a/node/rpc/src/mpool_api.rs b/node/rpc/src/mpool_api.rs index 9ed2f5f3a24b..64aea2cab57d 100644 --- a/node/rpc/src/mpool_api.rs +++ b/node/rpc/src/mpool_api.rs @@ -188,6 +188,8 @@ where if from.protocol() == Protocol::ID { umsg.from = key_addr; } + let nonce = data.mpool.get_sequence(&from).await?; + umsg.sequence = nonce; let key = wallet::find_key(&key_addr, &*keystore)?; let sig = wallet::sign( *key.key_info.key_type(), From fd3eb4c649a6f6f4377f5a864c424e1749787b44 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Wed, 16 Dec 2020 20:13:30 -0500 Subject: [PATCH 12/18] destructure it --- node/rpc/src/chain_api.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/rpc/src/chain_api.rs b/node/rpc/src/chain_api.rs index a2ef48ea85cf..e7d0e087c6e1 100644 --- a/node/rpc/src/chain_api.rs +++ b/node/rpc/src/chain_api.rs @@ -290,7 +290,7 @@ where KS: KeyStore + Send + Sync + 'static, B: Beacon + Send + Sync + 'static, { - let (tsk, pers, epoch, entropy) = params; + let (TipsetKeysJson(tsk), pers, epoch, entropy) = params; Ok(data .state_manager .chain_store() From 1f51ef9a33d5190d70ae248d170d29f3a9ba942c Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Wed, 16 Dec 2020 22:23:36 -0500 Subject: [PATCH 13/18] state_miner_initial_pledge_collateral --- blockchain/state_manager/src/lib.rs | 11 ++- node/rpc/src/lib.rs | 11 ++- node/rpc/src/state_api.rs | 88 ++++++++++++++++++-- vm/actor_interface/src/builtin/reward/mod.rs | 31 +++++++ 4 files changed, 130 insertions(+), 11 deletions(-) diff --git a/blockchain/state_manager/src/lib.rs b/blockchain/state_manager/src/lib.rs index be338a4c0dee..a9a286b767c8 100644 --- a/blockchain/state_manager/src/lib.rs +++ b/blockchain/state_manager/src/lib.rs @@ -33,8 +33,8 @@ use futures::channel::oneshot; use futures::select; use futures::stream::StreamExt; use futures::FutureExt; -use interpreter::LookbackStateGetter; use interpreter::{resolve_to_key_addr, ApplyRet, BlockMessages, Rand, VM}; +use interpreter::{CircSupplyCalc, LookbackStateGetter}; use ipld_amt::Amt; use lazycell::AtomicLazyCell; use log::{debug, info, trace, warn}; @@ -1189,6 +1189,15 @@ where } Ok(()) } + + /// Retrieves total circulating supply on the network. + pub fn get_circulating_supply( + self: &Arc, + height: ChainEpoch, + state_tree: &StateTree, + ) -> Result> { + self.genesis_info.get_supply(height, state_tree) + } } pub struct MiningBaseInfo { diff --git a/node/rpc/src/lib.rs b/node/rpc/src/lib.rs index 2df212914938..5a852a0b1ebc 100644 --- a/node/rpc/src/lib.rs +++ b/node/rpc/src/lib.rs @@ -253,20 +253,25 @@ where state_miner_pre_commit_deposit_for_power::, false, ) + .with_method( + "Filecoin.StateMinerInitialPledgeCollateral", + state_miner_initial_pledge_collateral::, + false, + ) .with_method("Filecoin.StateReplay", state_replay::, false) .with_method( "Filecoin.StateGetActor", - state_get_actor::, + state_get_actor::, false, ) .with_method( "Filecoin.StateAccountKey", - state_account_key::, + state_account_key::, false, ) .with_method( "Filecoin.StateLookupId", - state_lookup_id::, + state_lookup_id::, false, ) .with_method( diff --git a/node/rpc/src/state_api.rs b/node/rpc/src/state_api.rs index 641ed15674db..57e593d6979d 100644 --- a/node/rpc/src/state_api.rs +++ b/node/rpc/src/state_api.rs @@ -9,7 +9,6 @@ use actor::{ reward::{self}, }; use address::{json::AddressJson, Address}; -use async_std::task; use beacon::{json::BeaconEntryJson, Beacon, BeaconEntry}; use bitfield::json::BitFieldJson; use blocks::{ @@ -418,6 +417,7 @@ pub(crate) async fn state_get_actor< DB: BlockStore + Send + Sync + 'static, KS: KeyStore + Send + Sync + 'static, B: Beacon + Send + Sync + 'static, + V: ProofVerifier + Send + Sync + 'static, >( data: Data>, Params(params): Params<(AddressJson, TipsetKeysJson)>, @@ -430,7 +430,7 @@ pub(crate) async fn state_get_actor< .chain_store() .tipset_from_keys(&key.into()) .await?; - let state = state_for_ts(&state_manager, tipset).await?; + let state = state_for_ts::(&state_manager, tipset).await?; Ok(state.get_actor(&actor)?.map(ActorStateJson::from)) } @@ -458,6 +458,7 @@ pub(crate) async fn state_account_key< DB: BlockStore + Send + Sync + 'static, KS: KeyStore + Send + Sync + 'static, B: Beacon + Send + Sync + 'static, + V: ProofVerifier + Send + Sync + 'static, >( data: Data>, Params(params): Params<(AddressJson, TipsetKeysJson)>, @@ -470,7 +471,7 @@ pub(crate) async fn state_account_key< .chain_store() .tipset_from_keys(&key.into()) .await?; - let state = state_for_ts(&state_manager, tipset).await?; + let state = state_for_ts::(&state_manager, tipset).await?; let address = interpreter::resolve_to_key_addr(&state, state_manager.blockstore(), &actor)?; Ok(Some(address.into())) } @@ -479,6 +480,7 @@ pub(crate) async fn state_lookup_id< DB: BlockStore + Send + Sync + 'static, KS: KeyStore + Send + Sync + 'static, B: Beacon + Send + Sync + 'static, + V: ProofVerifier + Send + Sync + 'static, >( data: Data>, Params(params): Params<(AddressJson, TipsetKeysJson)>, @@ -491,7 +493,7 @@ pub(crate) async fn state_lookup_id< .chain_store() .tipset_from_keys(&key.into()) .await?; - let state = state_for_ts(&state_manager, tipset).await?; + let state = state_for_ts::(&state_manager, tipset).await?; state.lookup_id(&address).map_err(|e| e.into()) } @@ -848,21 +850,93 @@ pub(crate) async fn state_miner_pre_commit_deposit_for_power< } }; - // return types.BigDiv(types.BigMul(deposit, initialPledgeNum), initialPledgeDen), nil let ret: BigInt = (deposit * 110) / 100; Ok(ret.to_string()) } +pub(crate) async fn state_miner_initial_pledge_collateral< + DB: BlockStore + Send + Sync + 'static, + KS: KeyStore + Send + Sync + 'static, + B: Beacon + Send + Sync + 'static, + V: ProofVerifier + Send + Sync + 'static, +>( + data: Data>, + Params(params): Params<(AddressJson, SectorPreCommitInfo, TipsetKeysJson)>, +) -> Result { + let (AddressJson(maddr), pci, TipsetKeysJson(tsk)) = params; + let ts = data.chain_store.tipset_from_keys(&tsk).await?; + let (state, _) = data.state_manager.tipset_state::(&ts).await?; + let state = StateTree::new_from_root(data.chain_store.db.as_ref(), &state)?; + let ssize = pci.seal_proof.sector_size()?; + + let actor = state + .get_actor(market::ADDRESS)? + .ok_or("couldnt load market actor")?; + let (w, vw) = market::State::load(data.state_manager.blockstore(), &actor)? + .verify_deals_for_activation( + data.state_manager.blockstore(), + &pci.deal_ids, + &maddr, + pci.expiration, + ts.epoch(), + )?; + let duration = pci.expiration - ts.epoch(); + let sector_weight = actor::actorv2::miner::qa_power_for_weight(ssize, duration, &w, &vw); + + let actor = state + .get_actor(power::ADDRESS)? + .ok_or("couldnt load market actor")?; + let initial_pledge = match power::State::load(data.state_manager.blockstore(), &actor)? { + power::State::V0(s) => { + let power_smoothed = s.this_epoch_qa_power_smoothed; + let total_locked = s.total_pledge_collateral; + let reward_actor = state + .get_actor(reward::ADDRESS)? + .ok_or("couldnt load market actor")?; + let circ_supply = data + .state_manager + .get_circulating_supply(ts.epoch(), &state)?; + reward::State::load(data.state_manager.blockstore(), &reward_actor)? + .initial_pledge_for_power( + §or_weight, + &total_locked, + power_smoothed.into(), + &circ_supply, + ) + } + power::State::V2(s) => { + let power_smoothed = s.this_epoch_qa_power_smoothed; + let total_locked = s.total_pledge_collateral; + let reward_actor = state + .get_actor(reward::ADDRESS)? + .ok_or("couldnt load market actor")?; + let circ_supply = data + .state_manager + .get_circulating_supply(ts.epoch(), &state)?; + reward::State::load(data.state_manager.blockstore(), &reward_actor)? + .initial_pledge_for_power( + §or_weight, + &total_locked, + power_smoothed.into(), + &circ_supply, + ) + } + }; + let ret: BigInt = (initial_pledge * 110) / 100; + Ok(ret.to_string()) +} + /// returns a state tree given a tipset -async fn state_for_ts( +async fn state_for_ts( state_manager: &Arc>, ts: Arc, ) -> Result, JsonRpcError> where DB: BlockStore + Send + Sync + 'static, + V: ProofVerifier + Send + Sync + 'static, { let block_store = state_manager.blockstore(); - let (st, _) = task::block_on(state_manager.tipset_state::(&ts))?; + let (st, _) = state_manager.tipset_state::(&ts).await?; let state_tree = StateTree::new_from_root(block_store, &st)?; Ok(state_tree) } diff --git a/vm/actor_interface/src/builtin/reward/mod.rs b/vm/actor_interface/src/builtin/reward/mod.rs index d978f8115754..6dc8b876bb3b 100644 --- a/vm/actor_interface/src/builtin/reward/mod.rs +++ b/vm/actor_interface/src/builtin/reward/mod.rs @@ -74,4 +74,35 @@ impl State { ), } } + + pub fn initial_pledge_for_power( + &self, + sector_weight: &StoragePower, + _network_total_pledge: &TokenAmount, + network_qa_power: FilterEstimate, + circ_supply: &TokenAmount, + ) -> TokenAmount { + match self { + State::V0(st) => actorv0::miner::initial_pledge_for_power( + sector_weight, + &st.this_epoch_baseline_power, + &st.this_epoch_reward_smoothed, + &actorv0::util::smooth::FilterEstimate { + position: network_qa_power.position, + velocity: network_qa_power.velocity, + }, + circ_supply, + ), + State::V2(st) => actorv2::miner::initial_pledge_for_power( + sector_weight, + &st.this_epoch_baseline_power, + &st.this_epoch_reward_smoothed, + &actorv2::util::smooth::FilterEstimate { + position: network_qa_power.position, + velocity: network_qa_power.velocity, + }, + circ_supply, + ), + } + } } From aafaa7ad476fdd0f76786777befb2ae5c2f7e34a Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Thu, 17 Dec 2020 10:15:31 -0500 Subject: [PATCH 14/18] update go vec --- Cargo.lock | 15 ++++++++------- vm/actor_interface/Cargo.toml | 1 + vm/actor_interface/src/builtin/miner/mod.rs | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 79a00721afbb..7463508dea19 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,6 +24,7 @@ dependencies = [ "forest_cid 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "forest_encoding 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "forest_hash_utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "forest_json_utils 0.1.1", "forest_vm 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p", @@ -1964,7 +1965,7 @@ dependencies = [ "forest_bigint 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "forest_cid 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "forest_encoding 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "forest_json_utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "forest_json_utils 0.1.1", "forest_vm 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static", "num-derive", @@ -2220,7 +2221,7 @@ dependencies = [ "data-encoding", "data-encoding-macro", "forest_encoding 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "forest_json_utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "forest_json_utils 0.1.1", "leb128", "num-derive", "num-traits 0.2.14", @@ -2237,7 +2238,7 @@ dependencies = [ "data-encoding", "data-encoding-macro", "forest_encoding 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "forest_json_utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "forest_json_utils 0.1.1", "leb128", "num-derive", "num-traits 0.2.14", @@ -2362,7 +2363,7 @@ dependencies = [ "cid", "cs_serde_bytes", "cs_serde_cbor", - "forest_json_utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "forest_json_utils 0.1.1", "generic-array 0.14.4", "integer-encoding", "multibase 0.9.1", @@ -2509,9 +2510,9 @@ dependencies = [ [[package]] name = "forest_json_utils" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2bf972b7dade88cf8524249b2ae9d8e32b5d3ec7dbd3052abbcd1b8c2c29d62" +checksum = "0da39ba6848c04b22e70520a1339f04f304502a0ebfd4526ea8a566452ea62a8" dependencies = [ "serde", ] @@ -2584,7 +2585,7 @@ dependencies = [ "forest_cid 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "forest_crypto 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "forest_encoding 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "forest_json_utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "forest_json_utils 0.1.1", "forest_vm 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.14", "serde", diff --git a/vm/actor_interface/Cargo.toml b/vm/actor_interface/Cargo.toml index 7a6a27a54ae1..0d14d20a8680 100644 --- a/vm/actor_interface/Cargo.toml +++ b/vm/actor_interface/Cargo.toml @@ -19,6 +19,7 @@ libp2p = { version = "0.24", default-features = false } forest_bitfield = "0.1" num-bigint = { version = "0.1.1", package = "forest_bigint", features = ["json"] } forest_hash_utils = "0.1" +forest_json_utils = "0.1.1" [features] devnet = ["actorv0/devnet", "actorv2/devnet"] diff --git a/vm/actor_interface/src/builtin/miner/mod.rs b/vm/actor_interface/src/builtin/miner/mod.rs index d9cab5b0f3fc..06b19f6c64fb 100644 --- a/vm/actor_interface/src/builtin/miner/mod.rs +++ b/vm/actor_interface/src/builtin/miner/mod.rs @@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize}; use std::borrow::Cow; use std::error::Error; use vm::{ActorState, DealID, TokenAmount}; - +use forest_json_utils::go_vec_visitor; /// Miner actor method. pub type Method = actorv2::miner::Method; @@ -450,7 +450,7 @@ pub struct SectorPreCommitInfo { #[serde(with = "cid::json", rename = "SealedCID")] pub sealed_cid: Cid, pub seal_rand_epoch: ChainEpoch, - #[serde(rename = "DealIDs")] + #[serde(with = "go_vec_visitor", rename = "DealIDs")] pub deal_ids: Vec, pub expiration: ChainEpoch, /// Whether to replace a "committed capacity" no-deal sector (requires non-empty DealIDs) From 8f18f489db169ad1e9e2f41649363d148c28ef6b Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Thu, 17 Dec 2020 10:58:53 -0500 Subject: [PATCH 15/18] clippy --- vm/actor_interface/src/builtin/miner/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm/actor_interface/src/builtin/miner/mod.rs b/vm/actor_interface/src/builtin/miner/mod.rs index 06b19f6c64fb..bda4f6a76796 100644 --- a/vm/actor_interface/src/builtin/miner/mod.rs +++ b/vm/actor_interface/src/builtin/miner/mod.rs @@ -7,6 +7,7 @@ use clock::ChainEpoch; use encoding::BytesDe; use fil_types::{deadlines::DeadlineInfo, RegisteredSealProof, SectorNumber, SectorSize}; use forest_bitfield::BitField; +use forest_json_utils::go_vec_visitor; use ipld_blockstore::BlockStore; use libp2p::PeerId; use num_bigint::{bigint_ser, BigInt}; @@ -14,7 +15,6 @@ use serde::{Deserialize, Serialize}; use std::borrow::Cow; use std::error::Error; use vm::{ActorState, DealID, TokenAmount}; -use forest_json_utils::go_vec_visitor; /// Miner actor method. pub type Method = actorv2::miner::Method; From 4d2fd354a8e45fa207799ceca28e275ce7e6e8a4 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Thu, 17 Dec 2020 15:54:06 -0500 Subject: [PATCH 16/18] removed that enum match in the state api --- node/rpc/src/state_api.rs | 86 +++++++-------------- vm/actor_interface/src/builtin/power/mod.rs | 17 ++++ 2 files changed, 47 insertions(+), 56 deletions(-) diff --git a/node/rpc/src/state_api.rs b/node/rpc/src/state_api.rs index 57e593d6979d..31d47587da5a 100644 --- a/node/rpc/src/state_api.rs +++ b/node/rpc/src/state_api.rs @@ -830,25 +830,15 @@ pub(crate) async fn state_miner_pre_commit_deposit_for_power< let actor = state .get_actor(power::ADDRESS)? - .ok_or("couldnt load market actor")?; - let deposit = match power::State::load(data.state_manager.blockstore(), &actor)? { - power::State::V0(s) => { - let power_smoothed = s.this_epoch_qa_power_smoothed; - let reward_actor = state - .get_actor(reward::ADDRESS)? - .ok_or("couldnt load market actor")?; - reward::State::load(data.state_manager.blockstore(), &reward_actor)? - .pre_commit_deposit_for_power(power_smoothed.into(), §or_weight) - } - power::State::V2(s) => { - let power_smoothed = s.this_epoch_qa_power_smoothed; - let reward_actor = state - .get_actor(reward::ADDRESS)? - .ok_or("couldnt load market actor")?; - reward::State::load(data.state_manager.blockstore(), &reward_actor)? - .pre_commit_deposit_for_power(power_smoothed.into(), §or_weight) - } - }; + .ok_or("couldnt load power actor")?; + let power_smoothed = + power::State::load(data.state_manager.blockstore(), &actor)?.total_power_smoothed(); + + let reward_actor = state + .get_actor(reward::ADDRESS)? + .ok_or("couldnt load reward actor")?; + let deposit = reward::State::load(data.state_manager.blockstore(), &reward_actor)? + .pre_commit_deposit_for_power(power_smoothed, §or_weight); let ret: BigInt = (deposit * 110) / 100; Ok(ret.to_string()) @@ -885,43 +875,27 @@ pub(crate) async fn state_miner_initial_pledge_collateral< let actor = state .get_actor(power::ADDRESS)? - .ok_or("couldnt load market actor")?; - let initial_pledge = match power::State::load(data.state_manager.blockstore(), &actor)? { - power::State::V0(s) => { - let power_smoothed = s.this_epoch_qa_power_smoothed; - let total_locked = s.total_pledge_collateral; - let reward_actor = state - .get_actor(reward::ADDRESS)? - .ok_or("couldnt load market actor")?; - let circ_supply = data - .state_manager - .get_circulating_supply(ts.epoch(), &state)?; - reward::State::load(data.state_manager.blockstore(), &reward_actor)? - .initial_pledge_for_power( - §or_weight, - &total_locked, - power_smoothed.into(), - &circ_supply, - ) - } - power::State::V2(s) => { - let power_smoothed = s.this_epoch_qa_power_smoothed; - let total_locked = s.total_pledge_collateral; - let reward_actor = state - .get_actor(reward::ADDRESS)? - .ok_or("couldnt load market actor")?; - let circ_supply = data - .state_manager - .get_circulating_supply(ts.epoch(), &state)?; - reward::State::load(data.state_manager.blockstore(), &reward_actor)? - .initial_pledge_for_power( - §or_weight, - &total_locked, - power_smoothed.into(), - &circ_supply, - ) - } - }; + .ok_or("couldnt load power actor")?; + let power_state = power::State::load(data.state_manager.blockstore(), &actor)?; + let power_smoothed = power_state.total_power_smoothed(); + let total_locked = power_state.total_locked(); + + let circ_supply = data + .state_manager + .get_circulating_supply(ts.epoch(), &state)?; + + let reward_actor = state + .get_actor(reward::ADDRESS)? + .ok_or("couldnt load reward actor")?; + + let initial_pledge = reward::State::load(data.state_manager.blockstore(), &reward_actor)? + .initial_pledge_for_power( + §or_weight, + &total_locked, + power_smoothed.into(), + &circ_supply, + ); + let ret: BigInt = (initial_pledge * 110) / 100; Ok(ret.to_string()) } diff --git a/vm/actor_interface/src/builtin/power/mod.rs b/vm/actor_interface/src/builtin/power/mod.rs index a3bcd353371b..4d4048b3bdc2 100644 --- a/vm/actor_interface/src/builtin/power/mod.rs +++ b/vm/actor_interface/src/builtin/power/mod.rs @@ -1,6 +1,7 @@ // Copyright 2020 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT +use crate::FilterEstimate; use address::Address; use fil_types::StoragePower; use ipld_blockstore::BlockStore; @@ -122,6 +123,22 @@ impl State { State::V2(st) => st.miner_nominal_power_meets_consensus_minimum(s, miner), } } + + /// Returns this_epoch_qa_power_smoothed from the state. + pub fn total_power_smoothed(&self) -> FilterEstimate { + match self { + State::V0(st) => st.this_epoch_qa_power_smoothed.clone().into(), + State::V2(st) => st.this_epoch_qa_power_smoothed.clone().into(), + } + } + + /// Returns total locked funds + pub fn total_locked(&self) -> TokenAmount { + match self { + State::V0(st) => st.total_pledge_collateral.clone(), + State::V2(st) => st.total_pledge_collateral.clone(), + } + } } #[derive(Default, Debug, Serialize, Clone)] From 6208f6a0afd2a94cf625636822cb148af936b3bb Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Thu, 17 Dec 2020 16:16:15 -0500 Subject: [PATCH 17/18] clippy --- node/rpc/src/state_api.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/node/rpc/src/state_api.rs b/node/rpc/src/state_api.rs index 31d47587da5a..28f53c017194 100644 --- a/node/rpc/src/state_api.rs +++ b/node/rpc/src/state_api.rs @@ -889,12 +889,7 @@ pub(crate) async fn state_miner_initial_pledge_collateral< .ok_or("couldnt load reward actor")?; let initial_pledge = reward::State::load(data.state_manager.blockstore(), &reward_actor)? - .initial_pledge_for_power( - §or_weight, - &total_locked, - power_smoothed.into(), - &circ_supply, - ); + .initial_pledge_for_power(§or_weight, &total_locked, power_smoothed, &circ_supply); let ret: BigInt = (initial_pledge * 110) / 100; Ok(ret.to_string()) From fc07a09acf62b2336e71e8e10d08f386718bcbfe Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Thu, 17 Dec 2020 16:16:45 -0500 Subject: [PATCH 18/18] cargo lock --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index ebee51ba4985..1ae54e8be26f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,6 +24,7 @@ dependencies = [ "forest_cid 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "forest_encoding 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "forest_hash_utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "forest_json_utils 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "forest_vm 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "ipld_blockstore 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p",