Commit Graph

1118 Commits

Author SHA1 Message Date
Amine Khaldi
36bc639ed9
Annotate test_farmer_harvester_rpc.py (#15377)
Annotate test_farmer_harvester_rpc.py.
2023-05-24 16:49:53 -05:00
Adam Kelly
41e17cdec9
Typecheck node_height.py (#14940)
* Typecheck node_height.py

* typecheck node_height

* return false if peak is none per code review

---------

Co-authored-by: Kyle Altendorf <sda@fstab.net>
Co-authored-by: Earle Lowe <e.lowe@chia.net>
2023-05-23 19:52:49 -05:00
Kyle Altendorf
5d14f0a208
add test coverage for starting a node with an existing db (#15338)
* add test coverage for starting a node with an existing db

* Update chia/simulator/setup_services.py
2023-05-23 14:27:10 -05:00
Adam Kelly
d1e10ea920
Remove test_setproctitle.py from mypy exclusions (#14939)
* Remove test_setproctitle.py from mypy exclusions

* typecheck test_setproctitle.py

---------

Co-authored-by: Earle Lowe <e.lowe@chia.net>
2023-05-23 14:25:08 -05:00
Arvid Norberg
ff226e8cb7
make sure tests that use BlockTools use a single source of consensus constants (#15364)
make sure tests that use BlockTools use a single source of consensus constants. This is in preparations for being able to run tests with different sets of constants, e.g. the hard-fork constants
2023-05-23 12:02:28 -05:00
Arvid Norberg
f0433d2a47
Weight proof typing (#15316)
* add type hints to test_proof_of_space.py

* add type hints to weight_proof.py
2023-05-22 10:23:33 -05:00
dustinface
1777ecc2e8
server: Store Version objects instead of str in WSChiaConnection (#15330)
* server: Store `Version` objects instead of `str` in `WSChiaConnection`

* Test connection versions
2023-05-19 13:45:00 -05:00
Arvid Norberg
621c75e4ba
Fork infrastructure (#15299)
* remove softfork-logic for 1.7 softfork (which has already activated)

* add new constants for soft-fork3, hard-fork and the other plot-filter adjustments
2023-05-18 20:20:11 -05:00
dustinface
9e9c75912f
full_node: Refactor get_puzzle_and_solution_for_coin (#15323) 2023-05-17 17:34:33 -05:00
Amine Khaldi
b4c161ec57
Merge commit '61ad4dae37b9fd9a1dcd61416d3d7eaae0cc2fe3' into checkpoint/main_from_release_1.8.1_61ad4dae37b9fd9a1dcd61416d3d7eaae0cc2fe3 2023-05-17 11:15:52 +01:00
Arvid Norberg
61ad4dae37
optimize compact proofs (#15304) 2023-05-16 16:45:22 -05:00
Earle Lowe
432d2ee308
Add some more daemon "rpc" tests (#15215)
* Add some more daemon "rpc" tests

* fixes due to some platform differences

* Add unlock_keyring tests and some experiments with monkeypatch

* rewrote simpler tests into single paramterized test

* add parameters to patch function

* Use monkeypatch.context for better isolation

* remove monkeypatch and test by deleting the keyring file

* remove now unused monkeypatch function

* changes from PR suggestions

* more readable parameterization per suggestions

* datacases

* description and id property

* swap description and route order

* *cases

---------

Co-authored-by: Kyle Altendorf <sda@fstab.net>
2023-05-12 17:48:41 -05:00
Amine Khaldi
eb898dfe95
Identical spend aggregation (#13799)
* Exploring identical spend aggregation.

* Attempt to address review.

* Revert this.

* Explore spend-based processing instead of the bundle-based one.

* Attempt to address reviews.

* Update against chia_rs and add some improvements.

* Leverage the fact that we're in a function now to perform early exits.

* Explore propagating exceptions.

* Relax the exception handling.

* Add unit tests.

* Add some comments and perform some renames for more readability.

* Refactor tests and split them by scenario.

* Take Arvid's suggestion to simplify the check.

* Improve test readability.

* Make the set explicit instead of computing it with union().

* Run in MEMPOOL_MODE for cost and additions.

* Use int_from_bytes() instead of int.from_bytes().

* Add more unit tests for run_for_cost_and_additions (to cover coin amount 0 as well as a negative amount).

* Don't use as_python() for created coins.

* Account for the cost of create coin conditions and extract additions from the NPCResult.

* Rely on NPCResult for the maximum allowed cost.

* Stop looking for the relevant spend at the first occurrence (then process its created coins).

* Add a unit test for spending a coin in different ways then finding it spent in new peak.

This makes sure all mempool items that would spend that coin get removed.

* Parameterize the test for spending a coin in different ways then finding it spent in new peak, to account for both the optimized and the reorg code paths.

* Keep track of coin spends cost and additions in mempool items in case they won't make it into the block, so we don't rerun that again next time.

* Extend replace by fee tests with eligibility scenarios.

* Refactor find_duplicate_spends into get_deduplication_info and process_mempool_items into create_bundle_from_mempool_items.
Slightly refactor check_removals and create_bundle_from_mempool.

* Cast to uint64 in the return statement.

* Adapt to the recent addition of seq.

* Add unit tests for mempool items' bundle_coin_spends.

* Leverage the recently added make_test_conds when creating this npc_result.

* Pass in bundle_coin_spends and max_cost instead of InternalMempoolItem so that it remains internal.

* Add a test for the scenario where we pick a sub-optimal aggregation by deduplicating on solution A, seen in a relatively higher FPC item, then receiving better cost saving items on solution B after that one.

* Add some end-to-end tests for identical spend aggregation.

* Add a comment documenting why eligible_coin_spends map is ephemeral.
2023-05-12 10:55:53 -05:00
dustinface
b90d91d46b
server: Don't pass the host to WSChiaConnection (#14152)
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.
2023-05-09 15:58:20 -05:00
Earle Lowe
434cbc42dd
Increase test_create_coin_duplicates to 1 second (#15229) 2023-05-09 14:50:43 -05:00
Amine Khaldi
ab999d6192
Optimize check_removals() by checking for mempool conflicts all at once (#15202)
* Make conflicting_items a list instead of a set as we're only iterating over it, we're not leveraging set ownership.

This simplifies using can_replace() and also prepares ground to simplify check_removals() next.

* Optimize check_removals by checking for mempool conflicts all at once.
2023-05-04 13:21:18 -05:00
Kyle Altendorf
7cfa68139e
Add flexibility to log_exceptions() (#14992)
* Add flexibility to `log_exceptions()`

Allows configuration of the exception or exceptions to be caught, whether or not to show the traceback, the log level, and also adds the exception type to aid readability of errors like `KeyError` where the only text is the value of the key requested.

* add `log_exceptions(message=)`

* add tests for `chia.util.log_exceptions()`

* Update test_log_exceptions.py

* Update test_log_exceptions.py

* back to parametrize
2023-05-03 00:30:09 -05:00
Amine Khaldi
de6fb526b5
Implement get_items_by_coin_ids() for the mempool (#15069)
Implement get_items_by_coin_ids() for the mempool.
2023-04-27 09:55:01 -05:00
Amine Khaldi
cf44101bc6
Use "item" instead of "spend" in mempool's items functions names (#15103)
Use "item" instead of "spend" in mempool's items functions names.

With this we're consistent with mempool's internal items map (_items) and _row_to_item as well as the return types.
2023-04-24 12:45:37 -06:00
Amine Khaldi
f278d9ccf8
Simplify create_bundle_from_mempool's handling of removals (#15056)
Simplify create_bundle_from_mempool's handling of removals.

They're already taken care of by aggregation.
2023-04-17 16:34:22 -05:00
Amine Khaldi
3410cf3deb
Introduce and use the ability to honor spends IDs in make_test_conds (#15060)
Introduce and use the ability to honor spends IDs in make_test_conds.
2023-04-17 15:43:50 -05:00
Arvid Norberg
9b8cdd36da
limit expiring transactions (#14993)
limit the mempool size used for transactions with short expiration times. This makes it so transactions that expire in the next 15 minutes may not take more than one block worth of cost in the mempool
2023-04-14 15:23:24 -06:00
dustinface
4f7e2ff8c3
util: Cleanup Tuple[Optional[Err], ..] returns in condition_tools.py (#15009) 2023-04-14 15:20:36 -06:00
Almog De Paz
5b39e71842
Dl plugin service (#14883)
* generic downloader

* add s3 Downloader

* tests

* pre commit

* create uploader protocol, factor out upload code

* fix pre commit

* add s3 uploader

* add add helper for testing with real bucket

* typing

* lint

* logs

* start service separation

* working aiohttp s3 service

* lint

* multiple instances config

* break if failed to write

* better error handling

* update from conf before checking

* lint

* redundant config

* also update bucket

* improve exception handling

* remove old tests

* uae multiple uploaders

* Update chia/data_layer/data_layer.py

pr comments

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

* pr comments

* Apply typos fixes from code review

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

* Update chia/data_layer/s3_plugin_service.py

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

* scheme in conf

* use byte32 for store_ids list

* use dataclass instead of tuple for return value

* initial config handling for uploaders and downloaders

---------

Co-authored-by: Kyle Altendorf <sda@fstab.net>
Co-authored-by: Earle Lowe <30607889+emlowe@users.noreply.github.com>
Co-authored-by: Earle Lowe <e.lowe@chia.net>
2023-04-12 11:33:41 -06:00
dustinface
f0006b5353
server: peer_host + peer_port -> peer_info in WSChiaConnection (#14151) 2023-04-12 11:14:38 -06:00
Arvid Norberg
00a3647643
optimize Mempool.add_to_pool() (#14988)
* optimize at-capacity check in mempool.add_to_pool() by only computing the total cost once and remove all items in a single call

* use sqlite logic

* add test for Mempool.add_to_pool() when it's full
2023-04-07 12:09:46 -05:00
Arvid Norberg
624b24560a
Mempool insertion order (#14971)
* prepare mempool spends_by_feerate test for more test cases, move it to test_mempool.py (since it's testing the Mempool class)

* use insertion order as tie-breaker in mempool
2023-04-04 12:51:26 -05:00
Kyle Altendorf
b839dfa0c1
update black to 23.3.0 (#14537)
* unpin black

* Update setup.py

* Update .pre-commit-config.yaml

* black

* black

* 23.3.0

* cleanup
2023-04-04 12:50:58 -05:00
Arvid Norberg
20bfba0fa6
assert_before_height, assert_before_seconds fields in MempoolItem (#14931)
fix issue where assert_before_height and assert_before_seconds fields in MempoolItem would not be populated
2023-03-30 12:06:22 -05:00
Amine Khaldi
1577f4aa33
Fix the mempool fee rate calculation (#14926)
* Fix the mempool fee per cost calculation.

It's currently performing integer division instead of float division, resulting in incorrect sorting of mempool items by fee rate. Items with x.y FPC get all treated as items of x.0 FPC.

* Add unit tests for mempool's spends_by_feerate.
2023-03-29 12:12:14 -05:00
Amine Khaldi
db6386ab3b
Add unit tests for replace by fee dynamics (#14815)
* Add unit tests for replace by fee dynamics.

* Separate scenarios into their own tests.

* Remove the TestReplaceByFee class.
2023-03-28 10:41:08 -05:00
Amine Khaldi
faad1d7fd6
Improve core mempool test runs (#14914)
Improve mempool test runs.
2023-03-27 15:50:00 -05:00
dustinface
d83a6f8d14
consensus: Rename add block method/enum (#14459)
* `ReceiveBlockResult` -> `AddBlockResult`

* `Blockchain.receive_block` -> `Blockchain.add_block`
2023-03-27 12:57:37 -05:00
Amine Khaldi
8afba0814d
Remove no longer needed cost_per_byte cases (#14850)
Remove no longer needed cost_per_byte cases.
2023-03-24 18:29:50 -05:00
Amine Khaldi
7acba82607
Merge commit 'f637881f80049f5648acd1936a2da936b5ca79a1' into checkpoint/main_from_release_1.7.1_f637881f80049f5648acd1936a2da936b5ca79a1 2023-03-24 14:36:57 +01:00
Arvid Norberg
8dbfc4840a
enable soft-fork2 conditions (incl. ASSERT_BEFORE) (#14733)
* enable soft-fork2

* add blockchain (consensus) test for time-lock conditions (non-ephemeral spend)

* introduce new soft-fork rule to compare ASSERT_SECONDS_* conditions against the previous transaction block's timestamp (to be consistent with ASSERT_HEIGHT_* conditions)

* bump chia_rs. This updates the mempool rules to disallow relative height- and time conditions on ephemeral coin spends

* implement assert_before in mempool_check_time_locks. Extend ephemeral coin test in blockchain with assert_before conditions

* implement support for assert_before conditions in compute_assert_height()

* support assert-before in mempool

* add timelock rule

* address review comments
2023-03-23 11:30:10 -05:00
Arvid Norberg
8d7a462702
can_replace() tests (#14864)
* mempool min fee increase is a constant

* make can_replace() a free function rather than a member of mempool. It doesn't need to be a member, and a free function is easier to test

* simplify can_replace by passing in MempoolItem

* slightly simplify handling of conflicting mempool items in mempool_manager, to avoid double lookups

* simplify can_replace() by just passing removal_names instead of the whole dict

* add unit test for can_replace()
2023-03-21 18:41:16 -05:00
Arvid Norberg
f637881f80
1.7.1 fixes (#14860)
* Zstdwjb (#80)

* limit decompression output size

* added test

---------

Co-authored-by: William Blanke <wjb98672@gmail.com>

* check MAX_GENERATOR_REF_LIST_SIZE earlier (#68)

* make INFINITE_COST more reasonable (#69)

---------

Co-authored-by: William Allen <wallentx@users.noreply.github.com>
Co-authored-by: William Blanke <wjb98672@gmail.com>
2023-03-21 00:20:53 -05:00
Kyle Altendorf
f09d051552
fixup tests that do not close all event loops (#14851)
* remove event loop fixture from `test_dl_wallet`

* stop importing unused `Iterator`

* fixup more
2023-03-20 15:01:02 -05:00
Arvid Norberg
307b5726b3
Test cleanups (#14841)
* remove redundant test cases in test_blockchain.py test_ephemeral_timelock

* reorganize some test cases
2023-03-17 19:28:01 -05:00
Arvid Norberg
99ef78029b
disable soft-fork 2 (for now) (#14786)
disable soft-fork 2 (for now) until we properly think-through and settle on how to handle ephemeral coins
2023-03-09 19:13:15 -06:00
Amine Khaldi
7d770c1c1e
Add unit tests for create_bundle_from_mempool (#14700)
* Add unit tests for create_bundle_from_mempool().

* Factor out some shared code into a function.

* Add a variation for sending transactions in reverse order.

* Split some logic into functions.

* Refactor setting up the mempool with coins as well as big cost spend bundle handling.
2023-03-09 14:27:50 -06:00
Kyle Altendorf
c4c165eabd
avoid AttributeError when shutting down plotting (#3954)
* Remove valid # type: ignore

A user ran into an exception on this line that mypy should have caught.  Let's see what it says.

```python-traceback
2021-05-06T07:31:41.595 full_node full_node_server        : ERROR    Exception , exception Stack: Traceback (most recent call last):
  File "chia\server\server.py", line 356, in start_client
  File "aiohttp\client.py", line 763, in _ws_connect
  File "aiohttp\client.py", line 521, in _request
  File "aiohttp\connector.py", line 535, in connect
  File "aiohttp\connector.py", line 892, in _create_connection
  File "aiohttp\connector.py", line 1032, in _create_direct_connection
  File "aiohttp\connector.py", line 969, in _wrap_create_connection
  File "asyncio\base_events.py", line 949, in create_connection
  File "asyncio\selector_events.py", line 473, in sock_connect
concurrent.futures._base.CancelledError

2021-05-06T07:31:45.016 daemon asyncio                    : ERROR    Task exception was never retrieved
future: <Task finished coro=<kill_service() done, defined at chia\daemon\server.py:833> exception=AttributeError("'list' object has no attribute 'pid'")>
Traceback (most recent call last):
  File "chia\daemon\server.py", line 841, in kill_service
  File "chia\daemon\server.py", line 805, in kill_process
AttributeError: 'list' object has no attribute 'pid'
2021-05-06T07:32:09.965 full_node full_node_server        : ERROR    Exception:  <class 'concurrent.futures._base.CancelledError'>, closing connection None. Traceback (most recent call last):
  File "chia\server\server.py", line 531, in api_call
  File "asyncio\tasks.py", line 435, in wait_for
concurrent.futures._base.CancelledError

2021-05-06T07:33:20.573 full_node full_node_server        : ERROR    Exception , exception Stack: Traceback (most recent call last):
  File "chia\server\server.py", line 356, in start_client
  File "aiohttp\client.py", line 763, in _ws_connect
  File "aiohttp\client.py", line 521, in _request
  File "aiohttp\connector.py", line 535, in connect
  File "aiohttp\connector.py", line 892, in _create_connection
  File "aiohttp\connector.py", line 1032, in _create_direct_connection
  File "aiohttp\connector.py", line 969, in _wrap_create_connection
```

* fix plotter service killing

* just make it always be a list of processes for all services

* catch up tests

* Update chia/daemon/server.py
2023-03-09 04:22:38 -06:00
Arvid Norberg
b36a1f9eeb
Cleanup tests (#14776)
* clarify test with unknown condition opcode

* fix bug in mempool_manager test_ephemeral_timelock

* simplify test_blockchain test_ephemeral_timelock by factoring out the with_garbage parameter
2023-03-08 11:32:12 -06:00
Arvid Norberg
4ed31c50d5
Bump chia rs 0.2.4 (#14758)
* fix bug in make_test_conds() test utility

* bump chia_rs to 0.2.4, which preserves assert_seconds_relative 0 in parsing conditions. This allows for the 1.8.0 soft-fork to make the existing time-lock conditions stricter, > instead of >=. This is to match the existing ASSERT_HEIGHT_RELATIVE, which already is >

* fixup separating ENABLE_ASSERT_BEFORE from MEMPOOL_MODE

* Use a low value for SOFT_FORK2_HEIGHT during tests and cover the case before soft-fork2

---------

Co-authored-by: Adam Kelly <338792+aqk@users.noreply.github.com>
2023-03-07 15:29:54 -06:00
Kyle Altendorf
a42bf49050
catch up with mypy 1.1.1 (#14767) 2023-03-07 11:34:07 -06:00
Kyle Altendorf
e1d232883e
hint most chia.types (#14741)
* hint various chia.types

* hmm

* ints

* test todo
2023-03-06 16:34:22 -06:00
Earle Lowe
6e140f24fb
simplify and improve daemon connection handling (#14662)
* simplify daemon connection handling

* Add tests

* return list of service names during removal

* set remove raises KeyError

* Better test type hints

* Add types and code refactor

* fix test typos

* small type adjustments

* test code improvements

* Better error handling for bad json

* handle proper but unexpected JSON values

* Update chia/daemon/server.py

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

* test improvements

* check for empty thing equivalence

* Improved logging for ConnectionReset

---------

Co-authored-by: Kyle Altendorf <sda@fstab.net>
2023-03-06 12:49:38 -06:00
Kyle Altendorf
e5edbd9b3d
fix DataStore.get_tree_generation() detection of no generations (#14721)
* fix DataStore.get_tree_generation() detection of no generations

* revert unwanted change
2023-03-06 12:17:30 -06:00
Arvid Norberg
131c5ec5bf
parameterize Timelock and compute_assert_height tests (#14729)
* parameterize test_compute_assert_height

* parameterize tests in TestCheckTimelocks
2023-03-04 11:39:47 -06:00