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

Remove chia-blockchain dependency for most of chia_rs #887

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

Conversation

matt-o-how
Copy link
Contributor

This PR removes imports from test_blscache.py and deletes test_program_fidelity.py.

It also removes the python running from block_record.rs by implementing pot_iterations.py inside the class

@matt-o-how matt-o-how changed the title Remove chia-blockchain dependency in tests Remove chia-blockchain dependency for most of chia_rs Jan 17, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a really nice change. However, I think it would be good to check the correctness of this against the existing python implementation. One way to do that would be to break this off into a separate PR that still relies on the chia-blockchain dependency to compare the result between the rust and python implementation. Can you think of another way to be confident in the correctness of this port?

Copy link

coveralls-official bot commented Jan 17, 2025

Pull Request Test Coverage Report for Build 13418635508

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 242 of 288 (84.03%) changed or added relevant lines in 4 files are covered.
  • 333 unchanged lines in 14 files lost coverage.
  • Overall coverage decreased (-0.3%) to 84.085%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/chia-protocol/src/pot_iterations.rs 209 220 95.0%
crates/chia-protocol/src/block_record.rs 28 40 70.0%
crates/chia-protocol/src/pos_quality.rs 0 23 0.0%
Files with Coverage Reduction New Missed Lines %
crates/chia-protocol/src/lazy_node.rs 1 90.91%
crates/chia-puzzle-types/src/puzzles/singleton.rs 3 29.17%
crates/chia-puzzle-types/src/puzzles/standard.rs 3 76.32%
crates/chia-puzzle-types/src/puzzles/offer.rs 4 95.4%
crates/chia_streamable_macro/src/lib.rs 7 95.96%
wheel/src/run_program.rs 7 76.67%
crates/chia-consensus/src/fast_forward.rs 8 97.88%
wheel/src/api.rs 20 85.43%
crates/chia-bls/src/signature.rs 22 94.91%
crates/chia_py_streamable_macro/src/lib.rs 30 92.86%
Totals Coverage Status
Change from base Build 12797692864: -0.3%
Covered Lines: 13742
Relevant Lines: 16343

💛 - Coveralls

@@ -4,7 +4,9 @@
pub const UI_ACTUAL_SPACE_CONSTANT_FACTOR: f32 = 0.78;

// TODO: Update this when new plot format releases
pub fn expected_plot_size(k: u32) -> u64 {
#[cfg(feature = "py-bindings")]
#[pyo3::pyfunction]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you have to do #[cfg_attr(feature = "py-bindings", pyo3::pyfunction)] instead?

fn sp_total_iters_impl(&self, py: Python<'_>, constants: &Bound<'_, PyAny>) -> PyResult<u128> {
self.sp_sub_slot_total_iters_impl(py, constants)?
.checked_add(self.sp_iters_impl(py, constants)? as u128)
fn sp_iters_impl(&self, constants: &Bound<'_, PyAny>) -> PyResult<u64> {
Copy link
Contributor

Choose a reason for hiding this comment

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

now that these are implemented in rust, I don't think they should be limited to just the python bindings anymore. I imagine you put them here to simplify error handling, so make them return PyResult<>. If you make them part of the rust type and make them return chia_error::Result<> you could map those errors with map_err()

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


#[cfg(feature = "py-bindings")]
#[pyo3::pyfunction]
pub fn calculate_ip_iters(
Copy link
Contributor

Choose a reason for hiding this comment

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

do you feel like the unit tests below are sufficient to be confident that this is correct and identical to the python implementation?
I'm especially worried about integer width overflow

Comment on lines 340 to 345
num_sps_sub_slot: int,
num_sp_intervals_extra: int,
sub_slot_iters: int,
signage_point_index: int,
required_iters: int,
) -> int: ...
Copy link
Contributor

Choose a reason for hiding this comment

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

are all of these plain int in the python implementation? it seems like it might make sense to make them sized ints

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

)
assert sp_iters > ip_iters

# def test_win_percentage(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this commented-out code can be removed, right?

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


br = get_block_record(rng, ssi=ssi, spi=13, ri=1)
res = br.ip_iters_impl(DEFAULT_CONSTANTS)
assert res is not None
Copy link
Contributor

Choose a reason for hiding this comment

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

not None, it seems like the wrong value would also pass here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made this a specific value

Copy link
Contributor

@arvidn arvidn left a comment

Choose a reason for hiding this comment

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

I would suggest you have tests that attempt to overflow integers, and especially look at all as casts and see if there's a way to truncate integers, in tests

num_sps_sub_slot: u32,
sub_slot_iters: u64,
) -> pyo3::PyResult<u64> {
calculate_sp_interval_iters(num_sps_sub_slot, sub_slot_iters).map_err(Into::into)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can use ? instead of explicitly mapping the error with Into::into.

i.e.

Ok(calculate_sp_interval_iters(num_sps_sub_slot, sub_slot_iters)?)

Comment on lines 46 to 48
return Err(Error::Custom(format!(
"Invalid sp iters {sp_iters} for this ssi {sub_slot_iters}"
)));
Copy link
Contributor

Choose a reason for hiding this comment

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

I really think we should have error codes instead of free-form strings. Handling errors like this, programatically, is very brittle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants