From a039bc96beb0c08f278ed7754e8ac1e930873953 Mon Sep 17 00:00:00 2001 From: Amine Khaldi Date: Fri, 6 Sep 2024 14:37:50 +0100 Subject: [PATCH] Release the GIL when calling validate_clvm_and_signature in the python binding. --- wheel/src/api.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/wheel/src/api.rs b/wheel/src/api.rs index ebf03094b..43567b18a 100644 --- a/wheel/src/api.rs +++ b/wheel/src/api.rs @@ -421,17 +421,20 @@ fn fast_forward_singleton<'p>( #[pyfunction] #[pyo3(name = "validate_clvm_and_signature")] #[allow(clippy::type_complexity)] -pub fn py_validate_clvm_and_signature( +pub fn py_validate_clvm_and_signature<'a>( + py: Python<'a>, 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::(error_code) - })?; // cast validation error to int + })?; Ok((owned_conditions, additions, duration.as_secs_f32())) }