Skip to content

Commit

Permalink
[Enhcancement] get_state_circulating_supply. (#4157)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruseinov authored Apr 8, 2024
1 parent c46d82a commit c0ddd42
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/rpc/state_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::shim::{
state_tree::ActorState, version::NetworkVersion,
};
use crate::state_manager::chain_rand::ChainRand;
use crate::state_manager::vm_circ_supply::GenesisInfo;
use crate::state_manager::circulating_supply::GenesisInfo;
use crate::state_manager::{InvocResult, MarketBalance};
use crate::utils::db::car_stream::{CarBlock, CarWriter};
use ahash::{HashMap, HashMapExt};
Expand Down Expand Up @@ -864,8 +864,11 @@ pub async fn state_circulating_supply<DB: Blockstore + Send + Sync + 'static>(

let genesis_info = GenesisInfo::from_chain_config(state_manager.chain_config());

let supply =
genesis_info.get_circulating_supply(height, &state_manager.blockstore_owned(), root)?;
let supply = genesis_info.get_state_circulating_supply(
height,
&state_manager.blockstore_owned(),
root,
)?;

Ok(LotusJson(supply))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ impl GenesisInfo {
}
}

// Allows generation of the current circulating supply
/// Calculate total FIL circulating supply based on Genesis configuration and state of particular
/// actors at a given height and state root.
///
/// IMPORTANT: Easy to mistake for [`GenesisInfo::get_state_circulating_supply`], that's being
/// calculated differently.
pub fn get_vm_circulating_supply<DB: Blockstore>(
&self,
height: ChainEpoch,
Expand All @@ -81,6 +85,8 @@ impl GenesisInfo {
Ok(detailed.fil_circulating)
}

/// Calculate total FIL circulating supply based on Genesis configuration and state of particular
/// actors at a given height and state root.
pub fn get_vm_circulating_supply_detailed<DB: Blockstore>(
&self,
height: ChainEpoch,
Expand Down Expand Up @@ -112,8 +118,12 @@ impl GenesisInfo {
})
}

// This can be a lengthy operation
pub fn get_circulating_supply<DB: Blockstore>(
/// Calculate total FIL circulating supply based on state, traversing the state tree and
/// checking Actor types. This can be a lengthy operation.
///
/// IMPORTANT: Easy to mistake for [`GenesisInfo::get_vm_circulating_supply`], that's being
/// calculated differently.
pub fn get_state_circulating_supply<DB: Blockstore>(
&self,
height: ChainEpoch,
db: &Arc<DB>,
Expand Down
4 changes: 2 additions & 2 deletions src/state_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// SPDX-License-Identifier: Apache-2.0, MIT

pub mod chain_rand;
pub mod circulating_supply;
mod errors;
mod metrics;
pub mod utils;
pub mod vm_circ_supply;
pub use self::errors::*;
use self::utils::structured;

Expand Down Expand Up @@ -42,6 +42,7 @@ use anyhow::{bail, Context as _};
use bls_signatures::{PublicKey as BlsPublicKey, Serialize as _};
use chain_rand::ChainRand;
use cid::Cid;
pub use circulating_supply::GenesisInfo;
use fil_actor_interface::init::{self, State};
use fil_actor_interface::miner::SectorOnChainInfo;
use fil_actor_interface::miner::{MinerInfo, MinerPower, Partition};
Expand All @@ -67,7 +68,6 @@ use std::{num::NonZeroUsize, sync::Arc};
use tokio::sync::{broadcast::error::RecvError, Mutex as TokioMutex, RwLock};
use tracing::{debug, error, info, instrument, warn};
pub use utils::is_valid_for_sending;
pub use vm_circ_supply::GenesisInfo;

const DEFAULT_TIPSET_CACHE_SIZE: NonZeroUsize = nonzero!(1024usize);

Expand Down

0 comments on commit c0ddd42

Please sign in to comment.