Fantom-foundation/go-lachesis

View on GitHub
gossip/emitter.go

Summary

Maintainability
D
2 days
Test Coverage

File emitter.go has 643 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package gossip

import (
    "fmt"
    "math/big"
Severity: Minor
Found in gossip/emitter.go - About 5 hrs to fix

    Method Emitter.createEvent has 102 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (em *Emitter) createEvent(poolTxs map[common.Address]types.Transactions) *inter.Event {
        if em.myStakerID == 0 {
            // not a validator
            return nil
        }
    Severity: Major
    Found in gossip/emitter.go - About 3 hrs to fix

      Emitter has 21 methods (exceeds 20 allowed). Consider refactoring.
      Open

      type Emitter struct {
          txTime *lru.Cache // tx hash -> tx time
      
          net    *lachesis.Config
          config *EmitterConfig
      Severity: Minor
      Found in gossip/emitter.go - About 2 hrs to fix

        Method Emitter.createEvent has 14 return statements (exceeds 4 allowed).
        Open

        func (em *Emitter) createEvent(poolTxs map[common.Address]types.Transactions) *inter.Event {
            if em.myStakerID == 0 {
                // not a validator
                return nil
            }
        Severity: Major
        Found in gossip/emitter.go - About 1 hr to fix

          Method Emitter.isAllowedToEmit has 52 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (em *Emitter) isAllowedToEmit(e *inter.Event, selfParent *inter.EventHeaderData) bool {
              passedTime := e.ClaimedTime.Time().Sub(em.prevEmittedTime)
              // Slow down emitting if power is low
              {
                  threshold := em.config.NoTxsThreshold
          Severity: Minor
          Found in gossip/emitter.go - About 1 hr to fix

            Method Emitter.isMyTxTurn has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            func (em *Emitter) isMyTxTurn(txHash common.Hash, sender common.Address, accountNonce uint64, now time.Time, validatorsArr []idx.StakerID, validatorsArrStakes []pos.Stake, me idx.StakerID) bool {
            Severity: Major
            Found in gossip/emitter.go - About 50 mins to fix

              Method Emitter.isSynced has 8 return statements (exceeds 4 allowed).
              Open

              func (em *Emitter) isSynced() (bool, string, time.Duration) {
                  if em.intervals.SelfForkProtection == 0 {
                      return true, "", 0 // protection disabled
                  }
                  if em.world.PeersNum() == 0 {
              Severity: Major
              Found in gossip/emitter.go - About 50 mins to fix

                Method Emitter.isAllowedToEmit has 5 return statements (exceeds 4 allowed).
                Open

                func (em *Emitter) isAllowedToEmit(e *inter.Event, selfParent *inter.EventHeaderData) bool {
                    passedTime := e.ClaimedTime.Time().Sub(em.prevEmittedTime)
                    // Slow down emitting if power is low
                    {
                        threshold := em.config.NoTxsThreshold
                Severity: Major
                Found in gossip/emitter.go - About 35 mins to fix

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

                  func (em *Emitter) createEvent(poolTxs map[common.Address]types.Transactions) *inter.Event {
                      if em.myStakerID == 0 {
                          // not a validator
                          return nil
                      }
                  Severity: Minor
                  Found in gossip/emitter.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 Emitter.maxGasPowerToUse has 5 return statements (exceeds 4 allowed).
                  Open

                  func (em *Emitter) maxGasPowerToUse(e *inter.Event) uint64 {
                      // No txs in epoch tail, because tail events are unlikely to confirm
                      {
                          if em.isEpochTail(e) {
                              return 0
                  Severity: Major
                  Found in gossip/emitter.go - About 35 mins to fix

                    Method Emitter.addTxs has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
                    Open

                    func (em *Emitter) addTxs(e *inter.Event, poolTxs map[common.Address]types.Transactions) *inter.Event {
                        if poolTxs == nil || len(poolTxs) == 0 {
                            return e
                        }
                    
                    
                    Severity: Minor
                    Found in gossip/emitter.go - About 25 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