Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Simplify getting latest state with GetState() or FindStates() #758

@ixje

Description

@ixje

Summary or problem description
Assume I want to retrieve the latest state. The current flow to do so is

  1. call GetStateheight() to get the root index
  2. call GetStateRoot(index) to get the stateroot
  3. call GetState() or FindState() with the obtained stateroot

That's 2 RPC calls before I can call GetState or FindState. RPC calls can be slow and it regularly happens that I get an exception from the code below while using the contract download feature of neo-express simply because the CurrentLocalRootHash of the node has already changed before I could finally submit what I obtained as the latest root hash.

public JToken FindStates(JArray _params)
{
var root_hash = UInt256.Parse(_params[0].AsString());
if (!Settings.Default.FullState && StateStore.Singleton.CurrentLocalRootHash != root_hash)
throw new RpcException(-100, "Old state not supported");

Do you have any solution you want to propose?
One way to solve this is selecting a node with FullState enabled, but that severely limits the available RPC nodes to choose from while we're not even interested in the full state.

Instead I want to propose accepting null as first argument to GetState and FindState and automatically replace it with the latest root hash. e.g.

     UInt256.TryParse(_params[0].AsString(), root_hash); 
     if (root_hash is null) {
         root_hash = StateStore.Singleton.CurrentLocalRootHash;
     } else if (!Settings.Default.FullState && StateStore.Singleton.CurrentLocalRootHash != root_hash) 
         throw new RpcException(-100, "Old state not supported");

Note: It's up for discussion if GetProof() should also support this.

Where in the software does this update applies to?

  • Other: StateService plugin

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions