/
getters_sync_committee.go
62 lines (50 loc) · 1.79 KB
/
getters_sync_committee.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package state_native
import (
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/runtime/version"
)
// CurrentSyncCommittee of the current sync committee in beacon chain state.
func (b *BeaconState) CurrentSyncCommittee() (*ethpb.SyncCommittee, error) {
b.lock.RLock()
defer b.lock.RUnlock()
if b.version == version.Phase0 {
return nil, errNotSupported("CurrentSyncCommittee", b.version)
}
if b.currentSyncCommittee == nil {
return nil, nil
}
return b.currentSyncCommitteeVal(), nil
}
// 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)
}
// NextSyncCommittee of the next sync committee in beacon chain state.
func (b *BeaconState) NextSyncCommittee() (*ethpb.SyncCommittee, error) {
b.lock.RLock()
defer b.lock.RUnlock()
if b.version == version.Phase0 {
return nil, errNotSupported("NextSyncCommittee", b.version)
}
if b.nextSyncCommittee == nil {
return nil, nil
}
return b.nextSyncCommitteeVal(), nil
}
// 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 {
if data == nil {
return nil
}
return ðpb.SyncCommittee{
Pubkeys: bytesutil.SafeCopy2dBytes(data.Pubkeys),
AggregatePubkey: bytesutil.SafeCopyBytes(data.AggregatePubkey),
}
}