Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4536686
Add StateDecodeParams support for cron
sudo-shashank Jul 3, 2025
c023bd5
Merge branch 'main' into shashank/cron-state-decode-params
sudo-shashank Aug 6, 2025
5faf793
fix cron test
sudo-shashank Aug 6, 2025
0fe90fc
Merge branch 'main' into shashank/cron-state-decode-params
sudo-shashank Aug 6, 2025
fefc889
add test snapshot
sudo-shashank Aug 6, 2025
8c49811
Merge branch 'main' into shashank/cron-state-decode-params
sudo-shashank Aug 6, 2025
6008257
Merge branch 'main' into shashank/cron-state-decode-params
sudo-shashank Aug 6, 2025
d0262fb
Merge branch 'main' into shashank/cron-state-decode-params
sudo-shashank Aug 7, 2025
3695c2a
lint fix
sudo-shashank Aug 7, 2025
8738bbf
lint fix
sudo-shashank Aug 7, 2025
2f24606
Merge branch 'main' into shashank/cron-state-decode-params
sudo-shashank Aug 11, 2025
b9c51a3
Merge branch 'main' into shashank/cron-state-decode-params
sudo-shashank Aug 11, 2025
341633d
Merge branch 'main' into shashank/cron-state-decode-params
sudo-shashank Aug 11, 2025
b0a2c83
extend test_supported_actor_methods_registered
sudo-shashank Aug 11, 2025
a08506c
Merge branch 'main' into shashank/cron-state-decode-params
sudo-shashank Aug 11, 2025
862ac47
Merge branch 'main' into shashank/cron-state-decode-params
sudo-shashank Aug 13, 2025
3dd5e03
Merge branch 'main' into shashank/cron-state-decode-params
sudo-shashank Aug 13, 2025
18e8edf
Merge branch 'main' into shashank/cron-state-decode-params
sudo-shashank Aug 13, 2025
10bd13f
fix name
sudo-shashank Aug 13, 2025
a622b54
Merge branch 'main' into shashank/cron-state-decode-params
sudo-shashank Aug 13, 2025
b289ad5
Merge branch 'main' into shashank/cron-state-decode-params
sudo-shashank Aug 13, 2025
afb558a
Merge branch 'main' into shashank/cron-state-decode-params
akaladarshi Aug 14, 2025
d747488
Merge branch 'main' into shashank/cron-state-decode-params
sudo-shashank Aug 14, 2025
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
30 changes: 15 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ educe = { version = "0.6.0", features = ["Debug"], default-features = false }
enumflags2 = "0.7"
ethereum-types = { version = "0.15", features = ["ethbloom"] }
ez-jsonrpc-types = "0.5"
fil_actor_account_state = { version = "22.2" }
fil_actor_cron_state = { version = "22.2" }
fil_actor_datacap_state = { version = "22.2" }
fil_actor_eam_state = { version = "22.2" }
fil_actor_evm_state = { version = "22.2" }
fil_actor_init_state = { version = "22.2" }
fil_actor_market_state = { version = "22.2" }
fil_actor_miner_state = { version = "22.2" }
fil_actor_multisig_state = { version = "22.2" }
fil_actor_paych_state = { version = "22.2" }
fil_actor_power_state = { version = "22.2" }
fil_actor_reward_state = { version = "22.2" }
fil_actor_system_state = { version = "22.2" }
fil_actor_verifreg_state = { version = "22.2" }
fil_actors_shared = { version = "22.2", features = ["json"] }
fil_actor_account_state = { version = "22.4" }
fil_actor_cron_state = { version = "22.4" }
fil_actor_datacap_state = { version = "22.4" }
fil_actor_eam_state = { version = "22.4" }
fil_actor_evm_state = { version = "22.4" }
fil_actor_init_state = { version = "22.4" }
fil_actor_market_state = { version = "22.4" }
fil_actor_miner_state = { version = "22.4" }
fil_actor_multisig_state = { version = "22.4" }
fil_actor_paych_state = { version = "22.4" }
fil_actor_power_state = { version = "22.4" }
fil_actor_reward_state = { version = "22.4" }
fil_actor_system_state = { version = "22.4" }
fil_actor_verifreg_state = { version = "22.4" }
fil_actors_shared = { version = "22.4", features = ["json"] }
flate2 = "1"
flume = { workspace = true }
fs_extra = "1"
Expand Down
82 changes: 82 additions & 0 deletions src/lotus_json/actor_states/methods/cron_actor_params.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2019-2025 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use super::*;
use crate::shim::actors::cron::Entry;
use paste::paste;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, JsonSchema, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct CronConstructorParamsLotusJson {
#[schemars(with = "LotusJson<Vec<Entry>>")]
#[serde(with = "crate::lotus_json")]
pub entries: Vec<Entry>,
}

