gossip/emitter.go
File emitter.go
has 643 lines of code (exceeds 500 allowed). Consider refactoring. Open
Open
package gossip
import (
"fmt"
"math/big"
Method Emitter.createEvent
has 102 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (em *Emitter) createEvent(poolTxs map[common.Address]types.Transactions) *inter.Event {
if em.myStakerID == 0 {
// not a validator
return nil
}
Emitter
has 21 methods (exceeds 20 allowed). Consider refactoring. Open
Open
type Emitter struct {
txTime *lru.Cache // tx hash -> tx time
net *lachesis.Config
config *EmitterConfig
Method Emitter.createEvent
has 14 return statements (exceeds 4 allowed). Open
Open
func (em *Emitter) createEvent(poolTxs map[common.Address]types.Transactions) *inter.Event {
if em.myStakerID == 0 {
// not a validator
return nil
}
Method Emitter.isAllowedToEmit
has 52 lines of code (exceeds 50 allowed). Consider refactoring. Open
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
Method Emitter.isMyTxTurn
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
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 {
Method Emitter.isSynced
has 8 return statements (exceeds 4 allowed). Open
Open
func (em *Emitter) isSynced() (bool, string, time.Duration) {
if em.intervals.SelfForkProtection == 0 {
return true, "", 0 // protection disabled
}
if em.world.PeersNum() == 0 {
Method Emitter.isAllowedToEmit
has 5 return statements (exceeds 4 allowed). Open
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
Method Emitter.createEvent
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
Open
func (em *Emitter) createEvent(poolTxs map[common.Address]types.Transactions) *inter.Event {
if em.myStakerID == 0 {
// not a validator
return nil
}
- Read upRead up
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
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
Method Emitter.addTxs
has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring. Open
Open
func (em *Emitter) addTxs(e *inter.Event, poolTxs map[common.Address]types.Transactions) *inter.Event {
if poolTxs == nil || len(poolTxs) == 0 {
return e
}
- Read upRead up
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"