astreum 0.2.40__py3-none-any.whl → 0.2.42__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/_consensus/__init__.py +4 -0
- astreum/_consensus/account.py +95 -0
- astreum/_consensus/accounts.py +38 -0
- astreum/_consensus/block.py +9 -2
- astreum/_consensus/chain.py +65 -65
- astreum/_consensus/fork.py +99 -99
- astreum/_consensus/genesis.py +141 -0
- astreum/_consensus/receipt.py +11 -1
- astreum/_consensus/setup.py +15 -152
- astreum/_consensus/transaction.py +71 -23
- astreum/_consensus/workers/__init__.py +9 -0
- astreum/_consensus/workers/discovery.py +48 -0
- astreum/_consensus/workers/validation.py +122 -0
- astreum/_consensus/workers/verify.py +63 -0
- astreum/_storage/atom.py +24 -7
- astreum/models/block.py +22 -22
- astreum/node.py +755 -753
- astreum/utils/integer.py +25 -0
- {astreum-0.2.40.dist-info → astreum-0.2.42.dist-info}/METADATA +1 -1
- {astreum-0.2.40.dist-info → astreum-0.2.42.dist-info}/RECORD +23 -28
- astreum/lispeum/__init__.py +0 -0
- astreum/lispeum/environment.py +0 -40
- astreum/lispeum/expression.py +0 -86
- astreum/lispeum/parser.py +0 -41
- astreum/lispeum/tokenizer.py +0 -52
- astreum/models/account.py +0 -91
- astreum/models/accounts.py +0 -34
- astreum/models/transaction.py +0 -106
- astreum/relay/__init__.py +0 -0
- astreum/relay/peer.py +0 -9
- astreum/relay/route.py +0 -25
- astreum/relay/setup.py +0 -58
- {astreum-0.2.40.dist-info → astreum-0.2.42.dist-info}/WHEEL +0 -0
- {astreum-0.2.40.dist-info → astreum-0.2.42.dist-info}/licenses/LICENSE +0 -0
- {astreum-0.2.40.dist-info → astreum-0.2.42.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.
|
|
8
|
-
from astreum.
|
|
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
|
|
@@ -103,9 +103,9 @@ class Block:
|
|
|
103
103
|
stake_root = stake_trie.root_hash
|
|
104
104
|
|
|
105
105
|
# 2. three Account bodies
|
|
106
|
-
validator_acct = Account.create(balance=0, data=b"",
|
|
107
|
-
treasury_acct = Account.create(balance=1, data=stake_root,
|
|
108
|
-
burn_acct = Account.create(balance=0, data=b"",
|
|
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)
|
|
109
109
|
|
|
110
110
|
# 3. global Accounts structure
|
|
111
111
|
accts = Accounts()
|
|
@@ -190,7 +190,7 @@ class Block:
|
|
|
190
190
|
|
|
191
191
|
def _credit(addr: bytes, amt: int):
|
|
192
192
|
acc = blk.accounts.get_account(addr) or Account.create(0, b"", 0)
|
|
193
|
-
blk.accounts.set_account(addr, Account.create(acc.balance
|
|
193
|
+
blk.accounts.set_account(addr, Account.create(acc.balance + amt, acc.data, acc.counter))
|
|
194
194
|
|
|
195
195
|
if burn_amt:
|
|
196
196
|
_credit(BURN, burn_amt)
|
|
@@ -280,17 +280,17 @@ class Block:
|
|
|
280
280
|
|
|
281
281
|
sender_acct = self.accounts.get_account(sender_pk)
|
|
282
282
|
if (sender_acct is None
|
|
283
|
-
or sender_acct.
|
|
284
|
-
or sender_acct.balance
|
|
283
|
+
or sender_acct.counter != nonce
|
|
284
|
+
or sender_acct.balance < amount + fee):
|
|
285
285
|
raise ValueError("invalid or unaffordable transaction")
|
|
286
286
|
|
|
287
287
|
# --- debit sender --------------------------------------------------
|
|
288
288
|
self.accounts.set_account(
|
|
289
289
|
sender_pk,
|
|
290
290
|
Account.create(
|
|
291
|
-
balance=sender_acct.balance
|
|
292
|
-
data=sender_acct.data
|
|
293
|
-
|
|
291
|
+
balance=sender_acct.balance - amount - fee,
|
|
292
|
+
data=sender_acct.data,
|
|
293
|
+
counter=sender_acct.counter + 1,
|
|
294
294
|
)
|
|
295
295
|
)
|
|
296
296
|
|
|
@@ -298,14 +298,14 @@ class Block:
|
|
|
298
298
|
if recip_pk == TREASURY:
|
|
299
299
|
treasury = self.accounts.get_account(TREASURY)
|
|
300
300
|
|
|
301
|
-
trie = PatriciaTrie(node_get=None, root_hash=treasury.data
|
|
301
|
+
trie = PatriciaTrie(node_get=None, root_hash=treasury.data)
|
|
302
302
|
stake_bytes = trie.get(sender_pk) or b""
|
|
303
303
|
current_stake = int.from_bytes(stake_bytes, "big") if stake_bytes else 0
|
|
304
304
|
|
|
305
305
|
if amount > 0:
|
|
306
306
|
# stake **deposit**
|
|
307
307
|
trie.put(sender_pk, (current_stake + amount).to_bytes(32, "big"))
|
|
308
|
-
new_treas_bal = treasury.balance
|
|
308
|
+
new_treas_bal = treasury.balance + amount
|
|
309
309
|
else:
|
|
310
310
|
# stake **withdrawal**
|
|
311
311
|
if current_stake == 0:
|
|
@@ -315,13 +315,13 @@ class Block:
|
|
|
315
315
|
self.accounts.set_account(
|
|
316
316
|
sender_pk,
|
|
317
317
|
Account.create(
|
|
318
|
-
balance=sender_after.balance
|
|
319
|
-
data=sender_after.data
|
|
320
|
-
|
|
318
|
+
balance=sender_after.balance + current_stake,
|
|
319
|
+
data=sender_after.data,
|
|
320
|
+
counter=sender_after.counter,
|
|
321
321
|
)
|
|
322
322
|
)
|
|
323
323
|
trie.delete(sender_pk)
|
|
324
|
-
new_treas_bal = treasury.balance
|
|
324
|
+
new_treas_bal = treasury.balance # treasury balance unchanged
|
|
325
325
|
|
|
326
326
|
# write back treasury with new trie root
|
|
327
327
|
self.accounts.set_account(
|
|
@@ -329,7 +329,7 @@ class Block:
|
|
|
329
329
|
Account.create(
|
|
330
330
|
balance=new_treas_bal,
|
|
331
331
|
data=trie.root_hash,
|
|
332
|
-
|
|
332
|
+
counter=treasury.counter,
|
|
333
333
|
)
|
|
334
334
|
)
|
|
335
335
|
|
|
@@ -338,9 +338,9 @@ class Block:
|
|
|
338
338
|
self.accounts.set_account(
|
|
339
339
|
recip_pk,
|
|
340
340
|
Account.create(
|
|
341
|
-
balance=recip_acct.balance
|
|
342
|
-
data=recip_acct.data
|
|
343
|
-
|
|
341
|
+
balance=recip_acct.balance + amount,
|
|
342
|
+
data=recip_acct.data,
|
|
343
|
+
counter=recip_acct.counter,
|
|
344
344
|
)
|
|
345
345
|
)
|
|
346
346
|
|
|
@@ -417,7 +417,7 @@ class Block:
|
|
|
417
417
|
v_acct = dummy.accounts.get_account(self.validator_pk) or Account.create(0,b"",0)
|
|
418
418
|
dummy.accounts.set_account(
|
|
419
419
|
self.validator_pk,
|
|
420
|
-
Account.create(v_acct.balance
|
|
420
|
+
Account.create(v_acct.balance+rew, v_acct.data, v_acct.counter)
|
|
421
421
|
)
|
|
422
422
|
|
|
423
423
|
if dummy.accounts.root_hash != self.accounts_hash:
|