aergoio/aergo

View on GitHub

Showing 1,051 of 1,052 total issues

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

func NewBPNoticeDiscardHandler(pm p2pcommon.PeerManager, peer p2pcommon.RemotePeer, logger *log.Logger, actor p2pcommon.ActorService, sm p2pcommon.SyncManager) p2pcommon.MessageHandler {
    bh := &raftBPNoticeDiscardHandler{BaseMsgHandler: BaseMsgHandler{protocol: p2pcommon.BlockProducedNotice, pm: pm, sm: sm, peer: peer, actor: actor, logger: logger}}
    return bh
}
Severity: Minor
Found in p2p/subproto/raftstub.go and 1 other location - About 55 mins to fix
p2p/subproto/raftstub.go on lines 57..60

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

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 (rs *PRPCServer) BlackList(ctx context.Context, p1 *types.Paginations) (*types.PolarisPeerList, error) {
    result, err := rs.actorHelper.CallRequestDefaultTimeout(PolarisSvc,
        &BlackListMsg{p1.Ref, p1.Size})
    if err == nil {
        list := result.(*types.PolarisPeerList)
Severity: Minor
Found in cmd/polaris/server/prpc.go and 1 other location - About 55 mins to fix
cmd/polaris/server/prpc.go on lines 225..234

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

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 (rs *PRPCServer) WhiteList(ctx context.Context, p1 *types.Paginations) (*types.PolarisPeerList, error) {
    result, err := rs.actorHelper.CallRequestDefaultTimeout(PolarisSvc,
        &WhiteListMsg{p1.Ref, p1.Size})
    if err == nil {
        list := result.(*types.PolarisPeerList)
Severity: Minor
Found in cmd/polaris/server/prpc.go and 1 other location - About 55 mins to fix
cmd/polaris/server/prpc.go on lines 236..245

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

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 WalDB.convertFromRaft has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
Open

func (wal *WalDB) convertFromRaft(entries []raftpb.Entry) ([]*consensus.WalEntry, []*types.Block, []*raftpb.ConfChange) {
    lenEnts := len(entries)
    if lenEnts == 0 {
        return nil, nil, nil
    }
Severity: Minor
Found in consensus/impl/raftv2/waldb.go - About 55 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 PeerMeta.Equals has 9 return statements (exceeds 4 allowed).
Open

func (m PeerMeta) Equals(o PeerMeta) bool {
    if !types.IsSamePeerID(m.ID, o.ID) {
        return false
    }
    if m.Role != o.Role {
Severity: Major
Found in p2p/p2pcommon/peermeta.go - About 55 mins to fix

    Function sendVotingReward has 9 return statements (exceeds 4 allowed).
    Open

    func sendVotingReward(bState *state.BlockState, dummy []byte) error {
        vrSeed := func(stateRoot []byte) int64 {
            return int64(binary.LittleEndian.Uint64(stateRoot))
        }
    
    
    Severity: Major
    Found in consensus/impl/dpos/dpos.go - About 55 mins to fix

      Method Web3APIv1.GetReceipts has 9 return statements (exceeds 4 allowed).
      Open

      func (api *Web3APIv1) GetReceipts() (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 - About 55 mins to fix

        Function execGetState has 9 return statements (exceeds 4 allowed).
        Open

        func execGetState(cmd *cobra.Command, args []string) {
            var root []byte
            var err error
            if len(stateroot) != 0 {
                root, err = base58.Decode(stateroot)
        Severity: Major
        Found in cmd/aergocli/cmd/getstate.go - About 55 mins to fix

          Method Web3APIv1.ListBlockHeaders has 9 return statements (exceeds 4 allowed).
          Open

          func (api *Web3APIv1) ListBlockHeaders() (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 - About 55 mins to fix

            Method BlockFetcher.searchCandidateTask has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
            Open

            func (bf *BlockFetcher) searchCandidateTask() (*FetchTask, error) {
                getNewHashSet := func() (*HashSet, error) {
                    if bf.curHashSet == nil { //blocking
                        logger.Info().Msg("BlockFetcher waiting first hashset")
            
            
            Severity: Minor
            Found in syncer/blockfetcher.go - About 55 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 BlockFetcher.Start has 9 return statements (exceeds 4 allowed).
            Open

            func (bf *BlockFetcher) Start() {
                bf.waitGroup = &sync.WaitGroup{}
                bf.waitGroup.Add(1)
            
                schedTicker := time.NewTicker(schedTick)
            Severity: Major
            Found in syncer/blockfetcher.go - About 55 mins to fix

              Function newExecutor has 9 return statements (exceeds 4 allowed).
              Open

              func newExecutor(
                  contract []byte,
                  contractId []byte,
                  ctx *vmContext,
                  ci *types.CallInfo,
              Severity: Major
              Found in contract/vm.go - About 55 mins to fix

                Method StubSyncer.handleMessage has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                Open

                func (stubSyncer *StubSyncer) handleMessage(msg interface{}) bool {
                    //prefix handle
                    switch resmsg := msg.(type) {
                    case *message.FinderResult:
                        if resmsg.Ancestor != nil && resmsg.Err == nil && resmsg.Ancestor.No >= 0 {
                Severity: Minor
                Found in syncer/stubsyncer.go - About 55 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 CcArgument.parse has 9 return statements (exceeds 4 allowed).
                Open

                func (cc CcArgument) parse() (*types.MembershipChange, error) {
                    var (
                        cmd, name, address, peeridStr, idStr string
                        id                                   uint64
                        err                                  error
                Severity: Major
                Found in contract/enterprise/changecluster.go - About 55 mins to fix

                  Function CheckFeeDelegation has 9 return statements (exceeds 4 allowed).
                  Open

                  func CheckFeeDelegation(contractAddress []byte, bs *state.BlockState, bi *types.BlockHeaderInfo, cdb ChainAccessor,
                      contractState *statedb.ContractState, payload, txHash, sender, amount []byte) (err error) {
                      var ci types.CallInfo
                  
                      err = getCallInfo(&ci, payload, contractAddress)
                  Severity: Major
                  Found in contract/vm.go - About 55 mins to fix

                    Function newExecutor has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                    Open

                    func newExecutor(
                        contract []byte,
                        contractId []byte,
                        ctx *vmContext,
                        ci *types.CallInfo,
                    Severity: Minor
                    Found in contract/vm.go - About 55 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

                    Function SaveRecoveryPoint has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                    Open

                    func SaveRecoveryPoint(bs *state.BlockState) error {
                        defer CloseDatabase()
                    
                        for id, db := range database.DBs {
                            if db.tx != nil {
                    Severity: Minor
                    Found in contract/statesql.go - About 55 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

                    Function ParseUnit has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                    Open

                    func ParseUnit(s string) (*big.Int, error) {
                        result, ok := new(big.Int).SetString(strings.TrimSpace(s), 10)
                        if !ok {
                            lower := strings.ToLower(s)
                            for _, v := range unitlist {
                    Severity: Minor
                    Found in types/jsonrpc/unit.go - About 55 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

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

                    func NewGetClusterReqHandler(pm p2pcommon.PeerManager, peer p2pcommon.RemotePeer, logger *log.Logger, actor p2pcommon.ActorService, consAcc consensus.ConsensusAccessor) *getClusterRequestHandler {
                        ph := &getClusterRequestHandler{
                            BaseMsgHandler: BaseMsgHandler{protocol: p2pcommon.GetClusterRequest, pm: pm, peer: peer, actor: actor, logger: logger},
                            consAcc:        consAcc,
                        }
                    Severity: Minor
                    Found in p2p/subproto/getcluster.go and 1 other location - About 55 mins to fix
                    p2p/subproto/raftwrap.go on lines 29..35

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

                    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 (c *SQLiteConn) Query(query string, args []driver.Value) (driver.Rows, error) {
                        list := make([]namedValue, len(args))
                        for i, v := range args {
                            list[i] = namedValue{
                                Ordinal: i + 1,
                    Severity: Minor
                    Found in contract/sqlite3.go and 1 other location - About 55 mins to fix
                    contract/sqlite3.go on lines 732..741

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

                    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

                    Severity
                    Category
                    Status
                    Source
                    Language