Fantom-foundation/go-lachesis

View on GitHub
evmcore/tx_pool.go

Summary

Maintainability
F
5 days
Test Coverage

File tx_pool.go has 1137 lines of code (exceeds 500 allowed). Consider refactoring.
Open

// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
Severity: Major
Found in evmcore/tx_pool.go - About 2 days to fix

    TxPool has 39 methods (exceeds 20 allowed). Consider refactoring.
    Open

    type TxPool struct {
        config      TxPoolConfig
        chainconfig *params.ChainConfig
        chain       stateReader
        gasPrice    *big.Int
    Severity: Minor
    Found in evmcore/tx_pool.go - About 5 hrs to fix

      Method TxPool.truncatePending has a Cognitive Complexity of 44 (exceeds 20 allowed). Consider refactoring.
      Open

      func (pool *TxPool) truncatePending() {
          pending := uint64(0)
          for _, list := range pool.pending {
              pending += uint64(list.Len())
          }
      Severity: Minor
      Found in evmcore/tx_pool.go - About 4 hrs 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 TxPool.reset has a Cognitive Complexity of 41 (exceeds 20 allowed). Consider refactoring.
      Open

      func (pool *TxPool) reset(oldHead, newHead *EvmHeader) {
          // If we're reorging an old state, reinject all dropped transactions
          var reinject types.Transactions
      
          if oldHead != nil && oldHead.Hash != newHead.ParentHash {
      Severity: Minor
      Found in evmcore/tx_pool.go - About 3 hrs 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 TxPool.loop has a Cognitive Complexity of 33 (exceeds 20 allowed). Consider refactoring.
      Open

      func (pool *TxPool) loop() {
          defer pool.wg.Done()
      
          var (
              prevPending, prevQueued, prevStales int
      Severity: Minor
      Found in evmcore/tx_pool.go - About 2 hrs 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 TxPool.reset has 68 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (pool *TxPool) reset(oldHead, newHead *EvmHeader) {
          // If we're reorging an old state, reinject all dropped transactions
          var reinject types.Transactions
      
          if oldHead != nil && oldHead.Hash != newHead.ParentHash {
      Severity: Minor
      Found in evmcore/tx_pool.go - About 1 hr to fix

        Method TxPool.truncatePending has 61 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (pool *TxPool) truncatePending() {
            pending := uint64(0)
            for _, list := range pool.pending {
                pending += uint64(list.Len())
            }
        Severity: Minor
        Found in evmcore/tx_pool.go - About 1 hr to fix

          Method TxPool.add has 59 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err error) {
              // If the transaction is already known, discard it
              hash := tx.Hash()
              if pool.all.Get(hash) != nil {
                  log.Trace("Discarding already known transaction", "hash", hash)
          Severity: Minor
          Found in evmcore/tx_pool.go - About 1 hr to fix

            Method TxPool.loop has 55 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (pool *TxPool) loop() {
                defer pool.wg.Done()
            
                var (
                    prevPending, prevQueued, prevStales int
            Severity: Minor
            Found in evmcore/tx_pool.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

                Avoid deeply nested control flow statements.
                Open

                                    if pool.locals.contains(offenders[i]) {
                                        localGauge.Dec(int64(len(caps)))
                                    }
                Severity: Major
                Found in evmcore/tx_pool.go - About 45 mins to fix

                  Method TxPool.add has 7 return statements (exceeds 4 allowed).
                  Open

                  func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err error) {
                      // If the transaction is already known, discard it
                      hash := tx.Hash()
                      if pool.all.Get(hash) != nil {
                          log.Trace("Discarding already known transaction", "hash", hash)
                  Severity: Major
                  Found in evmcore/tx_pool.go - About 45 mins to fix

                    Method TxPool.reset has 6 return statements (exceeds 4 allowed).
                    Open

                    func (pool *TxPool) reset(oldHead, newHead *EvmHeader) {
                        // If we're reorging an old state, reinject all dropped transactions
                        var reinject types.Transactions
                    
                        if oldHead != nil && oldHead.Hash != newHead.ParentHash {
                    Severity: Major
                    Found in evmcore/tx_pool.go - About 40 mins to fix

                      Method TxPool.promoteExecutables has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
                      Open

                      func (pool *TxPool) promoteExecutables(accounts []common.Address) []*types.Transaction {
                          // Track the promoted transactions to broadcast them at once
                          var promoted []*types.Transaction
                      
                          // Iterate over all accounts and promote any executable transactions
                      Severity: Minor
                      Found in evmcore/tx_pool.go - About 25 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

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                                  for add.NumberU64() > rem.NumberU64() {
                                      included = append(included, add.Transactions...)
                                      if add = pool.chain.GetBlock(add.ParentHash, add.NumberU64()-1); add == nil {
                                          log.Error("Unrooted new chain seen by tx pool", "block", newHead.Number, "hash", newHead.Hash)
                                          return
                      Severity: Minor
                      Found in evmcore/tx_pool.go and 1 other location - About 35 mins to fix
                      evmcore/tx_pool.go on lines 1152..1158

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 103.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      Similar blocks of code found in 2 locations. Consider refactoring.
                      Open

                                  for rem.NumberU64() > add.NumberU64() {
                                      discarded = append(discarded, rem.Transactions...)
                                      if rem = pool.chain.GetBlock(rem.ParentHash, rem.NumberU64()-1); rem == nil {
                                          log.Error("Unrooted old chain seen by tx pool", "block", oldHead.Number, "hash", oldHead.Hash)
                                          return
                      Severity: Minor
                      Found in evmcore/tx_pool.go and 1 other location - About 35 mins to fix
                      evmcore/tx_pool.go on lines 1159..1165

                      Duplicated Code

                      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                      Tuning

                      This issue has a mass of 103.

                      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                      Refactorings

                      Further Reading

                      There are no issues that match your filters.

                      Category
                      Status