forest icon indicating copy to clipboard operation
forest copied to clipboard

StateDecodeParams Lotus-compatible RPC endpoint.

Open ruseinov opened this issue 2 years ago • 0 comments

Issue summary

A part of https://github.com/ChainSafe/forest/issues/3639

This endpoint takes address, tipset_keys, actor_method_number and method_params and tries to find the parameter type for a given method, then decode given params. Basically it servers as means of validation that the params for a given method have a correct format.

Here's the Go version of this endpoint: https://github.com/filecoin-project/lotus/blob/5e76b05b17771da6939c7b0bf65127c3dc70ee23/node/impl/full/state.go#L542-L558

Forest is missing a sizeable piece of infrastructure in order to be able to implement this feature, the investigation can start here: https://github.com/filecoinproject/lotus/blob/ac85a2e23b437f7935abeff24d7280b827ca88d9/chain/consensus/compute_state.go#L41-L58. This points at several missing pieces in fil-actor-states that allow for exporting methods.

Here's an example of how a method is exported in Lotus:

  1. List of exported actors: https://github.com/filecoin-project/specs-actors/blob/master/actors/builtin/exported/actors.go
  2. How methods are exported: https://github.com/filecoin-project/specs-actors/blob/master/actors/builtin/account/account_actor.go#L17-L20. Note, that we won't be able to do it exactly the same way as Rust does not have reflection, so we're going to have to represent params in a different way in order to be able to deserialise incoming bytes, perhaps using an enum.
  3. Here's how MethodMeta is put together on Lotus side: https://github.com/filecoin-project/lotus/blob/a83f120f3277501db6ee060701d789b4dbe6f1fa/chain/vm/invoker.go#L88-L167. All the methods seem to have exactly one param, it's type is extracted via reflection from any given actor method. For anything older that Version7 there is a special case, because there's also a runtime parameter on each of the methods.

Here's what we currently have:

  1. Exported method numbers: https://github.com/ChainSafe/fil-actor-states/blob/f44aadffb45c2930ce3b09bbd63ffa332616daa4/actors/cron/src/v11/mod.rs#L18-L21
  2. Method parameters: https://github.com/ChainSafe/fil-actor-states/blob/f44aadffb45c2930ce3b09bbd63ffa332616daa4/actors/cron/src/v11/mod.rs#L23C1-L29C2

The above is missing a mapping between methods and params. It also does not look like the Parameters are used anywhere.

Task summary

  • [ ] Create a registry that would allow us to find method params by actor code and method number.
  • [ ] Create enums that would represent said params for each actor of each version
  • [ ] Create version mapping so that we're able to register all the actors of all the available versions
  • [ ] Implement the RPC endpoint

Acceptance Criteria

  • [ ] RPC output is the same as Lotus'

Other information and links

ruseinov avatar Nov 30 '23 12:11 ruseinov