Skip to content

Commit

Permalink
Release the GIL when calling validate_clvm_and_signature in the pytho…
Browse files Browse the repository at this point in the history
…n binding.
  • Loading branch information
AmineKhaldi committed Sep 6, 2024
1 parent ed7ece8 commit 0be2755
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions crates/chia-consensus/src/spendbundle_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use clvmr::reduction::Reduction;
use clvmr::run_program::run_program;
use clvmr::serde::node_from_bytes;

const QUOTE_BYTES: usize = 2;

pub fn get_conditions_from_spendbundle(
a: &mut Allocator,
spend_bundle: &SpendBundle,
Expand All @@ -40,7 +42,6 @@ pub fn get_conditions_from_spendbundle(
});
// We don't pay the size cost (nor execution cost) of being wrapped by a
// quote (in solution_generator).
const QUOTE_BYTES: usize = 2;
let generator_length_without_quote = solution_generator(spends_info)?.len() - QUOTE_BYTES;
let byte_cost = generator_length_without_quote as u64 * constants.cost_per_byte;
subtract_cost(a, &mut cost_left, byte_cost)?;
Expand Down Expand Up @@ -351,7 +352,6 @@ mod tests {
&coin_spend.solution,
)
});
const QUOTE_BYTES: usize = 2;
let generator_length_without_quote = solution_generator(program_spends)
.expect("solution_generator failed")
.len()
Expand Down
9 changes: 6 additions & 3 deletions wheel/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,16 +422,19 @@ fn fast_forward_singleton<'p>(
#[pyo3(name = "validate_clvm_and_signature")]
#[allow(clippy::type_complexity)]
pub fn py_validate_clvm_and_signature(
py: Python<'_>,
new_spend: &SpendBundle,
max_cost: u64,
constants: &ConsensusConstants,
peak_height: u32,
) -> PyResult<(OwnedSpendBundleConditions, Vec<([u8; 32], GTElement)>, f32)> {
let (owned_conditions, additions, duration) =
validate_clvm_and_signature(new_spend, max_cost, constants, peak_height).map_err(|e| {
let (owned_conditions, additions, duration) = py
.allow_threads(|| validate_clvm_and_signature(new_spend, max_cost, constants, peak_height))
.map_err(|e| {
// cast validation error to int
let error_code: u32 = e.into();
PyErr::new::<PyTypeError, _>(error_code)
})?; // cast validation error to int
})?;
Ok((owned_conditions, additions, duration.as_secs_f32()))
}

Expand Down

0 comments on commit 0be2755

Please sign in to comment.