Fantom-foundation/go-lachesis

View on GitHub

Showing 291 of 829 total issues

Function importFile has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
Open

func importFile(srv *gossip.Service, check bool, fn string) error {
    // Watch for Ctrl-C while the import is running.
    // If a signal is received, the import will stop.
    interrupt := make(chan os.Signal, 1)
    signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM)
Severity: Minor
Found in cmd/lachesis/import.go - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method Election.String has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
Open

func (el *Election) String(voters []hash.Event) string {
    if voters == nil {
        votersM := make(map[hash.Event]bool)
        for vid := range el.votes {
            votersM[vid.fromRoot] = true
Severity: Minor
Found in poset/election/debug.go - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method ProtocolManager.makeFetcher has 11 return statements (exceeds 4 allowed).
Open

func (pm *ProtocolManager) makeFetcher(checkers *eventcheck.Checkers) (*fetcher.Fetcher, *ordering.EventBuffer) {
    // checkers
    firstCheck := func(e *inter.Event) error {
        if err := checkers.Basiccheck.Validate(e); err != nil {
            return err
Severity: Major
Found in gossip/handler.go - About 1 hr to fix

    Function DoEstimateGas has 11 return statements (exceeds 4 allowed).
    Open

    func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, gasCap uint64) (hexutil.Uint64, error) {
        // Binary search the gas requirement, as it may be higher than the amount used
        var (
            lo  uint64 = params.TxGas - 1
            hi  uint64
    Severity: Major
    Found in ethapi/api.go - About 1 hr to fix

      Method TxPool.validateTx has 11 return statements (exceeds 4 allowed).
      Open

      func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
          // Reject transactions over defined size to prevent DOS attacks
          if uint64(tx.Size()) > txMaxSize {
              return ErrOversizedData
          }
      Severity: Major
      Found in evmcore/tx_pool.go - About 1 hr to fix

        Function DoCall has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
        Open

        func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides map[common.Address]account, vmCfg vm.Config, timeout time.Duration, globalGasCap uint64) (*evmcore.ExecutionResult, error) {
            defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now())
        
            state, header, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
            if state == nil || err != nil {
        Severity: Minor
        Found in ethapi/api.go - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Method SendTxArgs.setDefaults has 52 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (args *SendTxArgs) setDefaults(ctx context.Context, b Backend) error {
            if args.GasPrice == nil {
                price, err := b.SuggestPrice(ctx)
                if err != nil {
                    return err
        Severity: Minor
        Found in ethapi/api.go - About 1 hr to fix

          Method Emitter.isAllowedToEmit has 52 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (em *Emitter) isAllowedToEmit(e *inter.Event, selfParent *inter.EventHeaderData) bool {
              passedTime := e.ClaimedTime.Time().Sub(em.prevEmittedTime)
              // Slow down emitting if power is low
              {
                  threshold := em.config.NoTxsThreshold
          Severity: Minor
          Found in gossip/emitter.go - About 1 hr to fix

            Method PublicTransactionPoolAPI.GetTransactionReceipt has 51 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, hash common.Hash) (map[string]interface{}, error) {
                tx, blockNumber, index, err := s.b.GetTransaction(ctx, hash)
                if tx == nil || err != nil {
                    return nil, err
                }
            Severity: Minor
            Found in ethapi/api.go - About 1 hr to fix

              Function DoCall has 8 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides map[common.Address]account, vmCfg vm.Config, timeout time.Duration, globalGasCap uint64) (*evmcore.ExecutionResult, error) {
              Severity: Major
              Found in ethapi/api.go - About 1 hr to fix

                Function precacheTransaction has 8 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                func precacheTransaction(config *params.ChainConfig, bc DummyChain, author *common.Address, gaspool *GasPool, statedb *state.StateDB, header *EvmHeader, tx *types.Transaction, cfg vm.Config) error {
                Severity: Major
                Found in evmcore/state_prefetcher.go - About 1 hr to fix

                  Function Dir has 9 return statements (exceeds 4 allowed).
                  Open

                  func Dir(src string, dst string) (err error) {
                      src = filepath.Clean(src)
                      dst = filepath.Clean(dst)
                  
                      si, err := os.Stat(src)
                  Severity: Major
                  Found in utils/iocopy/dir.go - About 55 mins to fix

                    Method FilterCriteria.UnmarshalJSON has 9 return statements (exceeds 4 allowed).
                    Open

                    func (args *FilterCriteria) UnmarshalJSON(data []byte) error {
                        type input struct {
                            BlockHash *common.Hash     `json:"blockHash"`
                            FromBlock *rpc.BlockNumber `json:"fromBlock"`
                            ToBlock   *rpc.BlockNumber `json:"toBlock"`
                    Severity: Major
                    Found in gossip/filters/api.go - About 55 mins to fix

                      Method ProtocolManager.txsyncLoop has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                      Open

                      func (pm *ProtocolManager) txsyncLoop() {
                          var (
                              pending = make(map[enode.ID]*txsync)
                              sending = false               // whether a send is active
                              pack    = new(txsync)         // the pack that is being sent
                      Severity: Minor
                      Found in gossip/sync.go - About 55 mins to fix

                      Cognitive Complexity

                      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                      A method's cognitive complexity is based on a few simple rules:

                      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                      • Code is considered more complex for each "break in the linear flow of the code"
                      • Code is considered more complex when "flow breaking structures are nested"

                      Further reading

                      Function ForEachRandFork has 7 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          nodes []idx.StakerID,
                          cheatersArr []idx.StakerID,
                          eventCount int,
                          parentCount int,
                          forksCount int,
                      Severity: Major
                      Found in inter/common.go - About 50 mins to fix

                        Method Emitter.isMyTxTurn has 7 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                        func (em *Emitter) isMyTxTurn(txHash common.Hash, sender common.Address, accountNonce uint64, now time.Time, validatorsArr []idx.StakerID, validatorsArrStakes []pos.Stake, me idx.StakerID) bool {
                        Severity: Major
                        Found in gossip/emitter.go - About 50 mins to fix

                          Method PublicSfcAPI.addStakerMetricFields has 8 return statements (exceeds 4 allowed).
                          Open

                          func (s *PublicSfcAPI) addStakerMetricFields(ctx context.Context, res map[string]interface{}, stakerID idx.StakerID) (map[string]interface{}, error) {
                              blocks, period, err := s.b.GetDowntime(ctx, idx.StakerID(stakerID))
                              if err != nil {
                                  return nil, err
                              }
                          Severity: Major
                          Found in ethapi/sfc_api.go - About 50 mins to fix

                            Method peer.readStatus has 8 return statements (exceeds 4 allowed).
                            Open

                            func (p *peer) readStatus(network uint64, status *ethStatusData, genesis common.Hash) (err error) {
                                msg, err := p.rw.ReadMsg()
                                if err != nil {
                                    return err
                                }
                            Severity: Major
                            Found in gossip/peer.go - About 50 mins to fix

                              Method PublicTransactionPoolAPI.Resend has 8 return statements (exceeds 4 allowed).
                              Open

                              func (s *PublicTransactionPoolAPI) Resend(ctx context.Context, sendArgs SendTxArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64) (common.Hash, error) {
                                  if sendArgs.Nonce == nil {
                                      return common.Hash{}, fmt.Errorf("missing transaction nonce in transaction spec")
                                  }
                                  if err := sendArgs.setDefaults(ctx, s.b); err != nil {
                              Severity: Major
                              Found in ethapi/api.go - About 50 mins to fix

                                Method PublicTransactionPoolAPI.SignTransaction has 8 return statements (exceeds 4 allowed).
                                Open

                                func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args SendTxArgs) (*SignTransactionResult, error) {
                                    if args.Gas == nil {
                                        return nil, fmt.Errorf("gas not specified")
                                    }
                                    if args.GasPrice == nil {
                                Severity: Major
                                Found in ethapi/api.go - About 50 mins to fix
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language