-
Notifications
You must be signed in to change notification settings - Fork 100
Simplify getting latest state with GetState() or FindStates() #758
Description
Summary or problem description
Assume I want to retrieve the latest state. The current flow to do so is
- call
GetStateheight()to get the root index - call
GetStateRoot(index)to get thestateroot - call
GetState()orFindState()with the obtainedstateroot
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.
neo-modules/src/StateService/StatePlugin.cs
Lines 294 to 298 in 7db1c79
| 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