mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
gocognit: Lower complexity threshold to 100, fix a few complexity issues (#10542)
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
parent
32ebe94515
commit
80ebbcf03e
@ -18,7 +18,7 @@ const batchSize = 10
|
||||
|
||||
var migrationStateValidatorsKey = []byte("migration_state_validator")
|
||||
|
||||
func migrateStateValidators(ctx context.Context, db *bolt.DB) error {
|
||||
func shouldMigrateValidators(db *bolt.DB) (bool, error) {
|
||||
migrateDB := false
|
||||
if updateErr := db.View(func(tx *bolt.Tx) error {
|
||||
mb := tx.Bucket(migrationsBucket)
|
||||
@ -46,11 +46,17 @@ func migrateStateValidators(ctx context.Context, db *bolt.DB) error {
|
||||
return nil
|
||||
}); updateErr != nil {
|
||||
log.WithError(updateErr).Errorf("could not migrate bucket: %s", stateBucket)
|
||||
return updateErr
|
||||
return false, updateErr
|
||||
}
|
||||
|
||||
// do not migrate the DB
|
||||
if !migrateDB {
|
||||
return migrateDB, nil
|
||||
}
|
||||
|
||||
func migrateStateValidators(ctx context.Context, db *bolt.DB) error {
|
||||
if ok, err := shouldMigrateValidators(db); err != nil {
|
||||
return err
|
||||
} else if !ok {
|
||||
// A migration is not required.
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,10 @@ func (s *Store) SaveStates(ctx context.Context, states []state.ReadOnlyBeaconSta
|
||||
})
|
||||
}
|
||||
|
||||
type withValidators interface {
|
||||
GetValidators() []*ethpb.Validator
|
||||
}
|
||||
|
||||
// SaveStatesEfficient stores multiple states to the db (new schema) using the provided corresponding roots.
|
||||
func (s *Store) SaveStatesEfficient(ctx context.Context, states []state.ReadOnlyBeaconState, blockRoots [][32]byte) error {
|
||||
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveStatesEfficient")
|
||||
@ -161,29 +165,12 @@ func (s *Store) SaveStatesEfficient(ctx context.Context, states []state.ReadOnly
|
||||
validatorsEntries := make(map[string]*ethpb.Validator) // It's a map to make sure that you store only new validator entries.
|
||||
validatorKeys := make([][]byte, len(states)) // For every state, this stores a compressed list of validator keys.
|
||||
for i, st := range states {
|
||||
var validators []*ethpb.Validator
|
||||
switch st.InnerStateUnsafe().(type) {
|
||||
case *ethpb.BeaconState:
|
||||
pbState, err := v1.ProtobufBeaconState(st.InnerStateUnsafe())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
validators = pbState.Validators
|
||||
case *ethpb.BeaconStateAltair:
|
||||
pbState, err := v2.ProtobufBeaconState(st.InnerStateUnsafe())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
validators = pbState.Validators
|
||||
case *ethpb.BeaconStateBellatrix:
|
||||
pbState, err := v3.ProtobufBeaconState(st.InnerStateUnsafe())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
validators = pbState.Validators
|
||||
default:
|
||||
return errors.New("invalid state type")
|
||||
pb, ok := st.InnerStateUnsafe().(withValidators)
|
||||
if !ok {
|
||||
return errors.New("could not cast state to interface with GetValidators()")
|
||||
}
|
||||
validators := pb.GetValidators()
|
||||
|
||||
// yank out the validators and store them in separate table to save space.
|
||||
var hashes []byte
|
||||
for _, val := range validators {
|
||||
|
@ -176,7 +176,9 @@
|
||||
"external/.*": "Third party code",
|
||||
"rules_go_work-.*": "Third party code",
|
||||
".*\\.pb.*.go": "Generated code is ok",
|
||||
".*generated\\.ssz\\.go": "Generated code is ok"
|
||||
".*generated\\.ssz\\.go": "Generated code is ok",
|
||||
".*_test\\.go": "Tests are ok (for now)",
|
||||
"tools/analyzers/ineffassign/ineffassign\\.go": "3rd party code with a massive switch statement"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ var Analyzer = &analysis.Analyzer{
|
||||
// > 50 Untestable code, very high risk
|
||||
//
|
||||
// This threshold should be lowered to 50 over time.
|
||||
const over = 130
|
||||
const over = 100
|
||||
|
||||
func run(pass *analysis.Pass) (interface{}, error) {
|
||||
inspect, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
|
||||
|
Loading…
Reference in New Issue
Block a user