consensus/impl/raftv2/blockfactory.go
File blockfactory.go
has 667 lines of code (exceeds 500 allowed). Consider refactoring. Open
Open
package raftv2
import (
"bytes"
"context"
BlockFactory
has 37 methods (exceeds 20 allowed). Consider refactoring. Open
Open
type BlockFactory struct {
*component.ComponentHub
consensus.ChainWAL
bpc *Cluster
Method BlockFactory.generateBlock
has 52 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (bf *BlockFactory) generateBlock(work *Work) (*types.Block, *state.BlockState, error) {
var (
bestBlock *types.Block
err error
)
Method BlockFactory.generateBlock
has 8 return statements (exceeds 4 allowed). Open
Open
func (bf *BlockFactory) generateBlock(work *Work) (*types.Block, *state.BlockState, error) {
var (
bestBlock *types.Block
err error
)
Method BlockFactory.controller
has 5 return statements (exceeds 4 allowed). Open
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
Method BlockFactory.QueueJob
has 5 return statements (exceeds 4 allowed). Open
Open
func (bf *BlockFactory) QueueJob(now time.Time, jq chan<- interface{}) {
bf.jobLock.Lock()
defer bf.jobLock.Unlock()
var (
Method BlockFactory.MakeConfChangeProposal
has 5 return statements (exceeds 4 allowed). Open
Open
func (bf *BlockFactory) MakeConfChangeProposal(req *types.MembershipChange) (*consensus.ConfChangePropose, error) {
var (
proposal *consensus.ConfChangePropose
err error
)
Method BlockFactory.ConfChange
has 5 return statements (exceeds 4 allowed). Open
Open
func (bf *BlockFactory) ConfChange(req *types.MembershipChange) (*consensus.Member, error) {
if bf.bpc == nil {
return nil, ErrorMembershipChange{ErrClusterNotReady}
}
Method BlockFactory.ClusterInfo
has 5 return statements (exceeds 4 allowed). Open
Open
func (bf *BlockFactory) ClusterInfo(bestBlockHash []byte) *types.GetClusterInfoResponse {
var (
hardStateInfo *types.HardStateInfo
mbrAttrs []*types.MemberAttr
bestBlock *types.Block
Method BlockFactory.worker
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
Open
func (bf *BlockFactory) worker() {
defer logger.Info().Msg("shutdown initiated. stop the service")
runtime.LockOSThread()
- 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"