lbryio/chainquery

View on GitHub

Showing 109 of 114 total issues

Function reprocessUpdatedClaims has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
Open

func reprocessUpdatedClaims(claimsChan chan *model.Claim, currentHeight uint64, processedClaims *int64) error {
    const BatchSize = 5000
    reprocessedNamesMap := make(map[string]bool, 500000)
    claimsBatch := make(model.ClaimSlice, 0, BatchSize)
    for {
Severity: Minor
Found in daemon/jobs/claimtriesync.go - About 35 mins 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 processTxSet has 5 return statements (exceeds 4 allowed).
Open

func processTxSet(txSet lbrycrd.RawMempoolVerboseResponse, lastBlock *model.Block, staleTxs model.TransactionSlice) (bool, error) {
    currTxMap := make(map[string]*model.Transaction)
    for _, tx := range staleTxs {
        currTxMap[tx.Hash] = tx
    }
Severity: Major
Found in daemon/jobs/mempoolsync.go - About 35 mins to fix

Function processClaimUpdateScript has 5 return statements (exceeds 4 allowed).
Open

func processClaimUpdateScript(script *[]byte, vout model.Output, tx model.Transaction, blockHeight uint64) (name string, claimID string, pubkeyscript []byte, err error) {
    name, claimID, value, pubkeyscript, err := lbrycrd.ParseClaimUpdateScript(*script)
    if err != nil {
        err := errors.Prefix("Claim update processing error", err)
        return name, claimID, pubkeyscript, err
Severity: Major
Found in daemon/processing/claim.go - About 35 mins to fix

Function getFirstAddressFromVout has 5 return statements (exceeds 4 allowed).
Open

func getFirstAddressFromVout(vout lbrycrd.Vout) (scriptAddress string, err error) {
    if vout.ScriptPubKey.Type == lbrycrd.NonStandard {
        scriptAddress, err = getAddressFromNonStandardVout(vout.ScriptPubKey.Hex)
        if errors.Is(err, lbrycrd.ErrNotClaimScript) {
            logrus.Warning(err)
Severity: Major
Found in daemon/processing/address.go - About 35 mins to fix

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

        if c.Vin.ScriptSigAsm.String != v.ScriptSig.Asm {
            c.Vin.ScriptSigAsm.String = v.ScriptSig.Asm
            c.Vin.ScriptSigAsm.Valid = v.ScriptSig.Asm != ""
            colsToUpdate = append(colsToUpdate, model.InputColumns.ScriptSigAsm)
        }
Severity: Minor
Found in daemon/jobs/chainsync.go and 1 other location - About 30 mins to fix
daemon/jobs/chainsync.go on lines 317..321

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 102.

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

        if c.Vin.ScriptSigHex.String != v.ScriptSig.Hex {
            c.Vin.ScriptSigHex.String = v.ScriptSig.Hex
            c.Vin.ScriptSigHex.Valid = v.ScriptSig.Hex != ""
            colsToUpdate = append(colsToUpdate, model.InputColumns.ScriptSigHex)
        }
Severity: Minor
Found in daemon/jobs/chainsync.go and 1 other location - About 30 mins to fix
daemon/jobs/chainsync.go on lines 322..326

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 102.

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 CertificateSync has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
Open

func CertificateSync() {
    if !certificateSyncRunning {
        metrics.JobLoad.WithLabelValues("certificate_sync").Inc()
        defer metrics.JobLoad.WithLabelValues("certificate_sync").Dec()
        defer metrics.Job(time.Now(), "certificate_sync")
Severity: Minor
Found in daemon/jobs/certificatesync.go - About 25 mins 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 ProcessVout has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
Open

func ProcessVout(jsonVout *lbrycrd.Vout, tx *m.Transaction, txDC *txDebitCredits, blockHeight uint64) error {
    defer metrics.Processing(time.Now(), "vout")
    vout := &m.Output{}
    foundVout := ds.GetOutput(tx.Hash, uint(jsonVout.N))
    if foundVout != nil {
Severity: Minor
Found in daemon/processing/outpoint.go - About 25 mins 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

Your code does not pass gofmt in 5 places. Go fmt your code!
Open

package lbrycrd
Severity: Minor
Found in lbrycrd/request.go by gofmt

Function SyncClaimCntInChannel has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
Open

func SyncClaimCntInChannel() error {
    latestBlock, err := model.Blocks(qm.Select(model.BlockColumns.Height), qm.OrderBy(model.BlockColumns.Height+" DESC")).OneG()
    if err != nil {
        return errors.Prefix(syncClaimsInChannel, err)
    }
Severity: Minor
Found in daemon/jobs/valuesync.go - About 25 mins 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

Your code does not pass gofmt in 4 places. Go fmt your code!
Open

package jobs
Severity: Minor
Found in daemon/jobs/valuesync.go by gofmt

Your code does not pass gofmt in 3 places. Go fmt your code!
Open

package processing
Severity: Minor
Found in daemon/processing/metadata.go by gofmt

Your code does not pass gofmt in 3 places. Go fmt your code!
Open

package processing
Severity: Minor
Found in daemon/processing/block.go by gofmt

Your code does not pass gofmt in 3 places. Go fmt your code!
Open

package apiactions
Severity: Minor
Found in apiactions/validation.go by gofmt

Your code does not pass gofmt in 2 places. Go fmt your code!
Open

package twilio
Severity: Minor
Found in twilio/twilio.go by gofmt

Your code does not pass gofmt in 2 places. Go fmt your code!
Open

package datastore
Severity: Minor
Found in datastore/datastore.go by gofmt

Your code does not pass gofmt in 2 places. Go fmt your code!
Open

package lbrycrd
Severity: Minor
Found in lbrycrd/client.go by gofmt

Your code does not pass gofmt in 2 places. Go fmt your code!
Open

package lbrycrd
Severity: Minor
Found in lbrycrd/script.go by gofmt

Your code does not pass gofmt in 2 places. Go fmt your code!
Open

package daemon
Severity: Minor
Found in daemon/daemon.go by gofmt

Your code does not pass gofmt in 1 place. Go fmt your code!
Open

package util
Severity: Minor
Found in util/utility.go by gofmt
Severity
Category
Status
Source
Language