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

Store correct block ID when switching forks #938

Merged
merged 4 commits into from
May 24, 2018
Merged

Conversation

abitmore
Copy link
Member

Related to #831 .

Copy link
Contributor

@jmjatlanta jmjatlanta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find. Are there tests that exercise forking, switching forks, etc? Can a test be developed to demonstrate this issue?

Update: Found it... block_tests::fork_blocks

@oxarbitrage oxarbitrage self-requested a review May 22, 2018 16:16
@pmconrad
Copy link
Contributor

Looks good. @jmjatlanta are you working on a test case?

@oxarbitrage
Copy link
Member

added some dumps at @abitmore code to see the difference and running block_tests::fork_blocks.

as can be seen, the new_block.id is always the same while (*ritr)->id goes changing.

3493398ms th_a       db_management.cpp:153         open                 ] Wiping object_database due to missing or wrong version
3493398ms th_a       object_database.cpp:93        wipe                 ] Wiping object database...
3493398ms th_a       object_database.cpp:95        wipe                 ] Done wiping object databse.
3493398ms th_a       object_database.cpp:106       open                 ] Opening object database from /tmp/graphene-tmp/6763-dedd-4834-4478 ...
3493398ms th_a       object_database.cpp:111       open                 ] Done opening object database.
3493410ms th_a       db_block.cpp:145              _push_block          ] Switching to fork: 0000000ec1a5fb3af98a58ae947eab44eb16e512
3493410ms th_a       db_block.cpp:155              _push_block          ] pushing blocks from fork 11 0000000b93898f176395f57845e7b356eb55b2db
3493410ms th_a       db_block.cpp:160              _push_block          ] new_block.id(): 0000000ec1a5fb3af98a58ae947eab44eb16e512 
3493410ms th_a       db_block.cpp:161              _push_block          ] (*ritr)->id: 0000000b93898f176395f57845e7b356eb55b2db 
3493410ms th_a       db_block.cpp:155              _push_block          ] pushing blocks from fork 12 0000000cfae33417202ce7ad1745b45c393aaca1
3493410ms th_a       db_block.cpp:160              _push_block          ] new_block.id(): 0000000ec1a5fb3af98a58ae947eab44eb16e512 
3493410ms th_a       db_block.cpp:161              _push_block          ] (*ritr)->id: 0000000cfae33417202ce7ad1745b45c393aaca1 
3493410ms th_a       db_block.cpp:155              _push_block          ] pushing blocks from fork 13 0000000d3dee6e52208fff4bebcf43e3a5c32da5
3493410ms th_a       db_block.cpp:160              _push_block          ] new_block.id(): 0000000ec1a5fb3af98a58ae947eab44eb16e512 
3493410ms th_a       db_block.cpp:161              _push_block          ] (*ritr)->id: 0000000d3dee6e52208fff4bebcf43e3a5c32da5 
3493410ms th_a       db_block.cpp:155              _push_block          ] pushing blocks from fork 14 0000000ec1a5fb3af98a58ae947eab44eb16e512
3493410ms th_a       db_block.cpp:168              _push_block          ] exception thrown while switching forks 10 assert_exception: Assert Exception
(skip & skip_merkle_check) || next_block.transaction_merkle_root == next_block.calculate_merkle_root(): 
    {"next_block.transaction_merkle_root":"0000000000000000000000000000000000000000","calc":"e6168d22cd56ae5854c8761377666cbf3bbbd554","next_block":{"previous":"0000000d3dee6e52208fff4bebcf43e3a5c32da5","timestamp":"2015-05-15T14:28:15","witness":"1.6.3","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"1f02c7e22da709666e48ff63924bc1c5116368f036704911c0b4f36f9a918e13806d2a907e45e04e0f188f6e175e80c764dfb17a5a10e3db9620411953efdc966e","transactions":[{"ref_block_num":0,"ref_block_prefix":0,"expiration":"1970-01-01T00:00:00","operations":[[0,{"fee":{"amount":0,"asset_id":"1.3.0"},"from":"1.2.0","to":"1.2.0","amount":{"amount":0,"asset_id":"1.3.0"},"extensions":[]}]],"extensions":[],"signatures":[],"operation_results":[]}]},"id":"0000000ec1a5fb3af98a58ae947eab44eb16e512"}
    th_a  db_block.cpp:495 _apply_block

    {"next_block.block_num()":14}
    th_a  db_block.cpp:547 _apply_block
3493411ms th_a       db_block.cpp:145              _push_block          ] Switching to fork: 0000000ec1a5fb3af98a58ae947eab44eb16e512
3493411ms th_a       db_block.cpp:155              _push_block          ] pushing blocks from fork 11 0000000b93898f176395f57845e7b356eb55b2db
3493411ms th_a       db_block.cpp:160              _push_block          ] new_block.id(): 0000000ec1a5fb3af98a58ae947eab44eb16e512 
3493411ms th_a       db_block.cpp:161              _push_block          ] (*ritr)->id: 0000000b93898f176395f57845e7b356eb55b2db 
3493411ms th_a       db_block.cpp:155              _push_block          ] pushing blocks from fork 12 0000000cfae33417202ce7ad1745b45c393aaca1
3493411ms th_a       db_block.cpp:160              _push_block          ] new_block.id(): 0000000ec1a5fb3af98a58ae947eab44eb16e512 
3493411ms th_a       db_block.cpp:161              _push_block          ] (*ritr)->id: 0000000cfae33417202ce7ad1745b45c393aaca1 
3493411ms th_a       db_block.cpp:155              _push_block          ] pushing blocks from fork 13 0000000d3dee6e52208fff4bebcf43e3a5c32da5
3493412ms th_a       db_block.cpp:160              _push_block          ] new_block.id(): 0000000ec1a5fb3af98a58ae947eab44eb16e512 
3493412ms th_a       db_block.cpp:161              _push_block          ] (*ritr)->id: 0000000d3dee6e52208fff4bebcf43e3a5c32da5 
3493412ms th_a       db_block.cpp:155              _push_block          ] pushing blocks from fork 14 0000000ec1a5fb3af98a58ae947eab44eb16e512
3493412ms th_a       db_block.cpp:160              _push_block          ] new_block.id(): 0000000ec1a5fb3af98a58ae947eab44eb16e512 
3493412ms th_a       db_block.cpp:161              _push_block          ] (*ritr)->id: 0000000ec1a5fb3af98a58ae947eab44eb16e512 

