Fantom-foundation/go-lachesis

View on GitHub

Showing 829 of 829 total issues

Similar blocks of code found in 3 locations. Consider refactoring.
Open

func (s *Store) GetAddressPOI(address common.Address) *big.Int {
    poiBytes, err := s.table.AddressPOIScore.Get(address.Bytes())
    if err != nil {
        s.Log.Crit("Failed to set key", "err", err)
    }
Severity: Major
Found in app/store_poi.go and 2 other locations - About 1 hr to fix
app/store_poi.go on lines 40..52
app/store_poi.go on lines 156..168

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 146.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 3 locations. Consider refactoring.
Open

func (s *Store) GetWeightedDelegationsFee(stakerID idx.StakerID) *big.Int {
    valBytes, err := s.table.StakerDelegationsFee.Get(stakerID.Bytes())
    if err != nil {
        s.Log.Crit("Failed to get key", "err", err)
    }
Severity: Major
Found in app/store_poi.go and 2 other locations - About 1 hr to fix
app/store_poi.go on lines 156..168
app/store_poi.go on lines 179..191

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 146.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 3 locations. Consider refactoring.
Open

func (s *Store) GetStakerPOI(stakerID idx.StakerID) *big.Int {
    poiBytes, err := s.table.StakerPOIScore.Get(stakerID.Bytes())
    if err != nil {
        s.Log.Crit("Failed to set key", "err", err)
    }
Severity: Major
Found in app/store_poi.go and 2 other locations - About 1 hr to fix
app/store_poi.go on lines 40..52
app/store_poi.go on lines 179..191

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 146.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function writeTo has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
Open

func writeTo(parent string, t *ast.Table, w io.Writer) (err error) {
    var fullName string
    if parent != "" {
        fullName = parent + "." + t.Name
    } else {
Severity: Minor
Found in utils/toml/file.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

Function ApplyTransaction has 10 arguments (exceeds 4 allowed). Consider refactoring.
Open

    config *params.ChainConfig,
    bc DummyChain,
    author *common.Address,
    gp *GasPool,
    statedb *state.StateDB,
Severity: Major
Found in evmcore/state_processor.go - About 1 hr to fix

    Method PublicTransactionPoolAPI.Resend has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
    Open

    func (s *PublicTransactionPoolAPI) Resend(ctx context.Context, sendArgs SendTxArgs, gasPrice *hexutil.Big, gasLimit *hexutil.Uint64) (common.Hash, error) {
        if sendArgs.Nonce == nil {
            return common.Hash{}, fmt.Errorf("missing transaction nonce in transaction spec")
        }
        if err := sendArgs.setDefaults(ctx, s.b); err != nil {
    Severity: Minor
    Found in ethapi/api.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

    Function filterLogs has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
    Open

    func filterLogs(logs []*types.Log, fromBlock, toBlock *big.Int, addresses []common.Address, topics [][]common.Hash) []*types.Log {
        var ret []*types.Log
    Logs:
        for _, log := range logs {
            if fromBlock != nil && fromBlock.Int64() >= 0 && fromBlock.Uint64() > log.BlockNumber {
    Severity: Minor
    Found in gossip/filters/filter.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

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    func (s *Store) SetSfcStaker(stakerID idx.StakerID, v *sfctype.SfcStaker) {
        s.mutex.Stakers.Lock()
        defer s.mutex.Stakers.Unlock()
    
        s.set(s.table.Stakers, stakerID.Bytes(), v)
    Severity: Major
    Found in app/store_sfc_stakers.go and 1 other location - About 1 hr to fix
    app/store_sfc_delegators.go on lines 12..22

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 144.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    func (s *Store) SetSfcDelegation(id sfctype.DelegationID, v *sfctype.SfcDelegation) {
        s.mutex.Delegations.Lock()
        defer s.mutex.Delegations.Unlock()
    
        s.set(s.table.Delegations, id.Bytes(), v)
    Severity: Major
    Found in app/store_sfc_delegators.go and 1 other location - About 1 hr to fix
    app/store_sfc_stakers.go on lines 32..42

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 144.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function DoCall has 55 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides map[common.Address]account, vmCfg vm.Config, timeout time.Duration, globalGasCap uint64) (*evmcore.ExecutionResult, error) {
        defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now())
    
        state, header, err := b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
        if state == nil || err != nil {
    Severity: Minor
    Found in ethapi/api.go - About 1 hr to fix

      Method TxPool.loop has 55 lines of code (exceeds 50 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 1 hr to fix

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

        func (s *Store) GetStakerClaimedRewards(stakerID idx.StakerID) *big.Int {
            amount, err := s.table.StakerOldRewards.Get(stakerID.Bytes())
            if err != nil {
                s.Log.Crit("Failed to erase key-value", "err", err)
            }
        Severity: Major
        Found in app/store_rewards_history.go and 2 other locations - About 1 hr to fix
        app/store_rewards_history.go on lines 46..55
        app/store_rewards_history.go on lines 81..90

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 141.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

        func (s *Store) GetDelegationClaimedRewards(id sfctype.DelegationID) *big.Int {
            amount, err := s.table.DelegationOldRewards.Get(id.Bytes())
            if err != nil {
                s.Log.Crit("Failed to erase key-value", "err", err)
            }
        Severity: Major
        Found in app/store_rewards_history.go and 2 other locations - About 1 hr to fix
        app/store_rewards_history.go on lines 11..20
        app/store_rewards_history.go on lines 81..90

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 141.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        func (h *HandlerT) StopGoTrace() error {
            h.mu.Lock()
            defer h.mu.Unlock()
            trace.Stop()
            if h.traceW == nil {
        Severity: Major
        Found in debug/trace.go and 1 other location - About 1 hr to fix
        debug/api.go on lines 119..131

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 141.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 3 locations. Consider refactoring.
        Open

        func (s *Store) GetStakerDelegationsClaimedRewards(stakerID idx.StakerID) *big.Int {
            amount, err := s.table.StakerDelegationsOldRewards.Get(stakerID.Bytes())
            if err != nil {
                s.Log.Crit("Failed to erase key-value", "err", err)
            }
        Severity: Major
        Found in app/store_rewards_history.go and 2 other locations - About 1 hr to fix
        app/store_rewards_history.go on lines 11..20
        app/store_rewards_history.go on lines 46..55

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 141.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

        func (h *HandlerT) StopCPUProfile() error {
            h.mu.Lock()
            defer h.mu.Unlock()
            pprof.StopCPUProfile()
            if h.cpuW == nil {
        Severity: Major
        Found in debug/api.go and 1 other location - About 1 hr to fix
        debug/trace.go on lines 51..63

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 141.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Method ProtocolManager.txsyncLoop has 54 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (pm *ProtocolManager) txsyncLoop() {
            var (
                pending = make(map[enode.ID]*txsync)
                sending = false               // whether a send is active
                pack    = new(txsync)         // the pack that is being sent
        Severity: Minor
        Found in gossip/sync.go - About 1 hr to fix

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

          func (s *Store) getOriginationScore(t kvdb.KeyValueStore, stakerID idx.StakerID) *big.Int {
              scoreBytes, err := t.Get(stakerID.Bytes())
              if err != nil {
                  s.Log.Crit("Failed to get key-value", "err", err)
              }
          Severity: Major
          Found in app/store_scores.go and 1 other location - About 1 hr to fix
          app/store_scores.go on lines 104..113

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 138.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

          func (s *Store) getValidationScore(t kvdb.KeyValueStore, stakerID idx.StakerID) *big.Int {
              scoreBytes, err := t.Get(stakerID.Bytes())
              if err != nil {
                  s.Log.Crit("Failed to get key-value", "err", err)
              }
          Severity: Major
          Found in app/store_scores.go and 1 other location - About 1 hr to fix
          app/store_scores.go on lines 187..196

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 138.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Function NewProtocolManager has 9 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              config *Config,
              notifier dagNotifier,
              txpool txPool,
              engineMu *sync.RWMutex,
              checkers *eventcheck.Checkers,
          Severity: Major
          Found in gossip/handler.go - About 1 hr to fix
            Severity
            Category
            Status
            Source
            Language