Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap to ThreadPoolExecutor and use chia_rs version of validate_clvm_and_signature() #18213

Open
wants to merge 32 commits into
base: main
Choose a base branch
from

Conversation

matt-o-how
Copy link
Contributor

@matt-o-how matt-o-how commented Jun 20, 2024

Purpose:

Migrate to using the chia_rs version of validate_clvm_and_signature and use ThreadPools for faster concurrent execution.
Until chia-rs is bumped to include the pyfunctions get_name_puzzle_conditions and validate_clvm_and_signature the tests for this will fail.

Current Behavior:

We currently use the Python version of validate_clvm_and_signature which forces us to use ProcessPools

New Behavior:

Use the chia_rs version of validate_clvm_and_signature and use ThreadPools for faster concurrent execution.

@matt-o-how matt-o-how added the Changed Required label for PR that categorizes merge commit message as "Changed" for changelog label Jun 20, 2024
@github-actions github-actions bot added the merge_conflict Branch has conflicts that prevent merge to main label Jul 16, 2024
Copy link
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the merge_conflict Branch has conflicts that prevent merge to main label Jul 16, 2024
Copy link
Contributor

Conflicts have been resolved. A maintainer will review the pull request shortly.

Copy link
Contributor

github-actions bot commented Aug 8, 2024

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the merge_conflict Branch has conflicts that prevent merge to main label Aug 8, 2024
@github-actions github-actions bot removed the merge_conflict Branch has conflicts that prevent merge to main label Aug 8, 2024
Copy link
Contributor

github-actions bot commented Aug 8, 2024

Conflicts have been resolved. A maintainer will review the pull request shortly.

@matt-o-how matt-o-how marked this pull request as ready for review August 9, 2024 13:01
@matt-o-how matt-o-how requested a review from a team as a code owner August 9, 2024 13:01
@matt-o-how matt-o-how requested a review from arvidn August 9, 2024 13:01
@arvidn arvidn closed this Aug 21, 2024
@arvidn arvidn reopened this Aug 21, 2024
@@ -507,7 +507,7 @@ async def test_duplicate_output() -> None:
async def test_block_cost_exceeds_max() -> None:
mempool_manager = await instantiate_mempool_manager(zero_calls_get_coin_records)
conditions = []
for i in range(2400):
for i in range(3800):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main reason some numbers change in this test, as I understand it, is because we no longer turn transactions into "simple generators" before running them. This is more efficient and also more accurate now that (with the hard fork) we no longer pay cost for the generator ROM. So:

  • transactions are cheaper on the chain since the hard fork
  • the new logic reflects this cheaper reality
  • the test therefore will fit more transactions in a block

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm that doesn't seem to be correct.

With the inclusion of byte cost in Chia-Network/chia_rs#679 we now have a higher cost than what's currently in main, not lower.

This highlighted line for example goes down from needing 2400 items in main, to needing just 2389 (not 3800), due to cost becoming higher, and the expected cost for https://github.com/Chia-Network/chia-blockchain/pull/18213/files#diff-6a5a9dba08be65c628eff46226c4f7d83c6dbf4bcb9c15649c228b9d8b244c76R581 as another example goes up from main's 10268283 to 19144088, not down to 6600088.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the inclusion of byte cost in Chia-Network/chia_rs#679 we now have a higher cost than what's currently in main, not lower.

I suspect this is a bug in the rust implementation. Although, as it turns out, the true reason these numbers had to change (so much) is because of the current issue with the rust implementation (not including size cost)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sent a fix for that in Chia-Network/chia_rs#680 and adapted to the fix here with #18537.

chia/full_node/mempool_manager.py Show resolved Hide resolved
chia/full_node/mempool_manager.py Show resolved Hide resolved
chia/full_node/mempool_manager.py Outdated Show resolved Hide resolved
chia/full_node/mempool_manager.py Outdated Show resolved Hide resolved
chia/types/eligible_coin_spends.py Outdated Show resolved Hide resolved
Copy link
Contributor

@AmineKhaldi AmineKhaldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I left some suggestions in addition to Arvid's points.

The core.full_node group seems to have some failed tests as well.

chia/_tests/core/mempool/test_mempool_manager.py Outdated Show resolved Hide resolved
chia/_tests/core/mempool/test_mempool_manager.py Outdated Show resolved Hide resolved
chia/_tests/core/mempool/test_singleton_fast_forward.py Outdated Show resolved Hide resolved
@@ -268,7 +268,6 @@ async def farm_block(
get_unspent_lineage_info_for_puzzle_hash=self.coin_store.get_unspent_lineage_info_for_puzzle_hash,
item_inclusion_filter=item_inclusion_filter,
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be an unintentional diff.

chia/full_node/mempool.py Outdated Show resolved Hide resolved
chia/types/eligible_coin_spends.py Outdated Show resolved Hide resolved
# generator = simple_solution_generator(new_sb)
assert mempool_item.conds is not None
try:
new_sbc_result = get_conditions_from_spendbundle(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would name this new_conditions or new_conds to fit their use below, better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -354,4 +354,4 @@ async def process_fast_forward_spends(
# change. Still, it's good form to update the spend bundle with the
# new coin spends
mempool_item.spend_bundle = new_sb
mempool_item.conds = new_npc_result.conds
mempool_item.conds = new_sbc_result
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a name like new_conditions or new_conds this reads better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@arvidn
Copy link
Contributor

arvidn commented Aug 26, 2024

@matt-o-how there's a problem with the rust implementation. get_conditions_from_spendbundle() doesn't take the bytes size into account when returning the cost. It needs to do something like this: https://github.com/Chia-Network/chia_rs/blob/main/crates/chia-consensus/src/gen/run_block_generator.rs#L81-L84

    let byte_cost = (puzzle.len() + solution.len()) as u64 * constants.cost_per_byte;
    subtract_cost(a, &mut cost_left, byte_cost)?;

matt-o-how and others added 27 commits September 4, 2024 17:02
Co-authored-by: Amine Khaldi <amine.khaldi@reactos.org>
Co-authored-by: Amine Khaldi <amine.khaldi@reactos.org>
Co-authored-by: Amine Khaldi <amine.khaldi@reactos.org>
Co-authored-by: Amine Khaldi <amine.khaldi@reactos.org>
Co-authored-by: Amine Khaldi <amine.khaldi@reactos.org>
… overhead into account, creating blocks that exceed the max size.
@github-actions github-actions bot added the merge_conflict Branch has conflicts that prevent merge to main label Sep 5, 2024
Copy link
Contributor

github-actions bot commented Sep 5, 2024

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changed Required label for PR that categorizes merge commit message as "Changed" for changelog merge_conflict Branch has conflicts that prevent merge to main
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants