2022-05-09 13:02:34 +00:00
|
|
|
package state_native
|
2022-01-13 11:23:53 +00:00
|
|
|
|
|
|
|
import (
|
2022-08-16 12:20:13 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v3/runtime/version"
|
2022-01-13 11:23:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// PreviousEpochAttestations corresponding to blocks on the beacon chain.
|
|
|
|
func (b *BeaconState) PreviousEpochAttestations() ([]*ethpb.PendingAttestation, error) {
|
2022-05-09 13:02:34 +00:00
|
|
|
if b.version != version.Phase0 {
|
|
|
|
return nil, errNotSupported("PreviousEpochAttestations", b.version)
|
|
|
|
}
|
|
|
|
|
2022-01-24 10:24:38 +00:00
|
|
|
if b.previousEpochAttestations == nil {
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
2022-01-24 10:24:38 +00:00
|
|
|
return b.previousEpochAttestationsVal(), nil
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 10:24:38 +00:00
|
|
|
// previousEpochAttestationsVal corresponding to blocks on the beacon chain.
|
2022-01-13 11:23:53 +00:00
|
|
|
// This assumes that a lock is already held on BeaconState.
|
2022-01-24 10:24:38 +00:00
|
|
|
func (b *BeaconState) previousEpochAttestationsVal() []*ethpb.PendingAttestation {
|
|
|
|
return ethpb.CopyPendingAttestationSlice(b.previousEpochAttestations)
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CurrentEpochAttestations corresponding to blocks on the beacon chain.
|
|
|
|
func (b *BeaconState) CurrentEpochAttestations() ([]*ethpb.PendingAttestation, error) {
|
2022-05-09 13:02:34 +00:00
|
|
|
if b.version != version.Phase0 {
|
|
|
|
return nil, errNotSupported("CurrentEpochAttestations", b.version)
|
|
|
|
}
|
|
|
|
|
2022-01-24 10:24:38 +00:00
|
|
|
if b.currentEpochAttestations == nil {
|
2022-01-13 11:23:53 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
b.lock.RLock()
|
|
|
|
defer b.lock.RUnlock()
|
|
|
|
|
2022-01-24 10:24:38 +00:00
|
|
|
return b.currentEpochAttestationsVal(), nil
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// currentEpochAttestations corresponding to blocks on the beacon chain.
|
|
|
|
// This assumes that a lock is already held on BeaconState.
|
2022-01-24 10:24:38 +00:00
|
|
|
func (b *BeaconState) currentEpochAttestationsVal() []*ethpb.PendingAttestation {
|
|
|
|
return ethpb.CopyPendingAttestationSlice(b.currentEpochAttestations)
|
2022-01-13 11:23:53 +00:00
|
|
|
}
|