Commit Graph

38 Commits

Author SHA1 Message Date
dustinface
fbc3127bd5
util: Rework get_host_addr (#14068)
* util: Rework `get_host_addr`

* Require `prefer_ipv6` to be named

* Remove outdated comment

* Improve result selection
2022-12-13 09:48:41 -06:00
dustinface
898543b874
server: Enable and fix mypy for all chia.server files (#13990)
Co-authored-by: Kyle Altendorf <sda@fstab.net>
2022-11-28 18:00:45 -06:00
dustinface
6edb2ce01e
isort: Remove all chia.server exceptions and sort the related files (#13994) 2022-11-23 13:01:29 -06:00
dustinface
cf77f58bf2
server: Make ChiaServer a dataclass (#13574)
* server: Make `ChiaServer` a `dataclass`

* Use existing logger

Co-authored-by: Kyle Altendorf <sda@fstab.net>

Co-authored-by: Kyle Altendorf <sda@fstab.net>
2022-11-03 11:28:23 -05:00
dustinface
345698aebd
server: Create ssl contexts earlier + store them instead of all paths (#13512) 2022-09-29 12:14:20 -05:00
Kyle Altendorf
81837a9e1c
Refactor away from post init for UPnP (#11837)
* Refactor away from post init for UPnP

* refactor UPnP to not be reusable

* update upnp in datalayer too

* add if_needed parameter to UPnP.shutdown()

* simpler

* be more lenient about startup failures, like before

* too many ways for UPnP to fail right now, revert to a smaller refactor approach instead of fixing them all up
2022-09-26 11:19:33 -05:00
Kyle Altendorf
3342a2a6a2
less _ for used variables (#13536) 2022-09-26 11:16:57 -05:00
dustinface
77932fcc11
util: Refactor select_port to not load the config (#13514)
* util: Refactor `select_port` to not load the config

* Fix `prefer_ipv6` config lookup

* Use `str2bool`
2022-09-23 17:47:26 -05:00
Kyle Altendorf
1dbf575a3e
RpcApiProtocol and RpcServiceProtocol (#11522)
* provide a skeleton hint protocol for rpc apis

* more

* more self.custom_get_connections = None

* fix RpcApiProtocol.service hinting

* catch up with RpcApiProtocol._state_changed()

* FullNode.server is now non-optional.  'ish

* drop another todo

* custom_get_connections -> get_connections

* just make get_connections() a mandatory method with a helper provided

* lots

* try again

* ._start_with_fingerprint()

* fill out the Service generic parameter in start scripts

* ... instead of pass

* add docstrings to the protocols

* remove no longer needed hasattr/not None checks

* remove outdated comment

* refactor Harvester._is_shutdown to ._shut_down
2022-09-21 22:49:01 -05:00
Kyle Altendorf
b9e6fd577e
Remove kwargs from Service.start() (#12294) 2022-09-16 16:22:53 -05:00
dustinface
7c9fb654a3
server|tests: Delay the harvester -> farmer connection in some tests (#12862)
* Introduce `Service.add_peer`

* Delay the harvester/farmer connection in some tests to avoid flakiness
2022-08-10 04:57:34 -05:00
dustinface
820889a316
rpc: Improve RPC server start/stop (#12768)
* rpc: Improve RPC server start/stop

* `RpcServer.stop` -> `RpcServer.close`
2022-08-06 01:07:41 -05:00
dustinface
e5297f411d
util: Unify lockfile handling (#12541)
* util: Unify lockfile handling

This patch:
- Renames `util.lock.lock_by_path` to `util.lock.lock_path` and improves it by using `FileLock`
- Unifies all places where we create lock files to use `chia.util.lock.lock_path`
- Changes the daemon lockfile from `start-daemon.launching` to `daemon.lock` like we have it with all `<service>.lock` in the `run` folder
- Drops the `fastener` dependency

* Move the not keyring related sync tests into `test_lockfile.py`
2022-08-04 12:59:39 -05:00
dustinface
f0a0f07116
daemon|server: Log chia_full_version_str in daemon and all services (#12356) 2022-07-15 21:08:30 -05:00
Kyle Altendorf
11b210809b
run pre-commit across platforms in ci (#12287)
* run pre-commit across platforms in ci

why?  because we have developers working on multiple platforms.

* pre-clean for pre-commit in ci

* chia setup python action

* fixup

* fix windows specific hinting

* no TypeAlias yet

* debug

* debug

* adjust activated.ps1

* verbose pre-commit

* exit better

* Revert "debug"

This reverts commit 93a100afc7.

* less debug

* less `|`

* Update .pre-commit-config.yaml

* Update activated.ps1
2022-07-15 21:08:07 -05:00
Kyle Altendorf
f2061d86d6
rework service creation to be hint checkable (#12153)
* rework service creation to be hint checkable

* fixup config vs. service_config

* more fixup

* service start cleanup

* Update nft_metadata_updater_default.clvm.hex

* reorder advertised_port= parameter

* undo unrelated tweaks

* Optional[RpcInfo]

* undo unrelated whitespace change
2022-07-13 11:43:48 -05:00
Kyle Altendorf
9a4316f96e
fixup (#12292)
* fixup

* add automated option to install action, default true

* try again

* make Install.ps1 accept -a

* oof

* again

* backup
2022-07-07 23:43:22 -05:00
Kyle Altendorf
1205418f22
Simplify service start configuration loading (#12204)
* Simplify service start configuration loading

* oops

* more oops

* rename `config` to `service_config` as appropriate

* rename `full_config` to `config`
2022-07-07 19:57:08 -05:00
Kyle Altendorf
ac1bee09e4
Initialize logging before Service instantiation (#12253) 2022-07-07 06:00:54 -05:00
Kyle Altendorf
e569817ac7
replace service running_new_process= parameter by .setup_process_global_state() method (#12172) 2022-07-01 13:47:01 -05:00
Mariano Sorgente
ab53d48995
Request header blocks, and new rate limits (#11636)
* new blob block api method integrated into wallet

* direct msg streaming of headers, rename, tests

* perform_handshake call fix

* updated trusted sync with new block header calls

* add max blocks limit to fetch

* added tests for rejected block header msgs

* avoid parsing transactions info if not required

* avoid looking up capabilities setting

* move block tests out of a class

* test fix

* Merge changes

* added docs and increased rate limits

* increased block header request interval from 32 to 128

* remove fetching hashes and use height range

* fetching by height in db v2

* update capabilities, other fixes

* fixed range block header call

* Add type hints

* Start work on optimizing fetch_last_tx_from_peer

* Huge speedup in trusted wallet sync

* Revert unintentional changes

* Fix trade issue

* Improve the code

* Str format

* Optimize handling of farming rewards

* Fix bug

* Performance fixes

* Optimizations to wallet syncing

* Don't return all coins in respond_additions

* Revert concurrency numbers

* More optimization of the caches

* Small optimization in coin_added

* Optimize request_additions significantly by using a cache

* fixes from feedback

* capabilities check fixes

* Increase rate limits to allow 250tps in verification requests

* Start work on rate limits

* New rate limit versioning support

* Revert unrelated changes

* revert return False

* Lint

* Revert cbi

* try tests with trusted peer

* Revert unrelated wallet changes

* Revert more debug changes

* Add test and throw on an error if not found

* Reject invalid requests

* Revert bad change with uint32, and change warning to info

* Parametrize wallet sync test

* Merge and LGTM

* More clean way to choose peers

* Fix lint

* add the new RejectBlockHeaders, RequestBlockHeaders and RespondBlockHeaders to the network protocol regression test and regenerate test files

* Rate limit diffs only

* Improve performance

* Simpler

* Lint

Co-authored-by: Sebastjan <trepca@gmail.com>
Co-authored-by: arvidn <arvid@libtorrent.org>
2022-06-11 01:35:41 -05:00
Mariano Sorgente
817baa3096
Bind port 0 to fix race condition when grabbing available ports (#11578)
* port 0 to fix flakiness

* Try fixing setup_full_system

* Try fixing setup_full_system, and lint

* More attempts to fix

* No more calls to get random ports in setup_nodes

* Revert accidental changes

* Timelord extra arg

* Try with port 0

* Fix daemon test, and lint

* Try without 0.0.0.0

* Back to 0.0.0.0

* Try a few timelord changes to get test running

* Increase timeout again

* Use the correct interface to get the port

* INFO logging to debug issue

* Revert "INFO logging to debug issue"

This reverts commit 7c379e5cca.

* Fix advertised port log

* Add extra log

* Logging back

* Rollback the timelord changes

* Try port 0 timelord

* Revert "Try port 0 timelord"

This reverts commit 4997faf3b2.

* Try full green, change ordering

* Remove unused var

* speed up simulation and cleanup

* Now try without the port config

* Fix a flaky call to get_event_loop

* Try getting the port dynamically

* No dynamic port

* Try changing the ordering

* Try adding a sleep

* Back to what works

* Timelord before vdf clients

* Dynamic port for 1st timelord

* Revert "Dynamic port for 1st timelord"

This reverts commit 0f322a15b7.

* Revert "Timelord before vdf clients"

This reverts commit 3286c34696.

* Revert "Back to what works"

This reverts commit 30380dffb7.

* Revert "Try adding a sleep"

This reverts commit 9212b665a6.

* Revert "Try changing the ordering"

This reverts commit a62597d70d.

* Revert "No dynamic port"

This reverts commit 5d2e15749b.

* Revert "Try getting the port dynamically"

This reverts commit ef9cd75679.

* Revert "Fix a flaky call to get_event_loop"

This reverts commit 01a000fdfb.

* Try one to 0

* Just not 0

* Don't get port dynamically

* Cleanup a bit

* Fix

* Some cleanup work

* Some cleanup work

* Fix daemon test

* Cleanup

* Remove arguments
2022-05-23 08:13:49 -07:00
Kyle Altendorf
0e419822e0
Allow services to set a non-default max request body size limit (#11516) 2022-05-14 02:08:10 -07:00
Arvid Norberg
9db85f3284
when running multiple services in the same process (in tests), don't initialize logging for all of them, and don't set the proctitle of the test (#10686) 2022-03-17 14:58:30 -07:00
Arvid Norberg
29bd136238
name processes we spawn in tests with a test_ prefix, to make it easier and find and kill them in case they're left running (#10318) 2022-02-19 12:39:17 -08:00
Kyle Altendorf
9a3194599d
do not enable signals on services in tests (#10290) 2022-02-18 07:49:19 -08:00
Mariano Sorgente
52e439ccbe
Ms.sync cancel (#10244)
* Start fixing other issues

* Fork point, sync cancelling, random peer

* Reduce logging

* Improve performance and have a fallback peer for fetching

* Disconnect not synced peers

* Make sure try catch doesn't fail

* Fix lint

* Update chia/wallet/wallet_node.py

Co-authored-by: Kyle Altendorf <sda@fstab.net>

* Pylint has a bug so ignore pylint for this line

Co-authored-by: Kyle Altendorf <sda@fstab.net>
2022-02-17 13:35:41 -08:00
Kyle Altendorf
767974cb93
reinstate pre-existing signal configuration on windows for services (#10263) 2022-02-16 15:26:03 -08:00
Kyle Altendorf
220e845d51
shutdown the weight proof process pool (#10163)
* shutdown the weight proof process pool

* use a context manager for the weight proof process pool executor

* record of the debug code

* mostly cleaned up

* suppress sync task cancellation propagation when awaited while closing

* breakup multi-second WeightProofHandler.validate_weight_proof with async sleeps

* move awaiting of sync task until after existing cancellation

* properly handle shutdown file with a new instance each time and a context manager

* cleanup
2022-02-15 12:22:23 -08:00
Yostra
ca84fa9f8d
Sync improvements (#9974)
* stash

* change log level

* stash changes

* cat tests

* add node id chia show

* make max sibscribe items configurable

* lint

* add logs for limits

* paralelize incluzion valdiation, don't diconnet from remote peers until local peer in synced

* wallet rate limit

* test log lvl, trusted, black

* only validation under semaphore

* flake mypy trade test

* reduce flakyness

* merge fix

* rename

* linting

* validate parallel, apply serial

* reduce falkyness

* lint

* Fix CAT tests

* black

* flaky test, total amount

* fix cat test

* skip existing state

* skip existing

* try other caches

* flake8

Co-authored-by: Matt Hauff <quexington@gmail.com>
Co-authored-by: William Blanke <wjb98672@gmail.com>
2022-01-28 19:16:47 -08:00
dustinface
b76b75f317
farmer|server|tests: Fix for farmer service crash if the keychain is empty (#9515)
* farmer: Run a start background task to wait if there are no keys yet

* farmer: Run the handshake in a background task if there are no keys yet

* tests: Yield the service in farmer/harvester setups

* tests: Introduce `start_service` in farmer/harvester setups

* server: Make `ChiaServer` and `Service` restartable

* tests: Test the delayed start/handshake in `test_farmer_harvester.py`

* tests: Move `test_farmer_harvester.py` to `tests/core/farmer_harvester`

Attempt to avoid issues due to the global block tools / shared keychain 
between tests

* farmer: Return `bool` in `Farmer.setup_keys`

* tests: Add `__init__.py` to `tests/farmer_harvester`
2021-12-14 18:03:59 -08:00
Chris Ross
2c4aaa1ec9
Resolve v6 addresses (#8861)
* Address deficiency discussed in #8552, add ability to resolve to IPv6
addresses for hostnames.

* If there is no prefer_ipv6 in the config, set it True (per @hoffmang9)
and write it back to config.yaml

* Pass prefer_ipv6 flag to get_host_addr, which required a little digging
for it in a few places that call get_host_addr.

* Update a couple things for consistency

* Move the load_config into Wallet's __init__ so it doesn't get called so
many times as it would in has_full_node.

* Pass None into get_host_addr if there's no preference in config, so we have only that one place where the coded default lives.  also fix an oversight where we were building a PeerInfo from a PeerInfo in some cases.

* Change the default here to match the default coded into util/network.py.  It seems that github testers can't handle trying to use IPv6 and this may be easier for average users (sadly)

* A test to see if manually creating the server on :: (IP6_ANY) lets tests connect to localhost with IPv6 on

* Revert back to IPv4 default and remove the override inserted into
TCPSite for testing.

* Don't test for ip6-localhost, as it's not on all systems.

* Bah.  Forced formatting of commented code...

* Add a type annotation for the addrset variable

* If we don't quote the socket enums, pylint gets upset because it has issues figuring out where/how they're defined.  So, quote them here.

Co-authored-by: Chris Ross <cross+chia@distal.com>
Co-authored-by: Kyle Altendorf <sda@fstab.net>
2021-11-22 14:34:03 -08:00
Yostra
ab4f44175b
service singleton (#6735) 2021-06-24 11:10:46 -07:00
Arvid Norberg
7800dbb58c
Cleanup shutdown (#6011)
* ignore signals in subprocesses

The sub-processes started by ProcessPoolExecutor will also receive SIGINT when the main process receives it. This results in the signal handler running in every subprocess and fail to create the task to close all connections. They print this error to stdout

* cleanup UPnP shutdown

make an explicit call to UPnP shutdown() (which joins the thread). Improve logging a bit

* wait for initialize_weight_proof task when shutting down
2021-05-26 12:18:12 -07:00
Mariano Sorgente
5ce56bce6d
Don't use a global (#5553)
* Don't use a global

* Only construct once
2021-05-19 17:41:53 -07:00
Will Bendick
39ef69643b
release upnp ports on shutdown (#4024)
* release upnp ports on shutdown

* lint

* explicitly removes port mapping first to handle possible unclean shutdowns

* catches exception

* moves upnp setup to thread

* lint

* moves upnp logic to a message queue on a worker thread

* lint
2021-05-14 14:11:19 -07:00
Nikolaj Kuntner
cbc9141689
add all none's (#4503)
Co-authored-by: Nikolaj Kuntner <>
2021-05-10 22:05:45 -07:00
Richard Kiss
f2b577dda1 git mv src chia 2021-04-04 21:41:39 -07:00