Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy #6

Closed
JustinDrake opened this issue Mar 2, 2019 · 1 comment
Closed

Copy #6

JustinDrake opened this issue Mar 2, 2019 · 1 comment

Comments

@JustinDrake
Copy link
Collaborator

func (st *BeaconState) Copy() *BeaconState {
	// copy over state
	stUn := *st
	res := &stUn
	// manually copy over slices
	// validators
	copy(res.validator_registry, st.validator_registry)
	copy(res.validator_balances, st.validator_balances)
	// randao
	copy(res.latest_randao_mixes, st.latest_randao_mixes)
	// recent state
	copy(res.latest_crosslinks, st.latest_crosslinks)
	copy(res.latest_block_roots, st.latest_block_roots)
	copy(res.latest_active_index_roots, st.latest_active_index_roots)
	copy(res.latest_slashed_balances, st.latest_slashed_balances)
	copy(res.latest_attestations, st.latest_attestations)
	copy(res.batched_block_roots, st.batched_block_roots)
	// eth1
	copy(res.eth1_data_votes, st.eth1_data_votes)
	return res
}
  1. Notice that (to be done with the new SSZ spec) many of these are not slices but arrays. Specifically latest_randao_mixes, latest_block_roots, latest_active_index_roots, latest_slashed_balances will all be arrays.
  2. Surely there's a better way to do this :)
@protolambda
Copy link
Owner

Stumbled on a incosistency in the spec, fixed it (I think): ethereum/consensus-specs#713

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants