-
Notifications
You must be signed in to change notification settings - Fork 189
Add support for cron actor in StateDecodeParams API
#5804
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
Changes from all commits
4536686
c023bd5
5faf793
0fe90fc
fefc889
8c49811
6008257
d0262fb
3695c2a
8738bbf
2f24606
b9c51a3
341633d
b0a2c83
a08506c
862ac47
3dd5e03
18e8edf
10bd13f
a622b54
b289ad5
afb558a
d747488
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 { | ||
| 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); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| use super::*; | ||
| mod account_authenticate_params; | ||
| mod account_constructor_params; | ||
| mod cron_actor_params; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should determine a unique naming convention for our modules: At least let not invent a forth one. (
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @elmattic we choose
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
||
| 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), | ||
| _ => {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about version 17?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. latest available is V16
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @akaladarshi do we have an issue raised to track these improvements? |
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.