aergoio/aergo

View on GitHub
chain/reorg.go

Summary

Maintainability
B
4 hrs
Test Coverage
C
72%

Method reorganizer.gather has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
Open

func (reorg *reorganizer) gather() error {
    //find branch root block , gather rollforward Target block
    var err error
    cdb := reorg.cs.cdb

Severity: Minor
Found in chain/reorg.go - About 1 hr 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 reorganizer.gather has 8 return statements (exceeds 4 allowed).
Open

func (reorg *reorganizer) gather() error {
    //find branch root block , gather rollforward Target block
    var err error
    cdb := reorg.cs.cdb

Severity: Major
Found in chain/reorg.go - About 50 mins to fix

    Method reorganizer.swapChain has 7 return statements (exceeds 4 allowed).
    Open

    func (reorg *reorganizer) swapChain() error {
        logger.Info().Msg("swap chain to new branch")
    
        if err := TestDebugger.Check(DEBUG_CHAIN_STOP, 1, nil); err != nil {
            return err
    Severity: Major
    Found in chain/reorg.go - About 45 mins to fix

      Method ChainService.reorg has 7 return statements (exceeds 4 allowed).
      Open

      func (cs *ChainService) reorg(topBlock *types.Block, marker *ReorgMarker) error {
          logger.Info().Uint64("blockNo", topBlock.GetHeader().GetBlockNo()).Str("hash", topBlock.ID()).
              Bool("recovery", (marker != nil)).Msg("reorg started")
      
          begT := time.Now()
      Severity: Major
      Found in chain/reorg.go - About 45 mins to fix

        Method reorganizer.gatherReco has 5 return statements (exceeds 4 allowed).
        Open

        func (reorg *reorganizer) gatherReco() error {
            var err error
        
            cdb := reorg.cs.cdb
        
        
        Severity: Major
        Found in chain/reorg.go - About 35 mins to fix

          Method reorganizer.initRecovery has 5 return statements (exceeds 4 allowed).
          Open

          func (reorg *reorganizer) initRecovery(marker *ReorgMarker) error {
              var startBlock, bestBlock, topBlock *types.Block
              var err error
          
              if marker == nil {
          Severity: Major
          Found in chain/reorg.go - About 35 mins to fix

            There are no issues that match your filters.

            Category
            Status