macro_rules! impl_lotus_json_for_cron_constructor_params {
($($version:literal),+) => {
$(
paste! {
impl HasLotusJson for fil_actor_cron_state::[<v $version>]::ConstructorParams {
type LotusJson = CronConstructorParamsLotusJson;

#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
use crate::shim::address::Address;
vec![(
json!({
"Entries": [
{
"Receiver": "f01",
"MethodNum": 2
},
{
"Receiver": "f02",
"MethodNum": 3
}
]
}),
Self {
Comment thread
sudo-shashank marked this conversation as resolved.
entries: vec![
fil_actor_cron_state::[<v $version>]::Entry {
receiver: Address::new_id(1).into(),
method_num: 2,
},
fil_actor_cron_state::[<v $version>]::Entry {
receiver: Address::new_id(2).into(),
method_num: 3,
},
],
},
)]
}

fn into_lotus_json(self) -> Self::LotusJson {
Self::LotusJson {
entries: self.entries.into_iter().map(Entry::[<V $version>]).collect(),
}
}

fn from_lotus_json(json: Self::LotusJson) -> Self {
Self {
entries: json.entries.into_iter().map(|entry| match entry {
Entry::[<V $version>](e) => e,
_ => {
let lotus_entry = entry.into_lotus_json();
fil_actor_cron_state::[<v $version>]::Entry {
receiver: lotus_entry.receiver.into(),
method_num: lotus_entry.method_num,
}
}
}).collect(),
}
}
}
}
)+
};
}

impl_lotus_json_for_cron_constructor_params!(8, 9, 10, 11, 12, 13, 14, 15, 16);
1 change: 1 addition & 0 deletions src/lotus_json/actor_states/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use super::*;
mod account_authenticate_params;
mod account_constructor_params;
mod cron_actor_params;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should determine a unique naming convention for our modules:
Right now we have 3:

- <actor-name>_<method>_params
- <actor-name>_actor
- <actor-name>_methods

At least let not invent a forth one. (<actor-name>_actor_params)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elmattic we choose <actor-name>_actor_params as suggested by @akaladarshi #5804 (review)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elmattic all the common actor methods will be moved to a single file, earlier all of them were separated, hence the discrepancies.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akaladarshi Do we have an issue to track this refactor?

mod datacap_actor_params;
mod evm_constructor_params;
mod init_constructor_params;
Expand Down
37 changes: 37 additions & 0 deletions src/rpc/registry/actors/cron.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2019-2025 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::rpc::registry::methods_reg::{MethodRegistry, register_actor_methods};
use crate::shim::message::MethodNum;
use anyhow::Result;
use cid::Cid;

macro_rules! register_cron_version {
($registry:expr, $code_cid:expr, $state_version:path) => {{
use $state_version::{ConstructorParams, Method};

register_actor_methods!(
$registry,
$code_cid,
[(Method::Constructor, ConstructorParams),]
);

// Register methods with empty params
register_actor_methods!($registry, $code_cid, [(Method::EpochTick, empty),]);
}};
}

pub(crate) fn register_actor_methods(registry: &mut MethodRegistry, cid: Cid, version: u64) {
match version {
8 => register_cron_version!(registry, cid, fil_actor_cron_state::v8),
9 => register_cron_version!(registry, cid, fil_actor_cron_state::v9),
10 => register_cron_version!(registry, cid, fil_actor_cron_state::v10),
11 => register_cron_version!(registry, cid, fil_actor_cron_state::v11),
12 => register_cron_version!(registry, cid, fil_actor_cron_state::v12),
13 => register_cron_version!(registry, cid, fil_actor_cron_state::v13),
14 => register_cron_version!(registry, cid, fil_actor_cron_state::v14),
15 => register_cron_version!(registry, cid, fil_actor_cron_state::v15),
16 => register_cron_version!(registry, cid, fil_actor_cron_state::v16),
_ => {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about version 17?

Copy link
Copy Markdown
Contributor Author

@sudo-shashank sudo-shashank Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

latest available is V16

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, should we trigger an error instead of performing a no-op?

Copy link
Copy Markdown
Contributor Author

@sudo-shashank sudo-shashank Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elmattic we should actually match against enum variants and not integer value directly
@akaladarshi has planned to fix this issue in a separate PR #5896 (comment)

Copy link
Copy Markdown
Contributor Author

@sudo-shashank sudo-shashank Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akaladarshi do we have an issue raised to track these improvements?

}
}
1 change: 1 addition & 0 deletions src/rpc/registry/actors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0, MIT

pub(crate) mod account;
pub(crate) mod cron;
pub(crate) mod datacap;
pub(crate) mod evm;
pub(crate) mod init;
Expand Down
4 changes: 3 additions & 1 deletion src/rpc/registry/methods_reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl MethodRegistry {

fn register_known_methods(&mut self) {
use crate::rpc::registry::actors::{
account, datacap, evm, init, miner, multisig, power, reward, system,
account, cron, datacap, evm, init, miner, multisig, power, reward, system,
};

for (&cid, &(actor_type, version)) in ACTOR_REGISTRY.iter() {
Expand All @@ -91,6 +91,7 @@ impl MethodRegistry {
}
BuiltinActor::Power => power::register_actor_methods(self, cid, version),
BuiltinActor::Reward => reward::register_actor_methods(self, cid, version),
BuiltinActor::Cron => cron::register_actor_methods(self, cid, version),
BuiltinActor::Multisig => multisig::register_actor_methods(self, cid, version),
_ => {}
}
Expand Down Expand Up @@ -261,6 +262,7 @@ mod test {
BuiltinActor::Account,
BuiltinActor::Miner,
BuiltinActor::EVM,
BuiltinActor::Cron,
BuiltinActor::DataCap,
];

Expand Down
22 changes: 22 additions & 0 deletions src/tool/subcommands/api_cmd/api_compare_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,14 @@ fn state_decode_params_api_tests(tipset: &Tipset) -> anyhow::Result<Vec<RpcTest>
))),
};

// TODO(go-state-types): https://github.com/filecoin-project/go-state-types/issues/396
// Enable this test when lotus supports it in go-state-types.
// let cron_constructor_params = fil_actor_cron_state::v16::ConstructorParams {
// entries: vec![fil_actor_cron_state::v16::Entry {
// receiver: Address::new_id(1000).into(),
// method_num: fil_actor_cron_state::v16::Method::EpochTick as u64,
// }],
// };
let multisig_constructor_params = fil_actor_multisig_state::v16::ConstructorParams {
signers: vec![Address::new_id(1000).into(), Address::new_id(1001).into()],
num_approvals_threshold: Default::default(),
Expand Down Expand Up @@ -2019,6 +2027,20 @@ fn state_decode_params_api_tests(tipset: &Tipset) -> anyhow::Result<Vec<RpcTest>
to_vec(&power_create_miner_params)?,
tipset.key().into(),
))?),
// TODO(go-state-types): https://github.com/filecoin-project/go-state-types/issues/396
// Enable this test when lotus supports it in go-state-types.
// RpcTest::identity(StateDecodeParams::request((
// Address::CRON_ACTOR,
// fil_actor_cron_state::v16::Method::Constructor as u64,
// to_vec(&cron_constructor_params)?,
// tipset.key().into(),
// ))?),
RpcTest::identity(StateDecodeParams::request((
Address::CRON_ACTOR,
fil_actor_cron_state::v16::Method::EpochTick as u64,
vec![],
tipset.key().into(),
))?),
RpcTest::identity(StateDecodeParams::request((
Address::POWER_ACTOR,
fil_actor_power_state::v16::Method::UpdateClaimedPower as u64,
Expand Down
1 change: 1 addition & 0 deletions src/tool/subcommands/api_cmd/test_snapshots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ filecoin_statedecodeparams_1753985928338431.rpcsnap.json.zst
filecoin_statedecodeparams_1753985928337192.rpcsnap.json.zst
filecoin_statedecodeparams_1753985928337443.rpcsnap.json.zst
filecoin_statedecodeparams_1753985928337618.rpcsnap.json.zst
filecoin_cron_epochtick_statedecodeparams_1754489337228993.rpcsnap.json.zst
filecoin_power_minercount_statedecodeparams_1754479441718517.rpcsnap.json.zst
filecoin_system_constructor_statedecodeparams_1754479441718641.rpcsnap.json.zst
filecoin_power_constructor_statedecodeparams_1754479441718709.rpcsnap.json.zst
Expand Down
Loading