-
Notifications
You must be signed in to change notification settings - Fork 189
feat: add support for eam actor in state decode params API #5994
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
akaladarshi
merged 13 commits into
main
from
akaladarshi/add-eam-actor-state-decode-param
Sep 3, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
15d941a
add support for the eam actor in state decode params api
akaladarshi 7c1e4dd
add snapshot tests for eam actor
akaladarshi a32e2dd
fix linter issue
akaladarshi c61cd1e
Merge branch 'main' into akaladarshi/add-eam-actor-state-decode-param
akaladarshi 4c5a6c2
Merge branch 'main' into akaladarshi/add-eam-actor-state-decode-param
akaladarshi f3d4d01
fix snapshot test issue
akaladarshi 45ceba1
Merge branch 'main' into akaladarshi/add-eam-actor-state-decode-param
akaladarshi 21f099b
Merge branch 'main' into akaladarshi/add-eam-actor-state-decode-param
akaladarshi 529f36f
Merge branch 'main' into akaladarshi/add-eam-actor-state-decode-param
akaladarshi bae37ce
address comment
akaladarshi a4fd371
Merge remote-tracking branch 'origin/main' into akaladarshi/add-eam-a…
akaladarshi a083967
Merge remote-tracking branch 'origin/main' into akaladarshi/add-eam-a…
akaladarshi b08b744
Merge branch 'main' into akaladarshi/add-eam-actor-state-decode-param
akaladarshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| // Copyright 2019-2025 ChainSafe Systems | ||
| // SPDX-License-Identifier: Apache-2.0, MIT | ||
|
|
||
| use super::*; | ||
| use fvm_ipld_encoding::RawBytes; | ||
| use paste::paste; | ||
| use schemars::JsonSchema; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| #[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] | ||
| #[serde(rename_all = "PascalCase")] | ||
| pub struct EAMCreateParamsLotusJson { | ||
| #[schemars(with = "LotusJson<RawBytes>")] | ||
| #[serde(with = "crate::lotus_json")] | ||
| pub initcode: RawBytes, | ||
| pub nonce: u64, | ||
| } | ||
|
|
||
| macro_rules! impl_eam_create_params { | ||
| ($($version:literal),+) => { | ||
| $( | ||
| paste! { | ||
| impl HasLotusJson for fil_actor_eam_state::[<v $version>]::CreateParams { | ||
| type LotusJson = EAMCreateParamsLotusJson; | ||
|
|
||
| #[cfg(test)] | ||
| fn snapshots() -> Vec<(serde_json::Value, Self)> { | ||
| vec![ | ||
| ( | ||
| json!({ | ||
| "Initcode": "ESIzRFU=", | ||
| "Nonce": 42 | ||
| }), | ||
| Self { | ||
| initcode: hex::decode("1122334455").unwrap(), | ||
| nonce: 42, | ||
| }, | ||
| ), | ||
| ] | ||
| } | ||
|
|
||
| fn into_lotus_json(self) -> Self::LotusJson { | ||
| EAMCreateParamsLotusJson { | ||
| initcode: RawBytes::new(self.initcode), | ||
| nonce: self.nonce, | ||
| } | ||
| } | ||
|
|
||
| fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { | ||
| Self { | ||
| initcode: lotus_json.initcode.into(), | ||
| nonce: lotus_json.nonce, | ||
| } | ||
| } | ||
| } | ||
| } | ||
| )+ | ||
| }; | ||
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] | ||
| #[serde(rename_all = "PascalCase")] | ||
| pub struct EAMCreate2ParamsLotusJson { | ||
| #[schemars(with = "LotusJson<Vec<u8>>")] | ||
| #[serde(with = "crate::lotus_json")] | ||
| pub initcode: Vec<u8>, | ||
| pub salt: [u8; 32], | ||
| } | ||
|
|
||
| macro_rules! impl_eam_create2_params { | ||
| ($($version:literal),+) => { | ||
| $( | ||
| paste! { | ||
| impl HasLotusJson for fil_actor_eam_state::[<v $version>]::Create2Params { | ||
| type LotusJson = EAMCreate2ParamsLotusJson; | ||
|
|
||
| #[cfg(test)] | ||
| fn snapshots() -> Vec<(serde_json::Value, Self)> { | ||
| vec![ | ||
| ( | ||
| json!({ | ||
| "Initcode": "ESIzRFU=", | ||
| "Salt": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] | ||
| }), | ||
| Self { | ||
| initcode: hex::decode("1122334455").unwrap(), | ||
| salt: [0; 32], | ||
| }, | ||
| ), | ||
| ] | ||
| } | ||
|
|
||
| fn into_lotus_json(self) -> Self::LotusJson { | ||
| EAMCreate2ParamsLotusJson { | ||
| initcode: self.initcode, | ||
| salt: self.salt, | ||
| } | ||
| } | ||
|
|
||
| fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { | ||
| Self { | ||
| initcode: lotus_json.initcode, | ||
| salt: lotus_json.salt, | ||
| } | ||
| } | ||
| } | ||
| } | ||
| )+ | ||
| }; | ||
| } | ||
|
|
||
| #[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] | ||
| #[serde(rename_all = "PascalCase")] | ||
| pub struct EAMCreateExternalParamsLotusJson( | ||
| #[schemars(with = "LotusJson<RawBytes>")] | ||
| #[serde(with = "crate::lotus_json")] | ||
| RawBytes, | ||
| ); | ||
|
|
||
| macro_rules! impl_eam_create_external_params { | ||
| ($($version:literal),+) => { | ||
| $( | ||
| paste! { | ||
| impl HasLotusJson for fil_actor_eam_state::[<v $version>]::CreateExternalParams { | ||
| type LotusJson = EAMCreateExternalParamsLotusJson; | ||
|
|
||
| #[cfg(test)] | ||
| fn snapshots() -> Vec<(serde_json::Value, Self)> { | ||
| vec![ | ||
| ( | ||
| json!("ESIzRFU="), | ||
| Self(hex::decode("1122334455").unwrap()), | ||
| ), | ||
| ] | ||
| } | ||
|
|
||
| fn into_lotus_json(self) -> Self::LotusJson { | ||
| EAMCreateExternalParamsLotusJson(RawBytes::new(self.0)) | ||
| } | ||
|
|
||
| fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { | ||
| Self(lotus_json.0.into()) | ||
| } | ||
| } | ||
| } | ||
| )+ | ||
| }; | ||
| } | ||
|
|
||
| impl_eam_create_params!(10, 11, 12, 13, 14, 15, 16); | ||
| impl_eam_create2_params!(10, 11, 12, 13, 14, 15, 16); | ||
| impl_eam_create_external_params!(10, 11, 12, 13, 14, 15, 16); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // 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 cid::Cid; | ||
|
|
||
| macro_rules! register_eam_reg_version { | ||
| ($registry:expr, $code_cid:expr, $state_version:path) => {{ | ||
| use $state_version::{Create2Params, CreateExternalParams, CreateParams, Method}; | ||
|
|
||
| // Constructor has no parameters | ||
| register_actor_methods!($registry, $code_cid, [(Method::Constructor, empty),]); | ||
|
|
||
| register_actor_methods!( | ||
| $registry, | ||
| $code_cid, | ||
| [ | ||
| (Method::Create, CreateParams), | ||
| (Method::Create2, Create2Params), | ||
| (Method::CreateExternal, CreateExternalParams), | ||
| ] | ||
| ); | ||
| }}; | ||
| } | ||
|
|
||
| pub(crate) fn register_actor_methods(registry: &mut MethodRegistry, cid: Cid, version: u64) { | ||
| match version { | ||
| 10 => register_eam_reg_version!(registry, cid, fil_actor_eam_state::v10), | ||
| 11 => register_eam_reg_version!(registry, cid, fil_actor_eam_state::v11), | ||
| 12 => register_eam_reg_version!(registry, cid, fil_actor_eam_state::v12), | ||
| 13 => register_eam_reg_version!(registry, cid, fil_actor_eam_state::v13), | ||
| 14 => register_eam_reg_version!(registry, cid, fil_actor_eam_state::v14), | ||
| 15 => register_eam_reg_version!(registry, cid, fil_actor_eam_state::v15), | ||
| 16 => register_eam_reg_version!(registry, cid, fil_actor_eam_state::v16), | ||
| _ => {} | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix Create2 LotusJson: base64 encoding for Salt, snapshot mismatch, and redundant/incorrect try_into.
[u8; 32]withoutserde(with = "crate::lotus_json"), so deserialization would expect an array of numbers, not a string.Selfusessalt: [0; 32]while the provided base64 decodes to 0..31, causing the snapshot to fail.try_into()on[u8; 32]to[u8; 32]is unnecessary and, as written, can be incorrect depending on trait impl expectations.Recommend representing Salt in the LotusJson type as
Vec<u8>(base64 viacrate::lotus_json) and convert to[u8; 32]infrom_lotus_json. Also fix the snapshot to reflect the actual bytes (0..31).#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, PartialEq)] #[serde(rename_all = "PascalCase")] pub struct EAMCreate2ParamsLotusJson { #[schemars(with = "LotusJson<Vec<u8>>")] #[serde(with = "crate::lotus_json")] pub initcode: Vec<u8>, - pub salt: [u8; 32], + #[schemars(with = "LotusJson<Vec<u8>>")] + #[serde(with = "crate::lotus_json")] + pub salt: Vec<u8>, } @@ fn snapshots() -> Vec<(serde_json::Value, Self)> { vec![ ( json!({ "Initcode": "ESIzRFU=", "Salt": "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8=" }), Self { initcode: hex::decode("1122334455").unwrap(), - salt: [0; 32], + salt: [ + 0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 28, 29, 30, 31 + ], }, ), ] } @@ fn into_lotus_json(self) -> Self::LotusJson { EAMCreate2ParamsLotusJson { initcode: self.initcode, - salt: self.salt, + salt: self.salt.to_vec(), } } fn from_lotus_json(lotus_json: Self::LotusJson) -> Self { Self { - initcode: lotus_json.initcode.into(), - salt: lotus_json.salt.try_into().unwrap_or_else(|_| [0; 32]), + initcode: lotus_json.initcode, + salt: <[u8; 32]>::try_from(lotus_json.salt).unwrap_or_else(|v: Vec<u8>| { + debug_assert_eq!(v.len(), 32, "EAM Create2 salt must be 32 bytes"); + [0; 32] + }), } }Also applies to: 77-91, 93-105
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@akaladarshi What do we do with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored the snapshot test