Fantom-foundation/go-lachesis

View on GitHub

Showing 291 of 829 total issues

Method EventHeaderData.UnmarshalBinary has 87 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (e *EventHeaderData) UnmarshalBinary(raw []byte) (err error) {
    defer func() {
        if r := recover(); r != nil {
            err = ErrInvalidEncoding
        }
Severity: Major
Found in inter/event_serializer.go - About 2 hrs to fix

    Method Index.fillEventVectors has 87 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (vi *Index) fillEventVectors(e *inter.EventHeaderData) allVecs {
        meIdx := vi.validatorIdxs[e.Creator]
        myVecs := allVecs{
            beforeSeq:  NewHighestBeforeSeq(len(vi.bi.BranchIDCreatorIdxs)),
            beforeTime: NewHighestBeforeTime(len(vi.bi.BranchIDCreatorIdxs)),
    Severity: Major
    Found in vector/index.go - About 2 hrs to fix

      Method TxPool.loop has a Cognitive Complexity of 33 (exceeds 20 allowed). Consider refactoring.
      Open

      func (pool *TxPool) loop() {
          defer pool.wg.Done()
      
          var (
              prevPending, prevQueued, prevStales int
      Severity: Minor
      Found in evmcore/tx_pool.go - About 2 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 MainGenesis has 85 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func MainGenesis() Genesis {
          g := Genesis{
              Time: genesisTime,
              Alloc: VAccounts{
                  Accounts: Accounts{
      Severity: Major
      Found in lachesis/genesis/genesis.go - About 2 hrs to fix

        Function DAGtoASCIIscheme has 84 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func DAGtoASCIIscheme(events Events) (string, error) {
            events = events.ByParents()
        
            var (
                scheme rows
        Severity: Major
        Found in inter/ascii_scheme.go - About 2 hrs to fix

          Store has 22 methods (exceeds 20 allowed). Consider refactoring.
          Open

          func (s *Store) IncBlocksMissed(stakerID idx.StakerID, periodDiff inter.Timestamp) {
              s.mutex.BlockDowntime.Lock()
              defer s.mutex.BlockDowntime.Unlock()
          
              missed := s.getBlocksMissed(stakerID)
          Severity: Minor
          Found in app/store_scores.go - About 2 hrs to fix

            Function GetAPIs has 82 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func GetAPIs(apiBackend Backend) []rpc.API {
                nonceLock := new(AddrLocker)
                orig := []rpc.API{
                    {
                        Namespace: "eth",
            Severity: Major
            Found in ethapi/backend.go - About 2 hrs to fix

              Method FilterCriteria.UnmarshalJSON has 82 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (args *FilterCriteria) UnmarshalJSON(data []byte) error {
                  type input struct {
                      BlockHash *common.Hash     `json:"blockHash"`
                      FromBlock *rpc.BlockNumber `json:"fromBlock"`
                      ToBlock   *rpc.BlockNumber `json:"toBlock"`
              Severity: Major
              Found in gossip/filters/api.go - About 2 hrs to fix

                Function DoEstimateGas has 81 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, gasCap uint64) (hexutil.Uint64, error) {
                    // Binary search the gas requirement, as it may be higher than the amount used
                    var (
                        lo  uint64 = params.TxGas - 1
                        hi  uint64
                Severity: Major
                Found in ethapi/api.go - About 2 hrs to fix

                  Method Election.ProcessRoot has 81 lines of code (exceeds 50 allowed). Consider refactoring.
                  Open

                  func (el *Election) ProcessRoot(newRoot RootAndSlot) (*Res, error) {
                      res, err := el.chooseAtropos()
                      if err != nil || res != nil {
                          return res, err
                      }
                  Severity: Major
                  Found in poset/election/election_math.go - About 2 hrs to fix

                    Method Store.MigrateMultiDelegations has 80 lines of code (exceeds 50 allowed). Consider refactoring.
                    Open

                    func (s *Store) MigrateMultiDelegations() error {
                        { // migrate s.table.Delegations
                            newKeys := make([][]byte, 0, 10000)
                            newValues := make([][]byte, 0, 10000)
                            {
                    Severity: Major
                    Found in app/store_migration.go - About 2 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 PeerPacksDownloader.loop has a Cognitive Complexity of 31 (exceeds 20 allowed). Consider refactoring.
                        Open

                        func (d *PeerPacksDownloader) loop() {
                            // Iterate the event fetching until a quit is requested
                            syncTicker := time.NewTicker(recheckInterval)
                            defer syncTicker.Stop()
                        
                        
                        Severity: Minor
                        Found in gossip/packsdownloader/peer_downloader.go - About 2 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 ForEachRandFork has 76 lines of code (exceeds 50 allowed). Consider refactoring.
                        Open

                        func ForEachRandFork(
                            nodes []idx.StakerID,
                            cheatersArr []idx.StakerID,
                            eventCount int,
                            parentCount int,
                        Severity: Major
                        Found in inter/common.go - About 2 hrs to fix

                          Function ExportState has 22 return statements (exceeds 4 allowed).
                          Open

                          func ExportState(path string, gdb *gossip.Store, cdb *poset.Store, net *lachesis.Config) (*genesisstore.Store, error) {
                              _ = os.RemoveAll(path)
                          
                              err := os.MkdirAll(path, 0700)
                              if err != nil {
                          Severity: Major
                          Found in cmd/lachesis/opera_export_state.go - About 2 hrs to fix

                            Method EventHeaderData.MarshalBinary has 73 lines of code (exceeds 50 allowed). Consider refactoring.
                            Open

                            func (e *EventHeaderData) MarshalBinary() ([]byte, error) {
                                isPrevEpochHashEmpty := (e.PrevEpochHash == hash.Zero)
                                isTxHashEmpty := (e.TxHash == EmptyTxHash)
                            
                                fields64 := []uint64{
                            Severity: Minor
                            Found in inter/event_serializer.go - About 1 hr to fix

                              Method ProtocolManager.handleMsg has 21 return statements (exceeds 4 allowed).
                              Open

                              func (pm *ProtocolManager) handleMsg(p *peer) error {
                                  // Read the next message from the remote peer, and ensure it's fully consumed
                                  msg, err := p.rw.ReadMsg()
                                  if err != nil {
                                      return err
                              Severity: Major
                              Found in gossip/handler.go - About 1 hr to fix

                                Method TxPool.reset has 68 lines of code (exceeds 50 allowed). Consider refactoring.
                                Open

                                func (pool *TxPool) reset(oldHead, newHead *EvmHeader) {
                                    // If we're reorging an old state, reinject all dropped transactions
                                    var reinject types.Transactions
                                
                                    if oldHead != nil && oldHead.Hash != newHead.ParentHash {
                                Severity: Minor
                                Found in evmcore/tx_pool.go - About 1 hr to fix

                                  Function lachesisOperaMigrationMain has 67 lines of code (exceeds 50 allowed). Consider refactoring.
                                  Open

                                  func lachesisOperaMigrationMain(ctx *cli.Context) error {
                                      if args := ctx.Args(); len(args) > 0 {
                                          return fmt.Errorf("invalid command: %q", args[0])
                                      }
                                  
                                  
                                  Severity: Minor
                                  Found in cmd/lachesis/opera_migration.go - About 1 hr to fix

                                    Method Metric.Write has 67 lines of code (exceeds 50 allowed). Consider refactoring.
                                    Open

                                    func (m *Metric) Write(out *dto.Metric) error {
                                        switch metric := m.m.(type) {
                                    
                                        case metrics.Meter:
                                            t := metric.Snapshot()
                                    Severity: Minor
                                    Found in metrics/prometheus/adapter.go - About 1 hr to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language