chain/chainservice.go
File chainservice.go
has 836 lines of code (exceeds 500 allowed). Consider refactoring. Open
Open
/**
* @file
* @copyright defined in aergo/LICENSE.txt
*/
Method ChainWorker.Receive
has 219 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (cw *ChainWorker) Receive(context actor.Context) {
var sdb *statedb.StateDB
getAccProof := func(sdb *statedb.StateDB, account, root []byte, compressed bool) (*types.AccountProof, error) {
address, err := getAddressNameResolved(sdb, account)
ChainService
has 29 methods (exceeds 20 allowed). Consider refactoring. Open
Open
type ChainService struct {
*component.BaseComponent
consensus.ChainConsensus
*Core
Method ChainWorker.Receive
has a Cognitive Complexity of 37 (exceeds 20 allowed). Consider refactoring. Open
Open
func (cw *ChainWorker) Receive(context actor.Context) {
var sdb *statedb.StateDB
getAccProof := func(sdb *statedb.StateDB, account, root []byte, compressed bool) (*types.AccountProof, error) {
address, err := getAddressNameResolved(sdb, account)
- 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
Function NewChainService
has 70 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func NewChainService(cfg *cfg.Config) *ChainService {
cs := &ChainService{
cfg: cfg,
op: NewOrphanPool(DfltOrphanPoolSize),
stat: newStats(),
Method ChainService.Receive
has 55 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (cs *ChainService) Receive(context actor.Context) {
if !cs.isRecovered() {
err := cs.Recover()
if err != nil {
logger.Fatal().Err(err).Msg("CHAIN DATA IS CRASHED, BUT CAN'T BE RECOVERED")
Method Core.initGenesis
has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring. Open
Open
func (core *Core) initGenesis(genesis *types.Genesis, mainnet bool, testmode bool) (*types.Block, error) {
gen := core.cdb.GetGenesisInfo()
if gen == nil {
logger.Info().Msg("generating genesis block..")
- 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 ChainService.getStaking
has 5 return statements (exceeds 4 allowed). Open
Open
func (cs *ChainService) getStaking(addr []byte) (*types.Staking, error) {
if cs.GetType() != consensus.ConsensusDPOS {
return nil, ErrNotSupportedConsensus
}
Method ChainService.getAccountVote
has 5 return statements (exceeds 4 allowed). Open
Open
func (cs *ChainService) getAccountVote(addr []byte) (*types.AccountVoteInfo, error) {
if cs.GetType() != consensus.ConsensusDPOS {
return nil, ErrNotSupportedConsensus
}
Method Core.init
has 5 return statements (exceeds 4 allowed). Open
Open
func (core *Core) init(dbType string, dataDir string, testModeOn bool, forceResetHeight types.BlockNo) error {
// init chaindb
if err := core.cdb.Init(dbType, dataDir); err != nil {
logger.Fatal().Err(err).Msg("failed to initialize chaindb")
return err
Method ChainWorker.Receive
has 5 return statements (exceeds 4 allowed). Open
Open
func (cw *ChainWorker) Receive(context actor.Context) {
var sdb *statedb.StateDB
getAccProof := func(sdb *statedb.StateDB, account, root []byte, compressed bool) (*types.AccountProof, error) {
address, err := getAddressNameResolved(sdb, account)