mirror of
https://github.com/logos-blockchain/logos-blockchain-specs.git
synced 2026-01-02 13:13:06 +00:00
Fix LIB calculations with short chain (#128)
Fix LIB calculation where the chain is shorter than K and add a regression test for this case
This commit is contained in:
parent
30ef110f24
commit
89dd2efacb
@ -401,7 +401,7 @@ class Follower:
|
||||
return
|
||||
# prune forks that do not descend from the last immutable block, this is needed to avoid Genesis rule to roll back
|
||||
# past the LIB
|
||||
self.lib = next(islice(iter_chain(self.local_chain, self.ledger_state), self.config.k, None), self.local_chain).block.id()
|
||||
self.lib = next(islice(iter_chain(self.local_chain, self.ledger_state), self.config.k, None), self.genesis_state).block.id()
|
||||
self.forks = [
|
||||
f for f in self.forks if is_ancestor(self.lib, f, self.ledger_state)
|
||||
]
|
||||
|
||||
@ -374,3 +374,26 @@ class TestForkChoice(TestCase):
|
||||
|
||||
assert follower.tip_id() == b12.id()
|
||||
assert follower.lib == b7.id(), follower.lib
|
||||
|
||||
def test_lib_calc_short_chain(self):
|
||||
# Test that the LIB is correctly calculated for a short chain
|
||||
n_a = Note(sk=0, value=10)
|
||||
notes = [n_a]
|
||||
config = mk_config(notes)
|
||||
config.k = 10
|
||||
genesis = mk_genesis_state(notes)
|
||||
follower = Follower(genesis, config)
|
||||
follower.to_online()
|
||||
|
||||
assert follower.lib == genesis.block.id(), follower.lib
|
||||
blocks = [genesis.block]
|
||||
for i in range(1, 11):
|
||||
b = mk_block(blocks[-1], i, n_a)
|
||||
blocks.append(b)
|
||||
follower.on_block(b)
|
||||
assert follower.lib == genesis.block.id(), follower.lib
|
||||
|
||||
b11 = mk_block(blocks[-1], 11, n_a)
|
||||
follower.on_block(b11)
|
||||
|
||||
assert follower.lib == blocks[1].id(), follower.lib
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user