astreum 0.3.16__py3-none-any.whl → 0.3.48__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 (65) hide show
  1. astreum/__init__.py +1 -2
  2. astreum/communication/__init__.py +15 -11
  3. astreum/communication/difficulty.py +39 -0
  4. astreum/communication/disconnect.py +57 -0
  5. astreum/communication/handlers/handshake.py +105 -62
  6. astreum/communication/handlers/object_request.py +226 -138
  7. astreum/communication/handlers/object_response.py +118 -10
  8. astreum/communication/handlers/ping.py +9 -0
  9. astreum/communication/handlers/route_request.py +7 -1
  10. astreum/communication/handlers/route_response.py +7 -1
  11. astreum/communication/incoming_queue.py +96 -0
  12. astreum/communication/message_pow.py +36 -0
  13. astreum/communication/models/peer.py +4 -0
  14. astreum/communication/models/ping.py +27 -6
  15. astreum/communication/models/route.py +4 -0
  16. astreum/communication/{start.py → node.py} +10 -11
  17. astreum/communication/outgoing_queue.py +108 -0
  18. astreum/communication/processors/incoming.py +110 -37
  19. astreum/communication/processors/outgoing.py +35 -2
  20. astreum/communication/processors/peer.py +133 -58
  21. astreum/communication/setup.py +272 -113
  22. astreum/communication/util.py +14 -0
  23. astreum/machine/evaluations/low_evaluation.py +5 -5
  24. astreum/machine/models/expression.py +5 -5
  25. astreum/node.py +96 -87
  26. astreum/storage/actions/get.py +285 -183
  27. astreum/storage/actions/set.py +171 -156
  28. astreum/storage/models/atom.py +0 -14
  29. astreum/storage/models/trie.py +2 -2
  30. astreum/storage/providers.py +24 -0
  31. astreum/storage/requests.py +13 -10
  32. astreum/storage/setup.py +20 -15
  33. astreum/utils/config.py +260 -43
  34. astreum/utils/logging.py +1 -1
  35. astreum/{consensus → validation}/__init__.py +0 -4
  36. astreum/validation/constants.py +2 -0
  37. astreum/{consensus → validation}/genesis.py +4 -6
  38. astreum/{consensus → validation}/models/account.py +1 -1
  39. astreum/validation/models/block.py +544 -0
  40. astreum/validation/models/fork.py +511 -0
  41. astreum/{consensus → validation}/models/receipt.py +18 -5
  42. astreum/{consensus → validation}/models/transaction.py +50 -8
  43. astreum/validation/node.py +190 -0
  44. astreum/{consensus → validation}/validator.py +1 -1
  45. astreum/validation/workers/__init__.py +8 -0
  46. astreum/{consensus → validation}/workers/validation.py +360 -333
  47. astreum/verification/__init__.py +4 -0
  48. astreum/{consensus/workers/discovery.py → verification/discover.py} +1 -1
  49. astreum/verification/node.py +61 -0
  50. astreum/verification/worker.py +183 -0
  51. {astreum-0.3.16.dist-info → astreum-0.3.48.dist-info}/METADATA +45 -9
  52. astreum-0.3.48.dist-info/RECORD +79 -0
  53. astreum/consensus/models/block.py +0 -364
  54. astreum/consensus/models/chain.py +0 -66
  55. astreum/consensus/models/fork.py +0 -100
  56. astreum/consensus/setup.py +0 -83
  57. astreum/consensus/start.py +0 -67
  58. astreum/consensus/workers/__init__.py +0 -9
  59. astreum/consensus/workers/verify.py +0 -90
  60. astreum-0.3.16.dist-info/RECORD +0 -72
  61. /astreum/{consensus → validation}/models/__init__.py +0 -0
  62. /astreum/{consensus → validation}/models/accounts.py +0 -0
  63. {astreum-0.3.16.dist-info → astreum-0.3.48.dist-info}/WHEEL +0 -0
  64. {astreum-0.3.16.dist-info → astreum-0.3.48.dist-info}/licenses/LICENSE +0 -0
  65. {astreum-0.3.16.dist-info → astreum-0.3.48.dist-info}/top_level.txt +0 -0
@@ -143,7 +143,7 @@ def low_eval(self, code: List[bytes], meter: Meter) -> Expr:
143
143
  if idx < 0 or length < 0:
144
144
  return error_expr("low_eval", "bad slice")
145
145
 
146
- atom = self.storage_get(key=id_b)
146
+ atom = self.get_atom(atom_id=id_b)
147
147
  if atom is None:
148
148
  return error_expr("low_eval", "unknown atom")
149
149
 
@@ -173,7 +173,7 @@ def low_eval(self, code: List[bytes], meter: Meter) -> Expr:
173
173
  if not meter.charge_bytes(len(id1_b) + len(id2_b)):
174
174
  return error_expr("low_eval", "meter limit")
175
175
 
