Skip to content

feat(rpc): Filecoin.StateCompute #5488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 1, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
### Added

- [#5461](https://github.com/ChainSafe/forest/pull/5461) Add `forest-tool shed migrate-state` command.
- [#5488](https://github.com/ChainSafe/forest/pull/5488) Add partial support for the `Filecoin.StateCompute` RPC method.

### Changed

Expand Down
1 change: 1 addition & 0 deletions docs/docs/users/guides/methods_filtering.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,5 @@ If you are running a public RPC node, it is recommended to filter certain method
# Potentially resource-intensive.
!Filecoin.EthCall
!eth_call
!Filecoin.StateCompute
```
2 changes: 1 addition & 1 deletion src/blocks/tipset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ mod lotus_json {

use super::TipsetKey;

#[derive(Clone, JsonSchema)]
#[derive(Debug, PartialEq, Clone, JsonSchema)]
#[schemars(rename = "Tipset")]
pub struct TipsetLotusJson(#[schemars(with = "TipsetLotusJsonInner")] Tipset);

Expand Down
4 changes: 2 additions & 2 deletions src/cli/subcommands/state_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::path::PathBuf;
use std::time::Duration;

use crate::rpc::state::StateCompute;
use crate::rpc::state::ForestStateCompute;
use crate::rpc::{self, prelude::*};
use crate::shim::clock::ChainEpoch;
use crate::shim::econ::TokenAmount;
Expand Down Expand Up @@ -51,7 +51,7 @@ impl StateCommands {
}
StateCommands::Compute { epoch } => {
let ret = client
.call(StateCompute::request((epoch,))?.with_timeout(Duration::MAX))
.call(ForestStateCompute::request((epoch,))?.with_timeout(Duration::MAX))
.await?;
println!("{ret}");
}
Expand Down
2 changes: 1 addition & 1 deletion src/interpreter/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ where
) -> ApplyBlockResult {
let mut receipts = Vec::new();
let mut events = Vec::new();
let mut processed = HashSet::<Cid>::default();
let mut processed = HashSet::default();

for block in messages.iter() {
let mut penalty = TokenAmount::zero();
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/actor_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;
use crate::shim::{address::Address, econ::TokenAmount, state_tree::ActorState};
use ::cid::Cid;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "ActorState")]
pub struct ActorStateLotusJson {
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use super::*;
use crate::shim::address::Address;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "Address")]
pub struct AddressLotusJson(
#[schemars(with = "String")]
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use fvm_shared4::clock::ChainEpoch;
use fvm_shared4::piece::PaddedPieceSize;
use fvm_shared4::ActorID;

#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "Allocation")]
pub struct AllocationLotusJson {
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/beacon_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::beacon::BeaconEntry;

use super::*;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "BeaconEntry")]
pub struct BeaconEntryLotusJson {
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/big_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;

use num::BigInt;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "BigInt")]
pub struct BigIntLotusJson(
#[schemars(with = "String")]
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/bit_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;

use fil_actors_shared::fvm_ipld_bitfield::{json::BitFieldJson, BitField};

#[derive(Serialize, Deserialize, JsonSchema)]
#[derive(Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "BitField")]
pub struct BitFieldLotusJson(#[schemars(with = "Option<Vec<u8>>")] pub BitFieldJson);

Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/block_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use serde::{Deserialize, Serialize};

use crate::blocks::{CachingBlockHeader, RawBlockHeader};

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "BlockHeader")]
pub struct BlockHeaderLotusJson {
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/cid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use super::*;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
#[schemars(rename = "Cid")]
pub struct CidLotusJson {
#[schemars(with = "String")]
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/key_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;

use crate::{key_management::KeyInfo, shim::crypto::SignatureType};

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "KeyInfo")]
pub struct KeyInfoLotusJson {
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::*;
use crate::shim::{address::Address, econ::TokenAmount, message::Message};
use fvm_ipld_encoding::RawBytes;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "Message")]
pub struct MessageLotusJson {
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/miner_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use fil_actor_miner_state::v12::{BeneficiaryTerm, PendingBeneficiaryChange};
use fvm_ipld_encoding::BytesDe;
use libp2p::PeerId;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "MinerInfo")]
pub struct MinerInfoLotusJson {
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/miner_power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;
use crate::shim::actors::miner::MinerPower;
use crate::shim::actors::power::Claim;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "MinerPower")]
pub struct MinerPowerLotusJson {
Expand Down
23 changes: 6 additions & 17 deletions src/lotus_json/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use fvm_ipld_encoding::RawBytes;
use super::*;
use crate::shim::executor::Receipt;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "Receipt")]
pub struct ReceiptLotusJson {
Expand Down Expand Up @@ -98,7 +98,6 @@ fn shapshots() {
///
/// See <https://github.com/ChainSafe/forest/issues/3459>.
#[test]
#[should_panic = "cannot serialize to v2 AND v3 from the same input"]
fn cannot_call_arbitrary_tests_on_receipt() {
use pretty_assertions::assert_eq;

Expand Down Expand Up @@ -130,19 +129,9 @@ fn cannot_call_arbitrary_tests_on_receipt() {
json
);

// both of these cannot pass at the same time...
assert_eq!(
v2,
serde_json::from_value::<LotusJson<_>>(json.clone())
.unwrap()
.into_inner(),
"cannot serialize to v2 AND v3 from the same input"
);
assert_eq!(
v3,
serde_json::from_value::<LotusJson<_>>(json)
.unwrap()
.into_inner(),
"cannot serialize to v2 AND v3 from the same input"
);
let deserialized = serde_json::from_value::<LotusJson<Receipt>>(json)
.unwrap()
.into_inner();
assert!(matches!(deserialized, Receipt::V3(_)));
assert_eq!(v3, deserialized);
}
2 changes: 1 addition & 1 deletion src/lotus_json/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use super::*;
use crate::shim::crypto::{Signature, SignatureType};

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "Signature")]
pub struct SignatureLotusJson {
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/signed_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ::cid::Cid;

use super::*;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "PascalCase")]
#[schemars(rename = "SignedMessage")]
pub struct SignedMessageLotusJson {
Expand Down
2 changes: 1 addition & 1 deletion src/lotus_json/token_amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::*;
use crate::shim::econ::TokenAmount;
use num::BigInt;

#[derive(Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(transparent)] // name the field for clarity
#[schemars(rename = "TokenAmount")]
pub struct TokenAmountLotusJson {
Expand Down
4 changes: 2 additions & 2 deletions src/lotus_json/vec_u8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use schemars::schema::*;
// This code looks odd so we can
// - use #[serde(with = "...")]
// - de/ser empty vecs as null
#[derive(Clone, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct VecU8LotusJson(Option<Inner>);

impl JsonSchema for VecU8LotusJson {
Expand All @@ -26,7 +26,7 @@ impl JsonSchema for VecU8LotusJson {
}
}

#[derive(Clone, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
struct Inner(#[serde(with = "base64_standard")] Vec<u8>);

impl HasLotusJson for Vec<u8> {
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/methods/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ fn load_api_messages_from_tipset(
Ok(messages)
}

#[derive(Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct BlockMessages {
#[serde(rename = "BlsMessages", with = "crate::lotus_json")]
#[schemars(with = "LotusJson<Vec<Message>>")]
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/methods/chain/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct ObjStat {
}
lotus_json_with_self!(ObjStat);

#[derive(Serialize, Deserialize, JsonSchema, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct Event {
/// Actor ID
Expand Down
25 changes: 22 additions & 3 deletions src/rpc/methods/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,32 @@ impl ExtBlockNumberOrHash {
}
}

#[derive(PartialEq, Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(untagged)] // try a Vec<String>, then a Vec<Tx>
pub enum Transactions {
Hash(Vec<String>),
Full(Vec<ApiEthTx>),
}

impl Transactions {
pub fn is_empty(&self) -> bool {
match self {
Self::Hash(v) => v.is_empty(),
Self::Full(v) => v.is_empty(),
}
}
}

impl PartialEq for Transactions {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Hash(a), Self::Hash(b)) => a == b,
(Self::Full(a), Self::Full(b)) => a == b,
_ => self.is_empty() && other.is_empty(),
}
}
}

impl Default for Transactions {
fn default() -> Self {
Self::Hash(vec![])
Expand Down Expand Up @@ -516,15 +535,15 @@ impl ApiEthTx {
}
}

#[derive(Debug, Clone, Default)]
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct EthSyncingResult {
pub done_sync: bool,
pub starting_block: i64,
pub current_block: i64,
pub highest_block: i64,
}

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(untagged)]
pub enum EthSyncingResultLotusJson {
DoneSync(bool),
Expand Down
23 changes: 22 additions & 1 deletion src/rpc/methods/eth/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ lotus_json_with_self!(EthFilterSpec);
/// - A list of block hashes
/// - A list of transaction hashes
/// - Or a list of logs
#[derive(PartialEq, Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(untagged)]
pub enum EthFilterResult {
Blocks(Vec<EthHash>),
Expand All @@ -502,6 +502,27 @@ pub enum EthFilterResult {
}
lotus_json_with_self!(EthFilterResult);

impl EthFilterResult {
pub fn is_empty(&self) -> bool {
match self {
Self::Blocks(v) => v.is_empty(),
Self::Txs(v) => v.is_empty(),
Self::Logs(v) => v.is_empty(),
}
}
}

impl PartialEq for EthFilterResult {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Blocks(a), Self::Blocks(b)) => a == b,
(Self::Txs(a), Self::Txs(b)) => a == b,
(Self::Logs(a), Self::Logs(b)) => a == b,
_ => self.is_empty() && other.is_empty(),
}
}
}

#[derive(PartialEq, Default, Serialize, Deserialize, Debug, Clone, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct EthCallTraceAction {
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/methods/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub struct ActorEventBlock {
pub value: LotusJson<Vec<u8>>,
}

#[derive(PartialEq, Clone, JsonSchema, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Clone, JsonSchema, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorEvent {
pub entries: Vec<EventEntry>,
Expand Down
6 changes: 3 additions & 3 deletions src/rpc/methods/net/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

// Net API
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "PascalCase")]
pub struct AddrInfo {
#[serde(rename = "ID")]
Expand All @@ -27,7 +27,7 @@ impl AddrInfo {
}
}

#[derive(Debug, Default, Serialize, Deserialize, Clone, JsonSchema)]
#[derive(Debug, Default, Serialize, Deserialize, Clone, JsonSchema, PartialEq)]
pub struct NetInfoResult {
pub num_peers: usize,
pub num_connections: u32,
Expand All @@ -52,7 +52,7 @@ impl From<libp2p::swarm::NetworkInfo> for NetInfoResult {
}
}

#[derive(Debug, Default, Serialize, Deserialize, Clone, JsonSchema)]
#[derive(Debug, Default, Serialize, Deserialize, Clone, JsonSchema, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct NatStatusResult {
pub reachability: i32,
Expand Down
Loading
Loading