Skip to content
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

Merged
merged 3 commits into from
Mar 21, 2024

Conversation

youngjoon-lee
Copy link
Contributor

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.

@youngjoon-lee youngjoon-lee self-assigned this Mar 18, 2024
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],
Copy link
Contributor

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.

Copy link
Contributor Author

@youngjoon-lee youngjoon-lee Mar 19, 2024

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)

Copy link
Contributor

@davidrusu davidrusu left a 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?

@youngjoon-lee
Copy link
Contributor Author

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!

@zeegomo
Copy link
Contributor

zeegomo commented Mar 18, 2024

Good catch, concerning that it was not caught by tests

@youngjoon-lee youngjoon-lee force-pushed the cryptarchia-fix-fork-creation branch from 792316f to 2460827 Compare March 19, 2024 02:27
@youngjoon-lee youngjoon-lee merged commit 601598f into master Mar 21, 2024
1 check passed
@youngjoon-lee youngjoon-lee deleted the cryptarchia-fix-fork-creation branch March 21, 2024 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants