mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 07:58:22 -05:00
Add static analyzer to discourage use of panic() (#15075)
* Implement static analysis to prevent panics * Add nopanic to nogo * Fix violations and add exclusions Fix violations and add exclusions for all * Changelog fragment * Use pass.Report instead of pass.Reportf * Remove strings.ToLower for checking init method name * Add exclusion for herumi init * Move api/client/beacon template function to init and its own file * Fix nopanic testcase
This commit is contained in:
@@ -104,7 +104,7 @@ func SetBenchmarkConfig() (func(), error) {
|
||||
undo, err := params.SetActiveWithUndo(c)
|
||||
return func() {
|
||||
if err := undo(); err != nil {
|
||||
panic(err)
|
||||
panic(err) // lint:nopanic -- Test code / impossible scenario.
|
||||
}
|
||||
}, err
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ func RandomBlobTx(rpc *rpc.Client, f *filler.Filler, sender common.Address, nonc
|
||||
func New4844Tx(nonce uint64, to *common.Address, gasLimit uint64, chainID, tip, feeCap, value *big.Int, code []byte, blobFeeCap *big.Int, blobData []byte, al types.AccessList) *types.Transaction {
|
||||
blobs, comms, proofs, versionedHashes, err := EncodeBlobs(blobData)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
panic(err) // lint:nopanic -- Test code.
|
||||
}
|
||||
tx := types.NewTx(&types.BlobTx{
|
||||
ChainID: uint256.MustFromBig(chainID),
|
||||
@@ -427,7 +427,7 @@ func randomAddress() common.Address {
|
||||
b := make([]byte, 20)
|
||||
_, err := mathRand.Read(b) // #nosec G404
|
||||
if err != nil {
|
||||
panic(err)
|
||||
panic(err) // lint:nopanic -- Test code.
|
||||
}
|
||||
return common.BytesToAddress(b)
|
||||
case 3:
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// lint:nopanic -- Test tooling / code.
|
||||
package components
|
||||
|
||||
import (
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
func InitForkCfg(start, end int, c *params.BeaconChainConfig) *params.BeaconChainConfig {
|
||||
c = c.Copy()
|
||||
if end < start {
|
||||
panic("end fork is less than the start fork")
|
||||
panic("end fork is less than the start fork") // lint:nopanic -- test code.
|
||||
}
|
||||
if start >= version.Altair {
|
||||
c.AltairForkEpoch = 0
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// lint:nopanic -- Test tooling / code.
|
||||
package simulator
|
||||
|
||||
import (
|
||||
|
||||
@@ -56,6 +56,7 @@ func (mr *MockPrysmChainClientMockRecorder) ValidatorCount(arg0, arg1, arg2 any)
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidatorCount", reflect.TypeOf((*MockPrysmChainClient)(nil).ValidatorCount), arg0, arg1, arg2)
|
||||
}
|
||||
|
||||
// ValidatorPerformance mocks base method.
|
||||
func (m *MockPrysmChainClient) ValidatorPerformance(arg0 context.Context, arg1 *ethpb.ValidatorPerformanceRequest) (*ethpb.ValidatorPerformanceResponse, error) {
|
||||
m.ctrl.T.Helper()
|
||||
@@ -70,5 +71,3 @@ func (mr *MockPrysmChainClientMockRecorder) ValidatorPerformance(arg0, arg1 any)
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ValidatorCount", reflect.TypeOf((*MockPrysmChainClient)(nil).ValidatorPerformance), arg0, arg1)
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user