mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-21 08:31:52 +03:00
Merge commit 'ca84fa9f8d332687534399fc824d6017effaed2e' into atari-merge_main_ca84fa9f8d332687534399fc824d6017effaed2e
This commit is contained in:
commit
95c5213fbb
@ -44,6 +44,7 @@ async def show_async(
|
||||
print("There is no blockchain found yet. Try again shortly")
|
||||
return None
|
||||
peak: Optional[BlockRecord] = blockchain_state["peak"]
|
||||
node_id = blockchain_state["node_id"]
|
||||
difficulty = blockchain_state["difficulty"]
|
||||
sub_slot_iters = blockchain_state["sub_slot_iters"]
|
||||
synced = blockchain_state["sync"]["synced"]
|
||||
@ -56,6 +57,8 @@ async def show_async(
|
||||
full_node_rpc_port = config["full_node"]["rpc_port"]
|
||||
|
||||
print(f"Network: {network_name} Port: {full_node_port} Rpc Port: {full_node_rpc_port}")
|
||||
print(f"Node ID: {node_id}")
|
||||
|
||||
print(f"Genesis Challenge: {genesis_challenge}")
|
||||
|
||||
if synced:
|
||||
|
@ -1420,6 +1420,7 @@ class FullNodeAPI:
|
||||
|
||||
hint_coin_ids = []
|
||||
# Add peer to the "Subscribed" dictionary
|
||||
max_items = self.full_node.config.get("max_subscribe_items", 200000)
|
||||
for puzzle_hash in request.puzzle_hashes:
|
||||
ph_hint_coins = await self.full_node.hint_store.get_coin_ids(puzzle_hash)
|
||||
hint_coin_ids.extend(ph_hint_coins)
|
||||
@ -1427,7 +1428,7 @@ class FullNodeAPI:
|
||||
self.full_node.ph_subscriptions[puzzle_hash] = set()
|
||||
if (
|
||||
peer.peer_node_id not in self.full_node.ph_subscriptions[puzzle_hash]
|
||||
and self.full_node.peer_sub_counter[peer.peer_node_id] < 100000
|
||||
and self.full_node.peer_sub_counter[peer.peer_node_id] < max_items
|
||||
):
|
||||
self.full_node.ph_subscriptions[puzzle_hash].add(peer.peer_node_id)
|
||||
self.full_node.peer_puzzle_hash[peer.peer_node_id].add(puzzle_hash)
|
||||
@ -1458,13 +1459,13 @@ class FullNodeAPI:
|
||||
|
||||
if peer.peer_node_id not in self.full_node.peer_sub_counter:
|
||||
self.full_node.peer_sub_counter[peer.peer_node_id] = 0
|
||||
|
||||
max_items = self.full_node.config.get("max_subscribe_items", 200000)
|
||||
for coin_id in request.coin_ids:
|
||||
if coin_id not in self.full_node.coin_subscriptions:
|
||||
self.full_node.coin_subscriptions[coin_id] = set()
|
||||
if (
|
||||
peer.peer_node_id not in self.full_node.coin_subscriptions[coin_id]
|
||||
and self.full_node.peer_sub_counter[peer.peer_node_id] < 100000
|
||||
and self.full_node.peer_sub_counter[peer.peer_node_id] < max_items
|
||||
):
|
||||
self.full_node.coin_subscriptions[coin_id].add(peer.peer_node_id)
|
||||
self.full_node.peer_coin_ids[peer.peer_node_id].add(coin_id)
|
||||
|
@ -104,6 +104,7 @@ class FullNodeRpcApi:
|
||||
"""
|
||||
Returns a summary of the node's view of the blockchain.
|
||||
"""
|
||||
node_id = self.service.server.node_id.hex()
|
||||
if self.service.initialized is False:
|
||||
res: Dict = {
|
||||
"blockchain_state": {
|
||||
@ -118,12 +119,12 @@ class FullNodeRpcApi:
|
||||
"difficulty": 0,
|
||||
"sub_slot_iters": 0,
|
||||
"space": 0,
|
||||
"mempool_size": 0,
|
||||
"mempool_cost": 0,
|
||||
"mempool_min_fees": {
|
||||
"cost_5000000": 0,
|
||||
},
|
||||
"block_max_cost": 0,
|
||||
"node_id": node_id,
|
||||
},
|
||||
}
|
||||
return res
|
||||
@ -202,6 +203,7 @@ class FullNodeRpcApi:
|
||||
"cost_5000000": mempool_min_fee_5m,
|
||||
},
|
||||
"block_max_cost": self.service.constants.MAX_BLOCK_COST_CLVM,
|
||||
"node_id": node_id,
|
||||
},
|
||||
}
|
||||
self.cached_blockchain_state = dict(response["blockchain_state"])
|
||||
|
@ -174,8 +174,10 @@ class RateLimiter:
|
||||
new_non_tx_count = self.non_tx_message_counts + 1
|
||||
new_non_tx_size = self.non_tx_cumulative_size + len(message.data)
|
||||
if new_non_tx_count > NON_TX_FREQ * proportion_of_limit:
|
||||
log.debug(f"Rate limit: {new_non_tx_count} > {NON_TX_FREQ} * {proportion_of_limit}")
|
||||
return False
|
||||
if new_non_tx_size > NON_TX_MAX_TOTAL_SIZE * proportion_of_limit:
|
||||
log.debug(f"Rate limit: {new_non_tx_size} > {NON_TX_MAX_TOTAL_SIZE} * {proportion_of_limit}")
|
||||
return False
|
||||
else:
|
||||
log.warning(f"Message type {message_type} not found in rate limits")
|
||||
@ -185,10 +187,13 @@ class RateLimiter:
|
||||
assert limits.max_total_size is not None
|
||||
|
||||
if new_message_counts > limits.frequency * proportion_of_limit:
|
||||
log.debug(f"Rate limit: {new_message_counts} > {limits.frequency} * {proportion_of_limit}")
|
||||
return False
|
||||
if len(message.data) > limits.max_size:
|
||||
log.debug(f"Rate limit: {len(message.data)} > {limits.max_size}")
|
||||
return False
|
||||
if new_cumulative_size > limits.max_total_size * proportion_of_limit:
|
||||
log.debug(f"Rate limit: {new_cumulative_size} > {limits.max_total_size} * {proportion_of_limit}")
|
||||
return False
|
||||
|
||||
ret = True
|
||||
|
@ -79,6 +79,10 @@ class Service:
|
||||
chia_ca_crt, chia_ca_key = chia_ssl_ca_paths(root_path, self.config)
|
||||
inbound_rlp = self.config.get("inbound_rate_limit_percent")
|
||||
outbound_rlp = self.config.get("outbound_rate_limit_percent")
|
||||
if NodeType == NodeType.WALLET:
|
||||
inbound_rlp = service_config.get("inbound_rate_limit_percent", inbound_rlp)
|
||||
outbound_rlp = service_config.get("outbound_rate_limit_percent", 60)
|
||||
|
||||
assert inbound_rlp and outbound_rlp
|
||||
self._server = ChiaServer(
|
||||
advertised_port,
|
||||
|
@ -382,6 +382,9 @@ full_node:
|
||||
# separate log file (under logging/sql.log).
|
||||
log_sqlite_cmds: False
|
||||
|
||||
# Number of coin_ids | puzzle hashes that node will let wallets subscribe to
|
||||
max_subscribe_items: 200000
|
||||
|
||||
# List of trusted DNS seeders to bootstrap from.
|
||||
# If you modify this, please change the hardcode as well from FullNode.set_server()
|
||||
dns_servers:
|
||||
@ -501,6 +504,10 @@ wallet:
|
||||
|
||||
short_sync_blocks_behind_threshold: 20
|
||||
|
||||
# wallet overrides for limits
|
||||
inbound_rate_limit_percent: 100
|
||||
outbound_rate_limit_percent: 60
|
||||
|
||||
data_layer:
|
||||
# TODO: consider name
|
||||
# TODO: organize consistently with other sections
|
||||
|
@ -315,7 +315,9 @@ class CATWallet:
|
||||
parent_coin = None
|
||||
coin_record = await self.wallet_state_manager.coin_store.get_coin_record(coin_name)
|
||||
if coin_record is None:
|
||||
coin_states: Optional[List[CoinState]] = await self.wallet_state_manager.get_coin_state([coin_name])
|
||||
coin_states: Optional[List[CoinState]] = await self.wallet_state_manager.wallet_node.get_coin_state(
|
||||
[coin_name]
|
||||
)
|
||||
if coin_states is not None:
|
||||
parent_coin = coin_states[0].coin
|
||||
if coin_record is not None:
|
||||
|
@ -88,6 +88,7 @@ class TradeManager:
|
||||
else completed trade or other side of trade canceled the trade by doing a spend.
|
||||
If our coins got farmed but coins from other side didn't, we successfully canceled trade by spending inputs.
|
||||
"""
|
||||
self.log.info(f"coins_of_interest_farmed: {coin_state}")
|
||||
trade = await self.get_trade_by_coin(coin_state.coin)
|
||||
if trade is None:
|
||||
self.log.error(f"Coin: {coin_state.coin}, not in any trade")
|
||||
@ -109,7 +110,7 @@ class TradeManager:
|
||||
our_settlement_ids: List[bytes32] = [c.name() for c in our_settlement_payments]
|
||||
|
||||
# And get all relevant coin states
|
||||
coin_states = await self.wallet_state_manager.get_coin_state(our_settlement_ids)
|
||||
coin_states = await self.wallet_state_manager.wallet_node.get_coin_state(our_settlement_ids)
|
||||
assert coin_states is not None
|
||||
coin_state_names: List[bytes32] = [cs.coin.name() for cs in coin_states]
|
||||
|
||||
@ -117,7 +118,6 @@ class TradeManager:
|
||||
if set(our_settlement_ids) & set(coin_state_names):
|
||||
height = coin_states[0].spent_height
|
||||
await self.trade_store.set_status(trade.trade_id, TradeStatus.CONFIRMED, True, height)
|
||||
|
||||
tx_records: List[TransactionRecord] = await self.calculate_tx_records_for_offer(offer, False)
|
||||
for tx in tx_records:
|
||||
if TradeStatus(trade.status) == TradeStatus.PENDING_ACCEPT:
|
||||
@ -348,7 +348,9 @@ class TradeManager:
|
||||
non_ephemeral_removals: List[Coin] = list(
|
||||
filter(lambda c: c.parent_coin_info not in all_removal_names, all_removals)
|
||||
)
|
||||
coin_states = await self.wallet_state_manager.get_coin_state([c.name() for c in non_ephemeral_removals])
|
||||
coin_states = await self.wallet_state_manager.wallet_node.get_coin_state(
|
||||
[c.name() for c in non_ephemeral_removals]
|
||||
)
|
||||
assert coin_states is not None
|
||||
return not any([cs.spent_height is not None for cs in coin_states])
|
||||
|
||||
|
@ -417,7 +417,7 @@ class Wallet:
|
||||
)
|
||||
)
|
||||
|
||||
self.log.info(f"Spends is {spends}")
|
||||
self.log.debug(f"Spends is {spends}")
|
||||
return spends
|
||||
|
||||
async def sign_transaction(self, coin_spends: List[CoinSpend]) -> SpendBundle:
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -101,10 +101,7 @@ class WalletNodeAPI:
|
||||
self, request: introducer_protocol.RespondPeersIntroducer, peer: WSChiaConnection
|
||||
):
|
||||
if self.wallet_node.wallet_peers is not None:
|
||||
if not self.wallet_node.has_full_node():
|
||||
await self.wallet_node.wallet_peers.respond_peers(request, peer.get_peer_info(), False)
|
||||
else:
|
||||
await self.wallet_node.wallet_peers.ensure_is_closed()
|
||||
await self.wallet_node.wallet_peers.respond_peers(request, peer.get_peer_info(), False)
|
||||
|
||||
if peer is not None and peer.connection_type is NodeType.INTRODUCER:
|
||||
await peer.close()
|
||||
@ -114,12 +111,10 @@ class WalletNodeAPI:
|
||||
async def respond_peers(self, request: full_node_protocol.RespondPeers, peer: WSChiaConnection):
|
||||
if self.wallet_node.wallet_peers is None:
|
||||
return None
|
||||
if not self.wallet_node.has_full_node():
|
||||
self.log.info(f"Wallet received {len(request.peer_list)} peers.")
|
||||
await self.wallet_node.wallet_peers.respond_peers(request, peer.get_peer_info(), True)
|
||||
else:
|
||||
self.log.info(f"Wallet received {len(request.peer_list)} peers, but ignoring, since we have a full node.")
|
||||
await self.wallet_node.wallet_peers.ensure_is_closed()
|
||||
|
||||
self.log.info(f"Wallet received {len(request.peer_list)} peers.")
|
||||
await self.wallet_node.wallet_peers.respond_peers(request, peer.get_peer_info(), True)
|
||||
|
||||
return None
|
||||
|
||||
@api_request
|
||||
|
@ -9,7 +9,6 @@ from typing import Any, Callable, Dict, List, Optional, Set, Tuple
|
||||
|
||||
import aiosqlite
|
||||
from blspy import G1Element, PrivateKey
|
||||
from chiabip158 import PyBIP158
|
||||
|
||||
from chia.consensus.coinbase import pool_parent_id, farmer_parent_id
|
||||
from chia.consensus.constants import ConsensusConstants
|
||||
@ -24,9 +23,7 @@ from chia.types.blockchain_format.program import Program
|
||||
from chia.types.blockchain_format.sized_bytes import bytes32
|
||||
from chia.types.coin_spend import CoinSpend
|
||||
from chia.types.full_block import FullBlock
|
||||
from chia.types.header_block import HeaderBlock
|
||||
from chia.types.mempool_inclusion_status import MempoolInclusionStatus
|
||||
from chia.types.weight_proof import WeightProof
|
||||
from chia.util.byte_types import hexstr_to_bytes
|
||||
from chia.util.db_wrapper import DBWrapper
|
||||
from chia.util.errors import Err
|
||||
@ -95,9 +92,6 @@ class WalletStateManager:
|
||||
|
||||
state_changed_callback: Optional[Callable]
|
||||
pending_tx_callback: Optional[Callable]
|
||||
subscribe_to_new_puzzle_hash: Any
|
||||
subscribe_to_coin_ids_update: Any
|
||||
get_coin_state: Any
|
||||
puzzle_hash_created_callbacks: Dict = defaultdict(lambda *x: None)
|
||||
db_path: Path
|
||||
db_connection: aiosqlite.Connection
|
||||
@ -130,16 +124,10 @@ class WalletStateManager:
|
||||
constants: ConsensusConstants,
|
||||
server: ChiaServer,
|
||||
root_path: Path,
|
||||
subscribe_to_new_puzzle_hash,
|
||||
get_coin_state,
|
||||
subscribe_to_coin_ids,
|
||||
wallet_node,
|
||||
name: str = None,
|
||||
):
|
||||
self = WalletStateManager()
|
||||
self.subscribe_to_new_puzzle_hash = subscribe_to_new_puzzle_hash
|
||||
self.get_coin_state = get_coin_state
|
||||
self.subscribe_to_coin_ids_update = subscribe_to_coin_ids
|
||||
self.new_wallet = False
|
||||
self.config = config
|
||||
self.constants = constants
|
||||
@ -347,7 +335,7 @@ class WalletStateManager:
|
||||
)
|
||||
puzzle_hashes = [record.puzzle_hash for record in derivation_paths]
|
||||
await self.puzzle_store.add_derivation_paths(derivation_paths, in_transaction)
|
||||
await self.subscribe_to_new_puzzle_hash(puzzle_hashes)
|
||||
await self.wallet_node.new_puzzle_hash_created(puzzle_hashes)
|
||||
if unused > 0:
|
||||
await self.puzzle_store.set_used_up_to(uint32(unused - 1), in_transaction)
|
||||
|
||||
@ -602,9 +590,11 @@ class WalletStateManager:
|
||||
assert parent_coin_state.spent_height == coin_state.created_height
|
||||
wallet_id = None
|
||||
wallet_type = None
|
||||
cs: CoinSpend = await self.wallet_node.fetch_puzzle_solution(
|
||||
cs: Optional[CoinSpend] = await self.wallet_node.fetch_puzzle_solution(
|
||||
peer, parent_coin_state.spent_height, parent_coin_state.coin
|
||||
)
|
||||
if cs is None:
|
||||
return None, None
|
||||
matched, curried_args = match_cat_puzzle(Program.from_bytes(bytes(cs.puzzle_reveal)))
|
||||
|
||||
if matched:
|
||||
@ -644,7 +634,6 @@ class WalletStateManager:
|
||||
peer,
|
||||
fork_height: Optional[uint32] = None,
|
||||
current_height: Optional[uint32] = None,
|
||||
weight_proof: Optional[WeightProof] = None,
|
||||
):
|
||||
created_h_none = []
|
||||
for coin_st in coin_states.copy():
|
||||
@ -665,9 +654,18 @@ class WalletStateManager:
|
||||
for coin_state_idx, coin_state in enumerate(coin_states):
|
||||
info = await self.get_wallet_id_for_puzzle_hash(coin_state.coin.puzzle_hash)
|
||||
local_record: Optional[WalletCoinRecord] = await self.coin_store.get_coin_record(coin_state.coin.name())
|
||||
self.log.info(f"new_coin_state received ({coin_state_idx + 1} / {len(coin_states)})")
|
||||
self.log.debug(f"{coin_state.coin.name()}: {coin_state}")
|
||||
|
||||
if local_record is not None:
|
||||
local_spent = None
|
||||
if local_record.spent_block_height != 0:
|
||||
local_spent = local_record.spent_block_height
|
||||
if (
|
||||
local_spent == coin_state.spent_height
|
||||
and local_record.confirmed_block_height == coin_state.created_height
|
||||
):
|
||||
continue
|
||||
|
||||
wallet_id = None
|
||||
wallet_type = None
|
||||
if info is not None:
|
||||
@ -763,15 +761,11 @@ class WalletStateManager:
|
||||
)
|
||||
await self.tx_store.add_transaction_record(tx_record, False)
|
||||
|
||||
children = await self.wallet_node.fetch_children(peer, coin_state.coin.name(), weight_proof)
|
||||
children = await self.wallet_node.fetch_children(peer, coin_state.coin.name())
|
||||
assert children is not None
|
||||
additions = [state.coin for state in children]
|
||||
if len(children) > 0:
|
||||
cs: CoinSpend = await self.wallet_node.fetch_puzzle_solution(
|
||||
peer, coin_state.spent_height, coin_state.coin
|
||||
)
|
||||
|
||||
fee = cs.reserved_fee()
|
||||
fee = 0
|
||||
|
||||
to_puzzle_hash = None
|
||||
# Find coin that doesn't belong to us
|
||||
@ -839,19 +833,22 @@ class WalletStateManager:
|
||||
await self.tx_store.set_confirmed(unconfirmed_record.name, coin_state.spent_height)
|
||||
|
||||
if record.wallet_type == WalletType.POOLING_WALLET:
|
||||
cs = await self.wallet_node.fetch_puzzle_solution(peer, coin_state.spent_height, coin_state.coin)
|
||||
wallet = self.wallets[uint32(record.wallet_id)]
|
||||
await wallet.apply_state_transitions(cs, coin_state.spent_height)
|
||||
if len(cs.additions()) > 0:
|
||||
added_pool_coin = cs.additions()[0]
|
||||
await self.coin_added(
|
||||
added_pool_coin,
|
||||
coin_state.spent_height,
|
||||
[],
|
||||
uint32(record.wallet_id),
|
||||
record.wallet_type,
|
||||
if coin_state.spent_height is not None:
|
||||
cs: CoinSpend = await self.wallet_node.fetch_puzzle_solution(
|
||||
peer, coin_state.spent_height, coin_state.coin
|
||||
)
|
||||
await self.add_interested_coin_id(added_pool_coin.name())
|
||||
wallet = self.wallets[uint32(record.wallet_id)]
|
||||
await wallet.apply_state_transitions(cs, coin_state.spent_height)
|
||||
if len(cs.additions()) > 0:
|
||||
added_pool_coin = cs.additions()[0]
|
||||
await self.coin_added(
|
||||
added_pool_coin,
|
||||
coin_state.spent_height,
|
||||
[],
|
||||
uint32(record.wallet_id),
|
||||
record.wallet_type,
|
||||
)
|
||||
await self.add_interested_coin_id(added_pool_coin.name())
|
||||
if record.wallet_type == WalletType.DATA_LAYER:
|
||||
singleton_spend = await self.wallet_node.fetch_puzzle_solution(
|
||||
peer, coin_state.spent_height, coin_state.coin
|
||||
@ -861,16 +858,20 @@ class WalletStateManager:
|
||||
|
||||
# Check if a child is a singleton launcher
|
||||
if children is None:
|
||||
children = await self.wallet_node.fetch_children(peer, coin_state.coin.name(), weight_proof)
|
||||
children = await self.wallet_node.fetch_children(peer, coin_state.coin.name())
|
||||
assert children is not None
|
||||
for child in children:
|
||||
if child.coin.puzzle_hash != SINGLETON_LAUNCHER_HASH:
|
||||
continue
|
||||
if await self.have_a_pool_wallet_with_launched_id(child.coin.name()):
|
||||
continue
|
||||
launcher_spend: CoinSpend = await self.wallet_node.fetch_puzzle_solution(
|
||||
if child.spent_height is None:
|
||||
continue
|
||||
launcher_spend: Optional[CoinSpend] = await self.wallet_node.fetch_puzzle_solution(
|
||||
peer, coin_state.spent_height, child.coin
|
||||
)
|
||||
if launcher_spend is None:
|
||||
continue
|
||||
pool_state = None
|
||||
try:
|
||||
pool_state = solution_to_pool_state(launcher_spend)
|
||||
@ -1079,7 +1080,7 @@ class WalletStateManager:
|
||||
|
||||
nodes = self.server.get_full_node_connections()
|
||||
for node in nodes:
|
||||
await self.subscribe_to_coin_ids_update(all_coins_names, node)
|
||||
await self.wallet_node.subscribe_to_coin_updates(all_coins_names, node)
|
||||
self.tx_pending_changed()
|
||||
self.state_changed("pending_transaction", tx_record.wallet_id)
|
||||
|
||||
@ -1141,7 +1142,7 @@ class WalletStateManager:
|
||||
|
||||
reorged: List[TransactionRecord] = await self.tx_store.get_transaction_above(height)
|
||||
await self.tx_store.rollback_to_block(height)
|
||||
|
||||
await self.coin_store.db_wrapper.commit_transaction()
|
||||
for record in reorged:
|
||||
if record.type in [
|
||||
TransactionType.OUTGOING_TX,
|
||||
@ -1149,6 +1150,7 @@ class WalletStateManager:
|
||||
TransactionType.INCOMING_TRADE,
|
||||
]:
|
||||
await self.tx_store.tx_reorged(record)
|
||||
|
||||
self.tx_pending_changed()
|
||||
|
||||
# Removes wallets that were created from a blockchain transaction which got reorged.
|
||||
@ -1275,65 +1277,12 @@ class WalletStateManager:
|
||||
self, puzzle_hash: bytes32, wallet_id: int, in_transaction: bool = False
|
||||
) -> None:
|
||||
await self.interested_store.add_interested_puzzle_hash(puzzle_hash, wallet_id, in_transaction)
|
||||
await self.subscribe_to_new_puzzle_hash([puzzle_hash])
|
||||
await self.wallet_node.new_puzzle_hash_created([puzzle_hash])
|
||||
|
||||
async def add_interested_coin_id(self, coin_id: bytes32) -> None:
|
||||
nodes = self.server.get_full_node_connections()
|
||||
for node in nodes:
|
||||
await self.subscribe_to_coin_ids_update([coin_id], node)
|
||||
|
||||
async def get_filter_additions_removals(
|
||||
self, new_block: HeaderBlock, transactions_filter: bytes, fork_point_with_peak: Optional[uint32]
|
||||
) -> Tuple[List[bytes32], List[bytes32]]:
|
||||
"""Returns a list of our coin ids, and a list of puzzle_hashes that positively match with provided filter."""
|
||||
# assert new_block.prev_header_hash in self.blockchain.blocks
|
||||
|
||||
tx_filter = PyBIP158([b for b in transactions_filter])
|
||||
|
||||
# Get all unspent coins
|
||||
my_coin_records: Set[WalletCoinRecord] = await self.coin_store.get_unspent_coins_at_height(None)
|
||||
|
||||
# Get additions on unconfirmed transactions
|
||||
unconfirmed_additions: Set[Coin] = set()
|
||||
for tx_record in await self.tx_store.get_all_unconfirmed():
|
||||
unconfirmed_additions.update(set(tx_record.additions))
|
||||
|
||||
# Filter coins up to and including fork point
|
||||
unspent_coin_names: Set[bytes32] = set()
|
||||
for coin in my_coin_records:
|
||||
unspent_coin_names.add(coin.name())
|
||||
|
||||
my_puzzle_hashes = self.puzzle_store.all_puzzle_hashes
|
||||
|
||||
removals_of_interest: List[bytes32] = []
|
||||
additions_of_interest: List[bytes32] = []
|
||||
|
||||
trade_removals = await self.trade_manager.get_coins_of_interest()
|
||||
for name, trade_coin in trade_removals.items():
|
||||
if tx_filter.Match(bytearray(trade_coin.name())):
|
||||
removals_of_interest.append(trade_coin.name())
|
||||
|
||||
for addition in unconfirmed_additions:
|
||||
if tx_filter.Match(bytearray(addition.name())):
|
||||
additions_of_interest.append(addition.name())
|
||||
|
||||
for coin_name in unspent_coin_names:
|
||||
if tx_filter.Match(bytearray(coin_name)):
|
||||
removals_of_interest.append(coin_name)
|
||||
|
||||
for puzzle_hash in my_puzzle_hashes:
|
||||
if tx_filter.Match(bytearray(puzzle_hash)):
|
||||
additions_of_interest.append(puzzle_hash)
|
||||
|
||||
for coin_id in await self.interested_store.get_interested_coin_ids():
|
||||
if tx_filter.Match(bytearray(coin_id)):
|
||||
removals_of_interest.append(coin_id)
|
||||
|
||||
for puzzle_hash, _ in await self.interested_store.get_interested_puzzle_hashes():
|
||||
if tx_filter.Match(bytearray(puzzle_hash)):
|
||||
additions_of_interest.append(puzzle_hash)
|
||||
|
||||
return additions_of_interest, removals_of_interest
|
||||
await self.wallet_node.subscribe_to_coin_updates([coin_id], node)
|
||||
|
||||
async def delete_trade_transactions(self, trade_id: bytes32):
|
||||
txs: List[TransactionRecord] = await self.tx_store.get_transactions_by_trade_id(trade_id)
|
||||
|
@ -257,7 +257,7 @@ class WalletTransactionStore:
|
||||
name=record.name,
|
||||
memos=record.memos,
|
||||
)
|
||||
await self.add_transaction_record(tx, True)
|
||||
await self.add_transaction_record(tx, False)
|
||||
|
||||
async def get_transaction_record(self, tx_id: bytes32) -> Optional[TransactionRecord]:
|
||||
"""
|
||||
@ -471,7 +471,7 @@ class WalletTransactionStore:
|
||||
to_delete.append(tx)
|
||||
for tx in to_delete:
|
||||
self.tx_record_cache.pop(tx.name)
|
||||
|
||||
self.tx_submitted = {}
|
||||
c1 = await self.db_connection.execute("DELETE FROM transaction_record WHERE confirmed_at_height>?", (height,))
|
||||
await c1.close()
|
||||
|
||||
|
@ -10,6 +10,7 @@ from chia.protocols import full_node_protocol
|
||||
from chia.types.peer_info import PeerInfo
|
||||
from chia.util.ints import uint16
|
||||
from chia.wallet.transaction_record import TransactionRecord
|
||||
from chia.wallet.wallet_node import WalletNode
|
||||
from tests.connection_utils import connect_and_get_peer
|
||||
from tests.setup_nodes import bt, self_hostname, setup_simulators_and_wallets
|
||||
from tests.time_out_assert import time_out_assert
|
||||
@ -22,6 +23,14 @@ def wallet_height_at_least(wallet_node, h):
|
||||
return False
|
||||
|
||||
|
||||
async def wallet_balance_at_least(wallet_node: WalletNode, balance):
|
||||
assert wallet_node.wallet_state_manager is not None
|
||||
b = await wallet_node.wallet_state_manager.get_confirmed_balance_for_wallet(1)
|
||||
if b >= balance:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -56,8 +65,11 @@ class TestMempoolPerformance:
|
||||
|
||||
await wallet_server.start_client(PeerInfo(self_hostname, uint16(server_1._port)), None)
|
||||
await time_out_assert(60, wallet_height_at_least, True, wallet_node, 399)
|
||||
send_amount = 40000000000000
|
||||
fee_amount = 2213
|
||||
await time_out_assert(60, wallet_balance_at_least, True, wallet_node, send_amount + fee_amount)
|
||||
|
||||
big_transaction: TransactionRecord = await wallet.generate_signed_transaction(40000000000000, ph, 2213)
|
||||
big_transaction: TransactionRecord = await wallet.generate_signed_transaction(send_amount, ph, fee_amount)
|
||||
|
||||
peer = await connect_and_get_peer(server_1, server_2)
|
||||
await full_node_api_1.respond_transaction(
|
||||
|
@ -63,18 +63,19 @@ class TestCATWallet:
|
||||
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
wallet_node.config["trusted_peers"] = {full_node_server.node_id: full_node_server.node_id}
|
||||
wallet_node.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()}
|
||||
else:
|
||||
wallet_node.config["trusted_peers"] = {}
|
||||
|
||||
await server_2.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
|
||||
for i in range(1, num_blocks):
|
||||
for i in range(0, num_blocks):
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
|
||||
funds = sum(
|
||||
[
|
||||
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i))
|
||||
for i in range(1, num_blocks - 1)
|
||||
for i in range(1, num_blocks + 1)
|
||||
]
|
||||
)
|
||||
|
||||
@ -118,21 +119,22 @@ class TestCATWallet:
|
||||
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
wallet_node.config["trusted_peers"] = {full_node_server.node_id: full_node_server.node_id}
|
||||
wallet_node_2.config["trusted_peers"] = {full_node_server.node_id: full_node_server.node_id}
|
||||
wallet_node.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()}
|
||||
wallet_node_2.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()}
|
||||
else:
|
||||
wallet_node.config["trusted_peers"] = {}
|
||||
wallet_node_2.config["trusted_peers"] = {}
|
||||
await server_2.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
|
||||
await server_3.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
|
||||
|
||||
for i in range(1, num_blocks):
|
||||
for i in range(0, num_blocks):
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
|
||||
funds = sum(
|
||||
[
|
||||
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i))
|
||||
for i in range(1, num_blocks - 1)
|
||||
for i in range(1, num_blocks + 1)
|
||||
]
|
||||
)
|
||||
|
||||
@ -175,9 +177,9 @@ class TestCATWallet:
|
||||
await time_out_assert(15, cat_wallet.get_pending_change_balance, 40)
|
||||
|
||||
for i in range(1, num_blocks):
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"\0"))
|
||||
|
||||
await time_out_assert(30, wallet.get_confirmed_balance, funds * 2 - 101)
|
||||
await time_out_assert(30, wallet.get_confirmed_balance, funds - 101)
|
||||
|
||||
await time_out_assert(15, cat_wallet.get_confirmed_balance, 40)
|
||||
await time_out_assert(15, cat_wallet.get_unconfirmed_balance, 40)
|
||||
@ -214,18 +216,19 @@ class TestCATWallet:
|
||||
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
wallet_node.config["trusted_peers"] = {full_node_server.node_id: full_node_server.node_id}
|
||||
wallet_node.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()}
|
||||
else:
|
||||
wallet_node.config["trusted_peers"] = {}
|
||||
await server_2.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
|
||||
|
||||
for i in range(1, num_blocks):
|
||||
for i in range(0, num_blocks):
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
|
||||
funds = sum(
|
||||
[
|
||||
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i))
|
||||
for i in range(1, num_blocks - 1)
|
||||
for i in range(1, num_blocks + 1)
|
||||
]
|
||||
)
|
||||
|
||||
@ -268,21 +271,22 @@ class TestCATWallet:
|
||||
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
wallet_node.config["trusted_peers"] = {full_node_server.node_id: full_node_server.node_id}
|
||||
wallet_node_2.config["trusted_peers"] = {full_node_server.node_id: full_node_server.node_id}
|
||||
wallet_node.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()}
|
||||
wallet_node_2.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()}
|
||||
else:
|
||||
wallet_node.config["trusted_peers"] = {}
|
||||
wallet_node_2.config["trusted_peers"] = {}
|
||||
await server_2.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
|
||||
await server_3.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
|
||||
|
||||
for i in range(1, num_blocks):
|
||||
for i in range(0, num_blocks):
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
|
||||
funds = sum(
|
||||
[
|
||||
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i))
|
||||
for i in range(1, num_blocks - 1)
|
||||
for i in range(1, num_blocks + 1)
|
||||
]
|
||||
)
|
||||
|
||||
@ -313,15 +317,19 @@ class TestCATWallet:
|
||||
assert cat_wallet.cat_info.limitations_program_hash == cat_wallet_2.cat_info.limitations_program_hash
|
||||
|
||||
cat_2_hash = await cat_wallet_2.get_new_inner_hash()
|
||||
tx_records = await cat_wallet.generate_signed_transaction([uint64(60)], [cat_2_hash])
|
||||
tx_records = await cat_wallet.generate_signed_transaction([uint64(60)], [cat_2_hash], fee=uint64(1))
|
||||
for tx_record in tx_records:
|
||||
await wallet.wallet_state_manager.add_pending_transaction(tx_record)
|
||||
await time_out_assert(
|
||||
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
|
||||
)
|
||||
if tx_record.spend_bundle is not None:
|
||||
await time_out_assert(
|
||||
15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
|
||||
)
|
||||
for i in range(1, num_blocks):
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
|
||||
await time_out_assert(30, wallet.get_confirmed_balance, funds - 101)
|
||||
await time_out_assert(30, wallet.get_unconfirmed_balance, funds - 101)
|
||||
|
||||
await time_out_assert(15, cat_wallet.get_confirmed_balance, 40)
|
||||
await time_out_assert(15, cat_wallet.get_unconfirmed_balance, 40)
|
||||
|
||||
@ -368,9 +376,9 @@ class TestCATWallet:
|
||||
|
||||
ph = await wallet_0.get_new_puzzlehash()
|
||||
if trusted:
|
||||
wallet_node_0.config["trusted_peers"] = {full_node_server.node_id: full_node_server.node_id}
|
||||
wallet_node_1.config["trusted_peers"] = {full_node_server.node_id: full_node_server.node_id}
|
||||
wallet_node_2.config["trusted_peers"] = {full_node_server.node_id: full_node_server.node_id}
|
||||
wallet_node_0.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()}
|
||||
wallet_node_1.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()}
|
||||
wallet_node_2.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()}
|
||||
else:
|
||||
wallet_node_0.config["trusted_peers"] = {}
|
||||
wallet_node_1.config["trusted_peers"] = {}
|
||||
@ -379,14 +387,11 @@ class TestCATWallet:
|
||||
await wallet_server_1.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
|
||||
await wallet_server_2.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
|
||||
|
||||
for i in range(1, num_blocks):
|
||||
for i in range(0, num_blocks):
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
|
||||
|
||||
funds = sum(
|
||||
[
|
||||
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i))
|
||||
for i in range(1, num_blocks - 1)
|
||||
]
|
||||
[calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks)]
|
||||
)
|
||||
|
||||
await time_out_assert(15, wallet_0.get_confirmed_balance, funds)
|
||||
@ -509,21 +514,22 @@ class TestCATWallet:
|
||||
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
wallet_node.config["trusted_peers"] = {full_node_server.node_id: full_node_server.node_id}
|
||||
wallet_node_2.config["trusted_peers"] = {full_node_server.node_id: full_node_server.node_id}
|
||||
wallet_node.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()}
|
||||
wallet_node_2.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()}
|
||||
else:
|
||||
wallet_node.config["trusted_peers"] = {}
|
||||
wallet_node_2.config["trusted_peers"] = {}
|
||||
await server_2.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
|
||||
await server_3.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
|
||||
|
||||
for i in range(1, num_blocks):
|
||||
for i in range(0, num_blocks):
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
|
||||
funds = sum(
|
||||
[
|
||||
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i))
|
||||
for i in range(1, num_blocks - 1)
|
||||
for i in range(1, num_blocks + 1)
|
||||
]
|
||||
)
|
||||
|
||||
@ -637,21 +643,22 @@ class TestCATWallet:
|
||||
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
wallet_node.config["trusted_peers"] = {full_node_server.node_id: full_node_server.node_id}
|
||||
wallet_node_2.config["trusted_peers"] = {full_node_server.node_id: full_node_server.node_id}
|
||||
wallet_node.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()}
|
||||
wallet_node_2.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()}
|
||||
else:
|
||||
wallet_node.config["trusted_peers"] = {}
|
||||
wallet_node_2.config["trusted_peers"] = {}
|
||||
await server_2.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
|
||||
await server_3.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
|
||||
|
||||
for i in range(1, num_blocks):
|
||||
for i in range(0, num_blocks):
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
|
||||
funds = sum(
|
||||
[
|
||||
calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i))
|
||||
for i in range(1, num_blocks - 1)
|
||||
for i in range(1, num_blocks + 1)
|
||||
]
|
||||
)
|
||||
|
||||
@ -690,8 +697,10 @@ class TestCATWallet:
|
||||
await time_out_assert(15, cat_wallet.get_unconfirmed_balance, 40)
|
||||
|
||||
# First we test that no wallet was created
|
||||
asyncio.sleep(10)
|
||||
assert len(wallet_node_2.wallet_state_manager.wallets.keys()) == 1
|
||||
async def check_wallets(node):
|
||||
return len(node.wallet_state_manager.wallets.keys())
|
||||
|
||||
await time_out_assert(10, check_wallets, 1, wallet_node_2)
|
||||
|
||||
# Then we update the wallet's default CATs
|
||||
wallet_node_2.wallet_state_manager.default_cats = {
|
||||
@ -719,14 +728,12 @@ class TestCATWallet:
|
||||
await time_out_assert(15, cat_wallet.get_unconfirmed_balance, 30)
|
||||
|
||||
# Now we check that another wallet WAS created
|
||||
async def check_wallets(wallet_node):
|
||||
return len(wallet_node.wallet_state_manager.wallets.keys())
|
||||
|
||||
await time_out_assert(10, check_wallets, 2, wallet_node_2)
|
||||
cat_wallet_2 = wallet_node_2.wallet_state_manager.wallets[2]
|
||||
|
||||
await time_out_assert(30, cat_wallet_2.get_confirmed_balance, 10)
|
||||
await time_out_assert(30, cat_wallet_2.get_unconfirmed_balance, 10)
|
||||
# Previous balance + balance that triggered creation
|
||||
await time_out_assert(30, cat_wallet_2.get_confirmed_balance, 70)
|
||||
await time_out_assert(30, cat_wallet_2.get_unconfirmed_balance, 70)
|
||||
|
||||
cat_hash = await cat_wallet.get_new_inner_hash()
|
||||
tx_records = await cat_wallet_2.generate_signed_transaction([uint64(5)], [cat_hash])
|
||||
@ -742,46 +749,3 @@ class TestCATWallet:
|
||||
|
||||
await time_out_assert(15, cat_wallet.get_confirmed_balance, 35)
|
||||
await time_out_assert(15, cat_wallet.get_unconfirmed_balance, 35)
|
||||
|
||||
# @pytest.mark.asyncio
|
||||
|
||||
# async def test_cat_melt_and_mint(self, two_wallet_nodes):
|
||||
# num_blocks = 3
|
||||
# full_nodes, wallets = two_wallet_nodes
|
||||
# full_node_api = full_nodes[0]
|
||||
# full_node_server = full_node_api.server
|
||||
# wallet_node, server_2 = wallets[0]
|
||||
# wallet_node_2, server_3 = wallets[1]
|
||||
# wallet = wallet_node.wallet_state_manager.main_wallet
|
||||
#
|
||||
# ph = await wallet.get_new_puzzlehash()
|
||||
#
|
||||
# await server_2.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
|
||||
# await server_3.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
|
||||
#
|
||||
# for i in range(1, num_blocks):
|
||||
# await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
|
||||
#
|
||||
# funds = sum(
|
||||
# [
|
||||
# calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i))
|
||||
# for i in range(1, num_blocks - 1)
|
||||
# ]
|
||||
# )
|
||||
#
|
||||
# await time_out_assert(15, wallet.get_confirmed_balance, funds)
|
||||
#
|
||||
# async with wallet_node.wallet_state_manager.lock:
|
||||
# cat_wallet: CATWallet = await CATWallet.create_new_cat_wallet(
|
||||
# wallet_node.wallet_state_manager, wallet, {"identifier": "genesis_by_id"}, uint64(100000)
|
||||
# )
|
||||
# tx_queue: List[TransactionRecord] = await wallet_node.wallet_state_manager.tx_store.get_not_sent()
|
||||
# tx_record = tx_queue[0]
|
||||
# await time_out_assert(
|
||||
# 15, tx_in_pool, True, full_node_api.full_node.mempool_manager, tx_record.spend_bundle.name()
|
||||
# )
|
||||
# for i in range(1, num_blocks):
|
||||
# await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
#
|
||||
# await time_out_assert(15, cat_wallet.get_confirmed_balance, 100000)
|
||||
# await time_out_assert(15, cat_wallet.get_unconfirmed_balance, 100000)
|
||||
|
@ -39,7 +39,7 @@ buffer_blocks = 4
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
async def wallets_prefarm(two_wallet_nodes):
|
||||
async def wallets_prefarm(two_wallet_nodes, trusted):
|
||||
"""
|
||||
Sets up the node with 10 blocks, and returns a payer and payee wallet.
|
||||
"""
|
||||
@ -56,6 +56,13 @@ async def wallets_prefarm(two_wallet_nodes):
|
||||
ph0 = await wallet_0.get_new_puzzlehash()
|
||||
ph1 = await wallet_1.get_new_puzzlehash()
|
||||
|
||||
if trusted:
|
||||
wallet_node_0.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()}
|
||||
wallet_node_1.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()}
|
||||
else:
|
||||
wallet_node_0.config["trusted_peers"] = {}
|
||||
wallet_node_1.config["trusted_peers"] = {}
|
||||
|
||||
await wallet_server_0.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
|
||||
await wallet_server_1.start_client(PeerInfo("localhost", uint16(full_node_server._port)), None)
|
||||
|
||||
@ -77,18 +84,11 @@ async def wallets_prefarm(two_wallet_nodes):
|
||||
)
|
||||
class TestCATTrades:
|
||||
@pytest.mark.asyncio
|
||||
async def test_cat_trades(self, wallets_prefarm, trusted):
|
||||
async def test_cat_trades(self, wallets_prefarm):
|
||||
wallet_node_maker, wallet_node_taker, full_node = wallets_prefarm
|
||||
wallet_maker = wallet_node_maker.wallet_state_manager.main_wallet
|
||||
wallet_taker = wallet_node_taker.wallet_state_manager.main_wallet
|
||||
|
||||
if trusted:
|
||||
wallet_node_maker.config["trusted_peers"] = {full_node.server.node_id: full_node.server.node_id}
|
||||
wallet_node_taker.config["trusted_peers"] = {full_node.server.node_id: full_node.server.node_id}
|
||||
else:
|
||||
wallet_node_maker.config["trusted_peers"] = {}
|
||||
wallet_node_taker.config["trusted_peers"] = {}
|
||||
|
||||
# Create two new CATs, one in each wallet
|
||||
async with wallet_node_maker.wallet_state_manager.lock:
|
||||
cat_wallet_maker: CATWallet = await CATWallet.create_new_cat_wallet(
|
||||
@ -119,8 +119,8 @@ class TestCATTrades:
|
||||
# Create the trade parameters
|
||||
MAKER_CHIA_BALANCE = 20 * 1000000000000 - 100
|
||||
TAKER_CHIA_BALANCE = 20 * 1000000000000 - 100
|
||||
await time_out_assert(15, wallet_maker.get_confirmed_balance, MAKER_CHIA_BALANCE)
|
||||
await time_out_assert(15, wallet_taker.get_unconfirmed_balance, TAKER_CHIA_BALANCE)
|
||||
await time_out_assert(25, wallet_maker.get_confirmed_balance, MAKER_CHIA_BALANCE)
|
||||
await time_out_assert(25, wallet_taker.get_unconfirmed_balance, TAKER_CHIA_BALANCE)
|
||||
MAKER_CAT_BALANCE = 100
|
||||
MAKER_NEW_CAT_BALANCE = 0
|
||||
TAKER_CAT_BALANCE = 0
|
||||
@ -400,18 +400,11 @@ class TestCATTrades:
|
||||
await time_out_assert(15, get_trade_and_status, TradeStatus.CONFIRMED, trade_manager_taker, trade_take)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_trade_cancellation(self, wallets_prefarm, trusted):
|
||||
async def test_trade_cancellation(self, wallets_prefarm):
|
||||
wallet_node_maker, wallet_node_taker, full_node = wallets_prefarm
|
||||
wallet_maker = wallet_node_maker.wallet_state_manager.main_wallet
|
||||
wallet_taker = wallet_node_taker.wallet_state_manager.main_wallet
|
||||
|
||||
if trusted:
|
||||
wallet_node_maker.config["trusted_peers"] = {full_node.server.node_id.hex(): full_node.server.node_id.hex()}
|
||||
wallet_node_taker.config["trusted_peers"] = {full_node.server.node_id.hex(): full_node.server.node_id.hex()}
|
||||
else:
|
||||
wallet_node_maker.config["trusted_peers"] = {}
|
||||
wallet_node_taker.config["trusted_peers"] = {}
|
||||
|
||||
async with wallet_node_maker.wallet_state_manager.lock:
|
||||
cat_wallet_maker: CATWallet = await CATWallet.create_new_cat_wallet(
|
||||
wallet_node_maker.wallet_state_manager, wallet_maker, {"identifier": "genesis_by_id"}, uint64(100)
|
||||
|
@ -60,7 +60,7 @@ class TestWalletSync:
|
||||
await full_node_api.full_node.respond_block(full_node_protocol.RespondBlock(block))
|
||||
|
||||
if trusted:
|
||||
wallet_node.config["trusted_peers"] = {full_node_server.node_id: full_node_server.node_id}
|
||||
wallet_node.config["trusted_peers"] = {full_node_server.node_id.hex(): full_node_server.node_id.hex()}
|
||||
else:
|
||||
wallet_node.config["trusted_peers"] = {}
|
||||
await wallet_server.start_client(PeerInfo(self_hostname, uint16(full_node_server._port)), None)
|
||||
@ -184,12 +184,12 @@ class TestWalletSync:
|
||||
# same tip at height num_blocks - 1.
|
||||
await time_out_assert(600, wallet_height_at_least, True, wallet_node, len(default_400_blocks) - 1)
|
||||
|
||||
await disconnect_all_and_reconnect(wallet_server, full_node_server)
|
||||
|
||||
# Tests a long reorg
|
||||
for block in default_1000_blocks:
|
||||
await full_node_api.full_node.respond_block(full_node_protocol.RespondBlock(block))
|
||||
|
||||
await disconnect_all_and_reconnect(wallet_server, full_node_server)
|
||||
|
||||
log.info(f"wallet node height is {wallet_node.wallet_state_manager.blockchain.get_peak_height()}")
|
||||
await time_out_assert(600, wallet_height_at_least, True, wallet_node, len(default_1000_blocks) - 1)
|
||||
|
||||
|
@ -67,7 +67,7 @@ class TestWalletSimulator:
|
||||
wallet = wallet_node.wallet_state_manager.main_wallet
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
wallet_node.config["trusted_peers"] = {server_1.node_id: server_1.node_id}
|
||||
wallet_node.config["trusted_peers"] = {server_1.node_id.hex(): server_1.node_id.hex()}
|
||||
else:
|
||||
wallet_node.config["trusted_peers"] = {}
|
||||
|
||||
@ -123,8 +123,8 @@ class TestWalletSimulator:
|
||||
wallet = wallet_node.wallet_state_manager.main_wallet
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
wallet_node.config["trusted_peers"] = {server_1.node_id: server_1.node_id}
|
||||
wallet_node_2.config["trusted_peers"] = {server_1.node_id: server_1.node_id}
|
||||
wallet_node.config["trusted_peers"] = {server_1.node_id.hex(): server_1.node_id.hex()}
|
||||
wallet_node_2.config["trusted_peers"] = {server_1.node_id.hex(): server_1.node_id.hex()}
|
||||
else:
|
||||
wallet_node.config["trusted_peers"] = {}
|
||||
wallet_node_2.config["trusted_peers"] = {}
|
||||
@ -179,10 +179,11 @@ class TestWalletSimulator:
|
||||
wallet = wallet_node.wallet_state_manager.main_wallet
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
wallet_node.config["trusted_peers"] = {fn_server.node_id: fn_server.node_id}
|
||||
wallet_node.config["trusted_peers"] = {fn_server.node_id.hex(): fn_server.node_id.hex()}
|
||||
else:
|
||||
wallet_node.config["trusted_peers"] = {}
|
||||
await server_2.start_client(PeerInfo(self_hostname, uint16(fn_server._port)), None)
|
||||
await asyncio.sleep(5)
|
||||
for i in range(0, num_blocks):
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(ph))
|
||||
|
||||
@ -190,7 +191,7 @@ class TestWalletSimulator:
|
||||
[calculate_pool_reward(uint32(i)) + calculate_base_farmer_reward(uint32(i)) for i in range(1, num_blocks)]
|
||||
)
|
||||
|
||||
await time_out_assert(5, wallet.get_confirmed_balance, funds)
|
||||
await time_out_assert(25, wallet.get_confirmed_balance, funds)
|
||||
|
||||
await full_node_api.reorg_from_index_to_new_index(ReorgProtocol(uint32(2), uint32(num_blocks + 6), 32 * b"0"))
|
||||
|
||||
@ -227,7 +228,12 @@ class TestWalletSimulator:
|
||||
|
||||
ph = await wallet_0.wallet_state_manager.main_wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
wallet_0.config["trusted_peers"] = {server_0.node_id: server_0.node_id}
|
||||
wallet_0.config["trusted_peers"] = {
|
||||
server_0.node_id.hex(): server_0.node_id.hex(),
|
||||
server_1.node_id.hex(): server_1.node_id.hex(),
|
||||
server_2.node_id.hex(): server_2.node_id.hex(),
|
||||
}
|
||||
|
||||
else:
|
||||
wallet_0.config["trusted_peers"] = {}
|
||||
|
||||
@ -282,8 +288,8 @@ class TestWalletSimulator:
|
||||
wallet_1 = wallet_node_1.wallet_state_manager.main_wallet
|
||||
ph = await wallet_0.get_new_puzzlehash()
|
||||
if trusted:
|
||||
wallet_node_0.config["trusted_peers"] = {server_0.node_id: server_0.node_id}
|
||||
wallet_node_1.config["trusted_peers"] = {server_0.node_id: server_0.node_id}
|
||||
wallet_node_0.config["trusted_peers"] = {server_0.node_id.hex(): server_0.node_id.hex()}
|
||||
wallet_node_1.config["trusted_peers"] = {server_0.node_id.hex(): server_0.node_id.hex()}
|
||||
else:
|
||||
wallet_node_0.config["trusted_peers"] = {}
|
||||
wallet_node_1.config["trusted_peers"] = {}
|
||||
@ -399,10 +405,10 @@ class TestWalletSimulator:
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
wallet_node.config["trusted_peers"] = {
|
||||
full_node_1.full_node.server.node_id: full_node_1.full_node.server.node_id
|
||||
full_node_1.full_node.server.node_id.hex(): full_node_1.full_node.server.node_id.hex()
|
||||
}
|
||||
wallet_node_2.config["trusted_peers"] = {
|
||||
full_node_1.full_node.server.node_id: full_node_1.full_node.server.node_id
|
||||
full_node_1.full_node.server.node_id.hex(): full_node_1.full_node.server.node_id.hex()
|
||||
}
|
||||
else:
|
||||
wallet_node.config["trusted_peers"] = {}
|
||||
@ -466,10 +472,10 @@ class TestWalletSimulator:
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
wallet_node.config["trusted_peers"] = {
|
||||
full_node_1.full_node.server.node_id: full_node_1.full_node.server.node_id
|
||||
full_node_1.full_node.server.node_id.hex(): full_node_1.full_node.server.node_id.hex()
|
||||
}
|
||||
wallet_node_2.config["trusted_peers"] = {
|
||||
full_node_1.full_node.server.node_id: full_node_1.full_node.server.node_id
|
||||
full_node_1.full_node.server.node_id.hex(): full_node_1.full_node.server.node_id.hex()
|
||||
}
|
||||
else:
|
||||
wallet_node.config["trusted_peers"] = {}
|
||||
@ -562,10 +568,10 @@ class TestWalletSimulator:
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
if trusted:
|
||||
wallet_node.config["trusted_peers"] = {
|
||||
full_node_1.full_node.server.node_id: full_node_1.full_node.server.node_id
|
||||
full_node_1.full_node.server.node_id.hex(): full_node_1.full_node.server.node_id.hex()
|
||||
}
|
||||
wallet_node_2.config["trusted_peers"] = {
|
||||
full_node_1.full_node.server.node_id: full_node_1.full_node.server.node_id
|
||||
full_node_1.full_node.server.node_id.hex(): full_node_1.full_node.server.node_id.hex()
|
||||
}
|
||||
else:
|
||||
wallet_node.config["trusted_peers"] = {}
|
||||
@ -651,8 +657,8 @@ class TestWalletSimulator:
|
||||
ph = await wallet.get_new_puzzlehash()
|
||||
ph2 = await wallet_2.get_new_puzzlehash()
|
||||
if trusted:
|
||||
wallet_node.config["trusted_peers"] = {fn_server.node_id: fn_server.node_id}
|
||||
wallet_node_2.config["trusted_peers"] = {fn_server.node_id: fn_server.node_id}
|
||||
wallet_node.config["trusted_peers"] = {fn_server.node_id.hex(): fn_server.node_id.hex()}
|
||||
wallet_node_2.config["trusted_peers"] = {fn_server.node_id.hex(): fn_server.node_id.hex()}
|
||||
else:
|
||||
wallet_node.config["trusted_peers"] = {}
|
||||
wallet_node_2.config["trusted_peers"] = {}
|
||||
@ -706,8 +712,8 @@ class TestWalletSimulator:
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
|
||||
# By this point, the transaction should be confirmed
|
||||
print(await wallet.get_confirmed_balance())
|
||||
await time_out_assert(15, wallet.get_confirmed_balance, funds - 1000)
|
||||
|
||||
unconfirmed = await wallet_node.wallet_state_manager.tx_store.get_unconfirmed_for_wallet(int(wallet.id()))
|
||||
assert len(unconfirmed) == 0
|
||||
tx_record = await wallet_node.wallet_state_manager.tx_store.get_transaction_record(tx.name)
|
||||
@ -728,7 +734,7 @@ class TestWalletSimulator:
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"trusted",
|
||||
[True, False],
|
||||
[False],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_address_sliding_window(self, wallet_node_100_pk, trusted):
|
||||
@ -757,21 +763,14 @@ class TestWalletSimulator:
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(puzzle_hashes[114]))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
|
||||
await time_out_assert(5, wallet.get_confirmed_balance, 2 * 10 ** 12)
|
||||
await time_out_assert(15, wallet.get_confirmed_balance, 2 * 10 ** 12)
|
||||
|
||||
# TODO: fix after merging new wallet. These 210 and 114 should be found
|
||||
# TODO: This is fixed in trusted mode, needs to work in untrusted too.
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(puzzle_hashes[50]))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
if trusted:
|
||||
await time_out_assert(15, wallet.get_confirmed_balance, 8 * 10 ** 12)
|
||||
else:
|
||||
await time_out_assert(15, wallet.get_confirmed_balance, 4 * 10 ** 12)
|
||||
|
||||
await time_out_assert(15, wallet.get_confirmed_balance, 8 * 10 ** 12)
|
||||
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(puzzle_hashes[113]))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(puzzle_hashes[209]))
|
||||
await full_node_api.farm_new_transaction_block(FarmNewBlockProtocol(32 * b"0"))
|
||||
if trusted:
|
||||
await time_out_assert(15, wallet.get_confirmed_balance, 12 * 10 ** 12)
|
||||
else:
|
||||
await time_out_assert(15, wallet.get_confirmed_balance, 8 * 10 ** 12)
|
||||
await time_out_assert(15, wallet.get_confirmed_balance, 12 * 10 ** 12)
|
||||
|
Loading…
Reference in New Issue
Block a user