Skip to content
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
18 changes: 1 addition & 17 deletions src/cli/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2019-2026 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use super::subcommands::Subcommand;
use crate::cli::subcommands::Cli;
use crate::cli_shared::logger;
use crate::networks::NetworkChain;
Expand Down Expand Up @@ -31,20 +30,5 @@ where

let (_bg_tasks, _guards) = logger::setup_logger(&crate::cli_shared::cli::CliOpts::default());

// Run command
match cmd {
Subcommand::Chain(cmd) => cmd.run(client).await,
Subcommand::Auth(cmd) => cmd.run(client).await,
Subcommand::Net(cmd) => cmd.run(client).await,
Subcommand::Sync(cmd) => cmd.run(client).await,
Subcommand::Mpool(cmd) => cmd.run(client).await,
Subcommand::State(cmd) => cmd.run(client).await,
Subcommand::Config(cmd) => cmd.run(&mut std::io::stdout()),
Subcommand::Info(cmd) => cmd.run(client).await,
Subcommand::Snapshot(cmd) => cmd.run(client).await,
Subcommand::Shutdown(cmd) => cmd.run(client).await,
Subcommand::Healthcheck(cmd) => cmd.run(client).await,
Subcommand::F3(cmd) => cmd.run(client).await,
Subcommand::WaitApi(cmd) => cmd.run(client).await,
}
cmd.run(client).await
}
10 changes: 7 additions & 3 deletions src/cli/subcommands/config_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::io::Write;
use anyhow::Context as _;
use clap::Subcommand;

use crate::cli::subcommands::Config;
use crate::{cli::subcommands::Config, rpc};

#[derive(Debug, Subcommand)]
pub enum ConfigCommands {
Expand All @@ -15,7 +15,11 @@ pub enum ConfigCommands {
}

impl ConfigCommands {
pub fn run<W: Write + Unpin>(self, sink: &mut W) -> anyhow::Result<()> {
pub async fn run(self, _: rpc::Client) -> anyhow::Result<()> {
self.run_internal(&mut std::io::stdout())
}

fn run_internal<W: Write + Unpin>(self, sink: &mut W) -> anyhow::Result<()> {
match self {
Self::Dump => writeln!(
sink,
Expand All @@ -37,7 +41,7 @@ mod tests {
let expected_config = Config::default();
let mut sink = std::io::BufWriter::new(Vec::new());

ConfigCommands::Dump.run(&mut sink).unwrap();
ConfigCommands::Dump.run_internal(&mut sink).unwrap();

let actual_config: Config = toml::from_str(std::str::from_utf8(sink.buffer()).unwrap())
.expect("Invalid configuration!");
Expand Down
21 changes: 14 additions & 7 deletions src/cli/subcommands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ mod state_cmd;
mod sync_cmd;
mod wait_api_cmd;

pub(crate) use crate::cli_shared::cli::Config;
use crate::cli_shared::cli::HELP_MESSAGE;
use crate::lotus_json::HasLotusJson;
use crate::utils::version::FOREST_VERSION_STRING;
use clap::Parser;
use tracing::error;

pub(super) use self::{
auth_cmd::AuthCommands, chain_cmd::ChainCommands, config_cmd::ConfigCommands,
f3_cmd::F3Commands, healthcheck_cmd::HealthcheckCommand, mpool_cmd::MpoolCommands,
net_cmd::NetCommands, shutdown_cmd::ShutdownCommand, snapshot_cmd::SnapshotCommands,
state_cmd::StateCommands, sync_cmd::SyncCommands, wait_api_cmd::WaitApiCommand,
};
use crate::cli::subcommands::info_cmd::InfoCommand;
pub(crate) use crate::cli_shared::cli::Config;
use crate::cli_shared::cli::HELP_MESSAGE;
use crate::lotus_json::HasLotusJson;
use crate::utils::version::FOREST_VERSION_STRING;
use clap::Parser;
use spire_enum::prelude::delegated_enum;
use tracing::error;

/// CLI structure generated when interacting with Forest binary
#[derive(Parser)]
Expand All @@ -49,6 +49,7 @@ pub struct Cli {
}

/// Forest binary sub-commands available.
#[delegated_enum]
#[derive(clap::Subcommand, Debug)]
pub enum Subcommand {
/// Interact with Filecoin blockchain
Expand Down Expand Up @@ -102,6 +103,12 @@ pub enum Subcommand {
WaitApi(WaitApiCommand),
}

impl Subcommand {
pub async fn run(self, client: crate::rpc::Client) -> anyhow::Result<()> {
delegate_subcommand!(self.run(client).await)
}
}

/// Print an error message and exit the program with an error code
/// Used for handling high level errors such as invalid parameters
pub fn cli_error_and_die(msg: impl AsRef<str>, code: i32) -> ! {
Expand Down
22 changes: 12 additions & 10 deletions src/networks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::sync::LazyLock;

use ahash::HashMap;
use cid::Cid;
use fil_actors_shared::v13::runtime::Policy;
use fvm_ipld_blockstore::Blockstore;
use itertools::Itertools;
use libp2p::Multiaddr;
Expand All @@ -20,11 +19,14 @@ use tracing::warn;
use crate::beacon::{BeaconPoint, BeaconSchedule, DrandBeacon, DrandConfig};
use crate::db::SettingsStore;
use crate::eth::EthChainId;
use crate::shim::clock::{ChainEpoch, EPOCH_DURATION_SECONDS, EPOCHS_IN_DAY};
use crate::shim::econ::TokenAmount;
use crate::shim::machine::BuiltinActorManifest;
use crate::shim::sector::{RegisteredPoStProofV3, RegisteredSealProofV3};
use crate::shim::version::NetworkVersion;
use crate::shim::{
clock::{ChainEpoch, EPOCH_DURATION_SECONDS, EPOCHS_IN_DAY},
econ::TokenAmount,
machine::BuiltinActorManifest,
runtime::Policy,
sector::{RegisteredPoStProofV3, RegisteredSealProofV3},
version::NetworkVersion,
};
use crate::utils::misc::env::env_or_default;
use crate::{make_butterfly_policy, make_calibnet_policy, make_devnet_policy, make_mainnet_policy};

Expand Down Expand Up @@ -297,7 +299,7 @@ impl ChainConfig {
propagation_delay_secs: env_or_default(ENV_FOREST_PROPAGATION_DELAY_SECS, 10),
genesis_network: GENESIS_NETWORK_VERSION,
height_infos: HEIGHT_INFOS.clone(),
policy: make_mainnet_policy!(v13),
policy: make_mainnet_policy!(v13).into(),
eth_chain_id: ETH_CHAIN_ID,
breeze_gas_tamping_duration: BREEZE_GAS_TAMPING_DURATION,
// 1 year on mainnet
Expand Down Expand Up @@ -331,7 +333,7 @@ impl ChainConfig {
propagation_delay_secs: env_or_default(ENV_FOREST_PROPAGATION_DELAY_SECS, 10),
genesis_network: GENESIS_NETWORK_VERSION,
height_infos: HEIGHT_INFOS.clone(),
policy: make_calibnet_policy!(v13),
policy: make_calibnet_policy!(v13).into(),
eth_chain_id: ETH_CHAIN_ID,
breeze_gas_tamping_duration: BREEZE_GAS_TAMPING_DURATION,
// 3 days on calibnet
Expand Down Expand Up @@ -365,7 +367,7 @@ impl ChainConfig {
propagation_delay_secs: env_or_default(ENV_FOREST_PROPAGATION_DELAY_SECS, 1),
genesis_network: *GENESIS_NETWORK_VERSION,
height_infos: HEIGHT_INFOS.clone(),
policy: make_devnet_policy!(v13),
policy: make_devnet_policy!(v13).into(),
eth_chain_id: ETH_CHAIN_ID,
breeze_gas_tamping_duration: BREEZE_GAS_TAMPING_DURATION,
// Devnet ramp is 200 epochs in Lotus (subject to change).
Expand Down Expand Up @@ -395,7 +397,7 @@ impl ChainConfig {
propagation_delay_secs: env_or_default(ENV_FOREST_PROPAGATION_DELAY_SECS, 6),
genesis_network: GENESIS_NETWORK_VERSION,
height_infos: HEIGHT_INFOS.clone(),
policy: make_butterfly_policy!(v13),
policy: make_butterfly_policy!(v13).into(),
eth_chain_id: ETH_CHAIN_ID,
breeze_gas_tamping_duration: BREEZE_GAS_TAMPING_DURATION,
// Butterflynet ramp is current set to 365 days in Lotus but this may change.
Expand Down
76 changes: 14 additions & 62 deletions src/rpc/methods/f3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@ pub use self::types::{
};
use self::{types::*, util::*};
use super::wallet::WalletSign;
use crate::shim::actors::{
convert::{
from_policy_v13_to_v9, from_policy_v13_to_v10, from_policy_v13_to_v11,
from_policy_v13_to_v12, from_policy_v13_to_v14, from_policy_v13_to_v15,
from_policy_v13_to_v16, from_policy_v13_to_v17,
},
miner, power,
};
use crate::shim::actors::{miner, power};
use crate::{
blocks::Tipset,
chain::index::ResolveNullTipset,
Expand Down Expand Up @@ -216,6 +209,7 @@ impl GetPowerTable {

let state: power::State = ctx.state_manager.get_actor_state(ts)?;
let mut id_power_worker_mappings = vec![];
let policy = &ctx.chain_config().policy;
match &state {
power::State::V8(s) => {
fn map_err<E: Display>(e: E) -> fil_actors_shared::v8::ActorError {
Expand All @@ -234,7 +228,7 @@ impl GetPowerTable {

let id = miner.id().map_err(map_err)?;
let ok = s.miner_nominal_power_meets_consensus_minimum(
&from_policy_v13_to_v9(&ctx.chain_config().policy),
&policy.into(),
&db,
&miner.into(),
)?;
Expand Down Expand Up @@ -277,7 +271,7 @@ impl GetPowerTable {

let id = miner.id().map_err(map_err)?;
let ok = s.miner_nominal_power_meets_consensus_minimum(
&from_policy_v13_to_v9(&ctx.chain_config().policy),
&policy.into(),
&db,
&miner.into(),
)?;
Expand Down Expand Up @@ -319,11 +313,8 @@ impl GetPowerTable {
}

let id = miner.id().map_err(map_err)?;
let (_, ok) = s.miner_nominal_power_meets_consensus_minimum(
&from_policy_v13_to_v10(&ctx.chain_config().policy),
&db,
id,
)?;
let (_, ok) =
s.miner_nominal_power_meets_consensus_minimum(&policy.into(), &db, id)?;
if !ok {
return Ok(());
}
Expand Down Expand Up @@ -362,11 +353,8 @@ impl GetPowerTable {
}

let id = miner.id().map_err(map_err)?;
let (_, ok) = s.miner_nominal_power_meets_consensus_minimum(
&from_policy_v13_to_v11(&ctx.chain_config().policy),
&db,
id,
)?;
let (_, ok) =
s.miner_nominal_power_meets_consensus_minimum(&policy.into(), &db, id)?;
if !ok {
return Ok(());
}
Expand All @@ -390,58 +378,22 @@ impl GetPowerTable {
})?;
}
power::State::V12(s) => {
handle_miner_state_v12_on!(
v12,
id_power_worker_mappings,
&ts,
s,
&from_policy_v13_to_v12(&ctx.chain_config().policy)
);
handle_miner_state_v12_on!(v12, id_power_worker_mappings, &ts, s, &policy.into());
}
power::State::V13(s) => {
handle_miner_state_v12_on!(
v13,
id_power_worker_mappings,
&ts,
s,
&ctx.chain_config().policy
);
handle_miner_state_v12_on!(v13, id_power_worker_mappings, &ts, s, &policy.into());
}
power::State::V14(s) => {
handle_miner_state_v12_on!(
v14,
id_power_worker_mappings,
&ts,
s,
&from_policy_v13_to_v14(&ctx.chain_config().policy)
);
handle_miner_state_v12_on!(v14, id_power_worker_mappings, &ts, s, &policy.into());
}
power::State::V15(s) => {
handle_miner_state_v12_on!(
v15,
id_power_worker_mappings,
&ts,
s,
&from_policy_v13_to_v15(&ctx.chain_config().policy)
);
handle_miner_state_v12_on!(v15, id_power_worker_mappings, &ts, s, &policy.into());
}
power::State::V16(s) => {
handle_miner_state_v12_on!(
v16,
id_power_worker_mappings,
&ts,
s,
&from_policy_v13_to_v16(&ctx.chain_config().policy)
);
handle_miner_state_v12_on!(v16, id_power_worker_mappings, &ts, s, &policy.into());
}
power::State::V17(s) => {
handle_miner_state_v12_on!(
v17,
id_power_worker_mappings,
&ts,
s,
&from_policy_v13_to_v17(&ctx.chain_config().policy)
);
handle_miner_state_v12_on!(v17, id_power_worker_mappings, &ts, s, &policy.into());
}
}
let mut power_entries = vec![];
Expand Down
17 changes: 8 additions & 9 deletions src/rpc/methods/msig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::rpc::types::*;
use crate::rpc::{ApiPaths, Ctx, Permission, RpcMethod};
use crate::shim::actors::MultisigActorStateLoad as _;
use crate::shim::actors::multisig;
use crate::shim::actors::multisig::ext::MultisigExt;
use crate::shim::{address::Address, econ::TokenAmount};
use enumflags2::BitFlags;
use fvm_ipld_blockstore::Blockstore;
Expand Down Expand Up @@ -35,7 +34,7 @@ impl RpcMethod<2> for MsigGetAvailableBalance {
.get_required_actor(&address, *ts.parent_state())?;
let actor_balance = TokenAmount::from(&actor.balance);
let ms = multisig::State::load(ctx.store(), actor.code, actor.state)?;
let locked_balance: TokenAmount = ms.locked_balance(height)?.into();
let locked_balance = ms.locked_balance(height)?;
let avail_balance = &actor_balance - locked_balance;
Ok(avail_balance)
}
Expand All @@ -62,14 +61,14 @@ impl RpcMethod<2> for MsigGetPending {
.get_actor_state_from_address(&ts, &address)?;
let txns = ms
.get_pending_txn(ctx.store())?
.iter()
.into_iter()
.map(|txn| Transaction {
id: txn.id,
to: txn.to.into(),
value: txn.value.clone().into(),
to: txn.to,
value: txn.value,
method: txn.method,
params: txn.params.clone(),
approved: txn.approved.iter().map(|item| item.into()).collect(),
params: txn.params,
approved: txn.approved,
})
.collect();
Ok(txns)
Expand Down Expand Up @@ -107,8 +106,8 @@ impl RpcMethod<3> for MsigGetVested {
let ms: multisig::State = ctx
.state_manager
.get_actor_state_from_address(&end_ts, &addr)?;
let start_lb: TokenAmount = ms.locked_balance(start_ts.epoch())?.into();
let end_lb: TokenAmount = ms.locked_balance(end_ts.epoch())?.into();
let start_lb = ms.locked_balance(start_ts.epoch())?;
let end_lb = ms.locked_balance(end_ts.epoch())?;
Ok(start_lb.atto() - end_lb.atto())
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/rpc/methods/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ use crate::shim::actors::{
power, reward, verifreg,
};
use crate::shim::actors::{
market::ext::BalanceTableExt as _,
miner::ext::{MinerStateExt as _, PartitionExt as _},
market::ext::BalanceTableExt as _, miner::ext::MinerStateExt as _,
power::ext::PowerStateExt as _,
};
use crate::shim::address::Payload;
Expand Down Expand Up @@ -274,7 +273,7 @@ impl RpcMethod<2> for StateVerifierStatus {
let ts = ctx.chain_store().load_required_tipset_or_heaviest(&tsk)?;
let aid = ctx.state_manager.lookup_required_id(&address, &ts)?;
let verifreg_state: verifreg::State = ctx.state_manager.get_actor_state(&ts)?;
Ok(verifreg_state.verifier_data_cap(ctx.store(), aid.into())?)
Ok(verifreg_state.verifier_data_cap(ctx.store(), aid)?)
}
}

Expand Down
1 change: 0 additions & 1 deletion src/shim/actors/builtin/account/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2019-2026 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use super::super::convert::{from_address_v3_to_v2, from_address_v4_to_v2};
use crate::shim::{self, address::Address};
use serde::Serialize;
use spire_enum::prelude::delegated_enum;
Expand Down
Loading
Loading