mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-09 04:21:20 +00:00
24987878e4
* Most of the PR changed files are extra and slightly more complicated unit tests. * Fixed Eth1DataVotes not inheriting genesis * Fixed Attestations simulation using wrong slot when reconstructing partecipation * Fixed Copy() operation on BeaconState on Eth1DataVotes * Used correct ListSSZ type for Eth1DataVotes and HistoricalSummaries * Fixed wrong []uint64 deltas on empty slots
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
package state
|
|
|
|
import (
|
|
"github.com/ledgerwatch/erigon/cl/clparams"
|
|
"github.com/ledgerwatch/erigon/cl/phase1/core/state/raw"
|
|
)
|
|
|
|
func (b *CachingBeaconState) CopyInto(bs *CachingBeaconState) (err error) {
|
|
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
|
|
}
|
|
|
|
func (b *CachingBeaconState) copyCachesInto(bs *CachingBeaconState) error {
|
|
if b.Version() == clparams.Phase0Version {
|
|
return bs.InitBeaconState()
|
|
}
|
|
if bs.publicKeyIndicies == nil {
|
|
bs.publicKeyIndicies = make(map[[48]byte]uint64)
|
|
}
|
|
for k := range bs.publicKeyIndicies {
|
|
delete(bs.publicKeyIndicies, k)
|
|
}
|
|
for pk, index := range b.publicKeyIndicies {
|
|
bs.publicKeyIndicies[pk] = index
|
|
}
|
|
// Sync caches
|
|
bs.activeValidatorsCache = copyLRU(bs.activeValidatorsCache, b.activeValidatorsCache)
|
|
bs.shuffledSetsCache = copyLRU(bs.shuffledSetsCache, b.shuffledSetsCache)
|
|
|
|
if b.totalActiveBalanceCache != nil {
|
|
bs.totalActiveBalanceCache = new(uint64)
|
|
*bs.totalActiveBalanceCache = *b.totalActiveBalanceCache
|
|
bs.totalActiveBalanceRootCache = b.totalActiveBalanceRootCache
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (b *CachingBeaconState) Copy() (bs *CachingBeaconState, err error) {
|
|
copied := New(b.BeaconConfig())
|
|
err = b.CopyInto(copied)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return copied, nil
|
|
}
|