aergoio/aergo

View on GitHub

Showing 1,051 of 1,052 total issues

Method batch.Run has a Cognitive Complexity of 62 (exceeds 20 allowed). Consider refactoring.
Open

func (c *batch) Run(args string) (string, uint64, []*types.Event, error) {
    stdOut := colorable.NewColorableStdout()

    var err error

Severity: Minor
Found in cmd/brick/exec/batch.go - About 7 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 a Cognitive Complexity of 61 (exceeds 20 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: Minor
Found in chain/chainhandle.go - About 7 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 mock_types.go has 711 lines of code (exceeds 500 allowed). Consider refactoring.
Open

// Code generated by MockGen. DO NOT EDIT.
// Source: github.com/aergoio/aergo/v2/types (interfaces: AergoRPCServiceClient)

// Package mock_types is a generated GoMock package.
package mock_types
Severity: Minor
Found in cmd/aergocli/cmd/mock_types/mock_types.go - About 7 hrs to fix

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

        switch txBody.Type {
        case types.TxType_NORMAL, types.TxType_REDEPLOY, types.TxType_TRANSFER, types.TxType_CALL, types.TxType_DEPLOY:
            rv, events, txFee, err = contract.Execute(execCtx, bs, cdb, tx.GetTx(), sender, receiver, bi, executionMode, false)
            sender.SubBalance(txFee)
        case types.TxType_GOVERNANCE:
    Severity: Major
    Found in contract/vm_direct/vm_direct.go and 1 other location - About 6 hrs to fix
    chain/chainhandle.go on lines 1004..1036

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

    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

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

        switch txBody.Type {
        case types.TxType_NORMAL, types.TxType_REDEPLOY, types.TxType_TRANSFER, types.TxType_CALL, types.TxType_DEPLOY:
            rv, events, txFee, err = contract.Execute(execCtx, bs, cdb, tx.GetTx(), sender, receiver, bi, executionMode, false)
            sender.SubBalance(txFee)
        case types.TxType_GOVERNANCE:
    Severity: Major
    Found in chain/chainhandle.go and 1 other location - About 6 hrs to fix
    contract/vm_direct/vm_direct.go on lines 486..517

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

    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 raftServer.serveChannels has a Cognitive Complexity of 55 (exceeds 20 allowed). Consider refactoring.
    Open

    func (rs *raftServer) serveChannels() {
        defer RecoverExit()
    
        snapshot, err := rs.raftStorage.Snapshot()
        if err != nil {
    Severity: Minor
    Found in consensus/impl/raftv2/raftserver.go - About 6 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 blockfactory.go has 667 lines of code (exceeds 500 allowed). Consider refactoring.
    Open

    package raftv2
    
    import (
        "bytes"
        "context"
    Severity: Minor
    Found in consensus/impl/raftv2/blockfactory.go - About 6 hrs to fix

      MockAergoRPCServiceClient has 44 methods (exceeds 20 allowed). Consider refactoring.
      Open

      type MockAergoRPCServiceClient struct {
          ctrl     *gomock.Controller
          recorder *MockAergoRPCServiceClientMockRecorder
      }
      Severity: Minor
      Found in cmd/aergocli/cmd/mock_types/mock_types.go - About 6 hrs to fix

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

        func executeTx(
            execCtx context.Context,
            ccc consensus.ChainConsensusCluster,
            cdb contract.ChainAccessor,
            bs *state.BlockState,
        Severity: Major
        Found in contract/vm_direct/vm_direct.go - About 5 hrs to fix

          MockAergoRPCServiceClientMockRecorder has 43 methods (exceeds 20 allowed). Consider refactoring.
          Open

          type MockAergoRPCServiceClientMockRecorder struct {
              mock *MockAergoRPCServiceClient
          }
          Severity: Minor
          Found in cmd/aergocli/cmd/mock_types/mock_types.go - About 5 hrs to fix

            Cluster has 41 methods (exceeds 20 allowed). Consider refactoring.
            Open

            type Cluster struct {
                component.ICompSyncRequester
                sync.Mutex
                cdb consensus.ChainDB
            
            
            Severity: Minor
            Found in consensus/impl/raftv2/cluster.go - About 5 hrs to fix

              remotePeerImpl has 40 methods (exceeds 20 allowed). Consider refactoring.
              Open

              type remotePeerImpl struct {
                  logger       *log.Logger
                  pingDuration time.Duration
              
                  manageNum  uint32
              Severity: Minor
              Found in p2p/remotepeer.go - About 5 hrs to fix

                ChainDB has 40 methods (exceeds 20 allowed). Consider refactoring.
                Open

                type ChainDB struct {
                    cc consensus.ChainConsensus
                
                    latest    atomic.Value //types.BlockNo
                    bestBlock atomic.Value // *types.Block
                Severity: Minor
                Found in chain/chaindb.go - About 5 hrs to fix

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

                      if err != nil {
                          // Reset events on error
                          if bi.ForkVersion >= 3 {
                              events = nil
                          }
                  Severity: Major
                  Found in contract/vm_direct/vm_direct.go and 1 other location - About 5 hrs to fix
                  chain/chainhandle.go on lines 1038..1086

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

                  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

                      if err != nil {
                          // Reset events on error
                          if bi.ForkVersion >= 3 {
                              events = nil
                          }
                  Severity: Major
                  Found in chain/chainhandle.go and 1 other location - About 5 hrs to fix
                  contract/vm_direct/vm_direct.go on lines 519..567

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

                  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 3 locations. Consider refactoring.
                  Open

                  func (api *Web3APIv1) GetBlock() (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 2 other locations - About 5 hrs to fix
                  rpc/web3/v1.go on lines 320..356
                  rpc/web3/v1.go on lines 515..551

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

                  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 3 locations. Consider refactoring.
                  Open

                  func (api *Web3APIv1) GetBlockMetadata() (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 2 other locations - About 5 hrs to fix
                  rpc/web3/v1.go on lines 282..318
                  rpc/web3/v1.go on lines 320..356

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

                  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 3 locations. Consider refactoring.
                  Open

                  func (api *Web3APIv1) GetBlockTransactionCount() (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 2 other locations - About 5 hrs to fix
                  rpc/web3/v1.go on lines 282..318
                  rpc/web3/v1.go on lines 515..551

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

                  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 AergoRPCService.getBlocks has a Cognitive Complexity of 48 (exceeds 20 allowed). Consider refactoring.
                  Open

                  func (rpc *AergoRPCService) getBlocks(ctx context.Context, in *types.ListParams) ([]*types.Block, error) {
                      var maxFetchSize uint32
                      // TODO refactor with almost same code is in p2pcmdblock.go
                      if in.Size > uint32(1000) {
                          maxFetchSize = uint32(1000)
                  Severity: Minor
                  Found in rpc/grpcserver.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 ValidateSystemTx has a Cognitive Complexity of 48 (exceeds 20 allowed). Consider refactoring.
                  Open

                  func ValidateSystemTx(account []byte, txBody *types.TxBody, sender *state.AccountState,
                      scs *statedb.ContractState, blockInfo *types.BlockHeaderInfo) (*SystemContext, error) {
                      var ci types.CallInfo
                      if err := json.Unmarshal(txBody.Payload, &ci); err != nil {
                          return nil, types.ErrTxInvalidPayload
                  Severity: Minor
                  Found in contract/system/validation.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

                  Severity
                  Category
                  Status
                  Source
                  Language