2021-11-22 17:37:55 +00:00
|
|
|
package v3
|
|
|
|
|
|
|
|
import (
|
2022-08-16 12:20:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
2021-11-22 17:37:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// currentSyncCommittee of the current sync committee in beacon chain state.
|
|
|
|
// This assumes that a lock is already held on BeaconState.
|
|
|
|
func (b *BeaconState) currentSyncCommittee() *ethpb.SyncCommittee {
|
|
|
|
if !b.hasInnerState() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return CopySyncCommittee(b.state.CurrentSyncCommittee)
|
|
|
|
}
|
|
|
|
|
|
|
|
// nextSyncCommittee of the next sync committee in beacon chain state.
|
|
|
|
// This assumes that a lock is already held on BeaconState.
|
|
|
|
func (b *BeaconState) nextSyncCommittee() *ethpb.SyncCommittee {
|
|
|
|
if !b.hasInnerState() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return CopySyncCommittee(b.state.NextSyncCommittee)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CurrentSyncCommittee of the current sync committee in beacon chain state.
|
|
|
|
func (b *BeaconState) CurrentSyncCommittee() (*ethpb.SyncCommittee, error) {
|
|
|
|
if !b.hasInnerState() {
|
2022-05-17 09:38:35 +00:00
|
|
|
return nil, ErrNilInnerState
|
2021-11-22 17:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
|
|
|
if b.state.CurrentSyncCommittee == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return b.currentSyncCommittee(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NextSyncCommittee of the next sync committee in beacon chain state.
|
|
|
|
func (b *BeaconState) NextSyncCommittee() (*ethpb.SyncCommittee, error) {
|
|
|
|
if !b.hasInnerState() {
|
2022-05-17 09:38:35 +00:00
|
|
|
return nil, ErrNilInnerState
|
2021-11-22 17:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
|
|
|
if b.state.NextSyncCommittee == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return b.nextSyncCommittee(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CopySyncCommittee copies the provided sync committee object.
|
|
|
|
func CopySyncCommittee(data *ethpb.SyncCommittee) *ethpb.SyncCommittee {
|
|
|
|
if data == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return ðpb.SyncCommittee{
|
|
|
|
Pubkeys: bytesutil.SafeCopy2dBytes(data.Pubkeys),
|
|
|
|
AggregatePubkey: bytesutil.SafeCopyBytes(data.AggregatePubkey),
|
|
|
|
}
|
|
|
|
}
|