astreum 0.2.29__py3-none-any.whl → 0.2.61__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 (58) hide show
  1. astreum/__init__.py +9 -1
  2. astreum/_communication/__init__.py +11 -0
  3. astreum/{models → _communication}/message.py +101 -64
  4. astreum/_communication/peer.py +23 -0
  5. astreum/_communication/ping.py +33 -0
  6. astreum/_communication/route.py +95 -0
  7. astreum/_communication/setup.py +322 -0
  8. astreum/_communication/util.py +42 -0
  9. astreum/_consensus/__init__.py +20 -0
  10. astreum/_consensus/account.py +95 -0
  11. astreum/_consensus/accounts.py +38 -0
  12. astreum/_consensus/block.py +311 -0
  13. astreum/_consensus/chain.py +66 -0
  14. astreum/_consensus/fork.py +100 -0
  15. astreum/_consensus/genesis.py +72 -0
  16. astreum/_consensus/receipt.py +136 -0
  17. astreum/_consensus/setup.py +115 -0
  18. astreum/_consensus/transaction.py +215 -0
  19. astreum/_consensus/workers/__init__.py +9 -0
  20. astreum/_consensus/workers/discovery.py +48 -0
  21. astreum/_consensus/workers/validation.py +125 -0
  22. astreum/_consensus/workers/verify.py +63 -0
  23. astreum/_lispeum/__init__.py +16 -0
  24. astreum/_lispeum/environment.py +13 -0
  25. astreum/_lispeum/expression.py +190 -0
  26. astreum/_lispeum/high_evaluation.py +236 -0
  27. astreum/_lispeum/low_evaluation.py +123 -0
  28. astreum/_lispeum/meter.py +18 -0
  29. astreum/_lispeum/parser.py +51 -0
  30. astreum/_lispeum/tokenizer.py +22 -0
  31. astreum/_node.py +198 -0
  32. astreum/_storage/__init__.py +7 -0
  33. astreum/_storage/atom.py +109 -0
  34. astreum/_storage/patricia.py +478 -0
  35. astreum/_storage/setup.py +35 -0
  36. astreum/models/block.py +48 -39
  37. astreum/node.py +755 -563
  38. astreum/utils/bytes.py +24 -0
  39. astreum/utils/integer.py +25 -0
  40. astreum/utils/logging.py +219 -0
  41. {astreum-0.2.29.dist-info → astreum-0.2.61.dist-info}/METADATA +50 -14
  42. astreum-0.2.61.dist-info/RECORD +57 -0
  43. astreum/lispeum/__init__.py +0 -2
  44. astreum/lispeum/environment.py +0 -40
  45. astreum/lispeum/expression.py +0 -86
  46. astreum/lispeum/parser.py +0 -41
  47. astreum/lispeum/tokenizer.py +0 -52
  48. astreum/models/account.py +0 -91
  49. astreum/models/accounts.py +0 -34
  50. astreum/models/transaction.py +0 -106
  51. astreum/relay/__init__.py +0 -0
  52. astreum/relay/peer.py +0 -9
  53. astreum/relay/route.py +0 -25
  54. astreum/relay/setup.py +0 -58
  55. astreum-0.2.29.dist-info/RECORD +0 -33
  56. {astreum-0.2.29.dist-info → astreum-0.2.61.dist-info}/WHEEL +0 -0
  57. {astreum-0.2.29.dist-info → astreum-0.2.61.dist-info}/licenses/LICENSE +0 -0
  58. {astreum-0.2.29.dist-info → astreum-0.2.61.dist-info}/top_level.txt +0 -0
astreum/models/block.py CHANGED
@@ -4,8 +4,8 @@ from threading import Thread
4
4
  from typing import List, Dict, Any, Optional, Union
5
5
 
6
6
  from astreum.crypto.wesolowski import vdf_generate, vdf_verify
7
- from astreum.models.account import Account
8
- from astreum.models.accounts import Accounts
7
+ from astreum._consensus.account import Account
8
+ from astreum._consensus.accounts import Accounts
9
9
  from astreum.models.patricia import PatriciaTrie
10
10
  from astreum.models.transaction import Transaction
11
11
  from ..crypto import ed25519
@@ -32,7 +32,7 @@ class Block:
32
32
  accounts: Optional[Accounts] = None,
33
33
  transaction_limit: Optional[int] = None,
34
34
  transactions_total_fees: Optional[int] = None,
35
- transactions_root_hash: Optional[bytes] = None,
35
+ transactions_hash: Optional[bytes] = None,
36
36
  transactions_count: Optional[int] = None,
37
37
  delay_difficulty: Optional[int] = None,
38
38
  delay_output: Optional[bytes] = None,
@@ -49,14 +49,14 @@ class Block:
49
49
  self.accounts = accounts
50
50
  self.transaction_limit = transaction_limit
51
51
  self.transactions_total_fees = transactions_total_fees
52
- self.transactions_root_hash = transactions_root_hash
52
+ self.transactions_hash = transactions_hash
53
53
  self.transactions_count = transactions_count
54
54
  self.delay_difficulty = delay_difficulty
55
55
  self.delay_output = delay_output
56
- self.delay_proof = delay_proof
57
- self.validator_pk = validator_pk
58
- self.body_tree = body_tree
59
- self.signature = signature
56
+ self.delay_proof = delay_proof
57
+ self.validator_pk = validator_pk
58
+ self.body_tree = body_tree
59
+ self.signature = signature
60
60
 
61
61
  @property
62
62
  def hash(self) -> bytes:
@@ -68,11 +68,20 @@ class Block:
68
68
  raise ValueError("Body tree not available for this block instance.")
69
69
  return self._body_tree.root_hash
70
70
 
71
- def get_signature(self) -> bytes:
72
- """Return the block's signature leaf."""
73
- if self._signature is None:
74
- raise ValueError("Signature not available for this block instance.")
75
- return self._signature
71
+ def get_signature(self) -> bytes:
72
+ """Return the block's signature leaf."""
73
+ if self._signature is None:
74
+ raise ValueError("Signature not available for this block instance.")
75
+ return self._signature
76
+
77
+ # Backwards/forwards alias for clarity with external specs
78
+ @property
79
+ def validator_public_key(self) -> Optional[bytes]:
80
+ return self.validator_pk
81
+
82
+ @validator_public_key.setter
83
+ def validator_public_key(self, value: Optional[bytes]) -> None:
84
+ self.validator_pk = value
76
85
 
77
86
  def get_field(self, name: str) -> Union[int, bytes]:
78
87
  """Query a single body field by name, returning an int or bytes."""
@@ -94,9 +103,9 @@ class Block:
94
103
  stake_root = stake_trie.root_hash
95
104
 
96
105
  # 2. three Account bodies
97
- validator_acct = Account.create(balance=0, data=b"", nonce=0)
98
- treasury_acct = Account.create(balance=1, data=stake_root, nonce=0)
99
- burn_acct = Account.create(balance=0, data=b"", nonce=0)
106
+ validator_acct = Account.create(balance=0, data=b"", counter=0)
107
+ treasury_acct = Account.create(balance=1, data=stake_root, counter=0)
108
+ burn_acct = Account.create(balance=0, data=b"", counter=0)
100
109
 
101
110
  # 3. global Accounts structure
102
111
  accts = Accounts()
@@ -116,7 +125,7 @@ class Block:
116
125
  accounts = accts,
117
126
  transactions_total_fees = 0,
118
127
  transaction_limit = 1,
119
- transactions_root_hash = b"\x00" * 32,
128
+ transactions_hash = b"\x00" * 32,
120
129
  transactions_count = 0,
121
130
  delay_difficulty = 1,
122
131
  delay_output = b"",
@@ -181,7 +190,7 @@ class Block:
181
190
 
182
191
  def _credit(addr: bytes, amt: int):
183
192
  acc = blk.accounts.get_account(addr) or Account.create(0, b"", 0)
184
- blk.accounts.set_account(addr, Account.create(acc.balance() + amt, acc.data(), acc.nonce()))
193
+ blk.accounts.set_account(addr, Account.create(acc.balance + amt, acc.data, acc.counter))
185
194
 
186
195
  if burn_amt:
187
196
  _credit(BURN, burn_amt)
@@ -210,7 +219,7 @@ class Block:
210
219
  # ------------------ timing & roots ----------------------------------
211
220
  blk.block_time = blk.timestamp - previous_block.timestamp
212
221
  blk.accounts_hash = blk.accounts.root_hash
213
- blk.transactions_root_hash = MerkleTree.from_leaves(blk.tx_hashes).root_hash
222
+ blk.transactions_hash = MerkleTree.from_leaves(blk.tx_hashes).root_hash
214
223
  blk.transactions_total_fees = blk.total_fees
215
224
 
216
225
  # ------------------ build full body root ----------------------------
@@ -225,7 +234,7 @@ class Block:
225
234
  "timestamp": blk.timestamp,
226
235
  "transaction_limit": blk.transaction_limit,
227
236
  "transactions_count": blk.transactions_count,
228
- "transactions_root_hash": blk.transactions_root_hash,
237
+ "transactions_hash": blk.transactions_hash,
229
238
  "transactions_total_fees": blk.transactions_total_fees,
230
239
  "validator_pk": blk.validator_pk,
231
240
  }
@@ -271,17 +280,17 @@ class Block:
271
280
 
272
281
  sender_acct = self.accounts.get_account(sender_pk)
