aergoio/aergo

View on GitHub

Showing 1,051 of 1,052 total issues

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

func NewAddressesReqHandler(pm p2pcommon.PeerManager, peer p2pcommon.RemotePeer, logger *log.Logger, actor p2pcommon.ActorService) *addressesRequestHandler {
    ph := &addressesRequestHandler{BaseMsgHandler{protocol: p2pcommon.AddressesRequest, pm: pm, peer: peer, actor: actor, logger: logger}}
    return ph
}
Severity: Major
Found in p2p/subproto/addrs.go and 4 other locations - About 35 mins to fix
p2p/subproto/addrs.go on lines 103..106
p2p/subproto/block.go on lines 127..130
p2p/subproto/getcluster.go on lines 68..71
p2p/subproto/tx.go on lines 65..68

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

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

func NewGetClusterRespHandler(pm p2pcommon.PeerManager, peer p2pcommon.RemotePeer, logger *log.Logger, actor p2pcommon.ActorService) *getClusterResponseHandler {
    ph := &getClusterResponseHandler{BaseMsgHandler{protocol: p2pcommon.GetClusterResponse, pm: pm, peer: peer, actor: actor, logger: logger}}
    return ph
}
Severity: Major
Found in p2p/subproto/getcluster.go and 4 other locations - About 35 mins to fix
p2p/subproto/addrs.go on lines 29..32
p2p/subproto/addrs.go on lines 103..106
p2p/subproto/block.go on lines 127..130
p2p/subproto/tx.go on lines 65..68

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

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 block.Size() > int(chain.MaxBlockSize()) {
        sm.logger.Info().Str(p2putil.LogPeerName, peer.Name()).Str(p2putil.LogBlkHash, block.BlockID().String()).Int("size", block.Size()).Msg("invalid blockProduced notice. block size exceed limit")
        return
    }
Severity: Minor
Found in p2p/syncmanager.go and 1 other location - About 35 mins to fix
p2p/syncmanager.go on lines 111..114

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

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 c.SystemContext.BlockInfo.ForkVersion < 2 {
        jsonArgs = `{"who":"` + types.EncodeAddress(sender.ID()) + `", "amount":"` + amount.String() + `"}`
    } else {
        jsonArgs = `["` + types.EncodeAddress(sender.ID()) + `", {"_bignum":"` + amount.String() + `"}]`
    }
Severity: Minor
Found in contract/system/staking.go and 1 other location - About 35 mins to fix
contract/system/staking.go on lines 110..114

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

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 (br *AncestorReceiver) StartGet() {
    // create message data
    req := &types.GetAncestorRequest{Hashes: br.hashes}
    mo := br.peer.MF().NewMsgRequestOrderWithReceiver(br.ReceiveResp, p2pcommon.GetAncestorRequest, req)
    br.requestID = mo.GetMsgID()
Severity: Minor
Found in p2p/ancestorreceiver.go and 1 other location - About 35 mins to fix
p2p/hashbynoreceiver.go on lines 37..43

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

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 CSetBreakPoint(contract_name_or_hex_c *C.char, line_c C.double) {

    contract_name_or_hex := C.GoString(contract_name_or_hex_c)
    line := uint64(line_c)

Severity: Minor
Found in contract/hook_dbg.go and 1 other location - About 35 mins to fix
contract/hook_dbg.go on lines 267..275

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

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 CDelBreakPoint(contract_name_or_hex_c *C.char, line_c C.double) {
    contract_name_or_hex := C.GoString(contract_name_or_hex_c)
    line := uint64(line_c)

    err := DelBreakPoint(HexAddrOrPlainStrToHexAddr(contract_name_or_hex), line)
Severity: Minor
Found in contract/hook_dbg.go and 1 other location - About 35 mins to fix
contract/hook_dbg.go on lines 255..264

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

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 (br *BlockHashByNoReceiver) StartGet() {
    // create message data
    req := &types.GetHashByNo{BlockNo: br.blockNo}
    mo := br.peer.MF().NewMsgRequestOrderWithReceiver(br.ReceiveResp, p2pcommon.GetHashByNoRequest, req)
    br.requestID = mo.GetMsgID()
Severity: Minor
Found in p2p/hashbynoreceiver.go and 1 other location - About 35 mins to fix
p2p/ancestorreceiver.go on lines 35..41

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

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 BlockFactory.ConfChange has 5 return statements (exceeds 4 allowed).
Open

func (bf *BlockFactory) ConfChange(req *types.MembershipChange) (*consensus.Member, error) {
    if bf.bpc == nil {
        return nil, ErrorMembershipChange{ErrClusterNotReady}
    }

Severity: Major
Found in consensus/impl/raftv2/blockfactory.go - About 35 mins to fix

    Method Cluster.makeProposal has 5 return statements (exceeds 4 allowed).
    Open

    func (cl *Cluster) makeProposal(req *types.MembershipChange, nowait bool) (*consensus.ConfChangePropose, error) {
        if cl.savedChange != nil {
            logger.Error().Str("cc", types.RaftConfChangeToString(cl.savedChange.Cc)).Msg("already exist pending conf change")
            return nil, ErrPendingConfChange
        }
    Severity: Major
    Found in consensus/impl/raftv2/cluster.go - About 35 mins to fix

      Method DPoS.getBpInfo has 5 return statements (exceeds 4 allowed).
      Open

      func (dpos *DPoS) getBpInfo(now time.Time) *bpInfo {
          s := slot.Time(now)
      
          if !s.IsFor(dpos.bpIdx(), dpos.bpc.Size()) {
              return nil
      Severity: Major
      Found in consensus/impl/dpos/dpos.go - About 35 mins to fix

        Method V030Handshaker.checkRemoteStatus has 5 return statements (exceeds 4 allowed).
        Open

        func (h *V030Handshaker) checkRemoteStatus(remotePeerStatus *types.Status) error {
            // check if chainID is same or not
            remoteChainID := types.NewChainID()
            err := remoteChainID.Read(remotePeerStatus.ChainID)
            if err != nil {
        Severity: Major
        Found in p2p/v030/v030handshake.go - About 35 mins to fix

          Method BlockFactory.controller has 5 return statements (exceeds 4 allowed).
          Open

          func (bf *BlockFactory) controller() {
              defer shutdownMsg("block factory controller")
          
              beginBlock := func(work *Work) error {
                  // This is only for draining an unconsumed message, which means
          Severity: Major
          Found in consensus/impl/raftv2/blockfactory.go - About 35 mins to fix

            Method SubProtocol.String has 5 return statements (exceeds 4 allowed).
            Open

            func (i SubProtocol) String() string {
                switch {
                case 1 <= i && i <= 9:
                    i -= 1
                    return _SubProtocol_name_0[_SubProtocol_index_0[i]:_SubProtocol_index_0[i+1]]
            Severity: Major
            Found in p2p/p2pcommon/subprotocol_string.go - About 35 mins to fix

              Method BlockFactory.worker has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
              Open

              func (bf *BlockFactory) worker() {
                  defer logger.Info().Msg("shutdown initiated. stop the service")
              
                  runtime.LockOSThread()
              
              
              Severity: Minor
              Found in consensus/impl/raftv2/blockfactory.go - About 35 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

              Method AergoRPCService.exportAccountWithFormat has 5 return statements (exceeds 4 allowed).
              Open

              func (rpc *AergoRPCService) exportAccountWithFormat(ctx context.Context, in *types.Personal, asKeystore bool) (*types.SingleBytes, 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 - About 35 mins to fix

                Method remotePeerImpl.handleMsg has 5 return statements (exceeds 4 allowed).
                Open

                func (p *remotePeerImpl) handleMsg(msg p2pcommon.Message) (err error) {
                    subProto := msg.Subprotocol()
                    defer func() {
                        if r := recover(); r != nil {
                            p.logger.Error().Stringer(p2putil.LogProtoID, subProto).Str("callStack", string(debug.Stack())).Interface("panic", r).Msg("There were panic in handler.")
                Severity: Major
                Found in p2p/remotepeer.go - About 35 mins to fix

                  Method AergoRPCService.SignTX has 5 return statements (exceeds 4 allowed).
                  Open

                  func (rpc *AergoRPCService) SignTX(ctx context.Context, in *types.Tx) (*types.Tx, 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 - About 35 mins to fix

                    Method BlockFactory.QueueJob has 5 return statements (exceeds 4 allowed).
                    Open

                    func (bf *BlockFactory) QueueJob(now time.Time, jq chan<- interface{}) {
                        bf.jobLock.Lock()
                        defer bf.jobLock.Unlock()
                    
                        var (
                    Severity: Major
                    Found in consensus/impl/raftv2/blockfactory.go - About 35 mins to fix

                      Method AergoRPCService.GetStaking has 5 return statements (exceeds 4 allowed).
                      Open

                      func (rpc *AergoRPCService) GetStaking(ctx context.Context, in *types.AccountAddress) (*types.Staking, error) {
                          if err := rpc.checkAuth(ctx, ReadBlockChain); err != nil {
                              return nil, err
                          }
                          var err error
                      Severity: Major
                      Found in rpc/grpcserver.go - About 35 mins to fix
                        Severity
                        Category
                        Status
                        Source
                        Language