astreum 0.3.1__py3-none-any.whl → 0.3.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. astreum/communication/handlers/handshake.py +89 -83
  2. astreum/communication/handlers/object_request.py +176 -0
  3. astreum/communication/handlers/object_response.py +115 -0
  4. astreum/communication/handlers/ping.py +6 -20
  5. astreum/communication/handlers/route_request.py +76 -0
  6. astreum/communication/handlers/route_response.py +53 -0
  7. astreum/communication/models/message.py +81 -58
  8. astreum/communication/models/peer.py +42 -14
  9. astreum/communication/models/route.py +2 -7
  10. astreum/communication/processors/__init__.py +0 -0
  11. astreum/communication/processors/incoming.py +98 -0
  12. astreum/communication/processors/outgoing.py +20 -0
  13. astreum/communication/setup.py +36 -75
  14. astreum/communication/start.py +9 -10
  15. astreum/communication/util.py +7 -0
  16. astreum/consensus/start.py +9 -10
  17. astreum/consensus/workers/discovery.py +6 -7
  18. astreum/consensus/workers/validation.py +307 -291
  19. astreum/consensus/workers/verify.py +8 -10
  20. astreum/crypto/chacha20poly1305.py +74 -0
  21. astreum/machine/evaluations/high_evaluation.py +237 -237
  22. astreum/machine/evaluations/low_evaluation.py +18 -18
  23. astreum/node.py +25 -6
  24. astreum/storage/actions/get.py +183 -69
  25. astreum/storage/actions/set.py +66 -20
  26. astreum/storage/requests.py +28 -0
  27. astreum/storage/setup.py +3 -25
  28. astreum/utils/config.py +48 -0
  29. {astreum-0.3.1.dist-info → astreum-0.3.9.dist-info}/METADATA +3 -3
  30. {astreum-0.3.1.dist-info → astreum-0.3.9.dist-info}/RECORD +33 -24
  31. astreum/communication/handlers/storage_request.py +0 -81
  32. {astreum-0.3.1.dist-info → astreum-0.3.9.dist-info}/WHEEL +0 -0
  33. {astreum-0.3.1.dist-info → astreum-0.3.9.dist-info}/licenses/LICENSE +0 -0
  34. {astreum-0.3.1.dist-info → astreum-0.3.9.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: astreum
3
- Version: 0.3.1
3
+ Version: 0.3.9
4
4
  Summary: Python library to interact with the Astreum blockchain and its virtual machine.
5
5
  Author-email: "Roy R. O. Okello" <roy@stelar.xyz>
6
6
  Project-URL: Homepage, https://github.com/astreum/lib-py
@@ -113,11 +113,11 @@ node.env_set(env_id, "int.add", int_add_fn)
113
113
 
114
114
  # 5) Retrieve the function and call it with bytes 1 and 2
115
115
  bound = node.env_get(env_id, "int.add")
116
- call = Expr.ListExpr([Expr.Byte(1), Expr.Byte(2), bound])
116
+ call = Expr.ListExpr([Expr.Bytes(b"\x01"), Expr.Bytes(b"\x02"), bound])
117
117
  res = node.high_eval(env_id, call)
118
118
 
119
119
  # sk returns a list of bytes; for 1+2 expect a single byte with value 3
120
- print([b.value for b in res.elements]) # [3]
120
+ print([int.from_bytes(b.value, 'big', signed=True) for b in res.elements]) # [3]
121
121
  ```
122
122
 
123
123
  ### Handling errors
@@ -1,22 +1,28 @@
1
1
  astreum/__init__.py,sha256=GkEW_ReYore8_0nEOvPnZLUa3lO7CgMWu6LeEjrGXEk,325
2
- astreum/node.py,sha256=cHZyq9ImhCB9PSROKR5lFsUau6VLCjRIfiJSZhCPFzI,2103
2
+ astreum/node.py,sha256=naKGkn97M3Khux3r8mZ81wsiAI6JFr4uhly4X_BspmU,2689
3
3
  astreum/communication/__init__.py,sha256=wNxzsAk8Fol9cGMPuVvY4etrrMqn3SjZq1dE82kFrxw,228
4
- astreum/communication/setup.py,sha256=qliXCj2uHvzullCPSVtUuEG9zdqHewKgYfQLfsM8tao,7236
5
- astreum/communication/start.py,sha256=lfud8VvLeKFbkF_TwHFODg20RVpClUa4a_zsHB7ynxk,1853
6
- astreum/communication/util.py,sha256=bJ3td3naDzmCelAJQpLwiDMoRBkijQl9YLROjsWyOrI,1256
4
+ astreum/communication/setup.py,sha256=We43HOZG0v18TZhEdkc8MWCvI9YvHw8s4fmauHEXDUc,5887
5
+ astreum/communication/start.py,sha256=wxL1cgChebhnaeEaY9flS6qybo_cFW2-tcRvjLxC8Hw,1823
6
+ astreum/communication/util.py,sha256=fS3u3giOOXmvN0_reb0oIaXsFESHAWz-bbAuzdzdGQ4,1575
7
7
  astreum/communication/handlers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- astreum/communication/handlers/handshake.py,sha256=twd18nnfYcyC8hLXZ0EDwUw-2mPQGRf1RYdW21x9CHM,2378
9
- astreum/communication/handlers/ping.py,sha256=xY-QT0IoeNPKR1hyruRwJa2N8_op7aPOCZUk9X-kZWk,1258
10
- astreum/communication/handlers/storage_request.py,sha256=rUWhoeOxVZHcvEMxi74hN9XF9SFHe9Uw-9q4pBP-KwE,2406
8
+ astreum/communication/handlers/handshake.py,sha256=79Y5ei8RHg53WIwzP1eO4dpDYdKvhr1qrbWMECf9D-E,2781
9
+ astreum/communication/handlers/object_request.py,sha256=n_ThJomdYXm6HPfkLMmCqRxO58xPCUOHXf1ddmG-OC8,7163
10
+ astreum/communication/handlers/object_response.py,sha256=X5MfYxd_b4SfKq3129Fi29ZfLynWNRyhGuoISiMHy20,3959
11
+ astreum/communication/handlers/ping.py,sha256=2fVynfVIsbWHtf7lpM6fTYWmeG0I1WSU3tmgCh9di7A,916
12
+ astreum/communication/handlers/route_request.py,sha256=KrucRgiM_oFNmwt93bRzNpeVHFATq3uhlNjGJIvzu-c,2477
13
+ astreum/communication/handlers/route_response.py,sha256=ZUKyXPpZzpVYKBgygMIlPjcmjrxi0s8M3COFfY5aO4A,1744
11
14
  astreum/communication/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
- astreum/communication/models/message.py,sha256=Wl1IITj7eY9_q0IOT4J7c5gsjS1bF51CH7GcSSuu5OM,3327
13
- astreum/communication/models/peer.py,sha256=CbqkyCwhFCiC2spd1-KjNdeVGNjjt2ECVs8uHot-ETI,875
15
+ astreum/communication/models/message.py,sha256=2qln_PpKkVEoPdSGeQxUWAFxcEsHB-lz7dzTAsO94HU,4485
16
+ astreum/communication/models/peer.py,sha256=834UyyErBGbZs4dxe_SWz3gnRGnvFyc-7XQPrdNvDFE,1669
14
17
  astreum/communication/models/ping.py,sha256=u_DQTZJsbMdYiDDqjdZDsLaN5na2m9WZjVeEM3zq9_Y,955
15
- astreum/communication/models/route.py,sha256=LRHx0R1MSIln92GQbyDrZpE_hfiHDiSG_3z1Ssq_1n4,4032
18
+ astreum/communication/models/route.py,sha256=NdmnI1J1wFs2pkm6W0Kv-29JeqGiHcKlw4-esT5ZFLA,3797
19
+ astreum/communication/processors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
+ astreum/communication/processors/incoming.py,sha256=10l6Az-Ul_2BvYpTXgPiL9bL0te1q3GB3aET0JednKE,3325
21
+ astreum/communication/processors/outgoing.py,sha256=09nAeTzvo3jGWl3SLgIQr8vfmO_IvdDqSG7_ZKThYPk,593
16
22
  astreum/consensus/__init__.py,sha256=VZR_NyGSD5VvZp3toD2zpdYwFDLBIcckeVZXFPlruuU,425
17
23
  astreum/consensus/genesis.py,sha256=RI9AzQFmDTgNFuiiTmW2dDiGcURIUGmThdRpxWrUOBk,1962
18
24
  astreum/consensus/setup.py,sha256=lrEapfpJXKqw4iwST11-tqPAI2VW2h3H6Ue4JDAtrP4,3142
19
- astreum/consensus/start.py,sha256=ZUa77cINmj5AzGR8dnZ1KS0OeDIyesSmrEOx0zo4HBI,2581
25
+ astreum/consensus/start.py,sha256=DM45Pw6JL5rew-KpcspINguH43ZUHr4v99tXjYqaEkE,2551
20
26
  astreum/consensus/validator.py,sha256=cqcmw1WEB8DkznNX_Mn8tmE956rVSNCPv1FicdL8EAQ,3647
21
27
  astreum/consensus/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
28
  astreum/consensus/models/account.py,sha256=3QcT59QUZynysLSbiywidFYVzYJ3LR6qia7JwXOwn4I,2690
@@ -27,10 +33,11 @@ astreum/consensus/models/fork.py,sha256=IbXRB93bUg2k3q3oQ9dOPzozV-rY-TEDFjYrw-WB
27
33
  astreum/consensus/models/receipt.py,sha256=KjKKjYp_LnP2zkX1FLIwD_4hqKV1b2TPfp43tY701q4,3336
28
34
  astreum/consensus/models/transaction.py,sha256=AYa1Q-BaYW3mkOv1e3WbvDFEsYamKMiFrja-eO2zU_Y,7475
29
35
  astreum/consensus/workers/__init__.py,sha256=bS5FjbevbIR5FHbVGnT4Jli17VIld_5auemRw4CaHFU,278
30
- astreum/consensus/workers/discovery.py,sha256=ckko9286WaK0qAaUpk_pHmQe_N3F87iGZu67OhCdtY8,2487
31
- astreum/consensus/workers/validation.py,sha256=1jwFUL1zztuzLiYAmi92-KTUq97yraFAhuvhNhFJeLs,12223
32
- astreum/consensus/workers/verify.py,sha256=eadF27iXOnMife_Pwz65lVwUyTEU8LGIcdGkCT_nzo0,3487
36
+ astreum/consensus/workers/discovery.py,sha256=u6HyxamMVJjYnPFPa_U95I2pN9UzHRQ-LOa7YYZT808,2453
37
+ astreum/consensus/workers/validation.py,sha256=uBkZVduHtwz8hUwDf_gFDiY8TfFaoYj40jx-s-EzuEU,13358
38
+ astreum/consensus/workers/verify.py,sha256=tBBrAHH8Xcg3uopmQSjT6iuZd1s-9FkLnJ_JgeW5HdU,3423
33
39
  astreum/crypto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
40
+ astreum/crypto/chacha20poly1305.py,sha256=01VtLx_bdJC86ifQeTA494ZdKbPM2MswDTLmAs9bl8c,2479
34
41
  astreum/crypto/ed25519.py,sha256=FRnvlN0kZlxn4j-sJKl-C9tqiz_0z4LZyXLj3KIj1TQ,1760
35
42
  astreum/crypto/quadratic_form.py,sha256=pJgbORey2NTWbQNhdyvrjy_6yjORudQ67jBz2ScHptg,4037
36
43
  astreum/crypto/wesolowski.py,sha256=SUgGXW3Id07dJtWzDcs4dluIhjqbRWQ8YWjn_mK78AQ,4092
@@ -39,24 +46,26 @@ astreum/machine/__init__.py,sha256=TjWf9RlGuOGbCqdjJKidh8W4pCzUoLpi3FgutssEGoQ,4
39
46
  astreum/machine/parser.py,sha256=Z_Y0Sax0rPh8JcIo19-iNDQoc5GTdGQkmfFyLpCB4bw,1757
40
47
  astreum/machine/tokenizer.py,sha256=6wPqR_D3h5BEvR78XKtD45ouy77RZBbz4Yh4jHSmN4o,2394
41
48
  astreum/machine/evaluations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
42
- astreum/machine/evaluations/high_evaluation.py,sha256=0tKOvW8T7EEHrL5pZtMUSnUszYTPWSP2xnEocr1eIOk,9778
43
- astreum/machine/evaluations/low_evaluation.py,sha256=n3LwHDD889PAoj1XW7D2Eu4WCalx5nl0mKoLrgdoLpo,10337
49
+ astreum/machine/evaluations/high_evaluation.py,sha256=cqYudR9WAdVz9dURDyuQhZsuhWbmjbdw9x3UxDEYpPI,9971
50
+ astreum/machine/evaluations/low_evaluation.py,sha256=_93r6DKkCwnaOKmVGSp8JBlUPZpKrA1GECqVnwLb9es,10370
44
51
  astreum/machine/evaluations/script_evaluation.py,sha256=eWouYUwTYzaqUyXqEe-lAJFIluW0gMeCDdXqle88oWw,864
45
52
  astreum/machine/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
46
53
  astreum/machine/models/environment.py,sha256=WjP6GRX_8e0-BAhzRLvQ6fYtKQEVR0LZi7DZNZS0TSE,1019
47
54
  astreum/machine/models/expression.py,sha256=yYr9ktk-NWPL4EXwHz7ePvr9eNvfSBQe3yzRUz06yas,7675
48
55
  astreum/machine/models/meter.py,sha256=5q2PFW7_jmgKVM1-vwE4RRjMfPEthUA4iu1CwR-Axws,505
49
56
  astreum/storage/__init__.py,sha256=Flk6WXT2xGFHWWJiZHK3O5OpjoLTOFMqqIiJTtD58kY,111
50
- astreum/storage/setup.py,sha256=udwLpSCFpneKH9DlxUB40EVjmhjqQQ2hS4dePwQKkL8,1508
51
- astreum/storage/actions/get.py,sha256=XRNOUzD3OjMpfFPyhQQt2rE5dpS_Hdp9Yf5SYELjm30,2572
52
- astreum/storage/actions/set.py,sha256=-eyHJW5xPRbkDV8YvPQsp_SEFkCt4HEQ0VK2soYRXvg,4210
57
+ astreum/storage/requests.py,sha256=q_rxG_k7POth93HmsUTCLSyNw-4EdFqqNExhIwm7Q0g,818
58
+ astreum/storage/setup.py,sha256=fnDZCxVskOAPDl-oTwq-iLiRCD3CKHOEgI4LALNJQWI,612
59
+ astreum/storage/actions/get.py,sha256=yf1HMYPMxRXTbZbSoe8JI6C4eWkcbScFQj-nGozBsCQ,6845
60
+ astreum/storage/actions/set.py,sha256=8MvlZS3MFvLc-apDb6mucxt1JBxw82lxMVoa0sTvdo8,5751
53
61
  astreum/storage/models/atom.py,sha256=FY_bgtoju59Yo7TL1DTFTr9_pRMNBuH6-u59D6bz2fc,3163
54
62
  astreum/storage/models/trie.py,sha256=Bn3ssPGI7YGS4iUH5ESvpG1NE6Ljx2Xo7wkEpQhjKUY,17587
55
63
  astreum/utils/bytes.py,sha256=9QTWC2JCdwWLB5R2mPtmjPro0IUzE58DL3uEul4AheE,846
64
+ astreum/utils/config.py,sha256=jiobdNFiF44BMmoifAG3feq57ZPIhjUG4FG71cn-kgY,1527
56
65
  astreum/utils/integer.py,sha256=iQt-klWOYVghu_NOT341MmHbOle4FDT3by4PNKNXscg,736
57
66
  astreum/utils/logging.py,sha256=mRDtWSCj8vKt58WGKLNSkK9Oa0graNVSoS8URby4Q9g,6684
58
- astreum-0.3.1.dist-info/licenses/LICENSE,sha256=gYBvRDP-cPLmTyJhvZ346QkrYW_eleke4Z2Yyyu43eQ,1089
59
- astreum-0.3.1.dist-info/METADATA,sha256=_fPZGHAf0_YTfkErbQwTEovrBE0x_MbUPp8uXJ04JUE,7716
60
- astreum-0.3.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
61
- astreum-0.3.1.dist-info/top_level.txt,sha256=1EG1GmkOk3NPmUA98FZNdKouhRyget-KiFiMk0i2Uz0,8
62
- astreum-0.3.1.dist-info/RECORD,,
67
+ astreum-0.3.9.dist-info/licenses/LICENSE,sha256=gYBvRDP-cPLmTyJhvZ346QkrYW_eleke4Z2Yyyu43eQ,1089
68
+ astreum-0.3.9.dist-info/METADATA,sha256=vlvV1wwS4GiKwUQhpEg3FqJ_I_5m4efioshBzwhs4bk,7766
69
+ astreum-0.3.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
70
+ astreum-0.3.9.dist-info/top_level.txt,sha256=1EG1GmkOk3NPmUA98FZNdKouhRyget-KiFiMk0i2Uz0,8
71
+ astreum-0.3.9.dist-info/RECORD,,
@@ -1,81 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING, Sequence
4
-
5
- from cryptography.hazmat.primitives import serialization
6
-
7
- if TYPE_CHECKING:
8
- from .... import Node
9
- from ..models.message import Message
10
-
11
-
12
- def handle_storage_request(node: "Node", addr: Sequence[object], message: "Message") -> None:
13
- """Process incoming storage request payloads, forwarding if needed."""
14
- logger = node.logger
15
- payload = message.content
16
- if len(payload) < 32:
17
- return
18
-
19
- atom_id = payload[:32]
20
- provider_bytes = payload[32:]
21
- if not provider_bytes:
22
- return
23
-
24
- try:
25
- provider_str = provider_bytes.decode("utf-8")
26
- except UnicodeDecodeError:
27
- return
28
-
29
- try:
30
- host, port = addr[0], int(addr[1])
31
- except Exception:
32
- return
33
- address_key = (host, port)
34
- sender_key_bytes = node.addresses.get(address_key)
35
- if sender_key_bytes is None:
36
- return
37
-
38
- try:
39
- local_key_bytes = node.relay_public_key.public_bytes(
40
- encoding=serialization.Encoding.Raw,
41
- format=serialization.PublicFormat.Raw,
42
- )
43
- except Exception:
44
- return
45
-
46
- def xor_distance(target: bytes, key: bytes) -> int:
47
- return int.from_bytes(
48
- bytes(a ^ b for a, b in zip(target, key)),
49
- byteorder="big",
50
- signed=False,
51
- )
52
-
53
- self_distance = xor_distance(atom_id, local_key_bytes)
54
-
55
- try:
56
- closest_peer = node.peer_route.closest_peer_for_hash(atom_id)
57
- except Exception:
58
- closest_peer = None
59
-
60
- if closest_peer is not None and closest_peer.public_key_bytes != sender_key_bytes:
61
- closest_distance = xor_distance(atom_id, closest_peer.public_key_bytes)
62
- if closest_distance < self_distance:
63
- target_addr = closest_peer.address
64
- if target_addr is not None and target_addr != addr:
65
- try:
66
- node.outgoing_queue.put((message.to_bytes(), target_addr))
67
- except Exception:
68
- return
69
- logger.debug(
70
- "Forwarded storage request for %s to %s",
71
- atom_id.hex(),
72
- target_addr,
73
- )
74
- return
75
-
76
- node.storage_index[atom_id] = provider_str.strip()
77
- logger.debug(
78
- "Stored provider %s for atom %s",
79
- provider_str.strip(),
80
- atom_id.hex(),
81
- )