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.
- astreum/__init__.py +1 -2
- astreum/communication/__init__.py +15 -11
- astreum/communication/difficulty.py +39 -0
- astreum/communication/disconnect.py +57 -0
- astreum/communication/handlers/handshake.py +105 -62
- astreum/communication/handlers/object_request.py +226 -138
- astreum/communication/handlers/object_response.py +118 -10
- astreum/communication/handlers/ping.py +9 -0
- astreum/communication/handlers/route_request.py +7 -1
- astreum/communication/handlers/route_response.py +7 -1
- astreum/communication/incoming_queue.py +96 -0
- astreum/communication/message_pow.py +36 -0
- astreum/communication/models/peer.py +4 -0
- astreum/communication/models/ping.py +27 -6
- astreum/communication/models/route.py +4 -0
- astreum/communication/{start.py → node.py} +10 -11
- astreum/communication/outgoing_queue.py +108 -0
- astreum/communication/processors/incoming.py +110 -37
- astreum/communication/processors/outgoing.py +35 -2
- astreum/communication/processors/peer.py +133 -58
- astreum/communication/setup.py +272 -113
- astreum/communication/util.py +14 -0
- astreum/machine/evaluations/low_evaluation.py +5 -5
- astreum/machine/models/expression.py +5 -5
- astreum/node.py +96 -87
- astreum/storage/actions/get.py +285 -183
- astreum/storage/actions/set.py +171 -156
- astreum/storage/models/atom.py +0 -14
- astreum/storage/models/trie.py +2 -2
- astreum/storage/providers.py +24 -0
- astreum/storage/requests.py +13 -10
- astreum/storage/setup.py +20 -15
- astreum/utils/config.py +260 -43
- astreum/utils/logging.py +1 -1
- astreum/{consensus → validation}/__init__.py +0 -4
- astreum/validation/constants.py +2 -0
- astreum/{consensus → validation}/genesis.py +4 -6
- astreum/{consensus → validation}/models/account.py +1 -1
- astreum/validation/models/block.py +544 -0
- astreum/validation/models/fork.py +511 -0
- astreum/{consensus → validation}/models/receipt.py +18 -5
- astreum/{consensus → validation}/models/transaction.py +50 -8
- astreum/validation/node.py +190 -0
- astreum/{consensus → validation}/validator.py +1 -1
- astreum/validation/workers/__init__.py +8 -0
- astreum/{consensus → validation}/workers/validation.py +360 -333
- astreum/verification/__init__.py +4 -0
- astreum/{consensus/workers/discovery.py → verification/discover.py} +1 -1
- astreum/verification/node.py +61 -0
- astreum/verification/worker.py +183 -0
- {astreum-0.3.16.dist-info → astreum-0.3.48.dist-info}/METADATA +45 -9
- astreum-0.3.48.dist-info/RECORD +79 -0
- astreum/consensus/models/block.py +0 -364
- astreum/consensus/models/chain.py +0 -66
- astreum/consensus/models/fork.py +0 -100
- astreum/consensus/setup.py +0 -83
- astreum/consensus/start.py +0 -67
- astreum/consensus/workers/__init__.py +0 -9
- astreum/consensus/workers/verify.py +0 -90
- astreum-0.3.16.dist-info/RECORD +0 -72
- /astreum/{consensus → validation}/models/__init__.py +0 -0
- /astreum/{consensus → validation}/models/accounts.py +0 -0
- {astreum-0.3.16.dist-info → astreum-0.3.48.dist-info}/WHEEL +0 -0
- {astreum-0.3.16.dist-info → astreum-0.3.48.dist-info}/licenses/LICENSE +0 -0
- {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.
|
|
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.
|
|
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.
|
|
199
|
-
atom2 = self.
|
|
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.
|
|
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
|
-
|
|
50
|
-
if not callable(
|
|
51
|
-
raise TypeError("node must provide a callable '
|
|
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 =
|
|
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.
|
|
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.
|
|
10
|
-
from astreum.communication.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
from astreum.
|
|
19
|
-
from astreum.
|
|
20
|
-
from astreum.
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
self.
|
|
56
|
-
self.
|
|
57
|
-
self.
|
|
58
|
-
self.
|
|
59
|
-
self.
|
|
60
|
-
|
|
61
|
-
connect =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|