Move to Super Linter 3.9.2 - now lint Black, flake8, mypy (#390)

* Try Super Linter at 3.9.0 and add linters

* 3.9.1 and set validate all to false

* Back to 3.9.1 and use only true VALIDATE_

* Place superlint in debug mode

* Try fix from 3.9.2

* black source. Start fixing flake8 issues

* Black tests, out of debug

* Black setup.py do to merge conflict
This commit is contained in:
Gene Hoffman 2020-09-01 15:30:23 -07:00
parent b9cf218642
commit 57c5e19353
57 changed files with 619 additions and 258 deletions

4
.github/linters/.flake8 vendored Normal file
View File

@ -0,0 +1,4 @@
[flake8]
max-line-length = 120
exclude = ./typings/**/*
ignore = E203,W503

View File

@ -178,7 +178,7 @@ never-returning-functions=optparse.Values,sys.exit
# List of additional names supposed to be defined in builtins. Remember that
# you should avoid to define new builtins when possible.
additional-builtins=
additional-builtins=cls
# Tells whether unused global variables should be treated as a violation.
allow-global-unused-variables=yes

View File

@ -45,25 +45,30 @@ jobs:
# Run Linter against code base #
################################
- name: Lint Code Base
uses: docker://github/super-linter:v3.5.1
uses: docker://github/super-linter:v3.9.2
env:
VALIDATE_ALL_CODEBASE: true
DEFAULT_BRANCH: master
LINTER_RULES_PATH: .github/linters
VALIDATE_YAML: true
VALIDATE_JSON: true
VALIDATE_MD: true
VALIDATE_BASH: true
VALIDATE_PYTHON: true
VALIDATE_JAVASCRIPT_STANDARD: false
VALIDATE_JAVASCRIPT_ES: true
VALIDATE_TYPESCRIPT_ES: true
# VALIDATE_CSS: true
VALIDATE_DOCKER: true
VALIDATE_GO: true
VALIDATE_HTML: true
VALIDATE_JAVASCRIPT_ES: true
VALIDATE_JSON: true
VALIDATE_MD: true
VALIDATE_POWERSHELL: true
VALIDATE_CSS: false
VALIDATE_ENV: true
VALIDATE_PYTHON: true
VALIDATE_PYTHON_PYLINT: true
VALIDATE_PYTHON_FLAKE8: true
VALIDATE_PYTHON_BLACK: true
VALIDATE_SHELL_SHFMT: true
VALIDATE_TYPESCRIPT_ES: true
VALIDATE_YAML: true
DISABLE_ERRORS: false
PYTHONPATH: ${{ github.workspace }}:$PYTHONPATH
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ACTIONS_RUNNER_DEBUG: true
...

View File

@ -10,12 +10,13 @@ dependencies = [
"clvm==0.4.1", # contract language
"clvm-tools==0.1.4", # clvm compiler tools
"aiohttp==3.6.2", # HTTP server for full node rpc
"aiosqlite@git+https://github.com/mariano54/aiosqlite.git@28cb5754deec562ac931da8fca799fb82df97a12#egg=aiosqlite", # asyncio wrapper for sqlite, to store blocks
"aiosqlite@git+https://github.com/mariano54/aiosqlite.git@28cb5754deec562ac931da8fca799fb82df97a12#egg=aiosqlite",
# asyncio wrapper for sqlite, to store blocks
"bitstring==3.1.7", # Binary data management library
"cbor2==5.1.2", # Used for network wire format
"colorlog==4.2.1", # Adds color to logs
"concurrent-log-handler==0.9.16", # Concurrently log and rotate logs
"cryptography==3.1", #Python cryptography library for TLS
"cryptography==3.1", # Python cryptography library for TLS
"keyring==21.4.0", # Store keys in MacOS Keychain, Windows Credential Locker
"keyrings.cryptfile==1.3.4", # Secure storage for keys on Linux (Will be replaced)
"PyYAML==5.3.1", # Used for config file format
@ -46,7 +47,9 @@ kwargs = dict(
install_requires=dependencies,
setup_requires=["setuptools_scm"],
extras_require=dict(
uvloop=["uvloop"], dev=dev_dependencies, upnp=upnp_dependencies,
uvloop=["uvloop"],
dev=dev_dependencies,
upnp=upnp_dependencies,
),
packages=[
"build_scripts",

View File

@ -60,7 +60,11 @@ def make_parser(parser):
help="Enter mnemonic you want to use",
)
parser.add_argument(
"-k", "--key", type=str, default=None, help="Enter the raw private key in hex",
"-k",
"--key",
type=str,
default=None,
help="Enter the raw private key in hex",
)
parser.add_argument(
"-f",
@ -87,11 +91,19 @@ def make_parser(parser):
)
parser.add_argument(
"-p", "--public_key", type=str, default=None, help="Enter the pk in hex",
"-p",
"--public_key",
type=str,
default=None,
help="Enter the pk in hex",
)
parser.add_argument(
"-s", "--signature", type=str, default=None, help="Enter the signature in hex",
"-s",
"--signature",
type=str,
default=None,
help="Enter the signature in hex",
)
parser.add_argument(

View File

@ -9,10 +9,16 @@ from src.util.service_groups import all_groups, services_for_groups
def make_parser(parser):
parser.add_argument(
"-r", "--restart", action="store_true", help="Restart of running processes",
"-r",
"--restart",
action="store_true",
help="Restart of running processes",
)
parser.add_argument(
"group", choices=all_groups(), type=str, nargs="+",
"group",
choices=all_groups(),
type=str,
nargs="+",
)
parser.set_defaults(function=start)

View File

@ -7,10 +7,17 @@ from src.util.service_groups import all_groups, services_for_groups
def make_parser(parser):
parser.add_argument(
"-d", "--daemon", action="store_true", help="Stop daemon",
"-d",
"--daemon",
action="store_true",
help="Stop daemon",
)
parser.add_argument(
"group", choices=all_groups(), type=str, nargs="+", default=None,
"group",
choices=all_groups(),
type=str,
nargs="+",
default=None,
)
parser.set_defaults(function=stop)

View File

@ -3,7 +3,7 @@ from src.util.ints import uint32
def find_fork_point_in_chain(hash_to_block: Dict, block_1: Any, block_2: Any) -> uint32:
""" Tries to find height where new chain (block_2) diverged from block_1 (assuming prev blocks
"""Tries to find height where new chain (block_2) diverged from block_1 (assuming prev blocks
are all included in chain)"""
while block_2.height > 0 or block_1.height > 0:
if block_2.height > block_1.height:

View File

@ -5,7 +5,10 @@ from src.consensus.pos_quality import quality_str_to_quality
def calculate_iterations_quality(
quality: bytes32, size: int, difficulty: int, min_iterations: int,
quality: bytes32,
size: int,
difficulty: int,
min_iterations: int,
) -> uint64:
"""
Calculates the number of iterations from the quality. The quality is converted to a number

View File

@ -134,7 +134,10 @@ class Farmer:
)
estimate_min = uint64(int(estimate_min))
number_iters: uint64 = calculate_iterations_quality(
quality_string, plot_size, difficulty, estimate_min,
quality_string,
plot_size,
difficulty,
estimate_min,
)
return number_iters
@ -234,7 +237,10 @@ class Farmer:
)
estimate_min = uint64(int(estimate_min))
number_iters: uint64 = calculate_iterations_quality(
computed_quality_string, response.proof.size, difficulty, estimate_min,
computed_quality_string,
response.proof.size,
difficulty,
estimate_min,
)
estimate_secs: float = number_iters / self.proof_of_time_estimate_ips

View File

@ -127,7 +127,10 @@ async def validate_unfinished_block_header(
min_iters = uint64(constants.MIN_ITERS_STARTING)
number_of_iters: uint64 = calculate_iterations_quality(
pos_quality_string, proof_of_space.size, difficulty, min_iters,
pos_quality_string,
proof_of_space.size,
difficulty,
min_iters,
)
assert count_significant_bits(difficulty) <= constants.SIGNIFICANT_BITS

View File

@ -158,7 +158,12 @@ class BlockStore:
def add_proof_of_time(
self, challenge: bytes32, iter: uint64, height: uint32
) -> None:
self.proof_of_time_heights[(challenge, iter,)] = height
self.proof_of_time_heights[
(
challenge,
iter,
)
] = height
def get_height_proof_of_time(
self, challenge: bytes32, iter: uint64

View File

@ -117,7 +117,9 @@ class Blockchain:
self._shut_down = True
self.pool.shutdown(wait=True)
async def _load_chain_from_store(self,) -> None:
async def _load_chain_from_store(
self,
) -> None:
"""
Initializes the state of the Blockchain class from the database. Sets the LCA, tips,
headers, height_to_hash, and block_store DiffStores.
@ -842,7 +844,10 @@ class Blockchain:
for npc in npc_list:
unspent = removal_coin_records[npc.coin_name]
error = blockchain_check_conditions_dict(
unspent, removal_coin_records, npc.condition_dict, block.header,
unspent,
removal_coin_records,
npc.condition_dict,
block.header,
)
if error:
return error

View File

@ -180,7 +180,11 @@ class CoinStore:
if current is None:
return
spent: CoinRecord = CoinRecord(
current.coin, current.confirmed_block_index, index, True, current.coinbase,
current.coin,
current.confirmed_block_index,
index,
True,
current.coinbase,
) # type: ignore # noqa
await self.add_coin_record(spent)

View File

@ -135,12 +135,14 @@ def get_next_difficulty(
# Only change by a max factor, to prevent attacks, as in greenpaper, and must be at least 1
max_diff = uint64(
truncate_to_significant_bits(
constants.DIFFICULTY_FACTOR * Tc, constants.SIGNIFICANT_BITS,
constants.DIFFICULTY_FACTOR * Tc,
constants.SIGNIFICANT_BITS,
)
)
min_diff = uint64(
truncate_to_significant_bits(
Tc // constants.DIFFICULTY_FACTOR, constants.SIGNIFICANT_BITS,
Tc // constants.DIFFICULTY_FACTOR,
constants.SIGNIFICANT_BITS,
)
)
if new_difficulty >= Tc:

View File

@ -376,7 +376,8 @@ class FullNode:
phr = self.sync_store.get_potential_hashes_received()
assert phr is not None
await asyncio.wait_for(
phr.wait(), timeout=sleep_interval,
phr.wait(),
timeout=sleep_interval,
)
break
# https://github.com/python/cpython/pull/13528
@ -409,7 +410,10 @@ class FullNode:
# Start processing blocks that we have received (no block yet)
block_processor = SyncBlocksProcessor(
self.sync_store, fork_point_height, uint32(tip_height), self.blockchain,
self.sync_store,
fork_point_height,
uint32(tip_height),
self.blockchain,
)
block_processor_task = asyncio.create_task(block_processor.process())
lca = self.blockchain.lca_block
@ -446,7 +450,9 @@ class FullNode:
new_lca = self.blockchain.lca_block
if new_lca != lca:
new_lca_req = wallet_protocol.NewLCA(
new_lca.header_hash, new_lca.height, new_lca.weight,
new_lca.header_hash,
new_lca.height,
new_lca.weight,
)
yield OutboundMessage(
NodeType.WALLET, Message("new_lca", new_lca_req), Delivery.BROADCAST
@ -614,7 +620,9 @@ class FullNode:
assert fees >= 0
assert cost is not None
new_tx = full_node_protocol.NewTransaction(
tx.transaction.name(), cost, uint64(tx.transaction.fees()),
tx.transaction.name(),
cost,
uint64(tx.transaction.fees()),
)
yield OutboundMessage(
NodeType.FULL_NODE,
@ -804,14 +812,16 @@ class FullNode:
yield _
async def _respond_compact_proof_of_time(
self, proof: ProofOfTime,
self,
proof: ProofOfTime,
) -> OutboundMessageGenerator:
"""
A proof of time, received by a peer full node. If we have the rest of the block,
we can complete it. Otherwise, we just verify and propagate the proof.
"""
height: Optional[uint32] = self.block_store.get_height_proof_of_time(
proof.challenge_hash, proof.number_of_iterations,
proof.challenge_hash,
proof.number_of_iterations,
)
if height is None:
self.log.info("No block for compact proof of time.")
@ -837,7 +847,8 @@ class FullNode:
block.transactions_filter,
)
if self.block_store.seen_compact_proof(
proof.challenge_hash, proof.number_of_iterations,
proof.challenge_hash,
proof.number_of_iterations,
):
return
await self.block_store.add_block(block_new)
@ -888,13 +899,19 @@ class FullNode:
if block.proof_of_time.witness_type != 0:
challenge_msg = timelord_protocol.ChallengeStart(
block.proof_of_time.challenge_hash, block.weight,
block.proof_of_time.challenge_hash,
block.weight,
)
pos_info_msg = timelord_protocol.ProofOfSpaceInfo(
block.proof_of_time.challenge_hash,
block.proof_of_time.number_of_iterations,
)
broadcast_list.append((challenge_msg, pos_info_msg,))
broadcast_list.append(
(
challenge_msg,
pos_info_msg,
)
)
# Scan only since the first uncompact block we know about.
# No block earlier than this will be uncompact in the future,
# unless a reorg happens. The range to scan next time
@ -1327,7 +1344,9 @@ class FullNode:
target_tip.height + 1, request.pool_target.puzzle_hash, cb_reward
)
fees_coin = create_fees_coin(
target_tip.height + 1, request.farmer_rewards_puzzle_hash, full_fee_reward,
target_tip.height + 1,
request.farmer_rewards_puzzle_hash,
full_fee_reward,
)
# Create addition Merkle set
@ -1628,7 +1647,8 @@ class FullNode:
difficulty,
)
timelord_request = timelord_protocol.ChallengeStart(
challenge_hash, respond_block.block.weight,
challenge_hash,
respond_block.block.weight,
)
# Tell timelord to stop previous challenge and start with new one
yield OutboundMessage(
@ -1664,7 +1684,9 @@ class FullNode:
new_lca = self.blockchain.lca_block
if new_lca != prev_lca:
new_lca_req = wallet_protocol.NewLCA(
new_lca.header_hash, new_lca.height, new_lca.weight,
new_lca.header_hash,
new_lca.height,
new_lca.weight,
)
yield OutboundMessage(
NodeType.WALLET, Message("new_lca", new_lca_req), Delivery.BROADCAST
@ -1798,7 +1820,9 @@ class FullNode:
assert fees >= 0
assert cost is not None
new_tx = full_node_protocol.NewTransaction(
tx.transaction.name(), cost, uint64(tx.transaction.fees()),
tx.transaction.name(),
cost,
uint64(tx.transaction.fees()),
)
yield OutboundMessage(
NodeType.FULL_NODE,
@ -1944,7 +1968,9 @@ class FullNode:
request.height, request.header_hash
)
yield OutboundMessage(
NodeType.WALLET, Message("reject_header_request", reject), Delivery.RESPOND,
NodeType.WALLET,
Message("reject_header_request", reject),
Delivery.RESPOND,
)
@api_request
@ -2016,7 +2042,9 @@ class FullNode:
)
yield OutboundMessage(
NodeType.WALLET, Message("respond_removals", response), Delivery.RESPOND,
NodeType.WALLET,
Message("respond_removals", response),
Delivery.RESPOND,
)
@api_request
@ -2091,7 +2119,9 @@ class FullNode:
)
yield OutboundMessage(
NodeType.WALLET, Message("respond_additions", response), Delivery.RESPOND,
NodeType.WALLET,
Message("respond_additions", response),
Delivery.RESPOND,
)
@api_request

View File

@ -22,7 +22,8 @@ class FullNodeStore:
unfinished_blocks_leader: Tuple[uint32, uint64]
# Blocks which we have created, but don't have proof of space yet, old ones are cleared
candidate_blocks: Dict[
bytes32, Tuple[Optional[Program], bytes, HeaderData, ProofOfSpace, uint32],
bytes32,
Tuple[Optional[Program], bytes, HeaderData, ProofOfSpace, uint32],
]
# Header hashes of unfinished blocks that we have seen recently
seen_unfinished_blocks: set

View File

@ -126,7 +126,8 @@ class MempoolManager:
program = best_solution_program(new_spend)
# npc contains names of the coins removed, puzzle_hashes and their spend conditions
fail_reason, npc_list, cost = calculate_cost_of_program(
program, self.constants.CLVM_COST_RATIO_CONSTANT,
program,
self.constants.CLVM_COST_RATIO_CONSTANT,
)
if fail_reason:
return None, MempoolInclusionStatus.FAILED, fail_reason

View File

@ -86,8 +86,8 @@ class SyncBlocksProcessor:
validation_start_time = time.time()
prevalidate_results = await self.blockchain.pre_validate_blocks_multiprocessing(
blocks
prevalidate_results = (
await self.blockchain.pre_validate_blocks_multiprocessing(blocks)
)
if self._shut_down:

View File

@ -230,12 +230,14 @@ class Harvester:
)
if quality_strings is not None:
for index, quality_str in enumerate(quality_strings):
response: harvester_protocol.ChallengeResponse = harvester_protocol.ChallengeResponse(
new_challenge.challenge_hash,
str(filename),
uint8(index),
quality_str,
prover.get_size(),
response: harvester_protocol.ChallengeResponse = (
harvester_protocol.ChallengeResponse(
new_challenge.challenge_hash,
str(filename),
uint8(index),
quality_str,
prover.get_size(),
)
)
all_responses.append(response)
return all_responses
@ -314,7 +316,9 @@ class Harvester:
proof_xs,
)
response = harvester_protocol.RespondProofOfSpace(
request.plot_id, request.response_number, proof_of_space,
request.plot_id,
request.response_number,
proof_of_space,
)
if response:
yield OutboundMessage(
@ -346,14 +350,18 @@ class Harvester:
# form a complete PrependSignature.
signature: G2Element = AugSchemeMPL.sign(local_sk, request.message, agg_pk)
response: harvester_protocol.RespondSignature = harvester_protocol.RespondSignature(
request.plot_id,
request.message,
local_sk.get_g1(),
plot_info.farmer_public_key,
signature,
response: harvester_protocol.RespondSignature = (
harvester_protocol.RespondSignature(
request.plot_id,
request.message,
local_sk.get_g1(),
plot_info.farmer_public_key,
signature,
)
)
yield OutboundMessage(
NodeType.FARMER, Message("respond_signature", response), Delivery.RESPOND,
NodeType.FARMER,
Message("respond_signature", response),
Delivery.RESPOND,
)

View File

@ -28,7 +28,12 @@ def check_plots(args, root_path):
for pk in config["farmer"]["pool_public_keys"]
]
_, provers, failed_to_open_filenames, no_key_filenames = load_plots(
{}, {}, pks, pool_public_keys, root_path, open_no_key_filenames=True,
{},
{},
pks,
pool_public_keys,
root_path,
open_no_key_filenames=True,
)
if len(provers) > 0:
log.info("")

View File

@ -355,8 +355,10 @@ class FullNodeRpcApi:
else:
header = None
coin_records = await self.service.blockchain.coin_store.get_coin_records_by_puzzle_hash(
puzzle_hash, header
coin_records = (
await self.service.blockchain.coin_store.get_coin_records_by_puzzle_hash(
puzzle_hash, header
)
)
return {"success": True, "coin_records": coin_records}

View File

@ -285,7 +285,9 @@ class WalletRpcApi:
raw_puzzle_hash = decode_puzzle_hash(puzzle_hash)
request = FarmNewBlockProtocol(raw_puzzle_hash)
msg = OutboundMessage(
NodeType.FULL_NODE, Message("farm_new_block", request), Delivery.BROADCAST,
NodeType.FULL_NODE,
Message("farm_new_block", request),
Delivery.BROADCAST,
)
self.service.server.push_message(msg)

View File

@ -44,7 +44,10 @@ async def initialize_pipeline(
# Maps a stream reader, writer and NodeType to a ChiaConnection object
connections_aiter = map_aiter(
partial_func.partial_async(
stream_reader_writer_to_connection, server_port, local_type, log,
stream_reader_writer_to_connection,
server_port,
local_type,
log,
),
join_aiters(srwt_aiter),
)
@ -61,7 +64,11 @@ async def initialize_pipeline(
outbound_handshake = Message(
"handshake",
Handshake(
network_id, protocol_version, node_id, uint16(server_port), local_type,
network_id,
protocol_version,
node_id,
uint16(server_port),
local_type,
),
)
@ -83,7 +90,9 @@ async def initialize_pipeline(
# Handles each message one at a time, and yields responses to send back or broadcast
responses_aiter = join_aiters(
map_aiter(
partial_func.partial_async_gen(handle_message, api), messages_aiter, 100,
partial_func.partial_async_gen(handle_message, api),
messages_aiter,
100,
)
)

View File

@ -13,7 +13,9 @@ def generate_selfsigned_cert(hostname="/CN=Chia Blockchain CA", key=None):
# Generate our key
if key is None:
key = rsa.generate_private_key(
public_exponent=65537, key_size=2048, backend=default_backend(),
public_exponent=65537,
key_size=2048,
backend=default_backend(),
)
name = x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, hostname)])

View File

@ -47,7 +47,8 @@ class ProofOfSpace(Streamable):
@staticmethod
def calculate_plot_id(
pool_public_key: G1Element, plot_public_key: G1Element,
pool_public_key: G1Element,
plot_public_key: G1Element,
) -> bytes32:
return bytes32(std_hash(bytes(pool_public_key) + bytes(plot_public_key)))

View File

@ -20,7 +20,8 @@ class ProofOfTime(Streamable):
def is_valid(self, discriminant_size_bits):
try:
disc: int = int(
create_discriminant(self.challenge_hash, discriminant_size_bits), 16,
create_discriminant(self.challenge_hash, discriminant_size_bits),
16,
)
x = ClassGroup.from_ab_discriminant(2, 1, disc)
y = ClassGroup.from_ab_discriminant(self.output.a, self.output.b, disc)

View File

@ -64,7 +64,9 @@ class BlockTools:
"""
def __init__(
self, root_path: Optional[Path] = None, real_plots: bool = False,
self,
root_path: Optional[Path] = None,
real_plots: bool = False,
):
self._tempdir = None
if root_path is None:
@ -305,7 +307,10 @@ class BlockTools:
)
)
if new_difficulty >= curr_difficulty:
new_difficulty = min(new_difficulty, max_diff,)
new_difficulty = min(
new_difficulty,
max_diff,
)
else:
new_difficulty = max([uint64(1), new_difficulty, min_diff])
@ -512,7 +517,8 @@ class BlockTools:
)
plot_pk = ProofOfSpace.generate_plot_public_key(
selected_plot_info.local_sk.get_g1(), selected_plot_info.farmer_public_key,
selected_plot_info.local_sk.get_g1(),
selected_plot_info.farmer_public_key,
)
proof_of_space: ProofOfSpace = ProofOfSpace(
challenge_hash,
@ -538,15 +544,29 @@ class BlockTools:
)
output = ClassgroupElement(
int512(int.from_bytes(result[0:int_size], "big", signed=True,)),
int512(
int.from_bytes(result[int_size : 2 * int_size], "big", signed=True,)
int.from_bytes(
result[0:int_size],
"big",
signed=True,
)
),
int512(
int.from_bytes(
result[int_size : 2 * int_size],
"big",
signed=True,
)
),
)
proof_bytes = result[2 * int_size : 4 * int_size]
proof_of_time = ProofOfTime(
challenge_hash, number_iters, output, uint8(0), proof_bytes,
challenge_hash,
number_iters,
output,
uint8(0),
proof_bytes,
)
# Use the extension data to create different blocks based on header hash

View File

@ -10,7 +10,8 @@ from src.util.mempool_check_conditions import get_name_puzzle_conditions
def calculate_cost_of_program(
program: Program, clvm_cost_ratio_constant: int,
program: Program,
clvm_cost_ratio_constant: int,
) -> Tuple[Optional[Err], List[NPC], uint64]:
"""
This function calculates the total cost of either block or a spendbundle

View File

@ -147,7 +147,7 @@ class Keychain:
str_bytes = bytes.fromhex(read_str)
return (
G1Element.from_bytes(str_bytes[: G1Element.SIZE]),
str_bytes[G1Element.SIZE :],
str_bytes[G1Element.SIZE :], # flake8: noqa
)
def _get_private_key_user(self, index: int):

View File

@ -346,9 +346,9 @@ def _deserialize(proof, pos, bits):
if t == EMPTY:
return _empty, pos + 1
if t == TERMINAL:
return TerminalNode(proof[pos + 1 : pos + 33], bits), pos + 33
return TerminalNode(proof[pos + 1 : pos + 33], bits), pos + 33 # flake8: noqa
if t == TRUNCATED:
return TruncatedNode(proof[pos + 1 : pos + 33]), pos + 33
return TruncatedNode(proof[pos + 1 : pos + 33]), pos + 33 # flake8: noqa
if t != MIDDLE:
raise SetError()
v0, pos = _deserialize(proof, pos + 1, bits + [0])

View File

@ -53,7 +53,10 @@ class CCWallet:
@staticmethod
async def create_new_cc(
wallet_state_manager: Any, wallet: Wallet, amount: uint64, name: str = None,
wallet_state_manager: Any,
wallet: Wallet,
amount: uint64,
name: str = None,
):
self = CCWallet()
self.base_puzzle_program = None
@ -497,8 +500,10 @@ class CCWallet:
return uint64(amount)
async def get_pending_change_balance(self) -> uint64:
unconfirmed_tx = await self.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(
self.wallet_info.id
unconfirmed_tx = (
await self.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(
self.wallet_info.id
)
)
addition_amount = 0
@ -664,7 +669,12 @@ class CCWallet:
coin.puzzle_hash
)
auditees.append(
(coin.parent_coin_info, coin_inner_puzzle[coin], coin.amount, 0,)
(
coin.parent_coin_info,
coin_inner_puzzle[coin],
coin.amount,
0,
)
)
primaries = [{"puzzlehash": to_address, "amount": amount}]
@ -694,7 +704,10 @@ class CCWallet:
puzzle = self.cc_info.puzzle_for_inner_puzzle(inner_puzzle)
main_coin_solution = CoinSolution(auditor, Program.to([puzzle, solution]),)
main_coin_solution = CoinSolution(
auditor,
Program.to([puzzle, solution]),
)
list_of_solutions.append(main_coin_solution)
# main = SpendBundle([main_coin_solution], ZERO96)

View File

@ -44,7 +44,12 @@ def is_ephemeral_solution(s: Program):
def cc_generate_eve_spend(coin: Coin, inner_puzzle: Program, genesis_id: bytes32):
full_puzzle = puzzle_for_inner_puzzle(inner_puzzle, genesis_id)
solution = Program.to([coin.parent_coin_info, coin.amount, 0, 0, 0])
list_of_solutions = [CoinSolution(coin, Program.to([full_puzzle, solution]),)]
list_of_solutions = [
CoinSolution(
coin,
Program.to([full_puzzle, solution]),
)
]
aggsig = AugSchemeMPL.aggregate([])
spend_bundle = SpendBundle(list_of_solutions, aggsig)
return spend_bundle

View File

@ -48,7 +48,9 @@ def int_as_bytes32(v: int) -> bytes32:
def generate_farmed_coin(
block_index: int, puzzle_hash: bytes32, amount: uint64,
block_index: int,
puzzle_hash: bytes32,
amount: uint64,
) -> Coin:
"""
Generate a (fake) coin which can be used as a starting point for a chain
@ -150,7 +152,10 @@ def test_spend_through_n(mod_code, n):
inner_puzzle_solution = Program.to(output_conditions)
spend_bundle = spend_bundle_for_spendable_ccs(
mod_code, genesis_coin_checker, spendable_cc_list, [inner_puzzle_solution],
mod_code,
genesis_coin_checker,
spendable_cc_list,
[inner_puzzle_solution],
)
debug_spend_bundle(spend_bundle)
@ -175,7 +180,10 @@ def test_spend_through_n(mod_code, n):
]
spend_bundle = spend_bundle_for_spendable_ccs(
mod_code, genesis_coin_checker, spendable_cc_list, inner_solutions,
mod_code,
genesis_coin_checker,
spendable_cc_list,
inner_solutions,
)
debug_spend_bundle(spend_bundle)

View File

@ -61,7 +61,9 @@ class RLWallet(AbstractWallet):
log: logging.Logger
@staticmethod
async def create_rl_admin(wallet_state_manager: Any,):
async def create_rl_admin(
wallet_state_manager: Any,
):
unused: Optional[
uint32
] = await wallet_state_manager.puzzle_store.get_unused_derivation_path()
@ -103,7 +105,9 @@ class RLWallet(AbstractWallet):
return self
@staticmethod
async def create_rl_user(wallet_state_manager: Any,):
async def create_rl_user(
wallet_state_manager: Any,
):
async with wallet_state_manager.puzzle_store.lock:
unused: Optional[
uint32
@ -331,14 +335,18 @@ class RLWallet(AbstractWallet):
return await self.wallet_state_manager.get_frozen_balance(self.wallet_info.id)
async def get_spendable_balance(self) -> uint64:
spendable_am = await self.wallet_state_manager.get_confirmed_spendable_balance_for_wallet(
self.wallet_info.id
spendable_am = (
await self.wallet_state_manager.get_confirmed_spendable_balance_for_wallet(
self.wallet_info.id
)
)
return spendable_am
async def get_pending_change_balance(self) -> uint64:
unconfirmed_tx = await self.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(
self.wallet_info.id
unconfirmed_tx = (
await self.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(
self.wallet_info.id
)
)
addition_amount = 0
@ -405,8 +413,10 @@ class RLWallet(AbstractWallet):
"""
Return keys for pubkey
"""
index_for_pubkey = await self.wallet_state_manager.puzzle_store.index_for_pubkey(
G1Element.from_bytes(clawback_pubkey)
index_for_pubkey = (
await self.wallet_state_manager.puzzle_store.index_for_pubkey(
G1Element.from_bytes(clawback_pubkey)
)
)
if index_for_pubkey is None:
raise Exception("index_for_pubkey is None")
@ -439,8 +449,10 @@ class RLWallet(AbstractWallet):
rl_parent_id = self.rl_coin_record.coin.parent_coin_info
if rl_parent_id == self.rl_info.rl_origin_id:
return self.rl_info.rl_origin
rl_parent = await self.wallet_state_manager.wallet_store.get_coin_record_by_coin_id(
rl_parent_id
rl_parent = (
await self.wallet_state_manager.wallet_store.get_coin_record_by_coin_id(
rl_parent_id
)
)
if rl_parent is None:
return None

View File

@ -17,16 +17,16 @@ def rl_puzzle_for_pk(
clawback_pk: bytes,
):
"""
Solution to this puzzle must be in format:
(1 my_parent_id, my_puzzlehash, my_amount, outgoing_puzzle_hash, outgoing_amount,
min_block_time, parent_parent_id, parent_amount)
RATE LIMIT LOGIC:
M - chia_per_interval
N - interval_blocks
V - amount being spent
MIN_BLOCK_AGE = V / (M / N)
if not (min_block_age * M >= V * N) do X (raise)
ASSERT_COIN_BLOCK_AGE_EXCEEDS min_block_age
Solution to this puzzle must be in format:
(1 my_parent_id, my_puzzlehash, my_amount, outgoing_puzzle_hash, outgoing_amount,
min_block_time, parent_parent_id, parent_amount)
RATE LIMIT LOGIC:
M - chia_per_interval
N - interval_blocks
V - amount being spent
MIN_BLOCK_AGE = V / (M / N)
if not (min_block_age * M >= V * N) do X (raise)
ASSERT_COIN_BLOCK_AGE_EXCEEDS min_block_age
"""
hex_pk = pubkey.hex()
@ -126,8 +126,8 @@ def solution_for_rl(
def rl_make_aggregation_puzzle(wallet_puzzle):
"""
If Wallet A wants to send further funds to Wallet B then they can lock them up using this code
Solution will be (my_id wallet_coin_primary_input wallet_coin_amount)
If Wallet A wants to send further funds to Wallet B then they can lock them up using this code
Solution will be (my_id wallet_coin_primary_input wallet_coin_amount)
"""
opcode_myid = hexlify(ConditionOpcode.ASSERT_MY_COIN_ID).decode("ascii")
opcode_consumed = hexlify(ConditionOpcode.ASSERT_COIN_CONSUMED).decode("ascii")

View File

@ -13,7 +13,8 @@ class UserSettings:
@staticmethod
async def create(
store: KeyValStore, name: str = None,
store: KeyValStore,
name: str = None,
):
self = UserSettings()
self.basic_store = store

View File

@ -38,7 +38,9 @@ class TradeManager:
@staticmethod
async def create(
wallet_state_manager: Any, db_connection, name: str = None,
wallet_state_manager: Any,
db_connection,
name: str = None,
):
self = TradeManager()
if name:
@ -203,8 +205,10 @@ class TradeManager:
result = {}
removals = bundle.removals()
for coin in removals:
coin_record = await self.wallet_state_manager.wallet_store.get_coin_record_by_coin_id(
coin.name()
coin_record = (
await self.wallet_state_manager.wallet_store.get_coin_record_by_coin_id(
coin.name()
)
)
if coin_record is None:
continue
@ -293,12 +297,14 @@ class TradeManager:
for add in additions:
if add not in removals and add.amount == 0:
zero_val_coin = add
new_spend_bundle = await wallet.create_spend_bundle_relative_amount(
amount, zero_val_coin
new_spend_bundle = (
await wallet.create_spend_bundle_relative_amount(
amount, zero_val_coin
)
)
else:
new_spend_bundle = await wallet.create_spend_bundle_relative_amount(
amount
new_spend_bundle = (
await wallet.create_spend_bundle_relative_amount(amount)
)
elif isinstance(wallet, Wallet):
if spend_bundle is None:
@ -419,8 +425,10 @@ class TradeManager:
] = await self.wallet_state_manager.get_wallet_for_colour(
colour
)
unspent = await self.wallet_state_manager.get_spendable_coins_for_wallet(
wallets[colour].wallet_info.id
unspent = (
await self.wallet_state_manager.get_spendable_coins_for_wallet(
wallets[colour].wallet_info.id
)
)
if coinsol.coin in [record.coin for record in unspent]:
return False, None, "can't respond to own offer"
@ -428,8 +436,10 @@ class TradeManager:
puzzle
)
innersol = cc_wallet_puzzles.inner_puzzle_solution(solution)
out_amount = cc_wallet_puzzles.get_output_amount_for_puzzle_and_solution(
innerpuzzlereveal, innersol
out_amount = (
cc_wallet_puzzles.get_output_amount_for_puzzle_and_solution(
innerpuzzlereveal, innersol
)
)
if colour in cc_discrepancies:
@ -465,8 +475,8 @@ class TradeManager:
coinsols.append(coinsol)
else:
# standard chia coin
unspent = await self.wallet_state_manager.get_spendable_coins_for_wallet(
1
unspent = (
await self.wallet_state_manager.get_spendable_coins_for_wallet(1)
)
if coinsol.coin in [record.coin for record in unspent]:
return False, None, "can't respond to own offer"
@ -579,7 +589,8 @@ class TradeManager:
Program.to(
[
cc_wallet_puzzles.puzzle_for_inner_puzzle(
inner_puzzle, colour,
inner_puzzle,
colour,
),
solution,
]
@ -661,7 +672,8 @@ class TradeManager:
Program.to(
[
cc_wallet_puzzles.puzzle_for_inner_puzzle(
auditor_inner_puzzle, bytes.fromhex(colour),
auditor_inner_puzzle,
bytes.fromhex(colour),
),
solution,
]

View File

@ -207,7 +207,11 @@ class TradeStore:
"""
cursor = await self.db_connection.execute(
"SELECT * from trade_records WHERE sent<? and confirmed=?", (4, 0,)
"SELECT * from trade_records WHERE sent<? and confirmed=?",
(
4,
0,
),
)
rows = await cursor.fetchall()
await cursor.close()

View File

@ -58,8 +58,10 @@ def get_discrepancies_for_spend_bundle(
)
innersol = cc_wallet_puzzles.inner_puzzle_solution(solution)
# Get output amounts by running innerpuzzle and solution
out_amount = cc_wallet_puzzles.get_output_amount_for_puzzle_and_solution(
innerpuzzlereveal, innersol
out_amount = (
cc_wallet_puzzles.get_output_amount_for_puzzle_and_solution(
innerpuzzlereveal, innersol
)
)
# add discrepancy to dict of discrepancies
if colour in cc_discrepancies:
@ -68,8 +70,10 @@ def get_discrepancies_for_spend_bundle(
cc_discrepancies[colour] = coinsol.coin.amount - out_amount
else: # standard chia coin
coin_amount = coinsol.coin.amount
out_amount = cc_wallet_puzzles.get_output_amount_for_puzzle_and_solution(
puzzle, solution
out_amount = (
cc_wallet_puzzles.get_output_amount_for_puzzle_and_solution(
puzzle, solution
)
)
diff = coin_amount - out_amount
if "chia" in cc_discrepancies:

View File

@ -37,7 +37,9 @@ class Wallet(AbstractWallet):
@staticmethod
async def create(
wallet_state_manager: Any, info: WalletInfo, name: str = None,
wallet_state_manager: Any,
info: WalletInfo,
name: str = None,
):
self = Wallet()
@ -66,14 +68,18 @@ class Wallet(AbstractWallet):
return await self.wallet_state_manager.get_frozen_balance(self.wallet_info.id)
async def get_spendable_balance(self) -> uint64:
spendable_am = await self.wallet_state_manager.get_confirmed_spendable_balance_for_wallet(
self.wallet_info.id
spendable_am = (
await self.wallet_state_manager.get_confirmed_spendable_balance_for_wallet(
self.wallet_info.id
)
)
return spendable_am
async def get_pending_change_balance(self) -> uint64:
unconfirmed_tx = await self.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(
self.wallet_info.id
unconfirmed_tx = (
await self.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(
self.wallet_info.id
)
)
addition_amount = 0

View File

@ -153,7 +153,9 @@ class WalletNode:
assert self.wallet_state_manager is not None
backup_settings: BackupInitialized = self.wallet_state_manager.user_settings.get_backup_settings()
backup_settings: BackupInitialized = (
self.wallet_state_manager.user_settings.get_backup_settings()
)
if backup_settings.user_initialized is False:
if new_wallet is True:
await self.wallet_state_manager.user_settings.user_created_new_wallet()
@ -395,8 +397,10 @@ class WalletNode:
raise TimeoutError("Took too long to fetch header hashes.")
# 2. Find fork point
fork_point_height: uint32 = self.wallet_state_manager.find_fork_point_alternate_chain(
self.header_hashes
fork_point_height: uint32 = (
self.wallet_state_manager.find_fork_point_alternate_chain(
self.header_hashes
)
)
fork_point_hash: bytes32 = self.header_hashes[fork_point_height]
@ -489,13 +493,11 @@ class WalletNode:
uint32(query_heights[batch_start_index])
].is_set()
if (
(
time.time() - last_request_time > sleep_interval
and blocks_missing
)
or (query_heights[batch_start_index])
> highest_height_requested
):
time.time() - last_request_time > sleep_interval
and blocks_missing
) or (
query_heights[batch_start_index]
) > highest_height_requested:
self.log.info(
f"Requesting sync header {query_heights[batch_start_index]}"
)
@ -619,7 +621,8 @@ class WalletNode:
highest_height_requested = uint32(batch_end - 1)
request_made = True
request_header = wallet_protocol.RequestHeader(
uint32(batch_start), self.header_hashes[batch_start],
uint32(batch_start),
self.header_hashes[batch_start],
)
yield OutboundMessage(
NodeType.FULL_NODE,
@ -905,7 +908,8 @@ class WalletNode:
# Only requests the previous block if we are not in sync mode, close to the new block,
# and don't have prev
header_request = wallet_protocol.RequestHeader(
uint32(block_record.height - 1), block_record.prev_header_hash,
uint32(block_record.height - 1),
block_record.prev_header_hash,
)
yield OutboundMessage(
NodeType.FULL_NODE,

View File

@ -115,7 +115,10 @@ class WalletPuzzleStore:
"""
cursor = await self.db_connection.execute(
"SELECT * FROM derivation_paths WHERE derivation_index=? and wallet_id=?;",
(index, wallet_id,),
(
index,
wallet_id,
),
)
row = await cursor.fetchone()
await cursor.close()
@ -138,7 +141,8 @@ class WalletPuzzleStore:
Returns the derivation record by index and wallet id.
"""
cursor = await self.db_connection.execute(
"SELECT * FROM derivation_paths WHERE puzzle_hash=?;", (puzzle_hash,),
"SELECT * FROM derivation_paths WHERE puzzle_hash=?;",
(puzzle_hash,),
)
row = await cursor.fetchone()
await cursor.close()
@ -159,7 +163,8 @@ class WalletPuzzleStore:
Sets a derivation path to used so we don't use it again.
"""
cursor = await self.db_connection.execute(
"UPDATE derivation_paths SET used=1 WHERE derivation_index<=?", (index,),
"UPDATE derivation_paths SET used=1 WHERE derivation_index<=?",
(index,),
)
await cursor.close()
await self.db_connection.commit()
@ -219,7 +224,10 @@ class WalletPuzzleStore:
"""
cursor = await self.db_connection.execute(
"SELECT * from derivation_paths WHERE puzzle_hash=? and wallet_id=?;",
(puzzle_hash.hex(), wallet_id,),
(
puzzle_hash.hex(),
wallet_id,
),
)
row = await cursor.fetchone()
await cursor.close()

View File

@ -154,7 +154,11 @@ class WalletStateManager:
wallet = await Wallet.create(config, wallet_info)
self.wallets[wallet_info.id] = wallet
elif wallet_info.type == WalletType.COLOURED_COIN.value:
wallet = await CCWallet.create(self, self.main_wallet, wallet_info,)
wallet = await CCWallet.create(
self,
self.main_wallet,
wallet_info,
)
self.wallets[wallet_info.id] = wallet
elif wallet_info.type == WalletType.RATE_LIMITED.value:
wallet = await RLWallet.create(self, wallet_info)
@ -229,7 +233,11 @@ class WalletStateManager:
wallet = await Wallet.create(self.config, wallet_info)
self.wallets[wallet_info.id] = wallet
elif wallet_info.type == WalletType.COLOURED_COIN.value:
wallet = await CCWallet.create(self, self.main_wallet, wallet_info,)
wallet = await CCWallet.create(
self,
self.main_wallet,
wallet_info,
)
self.wallets[wallet_info.id] = wallet
async def get_keys(self, hash: bytes32) -> Optional[Tuple[G1Element, PrivateKey]]:
@ -742,7 +750,9 @@ class WalletStateManager:
raise ValueError("Invalid genesis block")
async def receive_block(
self, block: BlockRecord, header_block: Optional[HeaderBlock] = None,
self,
block: BlockRecord,
header_block: Optional[HeaderBlock] = None,
) -> ReceiveBlockResult:
"""
Adds a new block to the blockchain. It doesn't have to be a new tip, can also be an orphan,
@ -782,8 +792,10 @@ class WalletStateManager:
async with self.puzzle_store.lock:
for addition in block.additions:
record = await self.puzzle_store.get_derivation_record_for_puzzle_hash(
addition.puzzle_hash.hex()
record = (
await self.puzzle_store.get_derivation_record_for_puzzle_hash(
addition.puzzle_hash.hex()
)
)
if record is None:
continue
@ -982,7 +994,10 @@ class WalletStateManager:
return False
number_of_iters: uint64 = calculate_iterations_quality(
quality_str, header_block.proof_of_space.size, difficulty, min_iters,
quality_str,
header_block.proof_of_space.size,
difficulty,
min_iters,
)
if header_block.proof_of_time is None:
@ -1193,7 +1208,10 @@ class WalletStateManager:
)
number_of_iters: uint64 = calculate_iterations_quality(
quality_str, header_block.proof_of_space.size, difficulty, min_iters,
quality_str,
header_block.proof_of_space.size,
difficulty,
min_iters,
)
# Validate potime

View File

@ -181,7 +181,8 @@ class WalletStore:
coins = set()
cursor = await self.db_connection.execute(
"SELECT * from coin_record WHERE spent=0 and wallet_id=?", (wallet_id,),
"SELECT * from coin_record WHERE spent=0 and wallet_id=?",
(wallet_id,),
)
rows = await cursor.fetchall()
await cursor.close()
@ -215,7 +216,11 @@ class WalletStore:
cursor_regular_coins = await self.db_connection.execute(
"SELECT * from coin_record WHERE spent=? and wallet_id=? and coinbase=?",
(0, wallet_id, 0,),
(
0,
wallet_id,
0,
),
)
regular_rows = await cursor_regular_coins.fetchall()
@ -381,7 +386,8 @@ class WalletStore:
height. This is used during reorgs to rollback the current lca.
"""
cursor = await self.db_connection.execute(
"UPDATE block_records SET in_lca_path=0 WHERE height>?", (from_height,),
"UPDATE block_records SET in_lca_path=0 WHERE height>?",
(from_height,),
)
await cursor.close()
await self.db_connection.commit()

View File

@ -260,7 +260,11 @@ class WalletTransactionStore:
"""
cursor = await self.db_connection.execute(
"SELECT * from transaction_record WHERE sent<? and confirmed=?", (4, 0,)
"SELECT * from transaction_record WHERE sent<? and confirmed=?",
(
4,
0,
),
)
rows = await cursor.fetchall()
await cursor.close()
@ -298,7 +302,10 @@ class WalletTransactionStore:
cursor = await self.db_connection.execute(
"SELECT * from transaction_record WHERE confirmed=? and wallet_id=?",
(0, wallet_id,),
(
0,
wallet_id,
),
)
rows = await cursor.fetchall()
await cursor.close()

View File

@ -79,7 +79,12 @@ class WalletUserStore:
async def update_wallet(self, wallet_info: WalletInfo):
cursor = await self.db_connection.execute(
"INSERT or REPLACE INTO users_wallets VALUES(?, ?, ?, ?)",
(wallet_info.id, wallet_info.name, wallet_info.type, wallet_info.data,),
(
wallet_info.id,
wallet_info.name,
wallet_info.type,
wallet_info.data,
),
)
await cursor.close()
await self.db_connection.commit()

View File

@ -286,8 +286,10 @@ class TestCCWallet:
await time_out_assert(15, cc_wallet_2.get_unconfirmed_balance, 60)
cc2_ph = await cc_wallet_2.get_new_cc_puzzle_hash()
tx_record = await wallet.wallet_state_manager.main_wallet.generate_signed_transaction(
10, cc2_ph, 0
tx_record = (
await wallet.wallet_state_manager.main_wallet.generate_signed_transaction(
10, cc2_ph, 0
)
)
await wallet.wallet_state_manager.add_pending_transaction(tx_record)

View File

@ -37,7 +37,10 @@ class TestPotIterations:
]
iters = [
calculate_iterations_quality(
qualities[i], farmer_ks[i], uint64(50000000), uint64(5000 * 30),
qualities[i],
farmer_ks[i],
uint64(50000000),
uint64(5000 * 30),
)
for i in range(len(qualities))
]

View File

@ -66,8 +66,8 @@ class TestBlockchainTransactions:
)
assert spend_bundle is not None
tx: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle
tx: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle)
)
async for _ in full_node_1.respond_transaction(tx):
outbound: OutboundMessage = _
@ -698,11 +698,15 @@ class TestBlockchainTransactions:
spent_block = blocks[1]
bad_block = blocks[2]
valid_cvp = ConditionVarPair(
ConditionOpcode.ASSERT_MY_COIN_ID, spent_block.get_coinbase().name(), None,
ConditionOpcode.ASSERT_MY_COIN_ID,
spent_block.get_coinbase().name(),
None,
)
valid_dic = {valid_cvp.opcode: [valid_cvp]}
bad_cvp = ConditionVarPair(
ConditionOpcode.ASSERT_MY_COIN_ID, bad_block.get_coinbase().name(), None,
ConditionOpcode.ASSERT_MY_COIN_ID,
bad_block.get_coinbase().name(),
None,
)
bad_dic = {bad_cvp.opcode: [bad_cvp]}
@ -776,7 +780,9 @@ class TestBlockchainTransactions:
# This condition requires block2 coinbase to be spent
block1_cvp = ConditionVarPair(
ConditionOpcode.ASSERT_COIN_CONSUMED, block2.get_coinbase().name(), None,
ConditionOpcode.ASSERT_COIN_CONSUMED,
block2.get_coinbase().name(),
None,
)
block1_dic = {block1_cvp.opcode: [block1_cvp]}
block1_spend_bundle = wallet_a.generate_signed_transaction(
@ -785,7 +791,9 @@ class TestBlockchainTransactions:
# This condition requires block1 coinbase to be spent
block2_cvp = ConditionVarPair(
ConditionOpcode.ASSERT_COIN_CONSUMED, block1.get_coinbase().name(), None,
ConditionOpcode.ASSERT_COIN_CONSUMED,
block1.get_coinbase().name(),
None,
)
block2_dic = {block2_cvp.opcode: [block2_cvp]}
block2_spend_bundle = wallet_a.generate_signed_transaction(
@ -1079,8 +1087,8 @@ class TestBlockchainTransactions:
)
assert spend_bundle is not None
tx: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle
tx: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle)
)
async for _ in full_node_1.respond_transaction(tx):
outbound: OutboundMessage = _

View File

@ -156,7 +156,11 @@ class TestFullNodeProtocol:
dic_h = {5: (program, aggsig)}
blocks_new = bt.get_consecutive_blocks(
test_constants, 3, blocks[:-1], 10, transaction_data_at_height=dic_h,
test_constants,
3,
blocks[:-1],
10,
transaction_data_at_height=dic_h,
)
# Already seen
msgs = [x async for x in full_node_1.new_transaction(new_transaction)]
@ -227,7 +231,9 @@ class TestFullNodeProtocol:
receiver_puzzlehash = wallet_receiver.get_new_puzzlehash()
spend_bundle = wallet_a.generate_signed_transaction(
100, receiver_puzzlehash, blocks[2].get_coinbase(),
100,
receiver_puzzlehash,
blocks[2].get_coinbase(),
)
assert spend_bundle is not None
respond_transaction = fnp.RespondTransaction(spend_bundle)
@ -255,7 +261,9 @@ class TestFullNodeProtocol:
# Invalid transaction does not propagate
spend_bundle = wallet_a.generate_signed_transaction(
100000000000000, receiver_puzzlehash, blocks[3].get_coinbase(),
100000000000000,
receiver_puzzlehash,
blocks[3].get_coinbase(),
)
assert spend_bundle is not None
respond_transaction = fnp.RespondTransaction(spend_bundle)
@ -277,7 +285,11 @@ class TestFullNodeProtocol:
blocks = await get_block_path(full_node_1)
blocks_new = bt.get_consecutive_blocks(
test_constants, 1, blocks[:-1], 10, seed=b"1212412",
test_constants,
1,
blocks[:-1],
10,
seed=b"1212412",
)
unf_block = FullBlock(
@ -341,7 +353,11 @@ class TestFullNodeProtocol:
blocks_list = await get_block_path(full_node_1)
blocks_new = bt.get_consecutive_blocks(
test_constants, 1, blocks_list, 10, seed=b"another seed",
test_constants,
1,
blocks_list,
10,
seed=b"another seed",
)
assert blocks_new[-1].proof_of_time is not None
new_pot = fnp.NewProofOfTime(
@ -381,7 +397,11 @@ class TestFullNodeProtocol:
blocks_list = await get_block_path(full_node_1)
blocks_new = bt.get_consecutive_blocks(
test_constants, 1, blocks_list, 10, seed=b"another seed 2",
test_constants,
1,
blocks_list,
10,
seed=b"another seed 2",
)
assert blocks_new[-1].proof_of_time is not None
assert blocks_new[-2].proof_of_time is not None
@ -428,7 +448,11 @@ class TestFullNodeProtocol:
blocks_list = await get_block_path(full_node_1)
blocks_new = bt.get_consecutive_blocks(
test_constants, 2, blocks_list, 10, seed=b"another seed 3",
test_constants,
2,
blocks_list,
10,
seed=b"another seed 3",
)
# Add one block
[_ async for _ in full_node_1.respond_block(fnp.RespondBlock(blocks_new[-2]))]
@ -469,7 +493,11 @@ class TestFullNodeProtocol:
blocks_list = await get_block_path(full_node_1)
blocks_new = bt.get_consecutive_blocks(
test_constants, 1, blocks_list[:], 4, seed=b"Another seed 4",
test_constants,
1,
blocks_list[:],
4,
seed=b"Another seed 4",
)
for block in blocks_new:
[_ async for _ in full_node_1.respond_block(fnp.RespondBlock(block))]
@ -583,7 +611,10 @@ class TestFullNodeProtocol:
# Don't propagate at old height
[_ async for _ in full_node_1.respond_block(fnp.RespondBlock(candidates[0]))]
blocks_new_3 = bt.get_consecutive_blocks(
test_constants, 1, blocks_new[:] + [candidates[0]], 10,
test_constants,
1,
blocks_new[:] + [candidates[0]],
10,
)
unf_block_new = FullBlock(
blocks_new_3[-1].proof_of_space,
@ -683,7 +714,11 @@ class TestFullNodeProtocol:
blocks_list = await get_block_path(full_node_1)
blocks_new = bt.get_consecutive_blocks(
test_constants, 5, blocks_list[:], 10, seed=b"Another seed 5",
test_constants,
5,
blocks_list[:],
10,
seed=b"Another seed 5",
)
# In sync mode
@ -744,7 +779,11 @@ class TestFullNodeProtocol:
# If orphan, don't send anything
blocks_orphan = bt.get_consecutive_blocks(
test_constants, 1, blocks_list[:-5], 10, seed=b"Another seed 6",
test_constants,
1,
blocks_list[:-5],
10,
seed=b"Another seed 6",
)
msgs = [
@ -789,13 +828,18 @@ class TestWalletProtocol:
blocks_list = await get_block_path(full_node_1)
blocks_new = bt.get_consecutive_blocks(
test_constants, 1, block_list=blocks_list, seed=b"test_request_additions",
test_constants,
1,
block_list=blocks_list,
seed=b"test_request_additions",
)
async for _ in full_node_1.respond_block(fnp.RespondBlock(blocks_new[-1])):
pass
spend_bundle = wallet_a.generate_signed_transaction(
100, wallet_a.get_new_puzzlehash(), blocks_new[-1].get_coinbase(),
100,
wallet_a.get_new_puzzlehash(),
blocks_new[-1].get_coinbase(),
)
spend_bundle_bad = wallet_a.generate_signed_transaction(
constants.MAX_COIN_AMOUNT,
@ -1000,7 +1044,9 @@ class TestWalletProtocol:
# If there are no transactions, empty proof and coins
blocks_new = bt.get_consecutive_blocks(
test_constants, 10, block_list=blocks_list,
test_constants,
10,
block_list=blocks_list,
)
for block in blocks_new:
[_ async for _ in full_node_1.respond_block(fnp.RespondBlock(block))]
@ -1180,7 +1226,9 @@ class TestWalletProtocol:
# If there are no transactions, only cb and fees additions
blocks_new = bt.get_consecutive_blocks(
test_constants, 10, block_list=blocks_list,
test_constants,
10,
block_list=blocks_list,
)
for block in blocks_new:
[_ async for _ in full_node_1.respond_block(fnp.RespondBlock(block))]
@ -1203,7 +1251,9 @@ class TestWalletProtocol:
for i in range(5):
spend_bundles.append(
wallet_a.generate_signed_transaction(
100, puzzle_hashes[i % 2], blocks_new[i - 8].get_coinbase(),
100,
puzzle_hashes[i % 2],
blocks_new[i - 8].get_coinbase(),
)
)
height_with_transactions = len(blocks_new) + 1

View File

@ -61,8 +61,8 @@ class TestMempool:
1000, receiver_puzzlehash, block.get_coinbase()
)
assert spend_bundle is not None
tx: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle
tx: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle)
)
async for _ in full_node_1.respond_transaction(tx):
outbound: OutboundMessage = _
@ -92,8 +92,8 @@ class TestMempool:
1000, receiver_puzzlehash, block.get_coinbase()
)
assert spend_bundle is not None
tx: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle
tx: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle)
)
async for _ in full_node_1.respond_transaction(tx):
@ -140,8 +140,8 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle1
tx1: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle1)
)
async for _ in full_node_1.respond_transaction(tx1):
outbound: OutboundMessage = _
@ -153,8 +153,8 @@ class TestMempool:
1000, other_receiver.get_new_puzzlehash(), block.get_coinbase()
)
assert spend_bundle2 is not None
tx2: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle2
tx2: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle2)
)
async for _ in full_node_1.respond_transaction(tx2):
pass
@ -185,8 +185,8 @@ class TestMempool:
1000, receiver_puzzlehash, block.get_coinbase()
)
assert spend_bundle1 is not None
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle1
tx1: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle1)
)
async for _ in full_node_1.respond_transaction(tx1):
outbound: OutboundMessage = _
@ -198,8 +198,8 @@ class TestMempool:
)
assert spend_bundle2 is not None
tx2: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle2
tx2: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle2)
)
async for _ in full_node_1.respond_transaction(tx2):
pass
@ -238,8 +238,8 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle1
tx1: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle1)
)
async for _ in full_node_1.respond_transaction(tx1):
outbound: OutboundMessage = _
@ -278,8 +278,8 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle1
tx1: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle1)
)
async for _ in full_node_1.respond_transaction(tx1):
outbound: OutboundMessage = _
@ -316,8 +316,8 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle1
tx1: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle1)
)
async for _ in full_node_1.respond_transaction(tx1):
outbound: OutboundMessage = _
@ -356,8 +356,8 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle1
tx1: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle1)
)
async for _ in full_node_1.respond_transaction(tx1):
outbound: OutboundMessage = _
@ -396,8 +396,8 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle1
tx1: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle1)
)
async for _ in full_node_1.respond_transaction(tx1):
outbound: OutboundMessage = _
@ -427,7 +427,9 @@ class TestMempool:
pass
cvp = ConditionVarPair(
ConditionOpcode.ASSERT_MY_COIN_ID, blocks[2].get_coinbase().name(), None,
ConditionOpcode.ASSERT_MY_COIN_ID,
blocks[2].get_coinbase().name(),
None,
)
dic = {cvp.opcode: [cvp]}
@ -436,8 +438,8 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle1
tx1: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle1)
)
async for _ in full_node_1.respond_transaction(tx1):
outbound: OutboundMessage = _
@ -478,8 +480,8 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle1
tx1: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle1)
)
async for _ in full_node_1.respond_transaction(tx1):
outbound: OutboundMessage = _
@ -523,8 +525,8 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle1
tx1: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle1)
)
async for _ in full_node_1.respond_transaction(tx1):
outbound: OutboundMessage = _
@ -533,8 +535,8 @@ class TestMempool:
# Sleep so that 3 sec passes
await asyncio.sleep(3)
tx2: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle1
tx2: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle1)
)
async for _ in full_node_1.respond_transaction(tx2):
outbound_2: OutboundMessage = _
@ -565,7 +567,9 @@ class TestMempool:
pass
cvp = ConditionVarPair(
ConditionOpcode.ASSERT_COIN_CONSUMED, block2.get_coinbase().name(), None,
ConditionOpcode.ASSERT_COIN_CONSUMED,
block2.get_coinbase().name(),
None,
)
dic = {cvp.opcode: [cvp]}
@ -579,8 +583,8 @@ class TestMempool:
bundle = SpendBundle.aggregate([spend_bundle1, spend_bundle2])
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
bundle
tx1: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(bundle)
)
async for _ in full_node_1.respond_transaction(tx1):
outbound: OutboundMessage = _
@ -611,7 +615,9 @@ class TestMempool:
pass
cvp = ConditionVarPair(
ConditionOpcode.ASSERT_COIN_CONSUMED, block2.get_coinbase().name(), None,
ConditionOpcode.ASSERT_COIN_CONSUMED,
block2.get_coinbase().name(),
None,
)
dic = {cvp.opcode: [cvp]}
@ -620,8 +626,8 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle1
tx1: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle1)
)
async for _ in full_node_1.respond_transaction(tx1):
outbound: OutboundMessage = _
@ -652,7 +658,11 @@ class TestMempool:
):
pass
cvp = ConditionVarPair(ConditionOpcode.ASSERT_FEE, int_to_bytes(10), None,)
cvp = ConditionVarPair(
ConditionOpcode.ASSERT_FEE,
int_to_bytes(10),
None,
)
dic = {cvp.opcode: [cvp]}
spend_bundle1 = wallet_a.generate_signed_transaction(
@ -661,8 +671,8 @@ class TestMempool:
assert spend_bundle1 is not None
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle1
tx1: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle1)
)
outbound_messages: List[OutboundMessage] = []
@ -700,7 +710,11 @@ class TestMempool:
):
pass
cvp = ConditionVarPair(ConditionOpcode.ASSERT_FEE, int_to_bytes(10), None,)
cvp = ConditionVarPair(
ConditionOpcode.ASSERT_FEE,
int_to_bytes(10),
None,
)
dic = {cvp.opcode: [cvp]}
spend_bundle1 = wallet_a.generate_signed_transaction(
@ -709,8 +723,8 @@ class TestMempool:
assert spend_bundle1 is not None
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle1
tx1: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle1)
)
outbound_messages: List[OutboundMessage] = []
@ -752,7 +766,11 @@ class TestMempool:
):
pass
cvp = ConditionVarPair(ConditionOpcode.ASSERT_FEE, int_to_bytes(10), None,)
cvp = ConditionVarPair(
ConditionOpcode.ASSERT_FEE,
int_to_bytes(10),
None,
)
dic = {cvp.opcode: [cvp]}
fee = 9
@ -772,8 +790,8 @@ class TestMempool:
assert combined.fees() == 4
tx1: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle1
tx1: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle1)
)
outbound_messages: List[OutboundMessage] = []
@ -824,8 +842,8 @@ class TestMempool:
spend_bundle_combined = SpendBundle.aggregate([spend_bundle1, spend_bundle2])
tx: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle_combined
tx: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle_combined)
)
messages = []
async for outbound in full_node_1.respond_transaction(tx):
@ -873,8 +891,8 @@ class TestMempool:
spend_bundle = wallet_a.sign_transaction(unsigned)
assert spend_bundle is not None
tx: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(
spend_bundle
tx: full_node_protocol.RespondTransaction = (
full_node_protocol.RespondTransaction(spend_bundle)
)
async for _ in full_node_1.respond_transaction(tx):
outbound: OutboundMessage = _

View File

@ -100,8 +100,10 @@ class TestTransactions:
10, wallet_0.wallet_state_manager.main_wallet.get_confirmed_balance, funds
)
tx = await wallet_0.wallet_state_manager.main_wallet.generate_signed_transaction(
10, ph1, 0
tx = (
await wallet_0.wallet_state_manager.main_wallet.generate_signed_transaction(
10, ph1, 0
)
)
await wallet_0.wallet_state_manager.main_wallet.push_transaction(tx)
@ -173,8 +175,10 @@ class TestTransactions:
10, wallet_0.wallet_state_manager.main_wallet.get_confirmed_balance, funds
)
tx = await wallet_0.wallet_state_manager.main_wallet.generate_signed_transaction(
10, token_bytes(), 0
tx = (
await wallet_0.wallet_state_manager.main_wallet.generate_signed_transaction(
10, token_bytes(), 0
)
)
await wallet_0.wallet_state_manager.main_wallet.push_transaction(tx)

View File

@ -451,7 +451,10 @@ async def setup_node_and_wallet(
async def setup_simulators_and_wallets(
simulator_count: int, wallet_count: int, dic: Dict, starting_height=None,
simulator_count: int,
wallet_count: int,
dic: Dict,
starting_height=None,
):
simulators: List[Tuple[FullNode, ChiaServer]] = []
wallets = []

View File

@ -22,7 +22,12 @@ class TestCostCalculation:
receiver = WalletTool()
num_blocks = 2
blocks = bt.get_consecutive_blocks(test_constants, num_blocks, [], 10,)
blocks = bt.get_consecutive_blocks(
test_constants,
num_blocks,
[],
10,
)
spend_bundle = wallet_tool.generate_signed_transaction(
blocks[1].get_coinbase().amount,

View File

@ -19,7 +19,12 @@ class TestMerkleSet:
WalletTool()
num_blocks = 10
blocks = bt.get_consecutive_blocks(test_constants, num_blocks, [], 10,)
blocks = bt.get_consecutive_blocks(
test_constants,
num_blocks,
[],
10,
)
merkle_set = MerkleSet()
merkle_set_reverse = MerkleSet()

View File

@ -191,8 +191,10 @@ class TestWalletSimulator:
5, wallet_0.wallet_state_manager.main_wallet.get_confirmed_balance, funds
)
tx = await wallet_0.wallet_state_manager.main_wallet.generate_signed_transaction(
10, token_bytes(), 0
tx = (
await wallet_0.wallet_state_manager.main_wallet.generate_signed_transaction(
10, token_bytes(), 0
)
)
await wallet_0.wallet_state_manager.main_wallet.push_transaction(tx)