176
- atom = self.storage_get(key=id_b)
176
+ atom = self.get_atom(atom_id=id_b)
177
177
  if atom is None:
178
178
  return error_expr("low_eval", "unknown atom")
179
179
 
@@ -195,8 +195,8 @@ def low_eval(self, code: List[bytes], meter: Meter) -> Expr:
195
195
  id2_b = stack.pop()
196
196
  id1_b = stack.pop()
197
197
 
198
- atom1 = self.storage_get(key=id1_b)
199
- atom2 = self.storage_get(key=id2_b)
198
+ atom1 = self.get_atom(atom_id=id1_b)
199
+ atom2 = self.get_atom(atom_id=id2_b)
200
200
  if atom1 is None or atom2 is None:
201
201
  return error_expr("low_eval", "unknown atom")
202
202
 
@@ -263,7 +263,7 @@ def low_eval(self, code: List[bytes], meter: Meter) -> Expr:
263
263
  if length > 32:
264
264
  return error_expr("low_eval", "load too wide")
265
265
 
266
- atom = self.storage_get(key=id_b)
266
+ atom = self.get_atom(atom_id=id_b)
267
267
  if atom is None:
268
268
  return error_expr("low_eval", "unknown atom")
269
269
 
@@ -46,16 +46,16 @@ class Expr:
46
46
  if not isinstance(root_hash, (bytes, bytearray)):
47
47
  raise TypeError("root hash must be bytes-like")
48
48
 
49
- storage_get = getattr(node, "storage_get", None)
50
- if not callable(storage_get):
51
- raise TypeError("node must provide a callable 'storage_get'")
49
+ get_atom = getattr(node, "get_atom", None)
50
+ if not callable(get_atom):
51
+ raise TypeError("node must provide a callable 'get_atom'")
52
52
 
53
53
  expr_id = bytes(root_hash)
54
54
 
55
55
  def _require(atom_id: Optional[bytes], context: str):
56
56
  if not atom_id:
57
57
  raise ValueError(f"missing atom id while decoding {context}")
58
- atom = storage_get(atom_id)
58
+ atom = get_atom(atom_id)
59
59
  if atom is None:
60
60
  raise ValueError(f"missing atom data while decoding {context}")
61
61
  return atom
@@ -197,7 +197,7 @@ def error_expr(topic: str, message: str) -> Expr.ListExpr:
197
197
 
198
198
  def get_expr_list_from_storage(self, key: bytes) -> Optional["ListExpr"]:
199
199
  """Load a list expression from storage using the given atom list root hash."""
200
- atoms = self.get_atom_list_from_storage(root_hash=key)
200
+ atoms = self.get_atom_list(key)
201
201
  if atoms is None:
202
202
  return None
203
203
 