*** No errors detected
root@oxarbitrage ~/bitshares/dev/pull938/bitshares-core # ./tests/chain_test -t block_tests/fork_blocks

i think this is the expected behavior, please check and confirm.

@jmjatlanta
Copy link
Contributor

I was not working on a test case, but I will.

{
fc::optional<signed_block> curr_block = db1.fetch_block_by_number( curr_block_num );
BOOST_CHECK( curr_block.valid() );
BOOST_CHECK_EQUAL( curr_block->previous, previous_block->id() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should fail with the old code, but is not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetch_block_by_number here will read data from _fork_db, thus will pass the check.

I think we can add more tests in the end: close db, reopen db, run this check again.

Copy link
Contributor

@jmjatlanta jmjatlanta May 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, the original problem still does not show up. I haven't dug too deeply, but I'm guessing the reindexing that happens when the database opens fixes things.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, reopen at this point doesn't work. Try generate 30 more blocks to push the 2 blocks out of fork_db.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, seems due to empty blocks. I'm trying to update the test case.

Copy link
Member Author

@abitmore abitmore May 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comment earlier about empty block is incorrect.

Actually PUSH_BLOCK( db1, good_block ); made all blocks stored in db1 correct. I'm trying to reproduce.

@abitmore abitmore requested a review from jmjatlanta May 24, 2018 11:49
@abitmore
Copy link
Member Author

@pmconrad @jmjatlanta @oxarbitrage test case fixed, please review again.

Copy link
Contributor

@pmconrad pmconrad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants