Skip to content

Commit

Permalink
Follower.unimported_orphans: ensure no orphans from same branch
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrusu committed Mar 21, 2024
1 parent 7de1929 commit 984a954
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions cryptarchia/cryptarchia.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,7 @@ def __init__(self, genesis_state: LedgerState, config: Config):
self.local_chain = Chain([], genesis=genesis_state.block)
self.genesis_state = genesis_state
self.ledger_state = {genesis_state.block: genesis_state.copy()}
self.epoch_state = {
(Epoch(0), genesis_state.block): EpochState(
stake_distribution_snapshot=genesis_state,
nonce_snapshot=genesis_state,
inferred_total_stake=config.initial_total_stake,
)
}
self.epoch_state = {}

def validate_header(self, block: BlockHeader, chain: Chain) -> bool:
# TODO: verify blocks are not in the 'future'
Expand Down Expand Up @@ -526,15 +520,20 @@ def on_block(self, block: BlockHeader):
new_state.apply(block)
self.ledger_state[block.id()] = new_state

def unimported_orphans(self, parent: Id) -> list[BlockHeader]:
def unimported_orphans(self, tip: Id) -> list[BlockHeader]:
"""
Returns all unimported orphans w.r.t. the given parent state.
Returns all unimported orphans w.r.t. the given tip's state.
Orphans are returned in the order that they should be imported.
"""
tip_state = self.ledger_state[parent].copy()
tip_state = self.ledger_state[tip].copy()

orphans = []
for fork in [self.local_chain, *self.forks]:
if fork.block_position(tip) is not None:
# the tip is a member of this fork, it doesn't make sense
# to take orphans from this fork as they are all already "imported"
continue

for block in fork.blocks:
for b in [*block.orphaned_proofs, block]:
if b.leader_proof.nullifier not in tip_state.nullifiers:
Expand Down

0 comments on commit 984a954

Please sign in to comment.