astreum/node.py CHANGED
@@ -1,95 +1,104 @@
1
- """Core Astreum Node implementation."""
2
-
3
- from __future__ import annotations
4
-
5
- import threading
6
- import uuid
7
- from typing import Dict
8
-
9
- from astreum.communication.start import connect_to_network_and_verify
10
- from astreum.communication.models.peer import (
11
- add_peer as peers_add_peer,
12
- replace_peer as peers_replace_peer,
13
- get_peer as peers_get_peer,
14
- remove_peer as peers_remove_peer,
15
- )
16
- from astreum.consensus.start import process_blocks_and_transactions
17
- from astreum.machine import Expr, high_eval, low_eval, script_eval
18
- from astreum.machine.models.environment import Env, env_get, env_set
19
- from astreum.machine.models.expression import get_expr_list_from_storage
20
- from astreum.storage.models.atom import get_atom_list_from_storage
1
+ """Core Astreum Node implementation."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import threading
6
+ import uuid
7
+ from typing import Dict
8
+
9
+ from astreum.communication.node import connect_node
10
+ from astreum.communication.util import get_bootstrap_peers
11
+ from astreum.communication.disconnect import disconnect_node
12
+ from astreum.communication.models.peer import (
13
+ add_peer as peers_add_peer,
14
+ replace_peer as peers_replace_peer,
15
+ get_peer as peers_get_peer,
16
+ remove_peer as peers_remove_peer,
17
+ )
18
+ from astreum.validation.node import validate_blockchain
19
+ from astreum.verification.node import verify_blockchain
20
+ from astreum.machine import Expr, high_eval, low_eval, script_eval
21
+ from astreum.machine.models.environment import Env, env_get, env_set
22
+ from astreum.machine.models.expression import get_expr_list_from_storage
21
23
  from astreum.storage.actions.get import (
22
24
  _hot_storage_get,
23
25
  _cold_storage_get,
24
26
  _network_get,
25
- storage_get,
26
- local_get,
27
- )
28
- from astreum.storage.actions.set import (
29
- _hot_storage_set,
30
- _cold_storage_set,
31
- _network_set,
27
+ get_atom_from_local_storage,
28
+ get_atom,
29
+ get_atom_list_from_local_storage,
30
+ get_atom_list,
32
31
  )
33
- from astreum.storage.requests import add_atom_req, has_atom_req, pop_atom_req
34
- from astreum.storage.setup import storage_setup
35
- from astreum.utils.config import config_setup
36
- from astreum.utils.logging import logging_setup
37
-
38
-
32
+ from astreum.storage.actions.set import (
33
+ _hot_storage_set,
34
+ _cold_storage_set,
35
+ _network_set,
36
+ )
37
+ from astreum.storage.requests import add_atom_req, has_atom_req, pop_atom_req
38
+ from astreum.storage.setup import storage_setup
39
+ from astreum.utils.config import config_setup
40
+ from astreum.utils.logging import logging_setup
41
+
42
+
39
43
  class Node:
40
44
  def __init__(self, config: dict = {}):
41
45
  self.config = config_setup(config=config)
42
-
43
- self.logger = logging_setup(self.config)
44
-
45
- self.logger.info("Starting Astreum Node")
46
-
47
- # Chain Configuration
48
- self.logger.info(f"Chain configured as: {self.config["chain"]} ({self.config["chain_id"]})")
49
-
50
- # Storage Setup
51
- storage_setup(self, config=self.config)
52
-
53
- # Machine Setup
54
- self.environments: Dict[uuid.UUID, Env] = {}
55
- self.machine_environments_lock = threading.RLock()
56
- self.is_connected = False
57
- self.latest_block_hash = None
58
- self.latest_block = None
59
- self.nonce_time_ms = 0 # rolling measurement of last nonce search duration
60
-
61
- connect = connect_to_network_and_verify
62
- validate = process_blocks_and_transactions
63
-
64
- low_eval = low_eval
65
- high_eval = high_eval
66
- script_eval = script_eval
67
-
68
- env_get = env_get
69
- env_set = env_set
70
-
71
- # Storage
72
- ## Get
73
- _hot_storage_get = _hot_storage_get
74
- _cold_storage_get = _cold_storage_get
75
- _network_get = _network_get
76
-
77
- ## Set
78
- _hot_storage_set = _hot_storage_set
79
- _cold_storage_set = _cold_storage_set
80
- _network_set = _network_set
81
-
82
- storage_get = storage_get
83
- local_get = local_get
84
-
85
- get_expr_list_from_storage = get_expr_list_from_storage
86
- get_atom_list_from_storage = get_atom_list_from_storage
87
-
88
- add_atom_req = add_atom_req
89
- has_atom_req = has_atom_req
90
- pop_atom_req = pop_atom_req
91
-
92
- add_peer = peers_add_peer
93
- replace_peer = peers_replace_peer
94
- get_peer = peers_get_peer
95
- remove_peer = peers_remove_peer
46
+ self.bootstrap_peers = get_bootstrap_peers(self)
47
+
48
+ self.logger = logging_setup(self.config)
49
+
50
+ self.logger.info("Starting Astreum Node")
51
+
52
+ # Chain Configuration
53
+ self.logger.info(f"Chain configured as: {self.config["chain"]} ({self.config["chain_id"]})")
54
+
55
+ # Storage Setup
56
+ storage_setup(self, config=self.config)
57
+
58
+ # Machine Setup
59
+ self.environments: Dict[uuid.UUID, Env] = {}
60
+ self.machine_environments_lock = threading.RLock()
61
+ self.is_connected = False
62
+ self.latest_block_hash = None
63
+ self.latest_block = None
64
+
65
+ connect = connect_node
66
+ disconnect = disconnect_node
67
+
68
+ verify = verify_blockchain
69
+
70
+ validate = validate_blockchain
71
+
72
+ low_eval = low_eval
73
+ high_eval = high_eval
74
+ script_eval = script_eval
75
+
76
+ env_get = env_get
77
+ env_set = env_set
78
+
79
+ # Storage
80
+ ## Get
81
+ _hot_storage_get = _hot_storage_get
82
+ _cold_storage_get = _cold_storage_get
83
+ _network_get = _network_get
84
+
85
+ ## Set
86
+ _hot_storage_set = _hot_storage_set
87
+ _cold_storage_set = _cold_storage_set
88
+ _network_set = _network_set
89
+
90
+ get_atom_from_local_storage = get_atom_from_local_storage
91
+ get_atom = get_atom
92
+ get_atom_list_from_local_storage = get_atom_list_from_local_storage
93
+ get_atom_list = get_atom_list
94
+
95
+ get_expr_list_from_storage = get_expr_list_from_storage
96
+
97
+ add_atom_req = add_atom_req
98
+ has_atom_req = has_atom_req
99
+ pop_atom_req = pop_atom_req
100
+
101
+ add_peer = peers_add_peer
102
+ replace_peer = peers_replace_peer
103
+ get_peer = peers_get_peer
104
+ remove_peer = peers_remove_peer