273
282
  if (sender_acct is None
274
- or sender_acct.nonce() != nonce
275
- or sender_acct.balance() < amount + fee):
283
+ or sender_acct.counter != nonce
284
+ or sender_acct.balance < amount + fee):
276
285
  raise ValueError("invalid or unaffordable transaction")
277
286
 
278
287
  # --- debit sender --------------------------------------------------
279
288
  self.accounts.set_account(
280
289
  sender_pk,
281
290
  Account.create(
282
- balance=sender_acct.balance() - amount - fee,
283
- data=sender_acct.data(),
284
- nonce=sender_acct.nonce() + 1,
291
+ balance=sender_acct.balance - amount - fee,
292
+ data=sender_acct.data,
293
+ counter=sender_acct.counter + 1,
285
294
  )
286
295
  )
287
296
 
@@ -289,14 +298,14 @@ class Block:
289
298
  if recip_pk == TREASURY:
290
299
  treasury = self.accounts.get_account(TREASURY)
291
300
 
292
- trie = PatriciaTrie(node_get=None, root_hash=treasury.data())
301
+ trie = PatriciaTrie(node_get=None, root_hash=treasury.data)
293
302
  stake_bytes = trie.get(sender_pk) or b""
294
303
  current_stake = int.from_bytes(stake_bytes, "big") if stake_bytes else 0
295
304
 
296
305
  if amount > 0:
297
306
  # stake **deposit**
298
307
  trie.put(sender_pk, (current_stake + amount).to_bytes(32, "big"))
299
- new_treas_bal = treasury.balance() + amount
308
+ new_treas_bal = treasury.balance + amount
300
309
  else:
301
310
  # stake **withdrawal**
302
311
  if current_stake == 0:
@@ -306,13 +315,13 @@ class Block:
306
315
  self.accounts.set_account(
307
316
  sender_pk,
308
317
  Account.create(
309
- balance=sender_after.balance() + current_stake,
310
- data=sender_after.data(),
311
- nonce=sender_after.nonce(),
318
+ balance=sender_after.balance + current_stake,
319
+ data=sender_after.data,
320
+ counter=sender_after.counter,
312
321
  )
313
322
  )
314
323
  trie.delete(sender_pk)
315
- new_treas_bal = treasury.balance() # treasury balance unchanged
324
+ new_treas_bal = treasury.balance # treasury balance unchanged
316
325
 
317
326
  # write back treasury with new trie root
318
327
  self.accounts.set_account(
@@ -320,7 +329,7 @@ class Block:
320
329
  Account.create(
321
330
  balance=new_treas_bal,
322
331
  data=trie.root_hash,
323
- nonce=treasury.nonce(),
332
+ counter=treasury.counter,
324
333
  )
325
334
  )
326
335
 
@@ -329,9 +338,9 @@ class Block:
329
338
  self.accounts.set_account(
330
339
  recip_pk,
331
340
  Account.create(
332
- balance=recip_acct.balance() + amount,
333
- data=recip_acct.data(),
334
- nonce=recip_acct.nonce(),
341
+ balance=recip_acct.balance + amount,
342
+ data=recip_acct.data,
343
+ counter=recip_acct.counter,
335
344
  )
336
345
  )
337
346
 
@@ -353,7 +362,7 @@ class Block:
353
362
  f_names = (
354
363
  "accounts_hash","block_time","delay_difficulty","delay_output","delay_proof",
355
364
  "number","prev_block_hash","timestamp","transaction_limit",
356
- "transactions_count","transactions_root_hash","transactions_total_fees",
365
+ "transactions_count","transactions_hash","transactions_total_fees",
357
366
  "validator_pk",
358
367
  )
359
368
  leaves = [
@@ -382,8 +391,8 @@ class Block:
382
391
  # ---------- 4. replay all txs -------------------------------------
383
392
  accs = Accounts(root_hash=prev_blk.get_field("accounts_hash"),
384
393
  node_get=remote_get_fn)
385
- tx_mt = MerkleTree(node_get=remote_get_fn,
386
- root_hash=self.transactions_root_hash)
394
+ tx_mt = MerkleTree(node_get=remote_get_fn,
395
+ root_hash=self.transactions_hash)
387
396
  if tx_mt.leaf_count() != self.transactions_count:
388
397
  raise ValueError("transactions_count mismatch")
389
398
 
@@ -408,7 +417,7 @@ class Block:
408
417
  v_acct = dummy.accounts.get_account(self.validator_pk) or Account.create(0,b"",0)
409
418
  dummy.accounts.set_account(
410
419
  self.validator_pk,
411
- Account.create(v_acct.balance()+rew, v_acct.data(), v_acct.nonce())
420
+ Account.create(v_acct.balance+rew, v_acct.data, v_acct.counter)
412
421
  )
413
422
 
414
423
  if dummy.accounts.root_hash != self.accounts_hash: