aergoio/aergo

View on GitHub

Showing 1,051 of 1,052 total issues

Function runCallCmd has a Cognitive Complexity of 39 (exceeds 20 allowed). Consider refactoring.
Open

func runCallCmd(cmd *cobra.Command, args []string) error {
    cmd.SilenceUsage = true

    caller, err := types.DecodeAddress(args[0])
    if err != nil {
Severity: Minor
Found in cmd/aergocli/cmd/contract.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 BlockFetcher.Start has a Cognitive Complexity of 39 (exceeds 20 allowed). Consider refactoring.
Open

func (bf *BlockFetcher) Start() {
    bf.waitGroup = &sync.WaitGroup{}
    bf.waitGroup.Add(1)

    schedTicker := time.NewTicker(schedTick)
Severity: Minor
Found in syncer/blockfetcher.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

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

func (rpc *AergoRPCService) ListBlockMetadataStream(in *types.Empty, stream types.AergoRPCService_ListBlockMetadataStreamServer) error {
    streamID := atomic.AddUint32(&rpc.streamID, 1)
    rpc.blockMetadataStreamLock.Lock()
    metadataStream := NewListBlockMetaStream(streamID, stream)
    rpc.blockMetadataStream[streamID] = metadataStream
Severity: Major
Found in rpc/grpcserver.go and 1 other location - About 3 hrs to fix
rpc/grpcserver.go on lines 378..401

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

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 (rpc *AergoRPCService) ListBlockStream(in *types.Empty, stream types.AergoRPCService_ListBlockStreamServer) error {
    streamId := atomic.AddUint32(&rpc.streamID, 1)
    rpc.blockStreamLock.Lock()
    blockStream := NewListBlockStream(streamId, stream)
    rpc.blockStream[streamId] = blockStream
Severity: Major
Found in rpc/grpcserver.go and 1 other location - About 3 hrs to fix
rpc/grpcserver.go on lines 411..433

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

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 (h *V030Handshaker) sendLocalStatus(ctx context.Context, hostStatus *types.Status) error {
    var err error
    container := createMessage(p2pcommon.StatusRequest, p2pcommon.NewMsgID(), hostStatus)
    if container == nil {
        h.logger.Warn().Stringer(p2putil.LogPeerID, types.LogPeerShort(h.peerID)).Msg("failed to create p2p message")
Severity: Major
Found in p2p/v030/v030handshake.go and 1 other location - About 3 hrs to fix
p2p/v200/v200handshake.go on lines 101..121

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

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 (h *V200Handshaker) sendLocalStatus(ctx context.Context, hostStatus *types.Status) error {
    var err error
    container := createMessage(p2pcommon.StatusRequest, p2pcommon.NewMsgID(), hostStatus)
    if container == nil {
        h.logger.Warn().Stringer(p2putil.LogPeerID, types.LogPeerShort(h.peerID)).Msg("failed to create p2p message")
Severity: Major
Found in p2p/v200/v200handshake.go and 1 other location - About 3 hrs to fix
p2p/v030/v030handshake.go on lines 80..100

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

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 (rpc *AergoRPCService) LockAccount(ctx context.Context, in *types.Personal) (*types.Account, error) {
    if err := rpc.checkAuth(ctx, WriteBlockChain); err != nil {
        return nil, err
    }
    result, err := rpc.hub.RequestFutureResult(message.AccountsSvc,
Severity: Major
Found in rpc/grpcserver.go and 1 other location - About 3 hrs to fix
rpc/grpcserver.go on lines 801..820

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

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 (rpc *AergoRPCService) UnlockAccount(ctx context.Context, in *types.Personal) (*types.Account, error) {
    if err := rpc.checkAuth(ctx, WriteBlockChain); err != nil {
        return nil, err
    }
    result, err := rpc.hub.RequestFutureResult(message.AccountsSvc,
Severity: Major
Found in rpc/grpcserver.go and 1 other location - About 3 hrs to fix
rpc/grpcserver.go on lines 779..798

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

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 syncTxManager.refineFrontCache has a Cognitive Complexity of 38 (exceeds 20 allowed). Consider refactoring.
Open

func (tm *syncTxManager) refineFrontCache() {
    now := time.Now()
    expireTime := now.Add(-txQueryTimeout)
    if tm.toNoticeIdQueue.Len() == 0 { // nothing to resend
        cleanupCounter++
Severity: Minor
Found in p2p/synctx.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

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

func (api *Web3APIv1) GetABI() (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 1108..1131

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

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) GetStaking() (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 904..928

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

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

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

func (cs *ChainService) getBestBlockNo() types.BlockNo {
    return cs.cdb.getBestBlockNo()
}
Severity: Minor
Found in chain/chainhandle.go - About 3 hrs to fix

    Method ChainWorker.Receive has a Cognitive Complexity of 37 (exceeds 20 allowed). Consider refactoring.
    Open

    func (cw *ChainWorker) Receive(context actor.Context) {
        var sdb *statedb.StateDB
    
        getAccProof := func(sdb *statedb.StateDB, account, root []byte, compressed bool) (*types.AccountProof, error) {
            address, err := getAddressNameResolved(sdb, account)
    Severity: Minor
    Found in chain/chainservice.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

    Function runCallCmd has 102 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func runCallCmd(cmd *cobra.Command, args []string) error {
        cmd.SilenceUsage = true
    
        caller, err := types.DecodeAddress(args[0])
        if err != nil {
    Severity: Major
    Found in cmd/aergocli/cmd/contract.go - About 3 hrs to fix

      Function luaSendAmount has 102 lines of code (exceeds 50 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: Major
      Found in contract/vm_callback.go - About 3 hrs to fix

        Method executor.call has 101 lines of code (exceeds 50 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: Major
        Found in contract/vm.go - About 3 hrs to fix

          MockRemotePeer has 26 methods (exceeds 20 allowed). Consider refactoring.
          Open

          type MockRemotePeer struct {
              ctrl     *gomock.Controller
              recorder *MockRemotePeerMockRecorder
          }
          Severity: Minor
          Found in p2p/p2pmock/mock_remotepeer.go - About 3 hrs to fix

            Method peerManager.runManagePeers has 97 lines of code (exceeds 50 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: Major
            Found in p2p/peermanager.go - About 2 hrs to fix

              MockRemotePeerMockRecorder has 25 methods (exceeds 20 allowed). Consider refactoring.
              Open

              type MockRemotePeerMockRecorder struct {
                  mock *MockRemotePeer
              }
              Severity: Minor
              Found in p2p/p2pmock/mock_remotepeer.go - About 2 hrs to fix

                MockContext has 25 methods (exceeds 20 allowed). Consider refactoring.
                Open

                type MockContext struct {
                    ctrl     *gomock.Controller
                    recorder *MockContextMockRecorder
                }
                Severity: Minor
                Found in p2p/p2pmock/mock_actorcontext.go - About 2 hrs to fix
                  Severity
                  Category
                  Status
                  Source
                  Language