Skip to content

Support more than SLOTS_PER_HISTORICAL_ROOT states when fetching state by root #12053

@rkapka

Description

@rkapka

🚀 Feature Request

Description

Several Beacon API endpoints include a {state_id} parameter, which can be substituted with a state root. This is limited to the last SLOTS_PER_HISTORICAL_ROOT state roots (8192 on Mainnet). This is because there is no easy way to fetch an arbitrary state by root from the database, and we keep the latest SLOTS_PER_HISTORICAL_ROOT state and block roots in memory, which allows us to do this:

for i, root := range headState.StateRoots() {
	if bytes.Equal(root, stateRoot) { // stateRoot is the requested root
		blockRoot := headState.BlockRoots()[i]
		return p.StateGenService.StateByRoot(ctx, bytesutil.ToBytes32(blockRoot))
	}
}

Describe the solution you'd like

It would be desirable to be able to use an arbitrary state root for the {state_id} parameter. One possible solution is to create a state_root -> block_root mapping in the database. This way we could get the block root efficiently and then use StateGenService to fetch the entire state.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apihelp-wantedLooking for external contributorsrestBeacon API related items

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions