mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
fixes runtime panic in state/getters (#5728)
* fixes runtime panic in state/getter * Merge branch 'master' into check-non-nil-in-state-getter * return empty map * Merge branch 'check-non-nil-in-state-getter' of github.com:prysmaticlabs/prysm into check-non-nil-in-state-getter
This commit is contained in:
parent
c614412885
commit
140aff4398
@ -450,6 +450,9 @@ func (b *BeaconState) ValidatorAtIndexReadOnly(idx uint64) (*ReadOnlyValidator,
|
||||
|
||||
// ValidatorIndexByPubkey returns a given validator by its 48-byte public key.
|
||||
func (b *BeaconState) ValidatorIndexByPubkey(key [48]byte) (uint64, bool) {
|
||||
if b == nil || b.valIdxMap == nil {
|
||||
return 0, false
|
||||
}
|
||||
b.lock.RLock()
|
||||
defer b.lock.RUnlock()
|
||||
idx, ok := b.valIdxMap[key]
|
||||
@ -457,6 +460,9 @@ func (b *BeaconState) ValidatorIndexByPubkey(key [48]byte) (uint64, bool) {
|
||||
}
|
||||
|
||||
func (b *BeaconState) validatorIndexMap() map[[48]byte]uint64 {
|
||||
if b == nil || b.valIdxMap == nil {
|
||||
return map[[48]byte]uint64{}
|
||||
}
|
||||
b.lock.RLock()
|
||||
defer b.lock.RUnlock()
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package state
|
||||
|
||||
import (
|
||||
"runtime/debug"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
@ -33,10 +34,44 @@ func TestNilState_NoPanic(t *testing.T) {
|
||||
var st *BeaconState
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Errorf("Method panicked when it was not supposed to: %v", r)
|
||||
t.Errorf("Method panicked when it was not supposed to: %v\n%v\n", r, string(debug.Stack()))
|
||||
}
|
||||
}()
|
||||
// retrieve elements from nil state
|
||||
_ = st.GenesisTime()
|
||||
_ = st.GenesisValidatorRoot()
|
||||
_ = st.GenesisUnixTime()
|
||||
_ = st.GenesisValidatorRoot()
|
||||
_ = st.Slot()
|
||||
_ = st.Fork()
|
||||
_ = st.LatestBlockHeader()
|
||||
_ = st.ParentRoot()
|
||||
_ = st.BlockRoots()
|
||||
_, err := st.BlockRootAtIndex(0)
|
||||
_ = st.StateRoots()
|
||||
_ = st.HistoricalRoots()
|
||||
_ = st.Eth1Data()
|
||||
_ = st.Eth1DataVotes()
|
||||
_ = st.Eth1DepositIndex()
|
||||
_ = st.ValidatorsReadOnly()
|
||||
_, err = st.ValidatorAtIndex(0)
|
||||
_, err = st.ValidatorAtIndexReadOnly(0)
|
||||
_, _ = st.ValidatorIndexByPubkey([48]byte{})
|
||||
_ = st.validatorIndexMap()
|
||||
_ = st.PubkeyAtIndex(0)
|
||||
_ = st.NumValidators()
|
||||
_ = st.Balances()
|
||||
_, err = st.BalanceAtIndex(0)
|
||||
_ = st.BalancesLength()
|
||||
_ = st.RandaoMixes()
|
||||
_, err = st.RandaoMixAtIndex(0)
|
||||
_ = st.RandaoMixesLength()
|
||||
_ = st.Slashings()
|
||||
_ = st.PreviousEpochAttestations()
|
||||
_ = st.CurrentEpochAttestations()
|
||||
_ = st.JustificationBits()
|
||||
_ = st.PreviousJustifiedCheckpoint()
|
||||
_ = st.CurrentJustifiedCheckpoint()
|
||||
_ = st.FinalizedCheckpoint()
|
||||
_ = err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user