Tribler/py-ipv8

Windows validation action still failing

qstokkink opened this issue · 3 comments

In #1225, I added a fallback for libsodium-based keys if import libnacl fails. However, I missed another location in the code that also imports libnacl (messaging.anonymization.tunnelcrypto):

Run python run_all_tests.py -a
Traceback (most recent call last):
  File "run_all_tests.py", line 261, in <module>
    test_class_names = find_all_test_class_names()
  File "run_all_tests.py", line 246, in find_all_test_class_names
    test_class_names.extend(derive_test_class_names(found_test))
  File "run_all_tests.py", line 230, in derive_test_class_names
    module_instance = importlib.import_module(module_name)
  File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "D:\a\py-ipv8\py-ipv8\ipv8\test\messaging\anonymization\test_community.py", line 8, in <module>
    from ....messaging.anonymization.community import TunnelCommunity, TunnelSettings
  File "D:\a\py-ipv8\py-ipv8\ipv8\messaging\anonymization\community.py", line 24, in <module>
    from .payload import *
  File "D:\a\py-ipv8\py-ipv8\ipv8\messaging\anonymization\payload.py", line 14, in <module>
    from ...messaging.anonymization.tunnelcrypto import CryptoException, SessionKeys, TunnelCrypto
  File "D:\a\py-ipv8\py-ipv8\ipv8\messaging\anonymization\tunnelcrypto.py", line 7, in <module>
    import libnacl
  File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\site-packages\libnacl\__init__.py", line 87, in <module>
    nacl = _get_nacl()
  File "C:\hostedtoolcache\windows\Python\3.8.10\x64\lib\site-packages\libnacl\__init__.py", line 36, in _get_nacl
    raise OSError(msg)
OSError: Could not locate nacl lib, searched for libsodium
Error: Process completed with exit code 1.

Since this relates to performance-critical code we could also consider simply skipping tests that touch this code if the libnacl import fails.

As far as I can see, we can't substitute libnacl with cryptography easily. The former uses Salsa20 to implement crypto_box_beforenm (ref) and cryptography doesn't seem to support Salsa20. The alternative would be to reconstruct Salsa20 from the ground up and that seems unworkable and impractical for a simple workaround.

The only real alternative is to then simply skip tests related to the tunnel crypto.

Another option would be to bring back NoTunnelCrypto when libnacl is not found while testing.

I've been convinced that installing the libsodium backend on the Windows testers is the only way for our validation test matrix to make sense. Workarounds seem to be too elaborate or (more generally) too error-prone and not testing the tunnels would casually ignore one of the integral parts of IPv8. We'll just have to bite the bullet and perform the GitHub Actions setup.