Commit Graph

444 Commits

Author SHA1 Message Date
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
Amine Khaldi
e76d9c56e6
Merge commit 'c6863fd92bfaf2838117a38656b0ac0d47d1e970' into checkpoint/main_from_release_1.8.1_c6863fd92bfaf2838117a38656b0ac0d47d1e970 2023-05-12 18:07:31 +01: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
Arvid Norberg
c6863fd92b
don't add transactions to the mempool before it has a valid peak (#15264) 2023-05-12 10:54:35 -05:00
Amine Khaldi
54686f1121
Don't leverage SQLite's generated column feature for fee_per_cost. We'll hopefully reintroduce it again in the future (#15243)
* Don't leverage SQLite's generated column feature for fee_per_cost. We'll hopefully reintroduce it again in the future.

* Lint.
2023-05-09 18:52:09 -05:00
dustinface
a2567f45a9
full_node: Drop peers_with_peak removals (#15165) 2023-05-09 14:46:22 -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
Amine Khaldi
808514a80b
Simplify handling additions and removals in validate_spend_bundle() (#15131)
Simplify handling additions and removals in validate_spend_bundle().
2023-04-27 09:56:14 -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
Arvid Norberg
536830b09b
Generator mod cleanup and simplification (#15055)
* remove unused run_generator_mempool() function

* move run_generator_unsafe() into the tests, which is the only place it's used

* remove (somewhat meaningless) setup_generator_args() and create_generator_args()

* remove unused GENERATOR_MOD in mempool_check_conditions.py

* remove redundant get_generator() function

* transition analyze-chain.py to use run_block_generator() and drop dependency on GENERATOR_MOD

* fixup type hints in test_rom.py

* fixup type hints in test_compression.py

* fixup type hints in test_generator_types.py
2023-04-18 16:30:10 -05:00
Matt Hauff
e5b94d34a0
Chialisp file extensions (#14996)
* Rename chialisp file extensions

* Add pre-commit check for .clvm files

* Delete sha256tree files

* remove hash files in favor of central dictionary

* Add check for missing files like hex and hash entries

* Enhance clsp pre-commit check

* Actually check hash matches

* Update tools/manage_clvm.py

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

* Update tools/manage_clvm.py

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

* Fix Windows file writing

* Fix setup.py package_data fields

* Load hash dict at runtime

* Move away from exception pattern

* Bad equality check

* Minor fixes

* remove trailing whitespace fix

---------

Co-authored-by: Kyle Altendorf <sda@fstab.net>
2023-04-18 11:27:17 -05: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
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
f0006b5353
server: peer_host + peer_port -> peer_info in WSChiaConnection (#14151) 2023-04-12 11:14:38 -06:00
Justin England
a1567febeb
avoid FullNode.fetch_block_batches() from putting two Nones into the batch queue (#14804)
<!-- 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:

Please weigh in on whether this should be applied to the release or
retargeted to main.

The `finally:` clause will already result in `None` being put into the
queue. I expect that the other `None` pushed before the `return` is
unnecessarily doubling this up. I don't know if the double `None` has
any negative effect.


<!-- 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) -->
2023-04-11 14:42:52 -06:00
Kyle Altendorf
16835f3eb1
add new peak and tidy new compact vdf limited semaphore full logging (#14831)
* add new peak and tidy new compact vdf limited semaphore full logging

* log the peer as well

* delayed formatting for debug logging

* -f
2023-04-11 14:23:30 -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
Amine Khaldi
e1064fac05
Simplify creating a spend bundle from mempool items and move this logic to the mempool (#14934)
Simplify creating a spend bundle from mempool items and move this logic to the mempool.
2023-04-05 12:56:57 -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
9a664d9424
Minor simplification to the mempool conflicts check (#14918)
Minor simplification to the mempool conflicts check.
2023-03-27 15:43:31 -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
dustinface
a5466ad646
server: Rename respond_peers to add_peers in node_dicovery.py (#14461)
server: `respond_peers` to `add_peers` `node_dicovery.py`
2023-03-27 10:15:53 -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
Kyle Altendorf
22aabb4c5c
remove traceback from LockQueue._run() cancellation debug logging (#14805) 2023-03-24 03:37:59 -05: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
dustinface
6b39c133c1
full_node: Avoid some list copying in FullNode.update_wallets (#14827)
* full_node: Just add `new_states` since the entries can't be `None`

* Drop list creation, `lookup_coin_ids` is already a list
2023-03-20 13:17:37 -05:00
Kyle Altendorf
2add074eed
avoid FullNode.fetch_block_batches() from putting two Nones into the batch queue 2023-03-11 08:43:20 -05:00
Arvid Norberg
1a66a9b3e3
in mempool, support sqlite without generated columns (#14788) 2023-03-09 19:13:43 -06: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
dustinface
d752569c34
full_node: Drop cache logs in BlockStore (#14777) 2023-03-08 12:14:21 -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
Arvid Norberg
9e8dae67b2
Bump chia_rs to 0.2.3. and ASSERT_MY_BIRTH_* (#14720)
* bump chia_rs to version 0.2.3

* add new error codes for assert_my_birth_*

* add new condition codes for ASSERT_MY_BIRTH_*

* add logic for ASSERT_MY_BIRTH_* conditions
2023-03-03 15:12:37 -06:00
Arvid Norberg
c7301693e1
sqlite-backed mempool (#14657)
* implement Mempool using an in-memory sqlite database

* remove_from_pool with empty list is a no-op

* the order is not important in get_coin_records_by_puzzle_hash() or get_block_spends()

* use format string in log statement

* make MempoolItem not streamable, to improve performance of creating objects
2023-03-03 15:04:21 -06:00
Arvid Norberg
8618ef0f52
Soft fork2 tests (#14712)
* use shorter names in test-ephemeral-coin test parameters

* use shorter names in TestConditions to make the test easier to read

* user shorter names in test_blockchain test_ephemeral_timelock, to make the test easier to read

* extend test_ephemeral_timelock to cover soft-fork 2

* extend test_conditions to cover soft-fork 2
2023-03-01 14:19:55 -06:00
Arvid Norberg
5a5cb2e58e
simplify fee estimator by not leaking MempoolItem into its interface (#14685) 2023-02-27 16:34:11 -06:00
Arvid Norberg
e195d268fb
simplify the mempool filter to only pass in the spend_bundle name (#14665)
simplify the mempool filter to only pass in the spend_bundle name. That's the only thing we use
2023-02-27 12:57:32 -06:00
Arvid Norberg
60dacd9f36
remove some redundant fields from MempoolItem (#14652) 2023-02-27 12:56:06 -06:00
Kyle Altendorf
ff5ef6e073
remove leading newlines from indented code blocks (#14653)
* remove leading newlines from indented code blocks

* catch another one
2023-02-23 21:53:48 -06:00
Kyle Altendorf
f2a6d8decf
drop trailing commas in unpacking assignment (#14655) 2023-02-23 10:43:14 -06:00
dustinface
c098ee9166
full_node: Rename some receive/respond prefixes to add (#14458)
* full_node: Rename `FullNode.resond_block` to `FullNode.add_bock`

The naming `respond_block` is confusing here imo, we have a full node
API method called `respond_block` but here in the `FullNode` class this
method is there to try adding a block to the full nodes's chain so i
think `add_block` is the better choice?

Also change the `respond_block: full_node_protocol.RespondBlock`
parameter to `block: FullBlock` which lets us get rid of many
`full_node_protocol.RespondBlock` wrappings.

* `FullNode.receive_block_batch` -> `FullNode.add_block_batch`

* `receive_unfinished_block` -> `add_unfinished_block` + change parameter

* `FullNode.respond_transaction` -> `FullNode.add_transaction`

* `FullNode.respond_end_of_sub_slot` -> `FullNode.add_end_of_sub_slot`

* `FullNode.respond_compact_vdf` -> `FullNode.add_compact_vdf`

* `respond_compact_proof_of_time` -> `add_compact_proof_of_time`

* `respond_transaction_semaphore` -> `add_transaction_semaphore`
2023-02-23 10:28:29 -06:00
Amine Khaldi
b019fe5962
Introduce BlockRecordProtocol as a subset of BlockRecord that the mempool manager uses for peak (#14628)
* Introduce BlockRecordProtocol as a subset of BlockRecord that the mempool manager uses for peak.

* Create BenchBlockRecord and use it for benchmarks/mempool.py.

* PR #14611 didn't land yet (keep 3.7 support for now).

* We don't need this guidance anymore.
2023-02-23 01:04:47 -06:00
Kyle Altendorf
c678f00acb
cleanup adjacent string literals (#14650) 2023-02-22 17:16:07 -06:00
Arvid Norberg
ed8cee2b4b
Mempool private implementation (#14593)
* fix test asserts to not require the same object, just the same value

* make Mempool's implementation private and give it a public interface

* fixup test that used to count fee *levels* but now count transactions
2023-02-22 12:26:04 -06:00