aergoio/aergo

View on GitHub
consensus/impl/raftv2/blockfactory.go

Summary

Maintainability
D
2 days
Test Coverage
F
0%

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

    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

      Method BlockFactory.generateBlock has 52 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (bf *BlockFactory) generateBlock(work *Work) (*types.Block, *state.BlockState, error) {
          var (
              bestBlock *types.Block
              err       error
          )
      Severity: Minor
      Found in consensus/impl/raftv2/blockfactory.go - About 1 hr to fix

        Method BlockFactory.generateBlock has 8 return statements (exceeds 4 allowed).
        Open

        func (bf *BlockFactory) generateBlock(work *Work) (*types.Block, *state.BlockState, error) {
            var (
                bestBlock *types.Block
                err       error
            )
        Severity: Major
        Found in consensus/impl/raftv2/blockfactory.go - About 50 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 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 BlockFactory.MakeConfChangeProposal has 5 return statements (exceeds 4 allowed).
              Open

              func (bf *BlockFactory) MakeConfChangeProposal(req *types.MembershipChange) (*consensus.ConfChangePropose, error) {
                  var (
                      proposal *consensus.ConfChangePropose
                      err      error
                  )
              Severity: Major
              Found in consensus/impl/raftv2/blockfactory.go - About 35 mins to fix

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

                  func (bf *BlockFactory) ClusterInfo(bestBlockHash []byte) *types.GetClusterInfoResponse {
                      var (
                          hardStateInfo *types.HardStateInfo
                          mbrAttrs      []*types.MemberAttr
                          bestBlock     *types.Block
                  Severity: Major
                  Found in consensus/impl/raftv2/blockfactory.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

                    There are no issues that match your filters.

                    Category
                    Status