TEMP: Printing/logging for debug of client/SPVnode interactions.

This commit is contained in:
Jonathan Moody 2022-12-05 11:56:15 -05:00
parent 87c30c5b05
commit c53e76011f
2 changed files with 15 additions and 7 deletions

View file

@ -30,6 +30,7 @@ from lbry.wallet.bip32 import PublicKey, PrivateKey
from lbry.wallet.coinselection import CoinSelector from lbry.wallet.coinselection import CoinSelector
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
log.setLevel("DEBUG")
LedgerType = Type['BaseLedger'] LedgerType = Type['BaseLedger']
@ -506,6 +507,7 @@ class Ledger(metaclass=LedgerRegistry):
def process_status_update(self, update): def process_status_update(self, update):
address, remote_status = update address, remote_status = update
print(f"**** status update {address} {remote_status}")
self._update_tasks.add(self.update_history(address, remote_status)) self._update_tasks.add(self.update_history(address, remote_status))
async def update_history(self, address, remote_status, address_manager: AddressManager = None, async def update_history(self, address, remote_status, address_manager: AddressManager = None,
@ -518,6 +520,7 @@ class Ledger(metaclass=LedgerRegistry):
return True return True
remote_history = await self.network.retriable_call(self.network.get_history, address) remote_history = await self.network.retriable_call(self.network.get_history, address)
print(f'>>>>>> {remote_history}')
remote_history = list(map(itemgetter('tx_hash', 'height'), remote_history)) remote_history = list(map(itemgetter('tx_hash', 'height'), remote_history))
we_need = set(remote_history) - set(local_history) we_need = set(remote_history) - set(local_history)
if not we_need: if not we_need:
@ -549,7 +552,7 @@ class Ledger(metaclass=LedgerRegistry):
continue continue
to_request[i] = (txid, remote_height) to_request[i] = (txid, remote_height)
log.debug( log.warning(
"request %i transactions, %i/%i for %s are already synced", len(to_request), len(already_synced), "request %i transactions, %i/%i for %s are already synced", len(to_request), len(already_synced),
len(remote_history), address len(remote_history), address
) )
@ -558,8 +561,8 @@ class Ledger(metaclass=LedgerRegistry):
self.maybe_has_channel_key(tx) self.maybe_has_channel_key(tx)
pending_synced_history[tx_indexes[tx.id]] = f"{tx.id}:{tx.height}:" pending_synced_history[tx_indexes[tx.id]] = f"{tx.id}:{tx.height}:"
if len(pending_synced_history) % 100 == 0: if len(pending_synced_history) % 100 == 0:
log.info("Syncing address %s: %d/%d", address, len(pending_synced_history), len(to_request)) log.warning("Syncing address %s: %d/%d", address, len(pending_synced_history), len(to_request))
log.info("Sync finished for address %s: %d/%d", address, len(pending_synced_history), len(to_request)) log.warning("Sync finished for address %s: %d/%d", address, len(pending_synced_history), len(to_request))
assert len(pending_synced_history) == len(remote_history), \ assert len(pending_synced_history) == len(remote_history), \
f"{len(pending_synced_history)} vs {len(remote_history)} for {address}" f"{len(pending_synced_history)} vs {len(remote_history)} for {address}"
@ -606,7 +609,7 @@ class Ledger(metaclass=LedgerRegistry):
self._known_addresses_out_of_sync.add(address) self._known_addresses_out_of_sync.add(address)
return False return False
else: else:
log.debug("finished syncing transaction history for %s, %i known txs", address, len(local_history)) log.warning("finished syncing transaction history for %s, %i known txs", address, len(local_history))
return True return True
async def maybe_verify_transaction(self, tx, remote_height, merkle=None): async def maybe_verify_transaction(self, tx, remote_height, merkle=None):
@ -621,6 +624,8 @@ class Ledger(metaclass=LedgerRegistry):
header = await self.headers.get(remote_height) header = await self.headers.get(remote_height)
tx.position = merkle['pos'] tx.position = merkle['pos']
tx.is_verified = merkle_root == header['merkle_root'] tx.is_verified = merkle_root == header['merkle_root']
if not tx.is_verified:
print(f"&&&&&&& {tx.height}: {merkle_root} != {header['merkle_root']}")
return tx return tx
def maybe_has_channel_key(self, tx): def maybe_has_channel_key(self, tx):

View file

@ -76,7 +76,9 @@ class ClientSession(BaseClientSession):
raise asyncio.TimeoutError raise asyncio.TimeoutError
if done: if done:
try: try:
return request.result() result = request.result()
log.warning("sent %s%s to %s:%i (%i timeout) result: %s", method, tuple(args), self.server[0], self.server[1], self.timeout, result)
return result
except ConnectionResetError: except ConnectionResetError:
log.error( log.error(
"wallet server (%s) reset connection upon our %s request, json of %i args is %i bytes", "wallet server (%s) reset connection upon our %s request, json of %i args is %i bytes",
@ -304,7 +306,7 @@ class Network:
await client.ensure_server_version() await client.ensure_server_version()
return client return client
except (asyncio.TimeoutError, ConnectionError, OSError, IncompatibleWalletServerError, RPCError): except (asyncio.TimeoutError, ConnectionError, OSError, IncompatibleWalletServerError, RPCError):
log.warning("Connecting to %s:%d failed", host, port) log.exception("Connecting to %s:%d failed", host, port)
client._close() client._close()
return return
@ -328,7 +330,8 @@ class Network:
features = await client.send_request('server.features', []) features = await client.send_request('server.features', [])
self.client, self.server_features = client, features self.client, self.server_features = client, features
log.debug("discover other hubs %s:%i", *client.server) log.debug("discover other hubs %s:%i", *client.server)
await self._update_hubs(await client.send_request('server.peers.subscribe', [])) # TODO: Enable this after herald.go supports 'server.peers.subscribe'.
#await self._update_hubs(await client.send_request('server.peers.subscribe', []))
log.info("subscribe to headers %s:%i", *client.server) log.info("subscribe to headers %s:%i", *client.server)
self._update_remote_height((await self.subscribe_headers(),)) self._update_remote_height((await self.subscribe_headers(),))
self._on_connected_controller.add(True) self._on_connected_controller.add(True)