aergoio/aergo

View on GitHub

Showing 1,051 of 1,052 total issues

Function luaDeployContract has a Cognitive Complexity of 48 (exceeds 20 allowed). Consider refactoring.
Open

func luaDeployContract(
    L *LState,
    service C.int,
    contract *C.char,
    args *C.char,
Severity: Minor
Found in contract/vm_callback.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

BlockFactory has 37 methods (exceeds 20 allowed). Consider refactoring.
Open

type BlockFactory struct {
    *component.ComponentHub
    consensus.ChainWAL

    bpc *Cluster
Severity: Minor
Found in consensus/impl/raftv2/blockfactory.go - About 4 hrs to fix

    Function ValidateEnterpriseTx has 144 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func ValidateEnterpriseTx(tx *types.TxBody, sender *state.AccountState,
        scs *statedb.ContractState, blockNo types.BlockNo) (*EnterpriseContext, error) {
        var ci types.CallInfo
        if err := json.Unmarshal(tx.Payload, &ci); err != nil {
            return nil, err
    Severity: Major
    Found in contract/enterprise/validate.go - About 4 hrs to fix

      Method SQLiteRows.Next has a Cognitive Complexity of 47 (exceeds 20 allowed). Consider refactoring.
      Open

      func (rc *SQLiteRows) Next(dest []driver.Value) error {
          rc.s.mu.Lock()
          defer rc.s.mu.Unlock()
          if rc.s.closed {
              return io.EOF
      Severity: Minor
      Found in contract/sqlite3.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 peerManager.runManagePeers has a Cognitive Complexity of 46 (exceeds 20 allowed). Consider refactoring.
      Open

      func (pm *peerManager) runManagePeers() {
      
          pm.logger.Info().Str("p2p_proto", p2putil.ProtocolIDsToString([]protocol.ID{p2pcommon.P2PSubAddr})).Msg("Starting p2p listening")
          pm.nt.AddStreamHandler(p2pcommon.P2PSubAddr, pm.wpManager.OnInboundConn)
      
      
      Severity: Minor
      Found in p2p/peermanager.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

      Function executeTx has 138 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func executeTx(execCtx context.Context, ccc consensus.ChainConsensusCluster, cdb contract.ChainAccessor, bs *state.BlockState, tx types.Transaction, bi *types.BlockHeaderInfo, executionMode int) error {
          var (
              txBody    = tx.GetBody()
              isQuirkTx = types.IsQuirkTx(tx.GetHash())
              account   []byte
      Severity: Major
      Found in chain/chainhandle.go - About 4 hrs to fix

        Function luaDeployContract has 136 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func luaDeployContract(
            L *LState,
            service C.int,
            contract *C.char,
            args *C.char,
        Severity: Major
        Found in contract/vm_callback.go - About 4 hrs to fix

          File vm_dummy.go has 599 lines of code (exceeds 500 allowed). Consider refactoring.
          Open

          package vm_dummy
          
          // helper functions
          import (
              "context"
          Severity: Minor
          Found in contract/vm_dummy/vm_dummy.go - About 4 hrs to fix

            P2P has 34 methods (exceeds 20 allowed). Consider refactoring.
            Open

            type P2P struct {
                *component.BaseComponent
            
                cfg *config.Config
            
            
            Severity: Minor
            Found in p2p/p2p.go - About 4 hrs to fix

              Web3APIv1 has 34 methods (exceeds 20 allowed). Consider refactoring.
              Open

              type Web3APIv1 struct {
                  rpc     *rpc.AergoRPCService
                  request *http.Request
              
                  handlerMap map[string]map[string]APIHandler
              Severity: Minor
              Found in rpc/web3/v1.go - About 4 hrs to fix

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

                func (ce *executor) call(instLimit C.int, target *LState) (ret C.int) {
                    defer func() {
                        if ret == 0 && target != nil {
                            if C.luaL_hasuncatchablerror(ce.L) != C.int(0) {
                                C.luaL_setuncatchablerror(target)
                Severity: Minor
                Found in contract/vm.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

                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

                  File vprt.go has 587 lines of code (exceeds 500 allowed). Consider refactoring.
                  Open

                  package system
                  
                  import (
                      "bytes"
                      "container/list"
                  Severity: Minor
                  Found in contract/system/vprt.go - About 4 hrs to fix

                    Function luaSendAmount has a Cognitive Complexity of 43 (exceeds 20 allowed). Consider refactoring.
                    Open

                    func luaSendAmount(L *LState, service C.int, contractId *C.char, amount *C.char) *C.char {
                    
                        ctx := contexts[service]
                        if ctx == nil {
                            return C.CString("[Contract.LuaSendAmount] contract state not found")
                    Severity: Minor
                    Found in contract/vm_callback.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

                    File blockfetcher.go has 576 lines of code (exceeds 500 allowed). Consider refactoring.
                    Open

                    package syncer
                    
                    import (
                        "bytes"
                        "container/list"
                    Severity: Minor
                    Found in syncer/blockfetcher.go - About 3 hrs to fix

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

                      func (api *Web3APIv1) GetBalance() (handler http.Handler, ok bool) {
                          values, err := url.ParseQuery(api.request.URL.RawQuery)
                          if err != nil {
                              return commonResponseHandler(&types.Empty{}, err), true
                          }
                      Severity: Major
                      Found in rpc/web3/v1.go and 1 other location - About 3 hrs to fix
                      rpc/web3/v1.go on lines 930..955

                      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 295.

                      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

                      func (api *Web3APIv1) GetAccountVotes() (handler http.Handler, ok bool) {
                          values, err := url.ParseQuery(api.request.URL.RawQuery)
                          if err != nil {
                              return commonResponseHandler(&types.Empty{}, err), true
                          }
                      Severity: Major
                      Found in rpc/web3/v1.go and 1 other location - About 3 hrs to fix
                      rpc/web3/v1.go on lines 255..280

                      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 295.

                      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

                      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

                        peerManager has 29 methods (exceeds 20 allowed). Consider refactoring.
                        Open

                        type peerManager struct {
                            status            int32
                            is                p2pcommon.InternalService
                            nt                p2pcommon.NetworkTransport
                            hsFactory         p2pcommon.HSHandlerFactory
                        Severity: Minor
                        Found in p2p/peermanager.go - About 3 hrs to fix

                          ChainService has 29 methods (exceeds 20 allowed). Consider refactoring.
                          Open

                          type ChainService struct {
                              *component.BaseComponent
                              consensus.ChainConsensus
                              *Core
                          
                          
                          Severity: Minor
                          Found in chain/chainservice.go - About 3 hrs to fix
                            Severity
                            Category
                            Status
                            Source
                            Language