cryptarchia: remove height from ledger state

This commit is contained in:
David Rusu 2024-11-02 00:08:08 +04:00
parent 9eabadd22d
commit 55da6dd79d
2 changed files with 6 additions and 9 deletions

View File

@ -211,7 +211,6 @@ class BlockHeader:
content_size: int
content_id: Id
leader_proof: MockLeaderProof
orphaned_proofs: List["BlockHeader"] = field(default_factory=list)
def __post_init__(self):
@ -291,7 +290,6 @@ class LedgerState:
# The number of observed leaders (blocks + orphans), this measurement is
# used in inferring total active stake in the network.
leader_count: int = 0
height: int = 0
def copy(self):
return LedgerState(
@ -329,8 +327,6 @@ class LedgerState:
for proof in itertools.chain(block.orphaned_proofs, [block]):
self.apply_leader_proof(proof.leader_proof)
self.height += 1
def apply_leader_proof(self, proof: MockLeaderProof):
self.nullifiers.add(proof.nullifier)
self.commitments_spend.add(proof.evolved_commitment)

View File

@ -2,7 +2,7 @@ from unittest import TestCase
import numpy as np
from .cryptarchia import Follower, Coin
from .cryptarchia import Follower, Coin, iter_chain
from .test_common import mk_config, mk_block, mk_genesis_state
@ -18,12 +18,13 @@ class TestLedgerStateUpdate(TestCase):
follower.on_block(block)
# Follower should have accepted the block
assert follower.tip_state().height == 1
assert len(list(iter_chain(follower.tip_id(), follower.ledger_state))) == 2
assert follower.tip() == block
follower.on_block(block)
assert follower.tip_state().height == 1
# Should have been a No-op
assert len(list(iter_chain(follower.tip_id(), follower.ledger_state))) == 2
assert follower.tip() == block
assert len(follower.ledger_state) == 2
assert len(follower.forks) == 0
@ -38,7 +39,7 @@ class TestLedgerStateUpdate(TestCase):
follower.on_block(block)
# Follower should have accepted the block
assert follower.tip_state().height == 1
assert len(list(iter_chain(follower.tip_id(), follower.ledger_state))) == 2
assert follower.tip() == block
# Follower should have updated their ledger state to mark the leader coin as spent
@ -48,7 +49,7 @@ class TestLedgerStateUpdate(TestCase):
follower.on_block(reuse_coin_block)
# Follower should *not* have accepted the block
assert follower.tip_state().height == 1
assert len(list(iter_chain(follower.tip_id(), follower.ledger_state))) == 2
assert follower.tip() == block
def test_ledger_state_is_properly_updated_on_reorg(self):