Skip to content

Commit

Permalink
Revert "Merge pull request #842 from Chia-Network/update_pyo3_0_23_3"
Browse files Browse the repository at this point in the history
This reverts commit ea4928b, reversing
changes made to 06b7d42.
  • Loading branch information
altendky committed Jan 7, 2025
1 parent aa5be05 commit e042944
Show file tree
Hide file tree
Showing 21 changed files with 131 additions and 159 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1801,9 +1801,9 @@ dependencies = [

[[package]]
name = "pyo3"
version = "0.23.3"
version = "0.22.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e484fd2c8b4cb67ab05a318f1fd6fa8f199fcc30819f08f07d200809dba26c15"
checksum = "f402062616ab18202ae8319da13fa4279883a2b8a9d9f83f20dbade813ce1884"
dependencies = [
"cfg-if",
"indoc",
Expand All @@ -1821,29 +1821,29 @@ dependencies = [

[[package]]
name = "pyo3-build-config"
version = "0.23.3"
version = "0.22.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc0e0469a84f208e20044b98965e1561028180219e35352a2afaf2b942beff3b"
checksum = "b14b5775b5ff446dd1056212d778012cbe8a0fbffd368029fd9e25b514479c38"
dependencies = [
"once_cell",
"target-lexicon",
]

[[package]]
name = "pyo3-ffi"
version = "0.23.3"
version = "0.22.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb1547a7f9966f6f1a0f0227564a9945fe36b90da5a93b3933fc3dc03fae372d"
checksum = "9ab5bcf04a2cdcbb50c7d6105de943f543f9ed92af55818fd17b660390fc8636"
dependencies = [
"libc",
"pyo3-build-config",
]

[[package]]
name = "pyo3-macros"
version = "0.23.3"
version = "0.22.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdb6da8ec6fa5cedd1626c886fc8749bdcbb09424a86461eb8cdf096b7c33257"
checksum = "0fd24d897903a9e6d80b968368a34e1525aeb719d568dba8b3d4bfa5dc67d453"
dependencies = [
"proc-macro2",
"pyo3-macros-backend",
Expand All @@ -1853,9 +1853,9 @@ dependencies = [

[[package]]
name = "pyo3-macros-backend"
version = "0.23.3"
version = "0.22.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38a385202ff5a92791168b1136afae5059d3ac118457bb7bc304c197c2d33e7d"
checksum = "36c011a03ba1e50152b4b394b479826cad97e7a21eb52df179cd91ac411cbfbe"
dependencies = [
"heck",
"proc-macro2",
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ sha2 = "0.10.8"
hkdf = "0.12.0"
hex = "0.4.3"
thiserror = "1.0.69"
pyo3 = "0.23.3"
pyo3 = "0.22.6"
arbitrary = "1.4.1"
rand = "0.8.5"
criterion = "0.5.1"
Expand Down
32 changes: 10 additions & 22 deletions crates/chia-bls/fuzz/fuzz_targets/blspy-fidelity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ fuzz_target!(|data: &[u8]| {
print(sys.executable)
"#, None, None).unwrap();
*/
let blspy = py.import("blspy").unwrap();
let blspy = py.import_bound("blspy").unwrap();
let aug = blspy.getattr("AugSchemeMPL").unwrap();

// Generate key pair from seed
let rust_sk = SecretKey::from_seed(data);
let py_sk = aug
.call_method1(
"key_gen",
PyTuple::new(py, [PyBytes::new(py, data)]).unwrap(),
PyTuple::new_bound(py, [PyBytes::new_bound(py, data)]),
)
.unwrap();

Expand All @@ -66,14 +66,10 @@ fuzz_target!(|data: &[u8]| {
let py_sk1 = aug
.call_method1(
"derive_child_sk_unhardened",
PyTuple::new(
PyTuple::new_bound(
py,
[
py_sk.clone(),
idx.into_pyobject(py).unwrap().clone().into_any(),
],
)
.unwrap(),
[py_sk.clone(), idx.to_object(py).bind(py).clone().into_any()],
),
)
.unwrap();
assert_eq!(to_bytes(&py_sk1), rust_sk1.to_bytes());
Expand All @@ -82,11 +78,7 @@ fuzz_target!(|data: &[u8]| {
let py_pk1 = aug
.call_method1(
"derive_child_pk_unhardened",
PyTuple::new(
py,
[py_pk, idx.into_pyobject(py).unwrap().clone().into_any()],
)
.unwrap(),
PyTuple::new_bound(py, [py_pk, idx.to_object(py).bind(py).clone().into_any()]),
)
.unwrap();
assert_eq!(to_bytes(&py_pk1), rust_pk1.to_bytes());
Expand All @@ -96,7 +88,7 @@ fuzz_target!(|data: &[u8]| {
let py_sig1 = aug
.call_method1(
"sign",
PyTuple::new(py, [py_sk1, PyBytes::new(py, data).into_any()]).unwrap(),
PyTuple::new_bound(py, [py_sk1, PyBytes::new_bound(py, data).into_any()]),
)
.unwrap();
assert_eq!(to_bytes(&py_sig1), rust_sig1.to_bytes());
Expand All @@ -107,11 +99,7 @@ fuzz_target!(|data: &[u8]| {
let py_sk2 = aug
.call_method1(
"derive_child_sk",
PyTuple::new(
py,
[py_sk, idx.into_pyobject(py).unwrap().clone().into_any()],
)
.unwrap(),
PyTuple::new_bound(py, [py_sk, idx.to_object(py).bind(py).clone().into_any()]),
)
.unwrap();
assert_eq!(to_bytes(&py_sk2), rust_sk2.to_bytes());
Expand All @@ -121,7 +109,7 @@ fuzz_target!(|data: &[u8]| {
let py_sig2 = aug
.call_method1(
"sign",
PyTuple::new(py, [py_sk2, PyBytes::new(py, data).into_any()]).unwrap(),
PyTuple::new_bound(py, [py_sk2, PyBytes::new_bound(py, data).into_any()]),
)
.unwrap();
assert_eq!(to_bytes(&py_sig2), rust_sig2.to_bytes());
Expand All @@ -131,7 +119,7 @@ fuzz_target!(|data: &[u8]| {
let py_agg = aug
.call_method1(
"aggregate",
PyTuple::new(py, [PyList::new(py, [py_sig1, py_sig2]).unwrap()]).unwrap(),
PyTuple::new_bound(py, [PyList::new_bound(py, [py_sig1, py_sig2])]),
)
.unwrap();
assert_eq!(to_bytes(&py_agg), rust_agg.to_bytes());
Expand Down
17 changes: 7 additions & 10 deletions crates/chia-bls/src/bls_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ impl BlsCache {
sig: &Signature,
) -> PyResult<bool> {
let pks = pks
.try_iter()?
.iter()?
.map(|item| item?.extract())
.collect::<PyResult<Vec<PublicKey>>>()?;

let msgs = msgs
.try_iter()?
.iter()?
.map(|item| item?.extract())
.collect::<PyResult<Vec<PyBackedBytes>>>()?;

Expand All @@ -184,21 +184,18 @@ impl BlsCache {
pub fn py_items(&self, py: pyo3::Python<'_>) -> PyResult<PyObject> {
use pyo3::prelude::*;
use pyo3::types::PyBytes;
let ret = PyList::empty(py);
let ret = PyList::empty_bound(py);
let c = self.cache.lock().expect("cache");
for (key, value) in &c.items {
ret.append((
PyBytes::new(py, key),
value.clone().into_pyobject(py)?.into_any(),
))?;
ret.append((PyBytes::new_bound(py, key), value.clone().into_py(py)))?;
}
Ok(ret.into())
}

#[pyo3(name = "update")]
pub fn py_update(&self, other: &Bound<'_, PySequence>) -> PyResult<()> {
let mut c = self.cache.lock().expect("cache");
for item in other.borrow().try_iter()? {
for item in other.borrow().iter()? {
let (key, value): (Vec<u8>, GTElement) = item?.extract()?;
c.put(
key.try_into()
Expand All @@ -212,11 +209,11 @@ impl BlsCache {
#[pyo3(name = "evict")]
pub fn py_evict(&self, pks: &Bound<'_, PyList>, msgs: &Bound<'_, PyList>) -> PyResult<()> {
let pks = pks
.try_iter()?
.iter()?
.map(|item| item?.extract())
.collect::<PyResult<Vec<PublicKey>>>()?;
let msgs = msgs
.try_iter()?
.iter()?
.map(|item| item?.extract())
.collect::<PyResult<Vec<PyBackedBytes>>>()?;
self.evict(pks.into_iter().zip(msgs));
Expand Down
5 changes: 1 addition & 4 deletions crates/chia-bls/src/gtelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ mod pybindings {
impl ToJsonDict for GTElement {
fn to_json_dict(&self, py: Python<'_>) -> PyResult<PyObject> {
let bytes = self.to_bytes();
Ok(("0x".to_string() + &hex::encode(bytes))
.into_pyobject(py)?
.into_any()
.unbind())
Ok(("0x".to_string() + &hex::encode(bytes)).into_py(py))
}
}

Expand Down
22 changes: 8 additions & 14 deletions crates/chia-bls/src/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,7 @@ mod pybindings {
impl ToJsonDict for PublicKey {
fn to_json_dict(&self, py: Python<'_>) -> PyResult<PyObject> {
let bytes = self.to_bytes();
Ok(("0x".to_string() + &hex::encode(bytes))
.into_pyobject(py)?
.into_any()
.unbind())
Ok(("0x".to_string() + &hex::encode(bytes)).into_py(py))
}
}

Expand Down Expand Up @@ -737,7 +734,7 @@ mod tests {
mod pytests {
use super::*;
use crate::SecretKey;
use pyo3::Python;
use pyo3::{IntoPy, Python};
use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};
use rstest::rstest;
Expand All @@ -753,7 +750,7 @@ mod pytests {
let pk = sk.public_key();
Python::with_gil(|py| {
let string = pk.to_json_dict(py).expect("to_json_dict");
let py_class = py.get_type::<PublicKey>();
let py_class = py.get_type_bound::<PublicKey>();
let pk2: PublicKey = PublicKey::from_json_dict(&py_class, py, string.bind(py))
.unwrap()
.extract(py)
Expand All @@ -772,14 +769,11 @@ mod pytests {
fn test_json_dict(#[case] input: &str, #[case] msg: &str) {
pyo3::prepare_freethreaded_python();
Python::with_gil(|py| {
let py_class = py.get_type::<PublicKey>();
let err = PublicKey::from_json_dict(
&py_class,
py,
&input.to_string().into_pyobject(py).unwrap().into_any(),
)
.unwrap_err();
assert_eq!(err.value(py).to_string(), msg.to_string());
let py_class = py.get_type_bound::<PublicKey>();
let err =
PublicKey::from_json_dict(&py_class, py, input.to_string().into_py(py).bind(py))
.unwrap_err();
assert_eq!(err.value_bound(py).to_string(), msg.to_string());
});
}
}
22 changes: 8 additions & 14 deletions crates/chia-bls/src/secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,7 @@ mod pybindings {
impl ToJsonDict for SecretKey {
fn to_json_dict(&self, py: Python<'_>) -> PyResult<PyObject> {
let bytes = self.to_bytes();
Ok(("0x".to_string() + &hex::encode(bytes))
.into_pyobject(py)?
.into_any()
.unbind())
Ok(("0x".to_string() + &hex::encode(bytes)).into_py(py))
}
}

Expand Down Expand Up @@ -559,7 +556,7 @@ mod tests {
#[cfg(feature = "py-bindings")]
mod pytests {
use super::*;
use pyo3::Python;
use pyo3::{IntoPy, Python};
use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};
use rstest::rstest;
Expand All @@ -574,7 +571,7 @@ mod pytests {
let sk = SecretKey::from_seed(&data);
Python::with_gil(|py| {
let string = sk.to_json_dict(py).expect("to_json_dict");
let py_class = py.get_type::<SecretKey>();
let py_class = py.get_type_bound::<SecretKey>();
let sk2 = SecretKey::from_json_dict(&py_class, py, string.bind(py))
.unwrap()
.extract(py)
Expand Down Expand Up @@ -609,14 +606,11 @@ mod pytests {
fn test_json_dict(#[case] input: &str, #[case] msg: &str) {
pyo3::prepare_freethreaded_python();
Python::with_gil(|py| {
let py_class = py.get_type::<SecretKey>();
let err = SecretKey::from_json_dict(
&py_class,
py,
&input.to_string().into_pyobject(py).unwrap().into_any(),
)
.unwrap_err();
assert_eq!(err.value(py).to_string(), msg.to_string());
let py_class = py.get_type_bound::<SecretKey>();
let err =
SecretKey::from_json_dict(&py_class, py, input.to_string().into_py(py).bind(py))
.unwrap_err();
assert_eq!(err.value_bound(py).to_string(), msg.to_string());
});
}
}
22 changes: 8 additions & 14 deletions crates/chia-bls/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,7 @@ mod pybindings {
impl ToJsonDict for Signature {
fn to_json_dict(&self, py: Python<'_>) -> PyResult<PyObject> {
let bytes = self.to_bytes();
Ok(("0x".to_string() + &hex::encode(bytes))
.into_pyobject(py)?
.into_any()
.unbind())
Ok(("0x".to_string() + &hex::encode(bytes)).into_py(py))
}
}

Expand Down Expand Up @@ -1257,7 +1254,7 @@ mod tests {
mod pytests {
use super::*;

use pyo3::Python;
use pyo3::{IntoPy, Python};
use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};
use rstest::rstest;
Expand All @@ -1275,7 +1272,7 @@ mod pytests {
let sig = sign(&sk, msg);
Python::with_gil(|py| {
let string = sig.to_json_dict(py).expect("to_json_dict");
let py_class = py.get_type::<Signature>();
let py_class = py.get_type_bound::<Signature>();
let sig2 = Signature::from_json_dict(&py_class, py, string.bind(py))
.unwrap()
.extract(py)
Expand All @@ -1294,14 +1291,11 @@ mod pytests {
fn test_json_dict(#[case] input: &str, #[case] msg: &str) {
pyo3::prepare_freethreaded_python();
Python::with_gil(|py| {
let py_class = py.get_type::<Signature>();
let err = Signature::from_json_dict(
&py_class,
py,
&input.to_string().into_pyobject(py).unwrap().into_any(),
)
.unwrap_err();
assert_eq!(err.value(py).to_string(), msg.to_string());
let py_class = py.get_type_bound::<Signature>();
let err =
Signature::from_json_dict(&py_class, py, input.to_string().into_py(py).bind(py))
.unwrap_err();
assert_eq!(err.value_bound(py).to_string(), msg.to_string());
});
}
}
2 changes: 1 addition & 1 deletion crates/chia-consensus/src/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl MerkleSet {
included_leaf: [u8; 32],
) -> PyResult<(bool, PyObject)> {
match self.generate_proof(&included_leaf) {
Ok((included, proof)) => Ok((included, PyBytes::new(py, &proof).into())),
Ok((included, proof)) => Ok((included, PyBytes::new_bound(py, &proof).into())),
Err(_) => Err(PyValueError::new_err("invalid proof")),
}
}
Expand Down
Loading

0 comments on commit e042944

Please sign in to comment.