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.
- Read upRead up
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
- Read upRead up
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.
- Read upRead up
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):
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
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):