* Fix problems with wallet node discovery
* Adjust tests to work more consistently
* Attempt to debug rate limit test
* Limit rate test to one consensus mode
* Extract `respond_signatures` logic
* Add `call_api_of_specific` method to `ChiaServer`
* Fix typehint for test fixture `farmer_one_harvester`
* Make test helper `add_dummy_connection` work with any node type
* Add `reply_types` to `request_signatures` of harvester
* Fix duplicate SP processing with multiple nodes
* Handle state in `request_signed_values`
* Add set typehint
* Add comment re `_process_respond_signatures()` usage
* Fix imports
* Fix wording to not confuse with SignedValues message
* server: Introduce `ApiProtocol`
* genericize (#5)
* `ApiProtocol.api_ready` -> `ApiProtocol.ready()`
* Add `ApiProtocol.log` and give APIs separate loggers
* Fix `CrawlerAPI`
* Drop some unrelated removals
* Fix some of the generic hinting
* Revert some changes in `timelord_api.py`
* Fix `CawlerAPI` readiness
* Fix hinting
* Get some `CrawlerAPI` coverage
---------
Co-authored-by: Kyle Altendorf <sda@fstab.net>
Use the one from the connection data like we do it with the port. The
result there is slightly different since its resolved so `localhost`
becomes an IP in `peer_info` but i anyway will open a PR soon to
transition from `str` to `IPAddress` in there.
<!-- Merging Requirements:
- Please give your PR a title that is release-note friendly
- In order to be merged, you must add the most appropriate category
Label (Added, Changed, Fixed) to your PR
-->
<!-- Explain why this is an improvement (Does this add missing
functionality, improve performance, or reduce complexity?) -->
### Purpose:
<!-- Does this PR introduce a breaking change? -->
### Current Behavior:
### New Behavior:
<!-- As we aim for complete code coverage, please include details
regarding unit, and regression tests -->
### Testing Notes:
<!-- Attach any visual examples, or supporting evidence (attach any
.gif/video/console output below) -->
<!-- Merging Requirements:
- Please give your PR a title that is release-note friendly
- In order to be merged, you must add the most appropriate category
Label (Added, Changed, Fixed) to your PR
-->
<!-- Explain why this is an improvement (Does this add missing
functionality, improve performance, or reduce complexity?) -->
### Purpose:
Self connection errors don't need to be `ERROR` level in the log nor do
they need to have tracebacks. This will mostly happen when a node is
unaware of one or more of its own public IPs being used by the network.
Could be IPv4 vs. IPv6, or multiple IPs, or just being behind a NAT.
<!-- Does this PR introduce a breaking change? -->
### Current Behavior:
```python-traceback
2023-03-22T14:00:46.076 full_node full_node_server : ERROR Exception Trying to connect to a peer (PeerInfo(_ip=IPv4Address('<REDACTED>'), _port=58445)) with the same peer_id: <REDACTED>, exception Stack: Traceback (most recent call last):
File "/home/ubuntu/chia-blockchain/chia/server/server.py", line 525, in start_client
raise RuntimeError(f"Trying to connect to a peer ({target_node}) with the same peer_id: {peer_id}")
RuntimeError: Trying to connect to a peer (PeerInfo(_ip=IPv4Address('<REDACTED>'), _port=58445)) with the same peer_id: <REDACTED>
```
### New Behavior:
`INFO` level logging without a traceback
<!-- As we aim for complete code coverage, please include details
regarding unit, and regression tests -->
### Testing Notes:
<!-- Attach any visual examples, or supporting evidence (attach any
.gif/video/console output below) -->
Refactor function `is_trusted_peer` to a standalone easily testable
function. Leverage the existing `is_localhost` function to extend
coverage to IPv6 local address for the trusted peer check
Added tests for the new standalone function
* dont wait for timeout on None response
* handle return msg by type
* remove empty line
* isort
* improve reply check
* use map to check reply, add has_capability helper
* fix has_capability
* unused import
* server: Enable and fix `mypy` in `server.py`
* Add a comment about the `Message` hint
Co-authored-by: Kyle Altendorf <sda@fstab.net>
* Tweak assert message
Co-authored-by: Kyle Altendorf <sda@fstab.net>
* Make `name` non-optional
Co-authored-by: Kyle Altendorf <sda@fstab.net>
* Properly reject incoming connections to crawlers
Co-authored-by: Kyle Altendorf <sda@fstab.net>
* Hint `StreamResponse` and return the existing `WebSocketResonse`
* Raise if `remote` is `None`
* Restore old behaviour: succeed, don't fail for self connection
* Raise `HTTPInternalServerError` if `remote` is `None`
* Cast config values to `int`
Co-authored-by: Kyle Altendorf <sda@fstab.net>
Seems like the idea was to log an overview of message types for the
currently active api calls whenever we have multiples of 100 running.
This currently isn't working at all because `len(message_types) % 100 ==
0` will only trigger if there are 100 different message types in the
counter (we don't even have that much different messages). A fix would
be to check `message_types.total() % 100 == 0`. But then, if we hover
around 100 active messages this will repeatedly trigger logs since we
decrement for each processed message, im not sure this all makes much
sense and we anyway log all received message types with `DEBUG` logs so
i decided to just drop this. If someone thinks we should keep it with
the fix or has ideas to make this a more reasonable log instead of
dropping it, let me know :)
* always call close callback
* Some further explorations
* some more explorations
* Add delay while connections are closed in test
* Add a delay to make sure connections drain
* Update chia/server/server.py
Co-authored-by: Kyle Altendorf <sda@fstab.net>
* Update tests/connection_utils.py
Co-authored-by: Kyle Altendorf <sda@fstab.net>
* use log_exceptions context manager
* set close flag correctly
* Added callback type and other changes
Co-authored-by: Kyle Altendorf <sda@fstab.net>
* Drop `get_full_node_connections` -> use `get_connections`
* Drop `connection_by_type`
I think the housekeeping required to have it isn't worth it since we
don't handle huge numbers of connections and `get_connections` should be
less enough overhead. Im open for complains though.
* more explicit and complete handling of api decorator data
* fix
* .message_class
* actually, those are different types...
* tweak
* simplify
* learn that functools.wraps copies random attributes
* configure isort to add the future annotations import
* apply the new isort setting
* remove type ignores for new mypy (#13539)
https://pypi.org/project/mypy/0.981/
* another