From 473ad02340cb7f369fc98031712dfcfde3b4f5bb Mon Sep 17 00:00:00 2001 From: elmattic Date: Thu, 30 Nov 2023 16:45:38 +0100 Subject: [PATCH 1/7] Scaffold code for StateVMCirculatingSupplyInternal endpoint --- src/rpc/mod.rs | 4 ++++ src/rpc/state_api.rs | 13 +++++++++++-- src/rpc_api/data_types.rs | 19 +++++++++++++++++++ src/rpc_api/mod.rs | 2 ++ src/rpc_client/state_ops.rs | 9 ++++++++- 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/rpc/mod.rs b/src/rpc/mod.rs index 1ac18935d926..89cd21385e3f 100644 --- a/src/rpc/mod.rs +++ b/src/rpc/mod.rs @@ -134,6 +134,10 @@ where ) .with_method(STATE_READ_STATE, state_read_state::) .with_method(STATE_SECTOR_GET_INFO, state_sector_get_info::) + .with_method( + STATE_VM_CIRCULATING_SUPPLY_INTERNAL, + state_vm_circulating_supply_internal::, + ) // Gas API .with_method(GAS_ESTIMATE_FEE_CAP, gas_estimate_fee_cap::) .with_method(GAS_ESTIMATE_GAS_LIMIT, gas_estimate_gas_limit::) diff --git a/src/rpc/state_api.rs b/src/rpc/state_api.rs index 98c267869a4f..ca0329c023b4 100644 --- a/src/rpc/state_api.rs +++ b/src/rpc/state_api.rs @@ -7,8 +7,8 @@ use crate::cid_collections::CidHashSet; use crate::libp2p::NetworkMessage; use crate::lotus_json::LotusJson; use crate::rpc_api::data_types::{ - ApiActorState, ApiDeadline, ApiInvocResult, MarketDeal, MessageLookup, RPCState, - SectorOnChainInfo, + ApiActorState, ApiDeadline, ApiInvocResult, CirculatingSupply, MarketDeal, MessageLookup, + RPCState, SectorOnChainInfo, }; use crate::shim::{ address::Address, clock::ChainEpoch, executor::Receipt, message::Message, @@ -586,3 +586,12 @@ pub(in crate::rpc) async fn state_sector_get_info( + data: Data>, + Params(LotusJson((tsk,))): Params>, +) -> Result, JsonRpcError> { + todo!() +} diff --git a/src/rpc_api/data_types.rs b/src/rpc_api/data_types.rs index bcb5b570a147..82a351338aec 100644 --- a/src/rpc_api/data_types.rs +++ b/src/rpc_api/data_types.rs @@ -763,3 +763,22 @@ impl PartialEq for GasTrace { && self.storage_gas == other.storage_gas } } + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "PascalCase")] +pub struct CirculatingSupply { + #[serde(with = "crate::lotus_json")] + pub fil_vested: TokenAmount, + #[serde(with = "crate::lotus_json")] + pub fil_mined: TokenAmount, + #[serde(with = "crate::lotus_json")] + pub fil_burnt: TokenAmount, + #[serde(with = "crate::lotus_json")] + pub fil_locked: TokenAmount, + #[serde(with = "crate::lotus_json")] + pub fil_circulating: TokenAmount, + #[serde(with = "crate::lotus_json")] + pub fil_reserve_disbursed: TokenAmount, +} + +lotus_json_with_self!(CirculatingSupply); diff --git a/src/rpc_api/mod.rs b/src/rpc_api/mod.rs index 02df8b62282a..bcc12a18b863 100644 --- a/src/rpc_api/mod.rs +++ b/src/rpc_api/mod.rs @@ -257,6 +257,8 @@ pub mod state_api { pub const STATE_SECTOR_GET_INFO: &str = "Filecoin.StateSectorGetInfo"; pub const STATE_SEARCH_MSG: &str = "Filecoin.StateSearchMsg"; pub const STATE_SEARCH_MSG_LIMITED: &str = "Filecoin.StateSearchMsgLimited"; + pub const STATE_VM_CIRCULATING_SUPPLY_INTERNAL: &str = + "Filecoin.StateVMCirculatingSupplyInternal"; } /// Gas API diff --git a/src/rpc_client/state_ops.rs b/src/rpc_client/state_ops.rs index 50cfde6c522b..c8806b1fc663 100644 --- a/src/rpc_client/state_ops.rs +++ b/src/rpc_client/state_ops.rs @@ -7,7 +7,8 @@ use crate::{ blocks::TipsetKeys, rpc_api::{ data_types::{ - ApiActorState, ApiDeadline, ApiInvocResult, MessageLookup, SectorOnChainInfo, + ApiActorState, ApiDeadline, ApiInvocResult, CirculatingSupply, MessageLookup, + SectorOnChainInfo, }, state_api::*, }, @@ -134,6 +135,12 @@ impl ApiInfo { RpcRequest::new(STATE_CIRCULATING_SUPPLY, (tsk,)) } + pub fn state_vm_circulating_supply_internal_req( + tsk: TipsetKeys, + ) -> RpcRequest { + RpcRequest::new(STATE_VM_CIRCULATING_SUPPLY_INTERNAL, (tsk,)) + } + pub fn state_decode_params_req( recipient: Address, method_number: MethodNum, From 1c3e41069c1b7a7b0888bd7b9a7fecfd46184ddf Mon Sep 17 00:00:00 2001 From: elmattic Date: Thu, 30 Nov 2023 19:28:54 +0100 Subject: [PATCH 2/7] Finish endpoint implementation --- src/rpc/state_api.rs | 12 ++++++++-- src/rpc_api/data_types.rs | 2 +- src/rpc_api/mod.rs | 4 ++++ src/state_manager/mod.rs | 35 ++++++++++++++++++++++++++++- src/state_manager/vm_circ_supply.rs | 20 ++++++++++------- src/tool/subcommands/api_cmd.rs | 3 +++ 6 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/rpc/state_api.rs b/src/rpc/state_api.rs index ca0329c023b4..cf8300b6c91f 100644 --- a/src/rpc/state_api.rs +++ b/src/rpc/state_api.rs @@ -12,7 +12,7 @@ use crate::rpc_api::data_types::{ }; use crate::shim::{ address::Address, clock::ChainEpoch, executor::Receipt, message::Message, - state_tree::ActorState, version::NetworkVersion, + state_tree::ActorState, state_tree::StateTree, version::NetworkVersion, }; use crate::state_manager::chain_rand::ChainRand; use crate::state_manager::{InvocResult, MarketBalance}; @@ -593,5 +593,13 @@ pub(in crate::rpc) async fn state_vm_circulating_supply_internal< data: Data>, Params(LotusJson((tsk,))): Params>, ) -> Result, JsonRpcError> { - todo!() + let ts = data.chain_store.load_required_tipset(&tsk)?; + + let state_tree = + StateTree::new_from_root(data.state_manager.blockstore_owned(), ts.parent_state())?; + + Ok(LotusJson( + data.state_manager + .get_vm_circulating_supply_detailed(ts.epoch(), &state_tree)?, + )) } diff --git a/src/rpc_api/data_types.rs b/src/rpc_api/data_types.rs index 82a351338aec..aa94c9b78861 100644 --- a/src/rpc_api/data_types.rs +++ b/src/rpc_api/data_types.rs @@ -764,7 +764,7 @@ impl PartialEq for GasTrace { } } -#[derive(Debug, Clone, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] pub struct CirculatingSupply { #[serde(with = "crate::lotus_json")] diff --git a/src/rpc_api/mod.rs b/src/rpc_api/mod.rs index bcc12a18b863..6dede748b0ed 100644 --- a/src/rpc_api/mod.rs +++ b/src/rpc_api/mod.rs @@ -96,6 +96,10 @@ pub static ACCESS_MAP: Lazy> = Lazy::new(|| { access.insert(state_api::STATE_GET_RANDOMNESS_FROM_BEACON, Access::Read); access.insert(state_api::STATE_READ_STATE, Access::Read); access.insert(state_api::STATE_SECTOR_GET_INFO, Access::Read); + access.insert( + state_api::STATE_VM_CIRCULATING_SUPPLY_INTERNAL, + Access::Read, + ); // Gas API access.insert(gas_api::GAS_ESTIMATE_GAS_LIMIT, Access::Read); diff --git a/src/state_manager/mod.rs b/src/state_manager/mod.rs index 991f3ed99880..b92084a70685 100644 --- a/src/state_manager/mod.rs +++ b/src/state_manager/mod.rs @@ -25,7 +25,7 @@ use crate::interpreter::{ }; use crate::message::{ChainMessage, Message as MessageTrait}; use crate::networks::ChainConfig; -use crate::rpc_api::data_types::{ApiInvocResult, MessageGasCost}; +use crate::rpc_api::data_types::{ApiInvocResult, CirculatingSupply, MessageGasCost}; use crate::shim::{ address::{Address, Payload, Protocol, BLS_PUB_LEN}, clock::ChainEpoch, @@ -35,6 +35,9 @@ use crate::shim::{ state_tree::{ActorState, StateTree}, version::NetworkVersion, }; +use crate::state_manager::vm_circ_supply::{ + get_fil_burnt, get_fil_locked, get_fil_mined, get_fil_reserve_disbursed, get_fil_vested, +}; use ahash::{HashMap, HashMapExt}; use chain_rand::ChainRand; use cid::Cid; @@ -367,6 +370,36 @@ where state.load_sectors(self.blockstore(), None) } + + pub fn get_vm_circulating_supply_detailed( + self: &Arc, + height: ChainEpoch, + state_tree: &StateTree, + ) -> anyhow::Result { + let genesis_info = GenesisInfo::from_chain_config(self.chain_config()); + + let fil_vested = get_fil_vested(&genesis_info, height); + let fil_mined = get_fil_mined(state_tree)?; + let fil_burnt = get_fil_burnt(state_tree)?; + let fil_locked = get_fil_locked(state_tree)?; + let fil_reserve_disbursed = if height > genesis_info.actors_v2_height { + get_fil_reserve_disbursed(state_tree)? + } else { + TokenAmount::default() + }; + let fil_circulating = TokenAmount::max( + &fil_vested + &fil_mined + &fil_reserve_disbursed - &fil_burnt - &fil_locked, + TokenAmount::default(), + ); + Ok(CirculatingSupply { + fil_vested, + fil_mined, + fil_burnt, + fil_locked, + fil_circulating, + fil_reserve_disbursed, + }) + } } impl StateManager diff --git a/src/state_manager/vm_circ_supply.rs b/src/state_manager/vm_circ_supply.rs index f9ae8e5bffd6..49246c87137b 100644 --- a/src/state_manager/vm_circ_supply.rs +++ b/src/state_manager/vm_circ_supply.rs @@ -45,7 +45,7 @@ pub(in crate::state_manager) struct GenesisInfo { /// Heights epoch ignition_height: ChainEpoch, - actors_v2_height: ChainEpoch, + pub actors_v2_height: ChainEpoch, calico_height: ChainEpoch, } @@ -118,7 +118,7 @@ fn get_actor_state( .with_context(|| format!("Failed to get Actor for address {addr}")) } -fn get_fil_vested(genesis_info: &GenesisInfo, height: ChainEpoch) -> TokenAmount { +pub fn get_fil_vested(genesis_info: &GenesisInfo, height: ChainEpoch) -> TokenAmount { let mut return_value = TokenAmount::default(); let pre_ignition = &genesis_info.vesting.genesis; @@ -149,7 +149,9 @@ fn get_fil_vested(genesis_info: &GenesisInfo, height: ChainEpoch) -> TokenAmount return_value } -fn get_fil_mined(state_tree: &StateTree) -> Result { +pub fn get_fil_mined( + state_tree: &StateTree, +) -> Result { let actor = state_tree .get_actor(&Address::REWARD_ACTOR)? .context("Reward actor address could not be resolved")?; @@ -158,7 +160,7 @@ fn get_fil_mined(state_tree: &StateTree) -> Result( +pub fn get_fil_market_locked( state_tree: &StateTree, ) -> Result { let actor = state_tree @@ -169,7 +171,7 @@ fn get_fil_market_locked( Ok(state.total_locked().into()) } -fn get_fil_power_locked( +pub fn get_fil_power_locked( state_tree: &StateTree, ) -> Result { let actor = state_tree @@ -180,7 +182,7 @@ fn get_fil_power_locked( Ok(state.into_total_locked().into()) } -fn get_fil_reserve_disbursed( +pub fn get_fil_reserve_disbursed( state_tree: &StateTree, ) -> Result { let fil_reserved: TokenAmount = TokenAmount::from_whole(300_000_000); @@ -190,7 +192,7 @@ fn get_fil_reserve_disbursed( Ok(TokenAmount::from(&*fil_reserved - &reserve_actor.balance)) } -fn get_fil_locked( +pub fn get_fil_locked( state_tree: &StateTree, ) -> Result { let market_locked = get_fil_market_locked(state_tree)?; @@ -198,7 +200,9 @@ fn get_fil_locked( Ok(power_locked + market_locked) } -fn get_fil_burnt(state_tree: &StateTree) -> Result { +pub fn get_fil_burnt( + state_tree: &StateTree, +) -> Result { let burnt_actor = get_actor_state(state_tree, &Address::BURNT_FUNDS_ACTOR)?; Ok(TokenAmount::from(&burnt_actor.balance)) diff --git a/src/tool/subcommands/api_cmd.rs b/src/tool/subcommands/api_cmd.rs index 98400ff0b739..f0d9afd662c6 100644 --- a/src/tool/subcommands/api_cmd.rs +++ b/src/tool/subcommands/api_cmd.rs @@ -440,6 +440,9 @@ fn snapshot_tests(store: &ManyCar, n_tipsets: usize) -> anyhow::Result Date: Fri, 1 Dec 2023 10:18:38 +0100 Subject: [PATCH 3/7] Move get_vm_circulating_supply_detailed to GenesisInfo --- src/rpc/state_api.rs | 13 ++++---- src/state_manager/mod.rs | 39 ++-------------------- src/state_manager/vm_circ_supply.rs | 52 ++++++++++++++++++++++------- 3 files changed, 50 insertions(+), 54 deletions(-) diff --git a/src/rpc/state_api.rs b/src/rpc/state_api.rs index cf8300b6c91f..4d1e76d845a2 100644 --- a/src/rpc/state_api.rs +++ b/src/rpc/state_api.rs @@ -15,6 +15,7 @@ use crate::shim::{ state_tree::ActorState, state_tree::StateTree, version::NetworkVersion, }; use crate::state_manager::chain_rand::ChainRand; +use crate::state_manager::vm_circ_supply::GenesisInfo; use crate::state_manager::{InvocResult, MarketBalance}; use crate::utils::db::car_stream::{CarBlock, CarWriter}; use ahash::{HashMap, HashMapExt}; @@ -595,11 +596,11 @@ pub(in crate::rpc) async fn state_vm_circulating_supply_internal< ) -> Result, JsonRpcError> { let ts = data.chain_store.load_required_tipset(&tsk)?; - let state_tree = - StateTree::new_from_root(data.state_manager.blockstore_owned(), ts.parent_state())?; + let genesis_info = GenesisInfo::from_chain_config(data.state_manager.chain_config()); - Ok(LotusJson( - data.state_manager - .get_vm_circulating_supply_detailed(ts.epoch(), &state_tree)?, - )) + Ok(LotusJson(genesis_info.get_vm_circulating_supply_detailed( + ts.epoch(), + &data.state_manager.blockstore_owned(), + ts.parent_state(), + )?)) } diff --git a/src/state_manager/mod.rs b/src/state_manager/mod.rs index 2d1500369f5d..026f0005e04e 100644 --- a/src/state_manager/mod.rs +++ b/src/state_manager/mod.rs @@ -12,7 +12,7 @@ use anyhow::{bail, Context as _}; use fil_actor_interface::init::{self, State}; use rayon::prelude::ParallelBridge; pub use utils::is_valid_for_sending; -mod vm_circ_supply; +pub mod vm_circ_supply; pub use self::errors::*; use crate::beacon::BeaconSchedule; use crate::blocks::{Tipset, TipsetKeys}; @@ -26,7 +26,7 @@ use crate::interpreter::{ }; use crate::message::{ChainMessage, Message as MessageTrait}; use crate::networks::ChainConfig; -use crate::rpc_api::data_types::{ApiInvocResult, CirculatingSupply, MessageGasCost}; +use crate::rpc_api::data_types::{ApiInvocResult, MessageGasCost}; use crate::shim::{ address::{Address, Payload, Protocol, BLS_PUB_LEN}, clock::ChainEpoch, @@ -36,9 +36,7 @@ use crate::shim::{ state_tree::{ActorState, StateTree}, version::NetworkVersion, }; -use crate::state_manager::vm_circ_supply::{ - get_fil_burnt, get_fil_locked, get_fil_mined, get_fil_reserve_disbursed, get_fil_vested, -}; +use crate::state_manager::vm_circ_supply::GenesisInfo; use ahash::{HashMap, HashMapExt}; use chain_rand::ChainRand; use cid::Cid; @@ -63,7 +61,6 @@ use std::{num::NonZeroUsize, sync::Arc}; use tokio::sync::{broadcast::error::RecvError, Mutex as TokioMutex, RwLock}; use tracing::{debug, error, info, instrument, warn}; use utils::structured; -use vm_circ_supply::GenesisInfo; const DEFAULT_TIPSET_CACHE_SIZE: NonZeroUsize = nonzero!(1024usize); @@ -371,36 +368,6 @@ where state.load_sectors(self.blockstore(), None) } - - pub fn get_vm_circulating_supply_detailed( - self: &Arc, - height: ChainEpoch, - state_tree: &StateTree, - ) -> anyhow::Result { - let genesis_info = GenesisInfo::from_chain_config(self.chain_config()); - - let fil_vested = get_fil_vested(&genesis_info, height); - let fil_mined = get_fil_mined(state_tree)?; - let fil_burnt = get_fil_burnt(state_tree)?; - let fil_locked = get_fil_locked(state_tree)?; - let fil_reserve_disbursed = if height > genesis_info.actors_v2_height { - get_fil_reserve_disbursed(state_tree)? - } else { - TokenAmount::default() - }; - let fil_circulating = TokenAmount::max( - &fil_vested + &fil_mined + &fil_reserve_disbursed - &fil_burnt - &fil_locked, - TokenAmount::default(), - ); - Ok(CirculatingSupply { - fil_vested, - fil_mined, - fil_burnt, - fil_locked, - fil_circulating, - fil_reserve_disbursed, - }) - } } impl StateManager diff --git a/src/state_manager/vm_circ_supply.rs b/src/state_manager/vm_circ_supply.rs index 49246c87137b..146488fa8657 100644 --- a/src/state_manager/vm_circ_supply.rs +++ b/src/state_manager/vm_circ_supply.rs @@ -5,6 +5,7 @@ use std::sync::Arc; use crate::chain::*; use crate::networks::{ChainConfig, Height}; +use crate::rpc_api::data_types::CirculatingSupply; use crate::shim::{ address::Address, clock::{ChainEpoch, EPOCHS_IN_DAY}, @@ -36,7 +37,7 @@ const CALICO_VESTING: [(ChainEpoch, usize); 6] = [ /// Genesis information used when calculating circulating supply. #[derive(Default, Clone)] -pub(in crate::state_manager) struct GenesisInfo { +pub struct GenesisInfo { vesting: GenesisInfoVesting, /// info about the Accounts in the genesis state @@ -88,6 +89,37 @@ impl GenesisInfo { Ok(fil_circulating) } + + pub fn get_vm_circulating_supply_detailed( + &self, + height: ChainEpoch, + db: &Arc, + root: &Cid, + ) -> anyhow::Result { + let state_tree = StateTree::new_from_root(Arc::clone(db), root)?; + + let fil_vested = get_fil_vested(self, height); + let fil_mined = get_fil_mined(&state_tree)?; + let fil_burnt = get_fil_burnt(&state_tree)?; + let fil_locked = get_fil_locked(&state_tree)?; + let fil_reserve_disbursed = if height > self.actors_v2_height { + get_fil_reserve_disbursed(&state_tree)? + } else { + TokenAmount::default() + }; + let fil_circulating = TokenAmount::max( + &fil_vested + &fil_mined + &fil_reserve_disbursed - &fil_burnt - &fil_locked, + TokenAmount::default(), + ); + Ok(CirculatingSupply { + fil_vested, + fil_mined, + fil_burnt, + fil_locked, + fil_circulating, + fil_reserve_disbursed, + }) + } } /// Vesting schedule info. These states are lazily filled, to avoid doing until @@ -118,7 +150,7 @@ fn get_actor_state( .with_context(|| format!("Failed to get Actor for address {addr}")) } -pub fn get_fil_vested(genesis_info: &GenesisInfo, height: ChainEpoch) -> TokenAmount { +fn get_fil_vested(genesis_info: &GenesisInfo, height: ChainEpoch) -> TokenAmount { let mut return_value = TokenAmount::default(); let pre_ignition = &genesis_info.vesting.genesis; @@ -149,9 +181,7 @@ pub fn get_fil_vested(genesis_info: &GenesisInfo, height: ChainEpoch) -> TokenAm return_value } -pub fn get_fil_mined( - state_tree: &StateTree, -) -> Result { +fn get_fil_mined(state_tree: &StateTree) -> Result { let actor = state_tree .get_actor(&Address::REWARD_ACTOR)? .context("Reward actor address could not be resolved")?; @@ -160,7 +190,7 @@ pub fn get_fil_mined( Ok(state.into_total_storage_power_reward().into()) } -pub fn get_fil_market_locked( +fn get_fil_market_locked( state_tree: &StateTree, ) -> Result { let actor = state_tree @@ -171,7 +201,7 @@ pub fn get_fil_market_locked( Ok(state.total_locked().into()) } -pub fn get_fil_power_locked( +fn get_fil_power_locked( state_tree: &StateTree, ) -> Result { let actor = state_tree @@ -182,7 +212,7 @@ pub fn get_fil_power_locked( Ok(state.into_total_locked().into()) } -pub fn get_fil_reserve_disbursed( +fn get_fil_reserve_disbursed( state_tree: &StateTree, ) -> Result { let fil_reserved: TokenAmount = TokenAmount::from_whole(300_000_000); @@ -192,7 +222,7 @@ pub fn get_fil_reserve_disbursed( Ok(TokenAmount::from(&*fil_reserved - &reserve_actor.balance)) } -pub fn get_fil_locked( +fn get_fil_locked( state_tree: &StateTree, ) -> Result { let market_locked = get_fil_market_locked(state_tree)?; @@ -200,9 +230,7 @@ pub fn get_fil_locked( Ok(power_locked + market_locked) } -pub fn get_fil_burnt( - state_tree: &StateTree, -) -> Result { +fn get_fil_burnt(state_tree: &StateTree) -> Result { let burnt_actor = get_actor_state(state_tree, &Address::BURNT_FUNDS_ACTOR)?; Ok(TokenAmount::from(&burnt_actor.balance)) From 77f1bdb4ad1c8998dd5b556cbd65d71067ca82b9 Mon Sep 17 00:00:00 2001 From: elmattic Date: Fri, 1 Dec 2023 10:22:23 +0100 Subject: [PATCH 4/7] Cleanup --- src/rpc/state_api.rs | 2 +- src/state_manager/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/state_api.rs b/src/rpc/state_api.rs index 4d1e76d845a2..e344e241134d 100644 --- a/src/rpc/state_api.rs +++ b/src/rpc/state_api.rs @@ -12,7 +12,7 @@ use crate::rpc_api::data_types::{ }; use crate::shim::{ address::Address, clock::ChainEpoch, executor::Receipt, message::Message, - state_tree::ActorState, state_tree::StateTree, version::NetworkVersion, + state_tree::ActorState, version::NetworkVersion, }; use crate::state_manager::chain_rand::ChainRand; use crate::state_manager::vm_circ_supply::GenesisInfo; diff --git a/src/state_manager/mod.rs b/src/state_manager/mod.rs index 026f0005e04e..d98d8217e50e 100644 --- a/src/state_manager/mod.rs +++ b/src/state_manager/mod.rs @@ -36,10 +36,10 @@ use crate::shim::{ state_tree::{ActorState, StateTree}, version::NetworkVersion, }; -use crate::state_manager::vm_circ_supply::GenesisInfo; use ahash::{HashMap, HashMapExt}; use chain_rand::ChainRand; use cid::Cid; +use vm_circ_supply::GenesisInfo; use fil_actor_interface::miner::SectorOnChainInfo; use fil_actor_interface::miner::{MinerInfo, MinerPower}; From af29853d6ed074a83c956469ffa4ecf4db73c98d Mon Sep 17 00:00:00 2001 From: elmattic Date: Fri, 1 Dec 2023 10:23:55 +0100 Subject: [PATCH 5/7] Move back to previous pos --- src/state_manager/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/state_manager/mod.rs b/src/state_manager/mod.rs index d98d8217e50e..0ff2fba3b02b 100644 --- a/src/state_manager/mod.rs +++ b/src/state_manager/mod.rs @@ -39,7 +39,6 @@ use crate::shim::{ use ahash::{HashMap, HashMapExt}; use chain_rand::ChainRand; use cid::Cid; -use vm_circ_supply::GenesisInfo; use fil_actor_interface::miner::SectorOnChainInfo; use fil_actor_interface::miner::{MinerInfo, MinerPower}; @@ -61,6 +60,7 @@ use std::{num::NonZeroUsize, sync::Arc}; use tokio::sync::{broadcast::error::RecvError, Mutex as TokioMutex, RwLock}; use tracing::{debug, error, info, instrument, warn}; use utils::structured; +use vm_circ_supply::GenesisInfo; const DEFAULT_TIPSET_CACHE_SIZE: NonZeroUsize = nonzero!(1024usize); From 7e57b201fa0676eac073dd8ea1df7cd0e67e3977 Mon Sep 17 00:00:00 2001 From: elmattic Date: Fri, 1 Dec 2023 10:28:44 +0100 Subject: [PATCH 6/7] Avoid code duplication --- src/state_manager/vm_circ_supply.rs | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/state_manager/vm_circ_supply.rs b/src/state_manager/vm_circ_supply.rs index 146488fa8657..626e26997ac1 100644 --- a/src/state_manager/vm_circ_supply.rs +++ b/src/state_manager/vm_circ_supply.rs @@ -46,7 +46,7 @@ pub struct GenesisInfo { /// Heights epoch ignition_height: ChainEpoch, - pub actors_v2_height: ChainEpoch, + actors_v2_height: ChainEpoch, calico_height: ChainEpoch, } @@ -72,22 +72,9 @@ impl GenesisInfo { db: &Arc, root: &Cid, ) -> Result { - let state_tree = StateTree::new_from_root(Arc::clone(db), root)?; - let fil_vested = get_fil_vested(self, height); - let fil_mined = get_fil_mined(&state_tree)?; - let fil_burnt = get_fil_burnt(&state_tree)?; - let fil_locked = get_fil_locked(&state_tree)?; - let fil_reserve_distributed = if height > self.actors_v2_height { - get_fil_reserve_disbursed(&state_tree)? - } else { - TokenAmount::default() - }; - let fil_circulating = TokenAmount::max( - &fil_vested + &fil_mined + &fil_reserve_distributed - &fil_burnt - &fil_locked, - TokenAmount::default(), - ); + let detailed = self.get_vm_circulating_supply_detailed(height, db, root)?; - Ok(fil_circulating) + Ok(detailed.fil_circulating) } pub fn get_vm_circulating_supply_detailed( From f6278a1195646f8931a7e8bce294dcb3b7443a4b Mon Sep 17 00:00:00 2001 From: elmattic Date: Fri, 1 Dec 2023 10:40:02 +0100 Subject: [PATCH 7/7] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12ccc2e510b0..16188f3bdabf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ ### Added +- [#3773](https://github.com/ChainSafe/forest/pull/3773) Implement the + `Filecoin.StateVMCirculatingSupplyInternal` lotus-compatible RPC API. - [#3748](https://github.com/ChainSafe/forest/pull/3748) Add timing for each message and gas charge in the JSON output of `forest-tool snapshot compute-state` and `Filecoin.StateCall` RPC API.