Skip to content

fix: filecoin read state API #5620

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

Conversation

akaladarshi
Copy link
Collaborator

@akaladarshi akaladarshi commented May 3, 2025

Summary of changes

Changes introduced in this pull request:

  • Adds actor_states module, which basically holds all the actor state implementing the HasLotusJson trait
  • Introduces actor_registgry reverse lookup map for CID -> BuiltinActor
  • Updates the StateReadState API to work with new changes
  • Added the support for reading the state of actors:
    • EVM
    • Miner
    • Market
    • Account
    • Cron
    • System

Reference issue to close (if applicable)

Partially Closes: #5596

Other information and links

We need to add remaining actor support as well (we could do this in separate PR's for the sake of reviewing smaller diff)

  • DataCap
  • Init
  • MultiSig
  • Power
  • Reward
  • VerifReg

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

@akaladarshi akaladarshi force-pushed the akaladarshi/fix-state-read-state-api branch from 3adf408 to 122015d Compare May 3, 2025 11:42
@akaladarshi
Copy link
Collaborator Author

akaladarshi commented May 15, 2025

Right now I'm using a specific commit for fil-actor-states crate, once we make a release in fil-actor-states I will update the Cargo.toml

Updated the fil-actor-states to version 22.2

@akaladarshi akaladarshi marked this pull request as ready for review May 16, 2025 08:01
@akaladarshi akaladarshi requested a review from a team as a code owner May 16, 2025 08:01
@akaladarshi akaladarshi requested review from hanabi1224 and elmattic and removed request for a team May 16, 2025 08:01
@hanabi1224
Copy link
Contributor

Could you add API compare tests and RPC snapshot tests for each type of actor state?

@akaladarshi akaladarshi requested a review from hanabi1224 May 21, 2025 20:45
@akaladarshi akaladarshi added the RPC requires calibnet RPC checks to run on CI label May 22, 2025
@akaladarshi akaladarshi self-assigned this May 22, 2025
Comment on lines +117 to +122
filecoin_statereadstate_1747857537534929.rpcsnap.json.zst
filecoin_statereadstate_1747857537535135.rpcsnap.json.zst
filecoin_statereadstate_1747857537535290.rpcsnap.json.zst
filecoin_statereadstate_1747857537534606.rpcsnap.json.zst
filecoin_statereadstate_1747857537535026.rpcsnap.json.zst
filecoin_statereadstate_1747857537535209.rpcsnap.json.zst
Copy link
Member

Choose a reason for hiding this comment

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

We really should have a way of commenting on what those snapshots are. Obviously not something to be done in this PR, but what we could do here is to add something to the name, e.g., statereadstate_account_1234.rpcsnap.json.zst, or something like this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, but we would have to manually change it after generating the files, also we'd need to fix the format for the file name as well.

tipset.key().into(),
))?),
RpcTest::identity(StateReadState::request((
Address::new_id(78216), // miner actor address `f078216`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Address::new_id(78216), // miner actor address `f078216`
Address::new_id(78216), // miner actor address `t078216`

Also, might be worth linking to a relevant page on a block explorer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.


match actor_type {
BuiltinActor::Account => {
let state = account::State::load(store, *code_cid, *state_cid).map_err(|e| {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of map_err, we could probably use anyhow's .context

Copy link
Member

Choose a reason for hiding this comment

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

It'd end up being less code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Refactored it.

Comment on lines 17 to 38
// Build a map from CIDs to actor types and versions once at startup
static CID_TO_ACTOR_TYPE: Lazy<HashMap<Cid, (BuiltinActor, u64)>> = Lazy::new(|| {
let mut map = HashMap::new();

// Populate the map using data from ACTOR_BUNDLES_METADATA
for ((_, _), metadata) in ACTOR_BUNDLES_METADATA.iter() {
if let Ok(version) = metadata.actor_major_version() {
for (actor_type, cid) in metadata.manifest.builtin_actors() {
map.insert(cid, (actor_type, version));
}
}
}

map
});

pub fn get_actor_type_from_code(code_cid: &Cid) -> anyhow::Result<(BuiltinActor, u64)> {
CID_TO_ACTOR_TYPE
.get(code_cid)
.copied()
.ok_or_else(|| anyhow!("Unknown actor code CID: {}", code_cid))
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: it'd be nice to have it as a separate struct so we can abstract away the underlying data structure. It'd only have read_actor_type(cid: &Cid) as a member method.

A unit test would also be nice to have.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

};
}

impl_tombstone_lotus_json!(V16, V15, V14, V13, V12, V11, V10);
Copy link
Member

Choose a reason for hiding this comment

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

Can we ensure, at compilation time, that all versions are covered? If it's too complex, let's have it as a follow-up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You mean through tests?.

Because I think this is already ensured as we are implementing HasLotusJson for the TombstoneState, which itself holds all the versions of the tombstone. and match on self will ensure that at compile time all the versions are covered.

Copy link
Member

Choose a reason for hiding this comment

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

Ah cool, didn't notice there was a match there. Excellent!

Copy link
Member

@LesnyRumcajs LesnyRumcajs left a comment

Choose a reason for hiding this comment

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

Excellent work @akaladarshi !

@akaladarshi akaladarshi force-pushed the akaladarshi/fix-state-read-state-api branch from 10bf489 to 12aac4d Compare May 27, 2025 11:04
@akaladarshi akaladarshi force-pushed the akaladarshi/fix-state-read-state-api branch from 12aac4d to 0874d91 Compare May 27, 2025 11:26
@akaladarshi
Copy link
Collaborator Author

akaladarshi commented May 27, 2025

@LesnyRumcajs I will raise a subsequent PR for adding more actor type support for StateReadState API, this PR has already become very big.

Then we can update the Changelog or should I update right now only?

@LesnyRumcajs
Copy link
Member

@LesnyRumcajs I will raise a subsequent PR for adding more actor type support for StateReadState API, this PR has already become very big.

Then we can update the Changelog or should I update right now only?

Either works fine for me.

@akaladarshi
Copy link
Collaborator Author

@LesnyRumcajs I will raise a subsequent PR for adding more actor type support for StateReadState API, this PR has already become very big.
Then we can update the Changelog or should I update right now only?

Either works fine for me.

Will do it in a Subsequent PR

@akaladarshi akaladarshi added this pull request to the merge queue May 28, 2025
Merged via the queue into ChainSafe:main with commit 7ab303c May 28, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RPC requires calibnet RPC checks to run on CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filecoin.StateReadState: Serialization error for Cbor protocol: TypeMismatch { name: \"CBOR tag\", byte: 0 }
3 participants