2023-01-21 21:33:50 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
2023-05-11 16:38:56 +00:00
|
|
|
"github.com/ledgerwatch/erigon/metrics/methelp"
|
|
|
|
|
2023-05-11 11:54:20 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/types/clonable"
|
2023-01-21 21:33:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (b *BeaconState) EncodeSSZ(buf []byte) ([]byte, error) {
|
2023-05-11 16:38:56 +00:00
|
|
|
h := methelp.NewHistTimer("encode_ssz_beacon_state_dur")
|
|
|
|
bts, err := b.BeaconState.EncodeSSZ(buf)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
h.PutSince()
|
|
|
|
sz := methelp.NewHistTimer("encode_ssz_beacon_state_size")
|
|
|
|
sz.Update(float64(len(bts)))
|
|
|
|
return bts, err
|
2023-01-21 21:33:50 +00:00
|
|
|
}
|
|
|
|
|
2023-05-05 09:19:24 +00:00
|
|
|
func (b *BeaconState) DecodeSSZ(buf []byte, version int) error {
|
2023-05-11 16:38:56 +00:00
|
|
|
h := methelp.NewHistTimer("decode_ssz_beacon_state_dur")
|
2023-05-05 09:19:24 +00:00
|
|
|
if err := b.BeaconState.DecodeSSZ(buf, version); err != nil {
|
2023-01-21 21:33:50 +00:00
|
|
|
return err
|
|
|
|
}
|
2023-05-11 16:38:56 +00:00
|
|
|
sz := methelp.NewHistTimer("decode_ssz_beacon_state_size")
|
|
|
|
sz.Update(float64(len(buf)))
|
|
|
|
h.PutSince()
|
2023-03-11 19:27:21 +00:00
|
|
|
return b.initBeaconState()
|
2023-01-21 21:33:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SSZ size of the Beacon State
|
|
|
|
func (b *BeaconState) EncodingSizeSSZ() (size int) {
|
2023-05-11 16:38:56 +00:00
|
|
|
sz := b.BeaconState.EncodingSizeSSZ()
|
|
|
|
return sz
|
2023-01-21 21:33:50 +00:00
|
|
|
}
|
|
|
|
|
2023-03-19 22:47:27 +00:00
|
|
|
func (b *BeaconState) Clone() clonable.Clonable {
|
2023-05-04 13:18:42 +00:00
|
|
|
return New(b.BeaconConfig())
|
2023-01-21 21:33:50 +00:00
|
|
|
}
|