astreum 0.1.19__py3-none-any.whl → 0.2.0__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.
Potentially problematic release.
This version of astreum might be problematic. Click here for more details.
- astreum/__init__.py +1 -2
- astreum/{node → _node}/__init__.py +1 -1
- astreum/{node → _node}/relay/envelope.py +1 -1
- astreum/{node → _node}/relay/message.py +1 -1
- astreum/{node → _node}/storage/merkle.py +65 -65
- astreum/{node → _node}/storage/patricia.py +3 -3
- astreum/{node → _node}/storage/storage.py +2 -0
- astreum/{node → _node}/utils.py +1 -1
- astreum/{node → _node}/validation/account.py +3 -3
- astreum/{node → _node}/validation/transaction.py +3 -3
- astreum/lispeum/__init__.py +2 -0
- astreum/lispeum/parser.py +1 -1
- astreum/machine/environment.py +0 -25
- astreum/node.py +1021 -0
- astreum-0.2.0.dist-info/METADATA +144 -0
- astreum-0.2.0.dist-info/RECORD +57 -0
- {astreum-0.1.19.dist-info → astreum-0.2.0.dist-info}/WHEEL +1 -1
- astreum/node/storage/__init__.py +0 -13
- astreum-0.1.19.dist-info/METADATA +0 -90
- astreum-0.1.19.dist-info/RECORD +0 -57
- /astreum/{node → _node}/relay/__init__.py +0 -0
- /astreum/{node → _node}/relay/bucket.py +0 -0
- /astreum/{node → _node}/relay/peer.py +0 -0
- /astreum/{node → _node}/relay/route.py +0 -0
- /astreum/{node/crypto → _node/storage}/__init__.py +0 -0
- /astreum/{node → _node}/storage/utils.py +0 -0
- /astreum/{node → _node}/validation/__init__.py +0 -0
- /astreum/{node → _node}/validation/_block/__init__.py +0 -0
- /astreum/{node → _node}/validation/_block/create.py +0 -0
- /astreum/{node → _node}/validation/_block/model.py +0 -0
- /astreum/{node → _node}/validation/_block/validate.py +0 -0
- /astreum/{node → _node}/validation/block.py +0 -0
- /astreum/{node → _node}/validation/constants.py +0 -0
- /astreum/{node → _node}/validation/stake.py +0 -0
- /astreum/{node → _node}/validation/vdf.py +0 -0
- /astreum/{utils → crypto}/__init__.py +0 -0
- /astreum/{node/crypto → crypto}/ed25519.py +0 -0
- /astreum/{node/crypto → crypto}/x25519.py +0 -0
- /astreum/{utils/bytes_format.py → format.py} +0 -0
- {astreum-0.1.19.dist-info → astreum-0.2.0.dist-info}/licenses/LICENSE +0 -0
- {astreum-0.1.19.dist-info → astreum-0.2.0.dist-info}/top_level.txt +0 -0
astreum/__init__.py
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
from
|
|
2
|
-
from .node import Node
|
|
1
|
+
from node import Node
|
|
@@ -8,7 +8,7 @@ from .relay import Relay, Topic
|
|
|
8
8
|
from ..machine import AstreumMachine
|
|
9
9
|
from .utils import hash_data
|
|
10
10
|
from .validation.block import Block
|
|
11
|
-
from .storage import Storage
|
|
11
|
+
from .storage.storage import Storage
|
|
12
12
|
|
|
13
13
|
class Node:
|
|
14
14
|
def __init__(self, config: dict):
|
|
@@ -34,7 +34,7 @@ import os
|
|
|
34
34
|
from dataclasses import dataclass
|
|
35
35
|
from typing import Optional, Tuple, List
|
|
36
36
|
from .message import Message, Topic
|
|
37
|
-
from astreum.
|
|
37
|
+
from astreum.format import encode, decode
|
|
38
38
|
from ..utils import hash_data
|
|
39
39
|
|
|
40
40
|
@dataclass
|
|
@@ -1,7 +1,71 @@
|
|
|
1
1
|
import blake3
|
|
2
2
|
from .storage import Storage
|
|
3
|
-
|
|
3
|
+
from astreum import format
|
|
4
4
|
|
|
5
|
+
class MerkleNode:
|
|
6
|
+
def __init__(self, leaf: bool, data: bytes):
|
|
7
|
+
"""
|
|
8
|
+
Initialize a Merkle node.
|
|
9
|
+
|
|
10
|
+
For a leaf node, `data` is the actual content to be stored.
|
|
11
|
+
For an internal node, `data` should be the concatenation of the two child hashes.
|
|
12
|
+
|
|
13
|
+
:param leaf: A boolean flag indicating whether this node is a leaf node (True) or an internal node (False).
|
|
14
|
+
:param data: The node's data. For leaves, the stored data; for internal nodes, concatenated child hashes.
|
|
15
|
+
"""
|
|
16
|
+
self.leaf = leaf
|
|
17
|
+
self.data = data
|
|
18
|
+
self._hash = None # Cached hash value to avoid recomputation.
|
|
19
|
+
|
|
20
|
+
@classmethod
|
|
21
|
+
def from_bytes(cls, data: bytes) -> 'MerkleNode':
|
|
22
|
+
"""
|
|
23
|
+
Deserialize a MerkleNode from its byte representation.
|
|
24
|
+
|
|
25
|
+
The input bytes are expected to be in the Astreum format, containing a leaf flag and node data.
|
|
26
|
+
|
|
27
|
+
:param data: The serialized node data.
|
|
28
|
+
:return: A new MerkleNode instance.
|
|
29
|
+
"""
|
|
30
|
+
leaf_flag, node_data = format.decode(data)
|
|
31
|
+
return cls(True if leaf_flag == 1 else False, node_data)
|
|
32
|
+
|
|
33
|
+
@classmethod
|
|
34
|
+
def from_storage(cls, storage: Storage, hash_value: bytes) -> 'MerkleNode' or None:
|
|
35
|
+
"""
|
|
36
|
+
Retrieve and deserialize a MerkleNode from storage using its hash.
|
|
37
|
+
|
|
38
|
+
:param storage: The Storage instance used to retrieve the node.
|
|
39
|
+
:param hash_value: The hash key under which the node is stored.
|
|
40
|
+
:return: A MerkleNode instance if found, otherwise None.
|
|
41
|
+
"""
|
|
42
|
+
node_bytes = storage.get(hash_value)
|
|
43
|
+
if node_bytes is None:
|
|
44
|
+
return None
|
|
45
|
+
return cls.from_bytes(node_bytes)
|
|
46
|
+
|
|
47
|
+
def to_bytes(self) -> bytes:
|
|
48
|
+
"""
|
|
49
|
+
Serialize the MerkleNode into bytes using the Astreum format.
|
|
50
|
+
|
|
51
|
+
The format encodes a list containing the leaf flag and the node data.
|
|
52
|
+
|
|
53
|
+
:return: The serialized bytes representing the node.
|
|
54
|
+
"""
|
|
55
|
+
return format.encode([1 if self.leaf else 0, self.data])
|
|
56
|
+
|
|
57
|
+
def hash(self) -> bytes:
|
|
58
|
+
"""
|
|
59
|
+
Compute (or retrieve a cached) hash of the node using the Blake3 algorithm.
|
|
60
|
+
|
|
61
|
+
For leaf nodes, the hash is computed over the actual data.
|
|
62
|
+
For internal nodes, the hash is computed over the concatenated child hashes.
|
|
63
|
+
|
|
64
|
+
:return: The Blake3 digest of the node's data.
|
|
65
|
+
"""
|
|
66
|
+
if self._hash is None:
|
|
67
|
+
self._hash = blake3.blake3(self.data).digest()
|
|
68
|
+
return self._hash
|
|
5
69
|
|
|
6
70
|
|
|
7
71
|
class MerkleTree:
|
|
@@ -158,67 +222,3 @@ class MerkleTree:
|
|
|
158
222
|
return new_node_hash
|
|
159
223
|
|
|
160
224
|
|
|
161
|
-
class MerkleNode:
|
|
162
|
-
def __init__(self, leaf: bool, data: bytes):
|
|
163
|
-
"""
|
|
164
|
-
Initialize a Merkle node.
|
|
165
|
-
|
|
166
|
-
For a leaf node, `data` is the actual content to be stored.
|
|
167
|
-
For an internal node, `data` should be the concatenation of the two child hashes.
|
|
168
|
-
|
|
169
|
-
:param leaf: A boolean flag indicating whether this node is a leaf node (True) or an internal node (False).
|
|
170
|
-
:param data: The node's data. For leaves, the stored data; for internal nodes, concatenated child hashes.
|
|
171
|
-
"""
|
|
172
|
-
self.leaf = leaf
|
|
173
|
-
self.data = data
|
|
174
|
-
self._hash = None # Cached hash value to avoid recomputation.
|
|
175
|
-
|
|
176
|
-
@classmethod
|
|
177
|
-
def from_bytes(cls, data: bytes) -> 'MerkleNode':
|
|
178
|
-
"""
|
|
179
|
-
Deserialize a MerkleNode from its byte representation.
|
|
180
|
-
|
|
181
|
-
The input bytes are expected to be in the Astreum format, containing a leaf flag and node data.
|
|
182
|
-
|
|
183
|
-
:param data: The serialized node data.
|
|
184
|
-
:return: A new MerkleNode instance.
|
|
185
|
-
"""
|
|
186
|
-
leaf_flag, node_data = bytes_format.decode(data)
|
|
187
|
-
return cls(True if leaf_flag == 1 else False, node_data)
|
|
188
|
-
|
|
189
|
-
@classmethod
|
|
190
|
-
def from_storage(cls, storage: Storage, hash_value: bytes) -> 'MerkleNode' or None:
|
|
191
|
-
"""
|
|
192
|
-
Retrieve and deserialize a MerkleNode from storage using its hash.
|
|
193
|
-
|
|
194
|
-
:param storage: The Storage instance used to retrieve the node.
|
|
195
|
-
:param hash_value: The hash key under which the node is stored.
|
|
196
|
-
:return: A MerkleNode instance if found, otherwise None.
|
|
197
|
-
"""
|
|
198
|
-
node_bytes = storage.get(hash_value)
|
|
199
|
-
if node_bytes is None:
|
|
200
|
-
return None
|
|
201
|
-
return cls.from_bytes(node_bytes)
|
|
202
|
-
|
|
203
|
-
def to_bytes(self) -> bytes:
|
|
204
|
-
"""
|
|
205
|
-
Serialize the MerkleNode into bytes using the Astreum format.
|
|
206
|
-
|
|
207
|
-
The format encodes a list containing the leaf flag and the node data.
|
|
208
|
-
|
|
209
|
-
:return: The serialized bytes representing the node.
|
|
210
|
-
"""
|
|
211
|
-
return bytes_format.encode([1 if self.leaf else 0, self.data])
|
|
212
|
-
|
|
213
|
-
def hash(self) -> bytes:
|
|
214
|
-
"""
|
|
215
|
-
Compute (or retrieve a cached) hash of the node using the Blake3 algorithm.
|
|
216
|
-
|
|
217
|
-
For leaf nodes, the hash is computed over the actual data.
|
|
218
|
-
For internal nodes, the hash is computed over the concatenated child hashes.
|
|
219
|
-
|
|
220
|
-
:return: The Blake3 digest of the node's data.
|
|
221
|
-
"""
|
|
222
|
-
if self._hash is None:
|
|
223
|
-
self._hash = blake3.blake3(self.data).digest()
|
|
224
|
-
return self._hash
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import blake3
|
|
2
2
|
from typing import Optional, List
|
|
3
3
|
from .storage import Storage
|
|
4
|
-
import astreum.
|
|
4
|
+
import astreum.format as format format.decode, format.encode
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
def common_prefix_length(a: bytes, b: bytes) -> int:
|
|
@@ -35,7 +35,7 @@ class PatriciaNode:
|
|
|
35
35
|
Expected format: [key, value, children]
|
|
36
36
|
where children is a list of child node hashes (bytes).
|
|
37
37
|
"""
|
|
38
|
-
decoded =
|
|
38
|
+
decoded = format.decode(data)
|
|
39
39
|
key, value, children = decoded
|
|
40
40
|
return cls(key, value, children)
|
|
41
41
|
|
|
@@ -59,7 +59,7 @@ class PatriciaNode:
|
|
|
59
59
|
|
|
60
60
|
Structure: [key, value, children]
|
|
61
61
|
"""
|
|
62
|
-
return
|
|
62
|
+
return format.encode([self.key, self.value, self.children])
|
|
63
63
|
|
|
64
64
|
def hash(self) -> bytes:
|
|
65
65
|
"""
|
|
@@ -39,6 +39,8 @@ class Storage:
|
|
|
39
39
|
self.pending_requests = {} # hash -> (start_time, event)
|
|
40
40
|
self.request_lock = threading.Lock()
|
|
41
41
|
|
|
42
|
+
|
|
43
|
+
|
|
42
44
|
def put(self, data_hash: bytes, data: bytes) -> bool:
|
|
43
45
|
"""Store data with its hash. Returns True if successful, False if space limit exceeded."""
|
|
44
46
|
data_size = len(data)
|
astreum/{node → _node}/utils.py
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from typing import Optional
|
|
2
2
|
from ..storage.patricia import PatriciaTrie
|
|
3
3
|
|
|
4
|
-
import astreum.
|
|
4
|
+
import astreum.format as format
|
|
5
5
|
class Account:
|
|
6
6
|
def __init__(self, public_key: bytes, balance: int, code: bytes, counter: int, data: bytes, secret_key: Optional[bytes] = None):
|
|
7
7
|
"""
|
|
@@ -30,7 +30,7 @@ class Account:
|
|
|
30
30
|
|
|
31
31
|
The public_key (and optional secret_key) must be provided separately.
|
|
32
32
|
"""
|
|
33
|
-
decoded =
|
|
33
|
+
decoded = format.decode(data)
|
|
34
34
|
balance, code, counter, account_data = decoded
|
|
35
35
|
return cls(public_key, balance, code, counter, account_data, secret_key=secret_key)
|
|
36
36
|
|
|
@@ -40,7 +40,7 @@ class Account:
|
|
|
40
40
|
|
|
41
41
|
Format: [balance, code, counter, data]
|
|
42
42
|
"""
|
|
43
|
-
return
|
|
43
|
+
return format.encode([
|
|
44
44
|
self.balance,
|
|
45
45
|
self.code,
|
|
46
46
|
self.counter,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from typing import Optional
|
|
2
2
|
import time
|
|
3
3
|
from .account import Account, get_account_from_storage
|
|
4
|
-
import astreum.
|
|
4
|
+
import astreum.format as format
|
|
5
5
|
|
|
6
6
|
class Transaction:
|
|
7
7
|
def __init__(
|
|
@@ -36,7 +36,7 @@ class Transaction:
|
|
|
36
36
|
Returns:
|
|
37
37
|
Transaction object
|
|
38
38
|
"""
|
|
39
|
-
decoded =
|
|
39
|
+
decoded = format.decode(data)
|
|
40
40
|
sender_public_key, recipient_public_key, amount, tx_data, counter, timestamp, signature = decoded
|
|
41
41
|
|
|
42
42
|
sender_account = None
|
|
@@ -63,7 +63,7 @@ class Transaction:
|
|
|
63
63
|
|
|
64
64
|
Format: [sender_hash, recipient_hash, amount, data, counter, timestamp, signature]
|
|
65
65
|
"""
|
|
66
|
-
return
|
|
66
|
+
return format.encode([
|
|
67
67
|
self.sender.public_key,
|
|
68
68
|
self.recipient.public_key,
|
|
69
69
|
self.amount,
|
astreum/lispeum/__init__.py
CHANGED
astreum/lispeum/parser.py
CHANGED
astreum/machine/environment.py
CHANGED
|
@@ -2,28 +2,3 @@ from typing import Dict, Optional
|
|
|
2
2
|
from astreum.lispeum.expression import Expr
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
class Environment:
|
|
6
|
-
def __init__(self, parent: 'Environment' = None, node: 'Node' = None):
|
|
7
|
-
self.data: Dict[str, Expr] = {}
|
|
8
|
-
self.parent = parent
|
|
9
|
-
self.node = node
|
|
10
|
-
|
|
11
|
-
def set(self, name: str, value: Expr):
|
|
12
|
-
if self.node:
|
|
13
|
-
self.node.post_global_storage(name, value)
|
|
14
|
-
else:
|
|
15
|
-
self.data[name] = value
|
|
16
|
-
|
|
17
|
-
def get(self, name: str) -> Optional[Expr]:
|
|
18
|
-
if self.node:
|
|
19
|
-
return self.node.query_global_storage(name)
|
|
20
|
-
|
|
21
|
-
if name in self.data:
|
|
22
|
-
return self.data[name]
|
|
23
|
-
elif self.parent:
|
|
24
|
-
return self.parent.get(name)
|
|
25
|
-
else:
|
|
26
|
-
return None
|
|
27
|
-
|
|
28
|
-
def __repr__(self):
|
|
29
|
-
return f"Environment({self.data})"
|