aergoio/aergo

View on GitHub
chain/chainservice.go

Summary

Maintainability
F
3 days
Test Coverage
F
24%

File chainservice.go has 836 lines of code (exceeds 500 allowed). Consider refactoring.
Open

/**
 *  @file
 *  @copyright defined in aergo/LICENSE.txt
 */

Severity: Major
Found in chain/chainservice.go - About 1 day to fix

    Method ChainWorker.Receive has 219 lines of code (exceeds 50 allowed). Consider refactoring.
    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)
    Severity: Major
    Found in chain/chainservice.go - About 7 hrs to fix

      ChainService has 29 methods (exceeds 20 allowed). Consider refactoring.
      Open

      type ChainService struct {
          *component.BaseComponent
          consensus.ChainConsensus
          *Core
      
      
      Severity: Minor
      Found in chain/chainservice.go - About 3 hrs to fix

        Method ChainWorker.Receive has a Cognitive Complexity of 37 (exceeds 20 allowed). Consider refactoring.
        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)
        Severity: Minor
        Found in chain/chainservice.go - About 3 hrs 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

        Function NewChainService has 70 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func NewChainService(cfg *cfg.Config) *ChainService {
            cs := &ChainService{
                cfg:  cfg,
                op:   NewOrphanPool(DfltOrphanPoolSize),
                stat: newStats(),
        Severity: Minor
        Found in chain/chainservice.go - About 1 hr to fix

          Method ChainService.Receive has 55 lines of code (exceeds 50 allowed). Consider refactoring.
          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")
          Severity: Minor
          Found in chain/chainservice.go - About 1 hr to fix

            Method Core.initGenesis has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
            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..")
            Severity: Minor
            Found in chain/chainservice.go - About 1 hr 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 ChainService.getStaking has 5 return statements (exceeds 4 allowed).
            Open

            func (cs *ChainService) getStaking(addr []byte) (*types.Staking, error) {
                if cs.GetType() != consensus.ConsensusDPOS {
                    return nil, ErrNotSupportedConsensus
                }
            
            
            Severity: Major
            Found in chain/chainservice.go - About 35 mins to fix

              Method ChainService.getAccountVote has 5 return statements (exceeds 4 allowed).
              Open

              func (cs *ChainService) getAccountVote(addr []byte) (*types.AccountVoteInfo, error) {
                  if cs.GetType() != consensus.ConsensusDPOS {
                      return nil, ErrNotSupportedConsensus
                  }
              
              
              Severity: Major
              Found in chain/chainservice.go - About 35 mins to fix

                Method Core.init has 5 return statements (exceeds 4 allowed).
                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
                Severity: Major
                Found in chain/chainservice.go - About 35 mins to fix

                  Method ChainWorker.Receive has 5 return statements (exceeds 4 allowed).
                  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)
                  Severity: Major
                  Found in chain/chainservice.go - About 35 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status