2023-01-21 21:33:50 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
2023-05-11 11:54:20 +00:00
|
|
|
"github.com/ledgerwatch/erigon-lib/types/clonable"
|
2023-09-03 01:09:27 +00:00
|
|
|
"github.com/ledgerwatch/erigon/metrics"
|
2023-01-21 21:33:50 +00:00
|
|
|
)
|
|
|
|
|
2023-07-19 22:20:33 +00:00
|
|
|
func (b *CachingBeaconState) EncodeSSZ(buf []byte) ([]byte, error) {
|
2023-09-03 01:09:27 +00:00
|
|
|
h := metrics.NewHistTimer("encode_ssz_beacon_state_dur")
|
2023-05-11 16:38:56 +00:00
|
|
|
bts, err := b.BeaconState.EncodeSSZ(buf)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
h.PutSince()
|
2023-09-03 01:09:27 +00:00
|
|
|
sz := metrics.NewHistTimer("encode_ssz_beacon_state_size")
|
2023-05-11 16:38:56 +00:00
|
|
|
sz.Update(float64(len(bts)))
|
|
|
|
return bts, err
|
2023-01-21 21:33:50 +00:00
|
|
|
}
|
|
|
|
|
2023-07-19 22:20:33 +00:00
|
|
|
func (b *CachingBeaconState) DecodeSSZ(buf []byte, version int) error {
|
2023-09-03 01:09:27 +00:00
|
|
|
h := metrics.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-09-03 01:09:27 +00:00
|
|
|
sz := metrics.NewHistTimer("decode_ssz_beacon_state_size")
|
2023-05-11 16:38:56 +00:00
|
|
|
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
|
2023-07-19 22:20:33 +00:00
|
|
|
func (b *CachingBeaconState) 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-07-19 22:20:33 +00:00
|
|
|
func (b *CachingBeaconState) Clone() clonable.Clonable {
|
2023-05-04 13:18:42 +00:00
|
|
|
return New(b.BeaconConfig())
|
2023-01-21 21:33:50 +00:00
|
|
|
}
|