Skip to content

Commit

Permalink
Merge pull request #743 from Chia-Network/verify-release-gil
Browse files Browse the repository at this point in the history
release GIL when validating signatures
  • Loading branch information
arvidn authored Oct 2, 2024
2 parents 3981915 + b216e5e commit 96a3fbd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 8 additions & 1 deletion tests/test_blspy_fidelity.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
from typing import Any, Type
import pytest
from concurrent.futures import ThreadPoolExecutor


def randbytes(n: int) -> bytes:
Expand All @@ -16,7 +17,8 @@ def randbytes(n: int) -> bytes:
# make sure chia_rs counterpart behaves the same as blspy
def test_bls() -> None:
print()
for round in range(200):

def run_test_suite(round: int) -> None:
sys.stdout.write(f"\r{round} ")
sys.stdout.flush()
seed = randbytes(32)
Expand Down Expand Up @@ -210,6 +212,11 @@ def test_bls() -> None:
with pytest.raises(ValueError, match="invalid length"):
obj2 = klass.from_json_dict(bytes(obj) + b"a")

pool = ThreadPoolExecutor(max_workers=8)
for round in range(200):
pool.submit(run_test_suite, round)
pool.shutdown()


# ------------------------------------- 8< ----------------------------------
#
Expand Down
7 changes: 4 additions & 3 deletions wheel/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,13 @@ impl AugSchemeMPL {
}

#[staticmethod]
pub fn verify(pk: &PublicKey, msg: &[u8], sig: &Signature) -> bool {
chia_bls::verify(sig, pk, msg)
pub fn verify(py: Python<'_>, pk: &PublicKey, msg: &[u8], sig: &Signature) -> bool {
py.allow_threads(|| chia_bls::verify(sig, pk, msg))
}

#[staticmethod]
pub fn aggregate_verify(
py: Python<'_>,
pks: &Bound<'_, PyList>,
msgs: &Bound<'_, PyList>,
sig: &Signature,
Expand All @@ -314,7 +315,7 @@ impl AugSchemeMPL {
data.push((pk, msg));
}

Ok(chia_bls::aggregate_verify(sig, data))
py.allow_threads(|| Ok(chia_bls::aggregate_verify(sig, data)))
}

#[staticmethod]
Expand Down

0 comments on commit 96a3fbd

Please sign in to comment.