mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 07:58:22 -05:00
Add Error checks for nil inner state (#10701)
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
// PreviousEpochAttestations corresponding to blocks on the beacon chain.
|
||||
func (b *BeaconState) PreviousEpochAttestations() ([]*ethpb.PendingAttestation, error) {
|
||||
if !b.hasInnerState() {
|
||||
return nil, nil
|
||||
return nil, ErrNilInnerState
|
||||
}
|
||||
if b.state.PreviousEpochAttestations == nil {
|
||||
return nil, nil
|
||||
@@ -32,7 +32,7 @@ func (b *BeaconState) previousEpochAttestations() []*ethpb.PendingAttestation {
|
||||
// CurrentEpochAttestations corresponding to blocks on the beacon chain.
|
||||
func (b *BeaconState) CurrentEpochAttestations() ([]*ethpb.PendingAttestation, error) {
|
||||
if !b.hasInnerState() {
|
||||
return nil, nil
|
||||
return nil, ErrNilInnerState
|
||||
}
|
||||
if b.state.CurrentEpochAttestations == nil {
|
||||
return nil, nil
|
||||
|
||||
@@ -56,9 +56,9 @@ func TestNilState_NoPanic(t *testing.T) {
|
||||
_ = st.RandaoMixesLength()
|
||||
_ = st.Slashings()
|
||||
_, err = st.PreviousEpochAttestations()
|
||||
require.NoError(t, err)
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.CurrentEpochAttestations()
|
||||
require.NoError(t, err)
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_ = st.JustificationBits()
|
||||
_ = st.PreviousJustifiedCheckpoint()
|
||||
_ = st.CurrentJustifiedCheckpoint()
|
||||
|
||||
@@ -3,7 +3,7 @@ package v2
|
||||
// CurrentEpochParticipation corresponding to participation bits on the beacon chain.
|
||||
func (b *BeaconState) CurrentEpochParticipation() ([]byte, error) {
|
||||
if !b.hasInnerState() {
|
||||
return nil, nil
|
||||
return nil, ErrNilInnerState
|
||||
}
|
||||
if b.state.CurrentEpochParticipation == nil {
|
||||
return nil, nil
|
||||
@@ -18,7 +18,7 @@ func (b *BeaconState) CurrentEpochParticipation() ([]byte, error) {
|
||||
// PreviousEpochParticipation corresponding to participation bits on the beacon chain.
|
||||
func (b *BeaconState) PreviousEpochParticipation() ([]byte, error) {
|
||||
if !b.hasInnerState() {
|
||||
return nil, nil
|
||||
return nil, ErrNilInnerState
|
||||
}
|
||||
if b.state.PreviousEpochParticipation == nil {
|
||||
return nil, nil
|
||||
|
||||
@@ -28,7 +28,7 @@ func (b *BeaconState) nextSyncCommittee() *ethpb.SyncCommittee {
|
||||
// CurrentSyncCommittee of the current sync committee in beacon chain state.
|
||||
func (b *BeaconState) CurrentSyncCommittee() (*ethpb.SyncCommittee, error) {
|
||||
if !b.hasInnerState() {
|
||||
return nil, nil
|
||||
return nil, ErrNilInnerState
|
||||
}
|
||||
|
||||
b.lock.RLock()
|
||||
@@ -44,7 +44,7 @@ func (b *BeaconState) CurrentSyncCommittee() (*ethpb.SyncCommittee, error) {
|
||||
// NextSyncCommittee of the next sync committee in beacon chain state.
|
||||
func (b *BeaconState) NextSyncCommittee() (*ethpb.SyncCommittee, error) {
|
||||
if !b.hasInnerState() {
|
||||
return nil, nil
|
||||
return nil, ErrNilInnerState
|
||||
}
|
||||
|
||||
b.lock.RLock()
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
testtmpl "github.com/prysmaticlabs/prysm/beacon-chain/state/testing"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
)
|
||||
|
||||
func TestBeaconState_SlotDataRace(t *testing.T) {
|
||||
@@ -51,28 +52,28 @@ func TestNilState_NoPanic(t *testing.T) {
|
||||
_ = st.BalancesLength()
|
||||
_ = st.RandaoMixes()
|
||||
_, err = st.RandaoMixAtIndex(0)
|
||||
_ = err
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_ = st.RandaoMixesLength()
|
||||
_ = st.Slashings()
|
||||
_, err = st.CurrentEpochParticipation()
|
||||
_ = err
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.PreviousEpochParticipation()
|
||||
_ = err
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_ = st.JustificationBits()
|
||||
_ = err
|
||||
_ = st.PreviousJustifiedCheckpoint()
|
||||
_ = st.CurrentJustifiedCheckpoint()
|
||||
_ = st.FinalizedCheckpoint()
|
||||
_, err = st.CurrentEpochParticipation()
|
||||
_ = err
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.PreviousEpochParticipation()
|
||||
_ = err
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.InactivityScores()
|
||||
_ = err
|
||||
_, err = st.CurrentSyncCommittee()
|
||||
_ = err
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.NextSyncCommittee()
|
||||
_ = err
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
}
|
||||
|
||||
func TestBeaconState_MatchCurrentJustifiedCheckpt(t *testing.T) {
|
||||
|
||||
@@ -3,7 +3,7 @@ package v3
|
||||
// CurrentEpochParticipation corresponding to participation bits on the beacon chain.
|
||||
func (b *BeaconState) CurrentEpochParticipation() ([]byte, error) {
|
||||
if !b.hasInnerState() {
|
||||
return nil, nil
|
||||
return nil, ErrNilInnerState
|
||||
}
|
||||
if b.state.CurrentEpochParticipation == nil {
|
||||
return nil, nil
|
||||
@@ -18,7 +18,7 @@ func (b *BeaconState) CurrentEpochParticipation() ([]byte, error) {
|
||||
// PreviousEpochParticipation corresponding to participation bits on the beacon chain.
|
||||
func (b *BeaconState) PreviousEpochParticipation() ([]byte, error) {
|
||||
if !b.hasInnerState() {
|
||||
return nil, nil
|
||||
return nil, ErrNilInnerState
|
||||
}
|
||||
if b.state.PreviousEpochParticipation == nil {
|
||||
return nil, nil
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
// LatestExecutionPayloadHeader of the beacon state.
|
||||
func (b *BeaconState) LatestExecutionPayloadHeader() (*ethpb.ExecutionPayloadHeader, error) {
|
||||
if !b.hasInnerState() {
|
||||
return nil, nil
|
||||
return nil, ErrNilInnerState
|
||||
}
|
||||
if b.state.LatestExecutionPayloadHeader == nil {
|
||||
return nil, nil
|
||||
|
||||
@@ -28,7 +28,7 @@ func (b *BeaconState) nextSyncCommittee() *ethpb.SyncCommittee {
|
||||
// CurrentSyncCommittee of the current sync committee in beacon chain state.
|
||||
func (b *BeaconState) CurrentSyncCommittee() (*ethpb.SyncCommittee, error) {
|
||||
if !b.hasInnerState() {
|
||||
return nil, nil
|
||||
return nil, ErrNilInnerState
|
||||
}
|
||||
|
||||
b.lock.RLock()
|
||||
@@ -44,7 +44,7 @@ func (b *BeaconState) CurrentSyncCommittee() (*ethpb.SyncCommittee, error) {
|
||||
// NextSyncCommittee of the next sync committee in beacon chain state.
|
||||
func (b *BeaconState) NextSyncCommittee() (*ethpb.SyncCommittee, error) {
|
||||
if !b.hasInnerState() {
|
||||
return nil, nil
|
||||
return nil, ErrNilInnerState
|
||||
}
|
||||
|
||||
b.lock.RLock()
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
testtmpl "github.com/prysmaticlabs/prysm/beacon-chain/state/testing"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
)
|
||||
|
||||
func TestBeaconState_SlotDataRace(t *testing.T) {
|
||||
@@ -55,23 +56,26 @@ func TestNilState_NoPanic(t *testing.T) {
|
||||
_ = st.RandaoMixesLength()
|
||||
_ = st.Slashings()
|
||||
_, err = st.CurrentEpochParticipation()
|
||||
_ = err
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.PreviousEpochParticipation()
|
||||
_ = err
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_ = st.JustificationBits()
|
||||
_ = st.PreviousJustifiedCheckpoint()
|
||||
_ = st.CurrentJustifiedCheckpoint()
|
||||
_ = st.FinalizedCheckpoint()
|
||||
_, err = st.CurrentEpochParticipation()
|
||||
_ = err
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.PreviousEpochParticipation()
|
||||
_ = err
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.InactivityScores()
|
||||
_ = err
|
||||
_, err = st.CurrentSyncCommittee()
|
||||
_ = err
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.NextSyncCommittee()
|
||||
_ = err
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
_, err = st.LatestExecutionPayloadHeader()
|
||||
require.ErrorIs(t, ErrNilInnerState, err)
|
||||
|
||||
}
|
||||
|
||||
func TestBeaconState_MatchCurrentJustifiedCheckpt(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user