Move BeaconBlockNil Checker Function to Consensus-Types/Wrapper Package (#10731)

* beacon block is nil wrapper

* gaz

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Raul Jordan
2022-05-20 23:29:16 +00:00
committed by GitHub
parent dc5fb92b28
commit 244e670b71
40 changed files with 98 additions and 93 deletions

View File

@@ -32,7 +32,10 @@ var (
// ErrUnsupportedBlindedBellatrixBlock is returned when accessing a blinded bellatrix block from unsupported method.
ErrUnsupportedBlindedBellatrixBlock = errors.New("unsupported blinded bellatrix block")
// ErrNilObjectWrapped is returned in a constructor when the underlying object is nil.
ErrNilObjectWrapped = errors.New("attempted to wrap nil object")
ErrNilObjectWrapped = errors.New("attempted to wrap nil object")
ErrNilSignedBeaconBlock = errors.New("signed beacon block can't be nil")
ErrNilBeaconBlock = errors.New("beacon block can't be nil")
ErrNilBeaconBlockBody = errors.New("beacon block body can't be nil")
)
// WrappedSignedBeaconBlock will wrap a signed beacon block to conform to the
@@ -159,3 +162,19 @@ func UnwrapGenericSignedBeaconBlock(gb *eth.GenericSignedBeaconBlock) (interface
return nil, errors.Wrapf(ErrUnsupportedSignedBeaconBlock, "unable to wrap block of type %T", gb)
}
}
// BeaconBlockIsNil checks if any composite field of input signed beacon block is nil.
// Access to these nil fields will result in run time panic,
// it is recommended to run these checks as first line of defense.
func BeaconBlockIsNil(b interfaces.SignedBeaconBlock) error {
if b == nil || b.IsNil() {
return ErrNilSignedBeaconBlock
}
if b.Block().IsNil() {
return ErrNilBeaconBlock
}
if b.Block().Body().IsNil() {
return ErrNilBeaconBlockBody
}
return nil
}