2022-05-09 13:02:34 +00:00
|
|
|
package state_native
|
2022-01-13 11:23:53 +00:00
|
|
|
|
|
|
|
import (
|
2023-03-17 18:52:56 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v4/encoding/bytesutil"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/runtime/version"
|
2022-01-13 11:23:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// CurrentSyncCommittee of the current sync committee in beacon chain state.
|
|
|
|
func (b *BeaconState) CurrentSyncCommittee() (*ethpb.SyncCommittee, error) {
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
2022-05-09 13:02:34 +00:00
|
|
|
if b.version == version.Phase0 {
|
|
|
|
return nil, errNotSupported("CurrentSyncCommittee", b.version)
|
|
|
|
}
|
|
|
|
|
2022-02-01 00:32:39 +00:00
|
|
|
if b.currentSyncCommittee == nil {
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2022-02-01 00:32:39 +00:00
|
|
|
return b.currentSyncCommitteeVal(), nil
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
2022-05-09 13:02:34 +00:00
|
|
|
// currentSyncCommitteeVal of the current sync committee in beacon chain state.
|
|
|
|
// This assumes that a lock is already held on BeaconState.
|
|
|
|
func (b *BeaconState) currentSyncCommitteeVal() *ethpb.SyncCommittee {
|
|
|
|
return copySyncCommittee(b.currentSyncCommittee)
|
|
|
|
}
|
|
|
|
|
2022-01-13 11:23:53 +00:00
|
|
|
// NextSyncCommittee of the next sync committee in beacon chain state.
|
|
|
|
func (b *BeaconState) NextSyncCommittee() (*ethpb.SyncCommittee, error) {
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
2022-05-09 13:02:34 +00:00
|
|
|
if b.version == version.Phase0 {
|
|
|
|
return nil, errNotSupported("NextSyncCommittee", b.version)
|
|
|
|
}
|
|
|
|
|
2022-02-01 00:32:39 +00:00
|
|
|
if b.nextSyncCommittee == nil {
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2022-02-01 00:32:39 +00:00
|
|
|
return b.nextSyncCommitteeVal(), nil
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
2022-05-09 13:02:34 +00:00
|
|
|
// nextSyncCommitteeVal of the next sync committee in beacon chain state.
|
|
|
|
// This assumes that a lock is already held on BeaconState.
|
|
|
|
func (b *BeaconState) nextSyncCommitteeVal() *ethpb.SyncCommittee {
|
|
|
|
return copySyncCommittee(b.nextSyncCommittee)
|
|
|
|
}
|
|
|
|
|
|
|
|
// copySyncCommittee copies the provided sync committee object.
|
|
|
|
func copySyncCommittee(data *ethpb.SyncCommittee) *ethpb.SyncCommittee {
|
2022-01-13 11:23:53 +00:00
|
|
|
if data == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return ðpb.SyncCommittee{
|
|
|
|
Pubkeys: bytesutil.SafeCopy2dBytes(data.Pubkeys),
|
|
|
|
AggregatePubkey: bytesutil.SafeCopyBytes(data.AggregatePubkey),
|
|
|
|
}
|
|
|
|
}
|