flow-go icon indicating copy to clipboard operation
flow-go copied to clipboard

[Access] Optimize public key handling in GetAccounts

Open peterargue opened this issue 1 year ago • 1 comments

Problem Definition

The GetAccount endpoints get an account either from local storage or an execution node. In both cases, the keys are first loaded from a binary format, decoded into crypto.PublicKey objects, then serialized back into binary blobs. This decode/encode step is unnecessary within these endpoints since the keys are never used.

Proposed Solution

Explore options to reduce this overhead. Currently, the GetAccount* endpoints return a *flow.Account which is consistent with other endpoints. However, this requires that the data is decoded.

Addressing this is most straight forward for requests served by ENs since the data is received over GRPC as binary, then transmitted to the client as binary. It should be possible to make this a pass-through operation.

For GetAccount requests handled by the local FVM, changes would need to be made to the environment to skip decoding the keys when requested via this method. they may still be needed when accessed via a script.

Allocs: image

Heap: image

peterargue avatar Jan 05 '24 23:01 peterargue

Looking into this further, the AccountInfo.GetAccount method is only used by the APIs to service external queries. Also, the format of the keys stored in account state is the same as that returned by the APIs. It should be possible then to update this code path to return the public key data as binary without decoding.

peterargue avatar Jan 23 '24 22:01 peterargue