---
# System prepended metadata

title: Best Way to handle state v0/v1 duplicates
tags: [hard_fork_1]

---

---
tags: hard_fork_1
---

# Best Way to handle state v0/v1 duplicates

## Say we have...

```go=
// BeaconState is in /beacon-chain/state/v0
type BeaconState struct {
	state                 *pbp2p.BeaconState
	dirtyFields           map[fieldIndex]interface{}
	...
}
```
```go=
// BeaconState is in /beacon-chain/state/v1
type BeaconState struct {
	state                 *pbp2p.BeaconStateV1
	dirtyFields           map[fieldIndex]interface{}
	...
}
```

`v1.BeaconState` will be implementing the same interface as `v0.BeaconState`

How can we avoid duplicate getter and setter code where `pbp2p.BeaconState` and `pbp2p.BeaconStateV1` have the same fields?

```go=
// In /beacon-chain/state/v0
// GenesisTime of the beacon state as a uint64.
func (b *BeaconState) GenesisTime() uint64 {
	if !b.hasInnerState() {
		return 0
	}

	b.lock.RLock()
	defer b.lock.RUnlock()

        // GenesisTime is a common field between pbp2p.BeaconState and pbp2p.BeaconStateV1
	return b.state.GenesisTime
}
```

```go=
// In /beacon-chain/state/v1. Can we avoid this?
// GenesisTime of the beacon state as a uint64.
func (b *BeaconState) GenesisTime() uint64 {
	if !b.hasInnerState() {
		return 0
	}

	b.lock.RLock()
	defer b.lock.RUnlock()

        // GenesisTime is a common field between pbp2p.BeaconState and pbp2p.BeaconStateV1
	return b.state.GenesisTime
}
```
