aergoio/aergo

View on GitHub
mempool/mempool.go

Summary

Maintainability
F
5 days
Test Coverage
F
41%

File mempool.go has 898 lines of code (exceeds 500 allowed). Consider refactoring.
Open

/**
 *  @file
 *  @copyright defined in aergo/LICENSE.txt
 */

Severity: Major
Found in mempool/mempool.go - About 1 day to fix

    Method MemPool.validateTx has a Cognitive Complexity of 68 (exceeds 20 allowed). Consider refactoring.
    Open

    func (mp *MemPool) validateTx(tx types.Transaction, account types.Address) error {
        if !mp.whitelist.Check(types.EncodeAddress(account)) {
            return types.ErrTxNotAllowedAccount
        }
        ns, err := mp.getAccountState(account)
    Severity: Minor
    Found in mempool/mempool.go - About 1 day 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

    MemPool has 33 methods (exceeds 20 allowed). Consider refactoring.
    Open

    type MemPool struct {
        *component.BaseComponent
    
        sync.RWMutex
        cfg *cfg.Config
    Severity: Minor
    Found in mempool/mempool.go - About 4 hrs to fix

      Method MemPool.validateTx has 118 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (mp *MemPool) validateTx(tx types.Transaction, account types.Address) error {
          if !mp.whitelist.Check(types.EncodeAddress(account)) {
              return types.ErrTxNotAllowedAccount
          }
          ns, err := mp.getAccountState(account)
      Severity: Major
      Found in mempool/mempool.go - About 3 hrs to fix

        Method MemPool.validateTx has 24 return statements (exceeds 4 allowed).
        Open

        func (mp *MemPool) validateTx(tx types.Transaction, account types.Address) error {
            if !mp.whitelist.Check(types.EncodeAddress(account)) {
                return types.ErrTxNotAllowedAccount
            }
            ns, err := mp.getAccountState(account)
        Severity: Major
        Found in mempool/mempool.go - About 2 hrs to fix

          Method MemPool.setStateDB has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
          Open

          func (mp *MemPool) setStateDB(block *types.Block) (bool, bool) {
              if mp.testConfig {
                  return true, false
              }
          
          
          Severity: Minor
          Found in mempool/mempool.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 MemPool.Receive has 58 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (mp *MemPool) Receive(context actor.Context) {
          
              switch msg := context.Message().(type) {
              case *message.MemPoolPut:
                  mp.verifier.Request(msg.Tx, context.Sender())
          Severity: Minor
          Found in mempool/mempool.go - About 1 hr to fix

            Method MemPool.removeOnBlockArrival has 56 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (mp *MemPool) removeOnBlockArrival(block *types.Block) error {
                var ag [2]time.Duration
                start := time.Now()
                mp.Lock()
                defer mp.Unlock()
            Severity: Minor
            Found in mempool/mempool.go - About 1 hr to fix

              Method MemPool.dumpTxsToFile has 52 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (mp *MemPool) dumpTxsToFile() {
                  if !mp.isRunning() {
                      return
                  }
                  mp.Info().Msg("start mempool dump")
              Severity: Minor
              Found in mempool/mempool.go - About 1 hr to fix

                Method MemPool.setStateDB has 51 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func (mp *MemPool) setStateDB(block *types.Block) (bool, bool) {
                    if mp.testConfig {
                        return true, false
                    }
                
                
                Severity: Minor
                Found in mempool/mempool.go - About 1 hr to fix

                  Method MemPool.getUnconfirmed has 7 return statements (exceeds 4 allowed).
                  Open

                  func (mp *MemPool) getUnconfirmed(accounts []types.Address, countOnly bool) []*unconfirmedTxs {
                      mp.RLock()
                      defer mp.RUnlock()
                  
                      getTxList := func(acc types.Address) (*txList, *time.Time) {
                  Severity: Major
                  Found in mempool/mempool.go - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                        if err != nil {
                                            mp.Warn().Err(err).Msg("failed to get whitelist")
                                        }
                    Severity: Major
                    Found in mempool/mempool.go - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                          if err != nil {
                                              mp.Warn().Err(err).Msg("failed to init whitelist")
                                          }
                      Severity: Major
                      Found in mempool/mempool.go - About 45 mins to fix

                        Method MemPool.getNameDest has 5 return statements (exceeds 4 allowed).
                        Open

                        func (mp *MemPool) getNameDest(account []byte, owner bool) []byte {
                            if mp.testConfig {
                                return account
                            }
                        
                        
                        Severity: Major
                        Found in mempool/mempool.go - About 35 mins to fix

                          Method MemPool.put has 5 return statements (exceeds 4 allowed).
                          Open

                          func (mp *MemPool) put(tx types.Transaction) error {
                              id := types.ToTxID(tx.GetHash())
                              acc := tx.GetBody().GetAccount()
                              if tx.HasVerifedAccount() {
                                  acc = tx.GetVerifedAccount()
                          Severity: Major
                          Found in mempool/mempool.go - About 35 mins to fix

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

                            func (mp *MemPool) dumpTxsToFile() {
                                if !mp.isRunning() {
                                    return
                                }
                                mp.Info().Msg("start mempool dump")
                            Severity: Minor
                            Found in mempool/mempool.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

                            There are no issues that match your filters.

                            Category
                            Status