bitcoin/bitcoin

View on GitHub
contrib/devtools/headerssync-params.py

Summary

Maintainability
C
1 day
Test Coverage

Function attack_rate has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

def attack_rate(period, bufsize, limit=None):
    """Compute maximal accepted headers per attack in (period, bufsize) configuration.

    If limit is provided, the computation is stopped early when the result is known to exceed the
    value in limit.
Severity: Minor
Found in contrib/devtools/headerssync-params.py - 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 find_bufsize has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

def find_bufsize(period, attack_headers, when, max_mem=None, min_bufsize=1):
    """Determine how big bufsize needs to be given a specific period length.

    Given a period, find the smallest value of bufsize such that the attack rate against the
    (period, bufsize) configuration is below attack_headers. If max_mem is provided, and no
Severity: Minor
Found in contrib/devtools/headerssync-params.py - 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 optimize has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

def optimize(when):
    """Find the best (period, bufsize) configuration."""

    # When period*bufsize = memory_scale, the per-peer memory for a mainchain sync and a maximally
    # long low-difficulty header sync are equal.
Severity: Minor
Found in contrib/devtools/headerssync-params.py - 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

Avoid deeply nested control flow statements.
Open

                    if limit is not None and rate >= limit:
                        return rate, None
                    # If the maximal term being added is negligible compared to rate, stop
                    # iterating.
                    if HEADER_BATCH_COUNT * prob < 1.0e-16 * rate * len(align_choices):
Severity: Major
Found in contrib/devtools/headerssync-params.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                        if HEADER_BATCH_COUNT * prob < 1.0e-16 * rate * len(align_choices):
                            break
                    # Update state from a new incoming batch (which is all forged)
                    after_good_commit += HEADER_BATCH_COUNT
    Severity: Major
    Found in contrib/devtools/headerssync-params.py - About 45 mins to fix

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

      def find_bufsize(period, attack_headers, when, max_mem=None, min_bufsize=1):
      Severity: Minor
      Found in contrib/devtools/headerssync-params.py - About 35 mins to fix

        There are no issues that match your filters.

        Category
        Status