Fantom-foundation/go-lachesis

View on GitHub
gossip/handler.go

Summary

Maintainability
F
5 days
Test Coverage

Method ProtocolManager.handleMsg has a Cognitive Complexity of 127 (exceeds 20 allowed). Consider refactoring.
Open

func (pm *ProtocolManager) handleMsg(p *peer) error {
    // Read the next message from the remote peer, and ensure it's fully consumed
    msg, err := p.rw.ReadMsg()
    if err != nil {
        return err
Severity: Minor
Found in gossip/handler.go - About 2 days 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 ProtocolManager.handleMsg has 233 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (pm *ProtocolManager) handleMsg(p *peer) error {
    // Read the next message from the remote peer, and ensure it's fully consumed
    msg, err := p.rw.ReadMsg()
    if err != nil {
        return err
Severity: Major
Found in gossip/handler.go - About 1 day to fix

    File handler.go has 740 lines of code (exceeds 500 allowed). Consider refactoring.
    Open

    package gossip
    
    import (
        "fmt"
        "math"
    Severity: Minor
    Found in gossip/handler.go - About 7 hrs to fix

      Method ProtocolManager.handleMsg has 21 return statements (exceeds 4 allowed).
      Open

      func (pm *ProtocolManager) handleMsg(p *peer) error {
          // Read the next message from the remote peer, and ensure it's fully consumed
          msg, err := p.rw.ReadMsg()
          if err != nil {
              return err
      Severity: Major
      Found in gossip/handler.go - About 1 hr to fix

        Method ProtocolManager.makeFetcher has 61 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (pm *ProtocolManager) makeFetcher(checkers *eventcheck.Checkers) (*fetcher.Fetcher, *ordering.EventBuffer) {
            // checkers
            firstCheck := func(e *inter.Event) error {
                if err := checkers.Basiccheck.Validate(e); err != nil {
                    return err
        Severity: Minor
        Found in gossip/handler.go - About 1 hr to fix

          Function NewProtocolManager has 9 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              config *Config,
              notifier dagNotifier,
              txpool txPool,
              engineMu *sync.RWMutex,
              checkers *eventcheck.Checkers,
          Severity: Major
          Found in gossip/handler.go - About 1 hr to fix

            Method ProtocolManager.makeFetcher has 11 return statements (exceeds 4 allowed).
            Open

            func (pm *ProtocolManager) makeFetcher(checkers *eventcheck.Checkers) (*fetcher.Fetcher, *ordering.EventBuffer) {
                // checkers
                firstCheck := func(e *inter.Event) error {
                    if err := checkers.Basiccheck.Validate(e); err != nil {
                        return err
            Severity: Major
            Found in gossip/handler.go - About 1 hr to fix

              Method ProtocolManager.onNewEpochLoop has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
              Open

              func (pm *ProtocolManager) onNewEpochLoop() {
                  defer pm.loopsWg.Done()
                  for {
                      select {
                      case myEpoch := <-pm.newEpochsCh:
              Severity: Minor
              Found in gossip/handler.go - About 45 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

              Avoid deeply nested control flow statements.
              Open

                      if fullRecipients < 4 {
                          fullRecipients = 4
                      }
              Severity: Major
              Found in gossip/handler.go - About 45 mins to fix

                There are no issues that match your filters.

                Category
                Status