astreum 0.1.10__py3-none-any.whl → 0.1.12__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/node/__init__.py +5 -4
- astreum/node/models.py +30 -5
- {astreum-0.1.10.dist-info → astreum-0.1.12.dist-info}/METADATA +1 -1
- {astreum-0.1.10.dist-info → astreum-0.1.12.dist-info}/RECORD +7 -7
- {astreum-0.1.10.dist-info → astreum-0.1.12.dist-info}/LICENSE +0 -0
- {astreum-0.1.10.dist-info → astreum-0.1.12.dist-info}/WHEEL +0 -0
- {astreum-0.1.10.dist-info → astreum-0.1.12.dist-info}/top_level.txt +0 -0
astreum/node/__init__.py
CHANGED
|
@@ -13,16 +13,17 @@ from astreum.lispeum.storage import store_expr, get_expr_from_storage
|
|
|
13
13
|
|
|
14
14
|
class Node:
|
|
15
15
|
def __init__(self, config: dict):
|
|
16
|
-
|
|
17
|
-
self.
|
|
16
|
+
# Ensure config is a dictionary, but allow it to be None
|
|
17
|
+
self.config = config if config is not None else {}
|
|
18
|
+
self.relay = Relay(self.config)
|
|
18
19
|
# Get the node_id from relay instead of generating our own
|
|
19
20
|
self.node_id = self.relay.node_id
|
|
20
|
-
self.storage = Storage(config)
|
|
21
|
+
self.storage = Storage(self.config)
|
|
21
22
|
self.storage.node = self # Set the storage node reference to self
|
|
22
23
|
|
|
23
24
|
# Latest block of the chain this node is following
|
|
24
25
|
self.latest_block = None
|
|
25
|
-
self.followed_chain_id = config.get('followed_chain_id', None)
|
|
26
|
+
self.followed_chain_id = self.config.get('followed_chain_id', None)
|
|
26
27
|
|
|
27
28
|
# Initialize machine
|
|
28
29
|
self.machine = AstreumMachine(node=self)
|
astreum/node/models.py
CHANGED
|
@@ -15,8 +15,21 @@ class Storage:
|
|
|
15
15
|
def __init__(self, config: dict):
|
|
16
16
|
self.max_space = config.get('max_storage_space', 1024 * 1024 * 1024) # Default 1GB
|
|
17
17
|
self.current_space = 0
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
|
|
19
|
+
# Check if storage_path is provided in config
|
|
20
|
+
storage_path = config.get('storage_path')
|
|
21
|
+
self.use_memory_storage = storage_path is None
|
|
22
|
+
|
|
23
|
+
# Initialize in-memory storage if no path provided
|
|
24
|
+
self.memory_storage = {} if self.use_memory_storage else None
|
|
25
|
+
|
|
26
|
+
# Only create storage path if not using memory storage
|
|
27
|
+
if not self.use_memory_storage:
|
|
28
|
+
self.storage_path = Path(storage_path)
|
|
29
|
+
self.storage_path.mkdir(parents=True, exist_ok=True)
|
|
30
|
+
# Calculate current space usage
|
|
31
|
+
self.current_space = sum(f.stat().st_size for f in self.storage_path.glob('*') if f.is_file())
|
|
32
|
+
|
|
20
33
|
self.max_object_recursion = config.get('max_object_recursion', 50)
|
|
21
34
|
self.network_request_timeout = config.get('network_request_timeout', 5.0) # Default 5 second timeout
|
|
22
35
|
self.node = None # Will be set by the Node after initialization
|
|
@@ -24,9 +37,6 @@ class Storage:
|
|
|
24
37
|
# In-progress requests tracking
|
|
25
38
|
self.pending_requests = {} # hash -> (start_time, event)
|
|
26
39
|
self.request_lock = threading.Lock()
|
|
27
|
-
|
|
28
|
-
# Calculate current space usage
|
|
29
|
-
self.current_space = sum(f.stat().st_size for f in self.storage_path.glob('*') if f.is_file())
|
|
30
40
|
|
|
31
41
|
def put(self, data_hash: bytes, data: bytes) -> bool:
|
|
32
42
|
"""Store data with its hash. Returns True if successful, False if space limit exceeded."""
|
|
@@ -34,6 +44,14 @@ class Storage:
|
|
|
34
44
|
if self.current_space + data_size > self.max_space:
|
|
35
45
|
return False
|
|
36
46
|
|
|
47
|
+
# If using memory storage, store in dictionary
|
|
48
|
+
if self.use_memory_storage:
|
|
49
|
+
if data_hash not in self.memory_storage:
|
|
50
|
+
self.memory_storage[data_hash] = data
|
|
51
|
+
self.current_space += data_size
|
|
52
|
+
return True
|
|
53
|
+
|
|
54
|
+
# Otherwise use file storage
|
|
37
55
|
file_path = self.storage_path / data_hash.hex()
|
|
38
56
|
|
|
39
57
|
# Don't store if already exists
|
|
@@ -54,6 +72,11 @@ class Storage:
|
|
|
54
72
|
|
|
55
73
|
def _local_get(self, data_hash: bytes) -> Optional[bytes]:
|
|
56
74
|
"""Get data from local storage only, no network requests."""
|
|
75
|
+
# If using memory storage, get from dictionary
|
|
76
|
+
if self.use_memory_storage:
|
|
77
|
+
return self.memory_storage.get(data_hash)
|
|
78
|
+
|
|
79
|
+
# Otherwise use file storage
|
|
57
80
|
file_path = self.storage_path / data_hash.hex()
|
|
58
81
|
if file_path.exists():
|
|
59
82
|
return file_path.read_bytes()
|
|
@@ -144,6 +167,8 @@ class Storage:
|
|
|
144
167
|
|
|
145
168
|
def contains(self, data_hash: bytes) -> bool:
|
|
146
169
|
"""Check if data exists in storage."""
|
|
170
|
+
if self.use_memory_storage:
|
|
171
|
+
return data_hash in self.memory_storage
|
|
147
172
|
return (self.storage_path / data_hash.hex()).exists()
|
|
148
173
|
|
|
149
174
|
def get_recursive(self, root_hash: bytes, max_depth: Optional[int] = None,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: astreum
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.12
|
|
4
4
|
Summary: Python library to interact with the Astreum blockchain and its Lispeum virtual machine.
|
|
5
5
|
Author-email: "Roy R. O. Okello" <roy@stelar.xyz>
|
|
6
6
|
Project-URL: Homepage, https://github.com/astreum/lib
|
|
@@ -20,8 +20,8 @@ astreum/lispeum/special/number/addition.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5
|
|
|
20
20
|
astreum/machine/__init__.py,sha256=GOdZl1tS9uIJHbq5WVcplifMDPDLQroX7CVew-K2YbA,15262
|
|
21
21
|
astreum/machine/environment.py,sha256=K0084U6B7wwjrDZ9b2_7cEcbBzsB7UOy_Zpbrr7B3GY,834
|
|
22
22
|
astreum/machine/error.py,sha256=MvqBaZZt33rNELNhUJ2lER3TE3aS8WVqsWF2hz2AwoA,38
|
|
23
|
-
astreum/node/__init__.py,sha256=
|
|
24
|
-
astreum/node/models.py,sha256=
|
|
23
|
+
astreum/node/__init__.py,sha256=EdGMa9pargAdB7KzjKBkhuFJ3G3wZF2VeIGkYFOCLws,22497
|
|
24
|
+
astreum/node/models.py,sha256=9Uf2_u55uxWG0ujjySvFJUO5Ub-EzlMnnMJWcgJHjHk,11980
|
|
25
25
|
astreum/node/relay/__init__.py,sha256=gQNYDxllkjZqE6bvgPOYkKu3QHkjPFn11RvtP-BxtKI,13994
|
|
26
26
|
astreum/node/relay/bucket.py,sha256=pcmollbbM-xeHlmDxLZnzvf0Ut-9v9RoN6SijYiQuu8,2893
|
|
27
27
|
astreum/node/relay/envelope.py,sha256=TfkynttoPX7smvMV7xEAdtIlfz-Z-EZjuhZ826csZxA,10078
|
|
@@ -30,8 +30,8 @@ astreum/node/relay/peer.py,sha256=DlvTR9j0BZQ1dW-p_9UGgfLvQqwNdpNLMSCYEW4FhyI,58
|
|
|
30
30
|
astreum/node/relay/route.py,sha256=fyOSsAe1mfsCVeN6LtQ_OEUEb1FiC5dobZBEJKNGU9U,5814
|
|
31
31
|
astreum/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
32
|
astreum/utils/bytes_format.py,sha256=X4tG5GGPweNCE54bHYkLFiuLTbmpy5upO_s1Cef-MGA,2711
|
|
33
|
-
astreum-0.1.
|
|
34
|
-
astreum-0.1.
|
|
35
|
-
astreum-0.1.
|
|
36
|
-
astreum-0.1.
|
|
37
|
-
astreum-0.1.
|
|
33
|
+
astreum-0.1.12.dist-info/LICENSE,sha256=gYBvRDP-cPLmTyJhvZ346QkrYW_eleke4Z2Yyyu43eQ,1089
|
|
34
|
+
astreum-0.1.12.dist-info/METADATA,sha256=LnGyI9YKLRNRWLolnyuHDgg0MKPSyLSwJho4FCTg1to,2942
|
|
35
|
+
astreum-0.1.12.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
|
36
|
+
astreum-0.1.12.dist-info/top_level.txt,sha256=1EG1GmkOk3NPmUA98FZNdKouhRyget-KiFiMk0i2Uz0,8
|
|
37
|
+
astreum-0.1.12.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|