erigon-pulse/cl/phase1/core/state/ssz.go
Giulio rebuffo 24987878e4
Resumable beacon state reconstruction (#8918)
* 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
2023-12-11 14:07:57 +01:00

40 lines
1.0 KiB
Go

package state
import (
"github.com/ledgerwatch/erigon-lib/metrics"
"github.com/ledgerwatch/erigon-lib/types/clonable"
)
func (b *CachingBeaconState) EncodeSSZ(buf []byte) ([]byte, error) {
h := metrics.NewHistTimer("encode_ssz_beacon_state_dur")
bts, err := b.BeaconState.EncodeSSZ(buf)
if err != nil {
return nil, err
}
h.PutSince()
sz := metrics.NewHistTimer("encode_ssz_beacon_state_size")
sz.Observe(float64(len(bts)))
return bts, err
}
func (b *CachingBeaconState) DecodeSSZ(buf []byte, version int) error {
h := metrics.NewHistTimer("decode_ssz_beacon_state_dur")
if err := b.BeaconState.DecodeSSZ(buf, version); err != nil {
return err
}
sz := metrics.NewHistTimer("decode_ssz_beacon_state_size")
sz.Observe(float64(len(buf)))
h.PutSince()
return b.InitBeaconState()
}
// SSZ size of the Beacon State
func (b *CachingBeaconState) EncodingSizeSSZ() (size int) {
sz := b.BeaconState.EncodingSizeSSZ()
return sz
}
func (b *CachingBeaconState) Clone() clonable.Clonable {
return New(b.BeaconConfig())
}