lbryio/chainquery

View on GitHub

Showing 107 of 112 total issues

Function checkHandleReorg has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
Open

func checkHandleReorg(height uint64, chainPrevHash string) (uint64, error) {
    prevHeight := height - 1
    depth := 0
    if height > 0 {
        prevBlock, err := model.Blocks(qm.Where(model.BlockColumns.Height+"=?", prevHeight), qm.Load("BlockHashTransactions")).OneG()
Severity: Minor
Found in daemon/processing/block.go - About 45 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 checkHandleReorg has 6 return statements (exceeds 4 allowed).
Open

func checkHandleReorg(height uint64, chainPrevHash string) (uint64, error) {
    prevHeight := height - 1
    depth := 0
    if height > 0 {
        prevBlock, err := model.Blocks(qm.Where(model.BlockColumns.Height+"=?", prevHeight), qm.Load("BlockHashTransactions")).OneG()
Severity: Major
Found in daemon/processing/block.go - About 40 mins to fix

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

func initVinWorkers(s *stop.Group, nrWorkers int, jobs <-chan vinToProcess, results chan<- error) {
    for i := 0; i < nrWorkers; i++ {
        s.Add(1)
        go func(worker int) {
            defer s.Done()
Severity: Minor
Found in daemon/processing/outpoint.go and 1 other location - About 40 mins to fix
daemon/processing/outpoint.go on lines 70..78

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

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 getPublicKeyScriptType has 6 return statements (exceeds 4 allowed).
Open

func getPublicKeyScriptType(script []byte) string {
    if isPayToPublicKey(script) {
        return p2PK
    } else if isPayToPublicKeyHashScript(script) {
        return p2PKH
Severity: Major
Found in lbrycrd/script.go - About 40 mins to fix

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

func initVoutWorkers(s *stop.Group, nrWorkers int, jobs <-chan voutToProcess, results chan<- error) {
    for i := 0; i < nrWorkers; i++ {
        s.Add(1)
        go func(worker int) {
            defer s.Done()
Severity: Minor
Found in daemon/processing/outpoint.go and 1 other location - About 40 mins to fix
daemon/processing/outpoint.go on lines 46..54

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

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 createUpdateVoutAddresses has 6 return statements (exceeds 4 allowed).
Open

func createUpdateVoutAddresses(tx *model.Transaction, outputs *[]lbrycrd.Vout, blockSeconds uint64) (map[string]uint64, error) {
    addressIDMap := make(map[string]uint64)
    for _, output := range *outputs {
        address, err := getFirstAddressFromVout(output)
        if err != nil {
Severity: Major
Found in daemon/processing/address.go - About 40 mins to fix

Method chainSyncStatus.alignClaim has 6 return statements (exceeds 4 allowed).
Open

func (c *chainSyncStatus) alignClaim() error {
    storedClaim := datastore.GetClaim(c.Vout.ClaimID.String)
    if storedClaim == nil {
        return errors.Err("could not find claim with id %s", c.Vout.ClaimID.String)
    }
Severity: Major
Found in daemon/jobs/chainsync.go - About 40 mins to fix

Function processSupport has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

func processSupport(claimID string, value []byte, support *model.Support, output model.Output, tx model.Transaction) (*model.Support, error) {
Severity: Minor
Found in daemon/processing/claim.go - About 35 mins to fix

Function processClaim has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

func processClaim(helper *c.StakeHelper, claim *model.Claim, value []byte, output model.Output, tx model.Transaction) (*model.Claim, error) {
Severity: Minor
Found in daemon/processing/claim.go - About 35 mins to fix

Method chainSyncStatus.alignTxs has 5 return statements (exceeds 4 allowed).
Open

func (c *chainSyncStatus) alignTxs(block *model.Block, txHashes []string) error {
    for _, txHash := range txHashes {
        lbrycrdTx, err := lbrycrd.GetRawTransactionResponse(txHash)
        if err != nil {
            return c.recordAndReturnError(c.LastHeight, "tx-hash-creation", err)
Severity: Major
Found in daemon/jobs/chainsync.go - About 35 mins to fix

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 GetIsExpiredAtHeight has 5 return statements (exceeds 4 allowed).
Open

func GetIsExpiredAtHeight(height, blockHeight uint) bool {
    if height == 0 {
        return false
    }
    if height >= expirationHardForkHeight {
Severity: Major
Found in daemon/jobs/claimtriesync.go - About 35 mins to fix

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

func checkTxs(missingData []BlockData, lbryBlock *lbrycrd.GetBlockResponse, transactions model.TransactionSlice) ([]BlockData, error) {
    for _, lbryTxHash := range lbryBlock.Tx {
        var tx *model.Transaction
        for _, transaction := range transactions {
            if transaction.Hash == lbryTxHash {
Severity: Minor
Found in daemon/jobs/chainvalidation.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 fixOutputs has 5 return statements (exceeds 4 allowed).
Open

func fixOutputs() error {
    wg := sync.WaitGroup{}
    spentClaimsChan := make(chan *model.Claim, 100)
    errorsChan := make(chan error, runtime.NumCPU())
    c := model.ClaimColumns
Severity: Major
Found in daemon/jobs/outputfixsync.go - About 35 mins to fix

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 updateSpentClaims has 5 return statements (exceeds 4 allowed).
Open

func updateSpentClaims() error {
    var lastProcessed uint64
    for {
        //Claims without updates
        claims, newLastProcessed, err := getSpentClaimsToUpdate(false, lastProcessed)
Severity: Major
Found in daemon/jobs/claimtriesync.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

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

func decodeFloat(data interface{}) (interface{}, error) {
    if n, ok := data.(json.Number); ok {
        val, err := n.Float64()
        if err != nil {
            return nil, errors.Wrap(err, 0)
Severity: Major
Found in lbrycrd/client.go - About 35 mins to fix

Function processClaimUpdateScript has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
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: Minor
Found in daemon/processing/claim.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

Severity
Category
Status
Source
Language