-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cryptarchia: fix try_create_fork to find parent block #84
Conversation
cryptarchia/cryptarchia.py
Outdated
if chain.contains_block(block): | ||
block_position = chain.block_position(block) | ||
block_position = chain.block_position(block.parent) | ||
if block_position != -1: | ||
return Chain( | ||
blocks=chain.blocks[:block_position], | ||
blocks=chain.blocks[: block_position + 1], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch, our tests weren't catching this? 😨
I was actually just writing some simulation tests over the weekend for the new total stake inference protocol and saw that different nodes ended up with a different number of LedgerStates at the end of the simulation. I didn't get to debugging that yet but I think this bug might be why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davidrusu @zeegomo I just added a test that covers all cases of fork creation. 2460827
Previously, this case hasn't been caught by tests because we've only tested the case which a fork is created from the genesis block, not from the middle of the chain.
def test_ledger_state_is_properly_updated_on_reorg(self): |
With the previous implementation, the test I added is failed as below:
test_fork_creation (cryptarchia.test_ledger_state_update.TestLedgerStateUpdate.test_fork_creation) ... FAIL
======================================================================
FAIL: test_fork_creation (cryptarchia.test_ledger_state_update.TestLedgerStateUpdate.test_fork_creation)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/rei/repos/nomos-specs/cryptarchia/test_ledger_state_update.py", line 112, in test_fork_creation
assert len(follower.forks) == 2, f"{len(follower.forks)}"
AssertionError: 1
----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (failures=1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to add a test to verify that forks are created correctly?
Sure. I'll add tests in this PR soon and re-request your review! |
Good catch, concerning that it was not caught by tests |
792316f
to
2460827
Compare
It seems that we should find the position of the "parent" of the block to be added when trying to create a fork, but the current implementation finds the position of the "block" to be added.
Please correct me if I'm wrong.