2023-05-04 13:18:42 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ledgerwatch/erigon/cl/clparams"
|
2023-05-13 21:44:07 +00:00
|
|
|
"github.com/ledgerwatch/erigon/cl/phase1/core/state/raw"
|
2023-05-04 13:18:42 +00:00
|
|
|
)
|
|
|
|
|
2023-07-19 22:20:33 +00:00
|
|
|
func (b *CachingBeaconState) CopyInto(bs *CachingBeaconState) (err error) {
|
2023-05-04 13:18:42 +00:00
|
|
|
if bs.BeaconState == nil {
|
|
|
|
bs.BeaconState = raw.New(b.BeaconConfig())
|
|
|
|
}
|
|
|
|
err = b.BeaconState.CopyInto(bs.BeaconState)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = b.copyCachesInto(bs)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-19 22:20:33 +00:00
|
|
|
func (b *CachingBeaconState) copyCachesInto(bs *CachingBeaconState) error {
|
2023-05-04 13:18:42 +00:00
|
|
|
if b.Version() == clparams.Phase0Version {
|
|
|
|
return bs.initBeaconState()
|
|
|
|
}
|
2023-05-10 19:37:50 +00:00
|
|
|
if bs.publicKeyIndicies == nil {
|
|
|
|
bs.publicKeyIndicies = make(map[[48]byte]uint64)
|
|
|
|
}
|
|
|
|
for k := range bs.publicKeyIndicies {
|
|
|
|
delete(bs.publicKeyIndicies, k)
|
|
|
|
}
|
2023-05-04 13:18:42 +00:00
|
|
|
for pk, index := range b.publicKeyIndicies {
|
|
|
|
bs.publicKeyIndicies[pk] = index
|
|
|
|
}
|
|
|
|
// Sync caches
|
2023-05-10 19:37:50 +00:00
|
|
|
bs.activeValidatorsCache = copyLRU(bs.activeValidatorsCache, b.activeValidatorsCache)
|
|
|
|
bs.shuffledSetsCache = copyLRU(bs.shuffledSetsCache, b.shuffledSetsCache)
|
2023-05-04 13:18:42 +00:00
|
|
|
|
|
|
|
if b.totalActiveBalanceCache != nil {
|
|
|
|
bs.totalActiveBalanceCache = new(uint64)
|
|
|
|
*bs.totalActiveBalanceCache = *b.totalActiveBalanceCache
|
|
|
|
bs.totalActiveBalanceRootCache = b.totalActiveBalanceRootCache
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-07-19 22:20:33 +00:00
|
|
|
func (b *CachingBeaconState) Copy() (bs *CachingBeaconState, err error) {
|
2023-05-04 13:18:42 +00:00
|
|
|
copied := New(b.BeaconConfig())
|
|
|
|
err = b.CopyInto(copied)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return copied, nil
|
|
|
|
}
|