Skip to content

Commit fee02eb

Browse files
committed
changelog
1 parent b99bc19 commit fee02eb

4 files changed

Lines changed: 49 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737

3838
- [#5867](https://github.com/ChainSafe/forest/pull/5867) Added `--unordered` to `forest-cli snapshot export` for exporting `CAR` blocks in non-deterministic order for better performance with more parallelization.
3939

40+
- [#5946](https://github.com/ChainSafe/forest/pull/5946) Added `--n-epochs` to `forest-cli state compute` for computating state trees in batch.
41+
42+
- [#5946](https://github.com/ChainSafe/forest/pull/5946) Added `--verbose` to `forest-cli state compute` for printing epochs and tipset keys along with state roots.
43+
4044
- [#5886](https://github.com/ChainSafe/forest/issues/5886) Add `forest-tool archive merge-f3` subcommand for merging a v1 Filecoin snapshot and an F3 snapshot into a v2 Filecoin snapshot.
4145

4246
- [#4976](https://github.com/ChainSafe/forest/issues/4976) Add support for the `Filecoin.EthSubscribe` and `Filecoin.EthUnsubscribe` API methods to enable subscriptions to Ethereum event types: `heads` and `logs`.

src/cli/subcommands/state_cmd.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0, MIT
33

44
use crate::lotus_json::HasLotusJson;
5-
use crate::rpc::state::ForestStateCompute;
5+
use crate::rpc::state::{ForestComputeStateOutput, ForestStateCompute};
66
use crate::rpc::{self, prelude::*};
77
use crate::shim::address::{CurrentNetwork, Error, Network, StrictAddress};
88
use crate::shim::clock::ChainEpoch;
@@ -21,13 +21,17 @@ pub enum StateCommands {
2121
#[arg(short, long)]
2222
save_to_file: Option<PathBuf>,
2323
},
24+
/// Compute state trees for epochs
2425
Compute {
2526
/// Which epoch to compute the state transition for
2627
#[arg(long)]
2728
epoch: ChainEpoch,
2829
/// Number of tipset epochs to compute state for. Default is 1
2930
#[arg(short, long)]
3031
n_epochs: Option<NonZeroUsize>,
32+
/// Print epoch and tipset key along with state root
33+
#[arg(short, long)]
34+
verbose: bool,
3135
},
3236
/// Read the state of an actor
3337
ReadState {
@@ -47,14 +51,27 @@ impl StateCommands {
4751
.await?;
4852
println!("{ret}");
4953
}
50-
StateCommands::Compute { epoch, n_epochs } => {
51-
let state_roots = client
54+
StateCommands::Compute {
55+
epoch,
56+
n_epochs,
57+
verbose,
58+
} => {
59+
let results = client
5260
.call(
5361
ForestStateCompute::request((epoch, n_epochs))?.with_timeout(Duration::MAX),
5462
)
5563
.await?;
56-
for state_root in state_roots {
57-
println!("{state_root}");
64+
for ForestComputeStateOutput {
65+
state_root,
66+
epoch,
67+
tipset_key,
68+
} in results
69+
{
70+
if verbose {
71+
println!("{state_root} (epoch: {epoch}, tipset key: {tipset_key})");
72+
} else {
73+
println!("{state_root}");
74+
}
5875
}
5976
}
6077
Self::ReadState { actor_address } => {

src/rpc/methods/state.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ impl RpcMethod<2> for ForestStateCompute {
14291429
const PERMISSION: Permission = Permission::Read;
14301430

14311431
type Params = (ChainEpoch, Option<NonZeroUsize>);
1432-
type Ok = Vec<Cid>;
1432+
type Ok = Vec<ForestComputeStateOutput>;
14331433

14341434
async fn handle(
14351435
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
@@ -1470,13 +1470,18 @@ impl RpcMethod<2> for ForestStateCompute {
14701470

14711471
let mut results = vec![];
14721472
while let Some(Ok(ts)) = futures.next().await {
1473+
let epoch = ts.epoch();
1474+
let tipset_key = ts.key().clone();
14731475
let StateOutput { state_root, .. } = ctx
14741476
.state_manager
14751477
.compute_tipset_state(ts, crate::state_manager::NO_CALLBACK, VMTrace::NotTraced)
14761478
.await?;
1477-
results.push(state_root);
1479+
results.push(ForestComputeStateOutput {
1480+
state_root,
1481+
epoch,
1482+
tipset_key,
1483+
});
14781484
}
1479-
14801485
Ok(results)
14811486
}
14821487
}

src/rpc/methods/state/types.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2019-2025 ChainSafe Systems
22
// SPDX-License-Identifier: Apache-2.0, MIT
33

4+
use crate::blocks::TipsetKey;
45
use crate::lotus_json::{LotusJson, lotus_json_with_self};
56
use crate::message::Message as _;
67
use crate::shim::executor::ApplyRet;
@@ -32,6 +33,20 @@ pub struct ComputeStateOutput {
3233

3334
lotus_json_with_self!(ComputeStateOutput);
3435

36+
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, PartialEq)]
37+
#[serde(rename_all = "PascalCase")]
38+
pub struct ForestComputeStateOutput {
39+
#[schemars(with = "LotusJson<Cid>")]
40+
#[serde(with = "crate::lotus_json")]
41+
pub state_root: Cid,
42+
pub epoch: ChainEpoch,
43+
#[schemars(with = "LotusJson<TipsetKey>")]
44+
#[serde(with = "crate::lotus_json")]
45+
pub tipset_key: TipsetKey,
46+
}
47+
48+
lotus_json_with_self!(ForestComputeStateOutput);
49+
3550
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema)]
3651
#[serde(rename_all = "PascalCase")]
3752
pub struct ApiInvocResult {

0 commit comments

Comments
 (0)