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

Improve startup time after crash #339

Merged
merged 12 commits into from
Sep 8, 2017
Merged

Conversation

pmconrad
Copy link
Contributor

Tl;dr: if during startup we have a (possibly old) object_database available, we should use it.

We have up to two on-disk representations of the blockchain state: the block log and the object_database. The object database can be reconstructed from the block log, this is what a "replay" does. A replay takes a long time, and this time is constantly growing. This PR is an attempt to mitigate that.

During startup, the application checks the availability and state of the on-disk representation. The old code applies some rather restrictive logic (object_database.head_block == block_log.last_block) to determine if the state from the object_database can be used. This prevents creating and using snapshots of the object_database.

The logic implemented by this PR is more natural, IMO:

  1. If we have an object_database, we should use it. Only if object_database.head_block > block_log.last_block we have an inconsistency (we cannot reconstruct that object_database from that block_log). In that case, treat the object_database as if it were absent.
  2. If we don't have an object_database, use genesis.
  3. From where we are now (genesis or object_database.head), replay all additional blocks from the block_log.
  4. If during step 3 we come across block_log.last - 10000 (an arbitrary number about 8 hours in the past), flush the object_database to disk, and continue. This snapshot will be available in the next restart, if the node crashes or does otherwise not exit cleanly.
  5. During step 3, at 50 blocks before block_log.last (another arbitrary number, about twice the number of active witnesses), switch from apply()ing blocks to push()ing blocks. This will populate the fork_database and enable switching to a different fork, if our block_log ends in a fork.

This change will greatly improve startup time for nodes, which will be particularly important ifwhen we experience another blockchain halt, like a couple of weeks ago.

…ional blocks in block_database

Fixed tests wrt db.open
Dont remove blocks from block db when popping blocks, handle edge case in replay wrt fork_db, adapted unit tests
@xeroc
Copy link
Member

xeroc commented Jul 30, 2017

The code is black magic for me, but the motives are great!! Please let's have this!

@oxarbitrage
Copy link
Member

very needed, i am in the process of test and review everything peter is submitting including this pull, we will definitely have this included with minor or no changes.
great work @pmconrad , having you actively developing in bitshares is the best that can happen to us.

@abitmore
Copy link
Member

abitmore commented Jul 30, 2017

Sounds great.

Will periodically flush cause lot's of IO, thus impact system performance and affect block processing/production?

//Update: it will only flush on startup during reindex, so it's ok.

skip_tapos_check |
skip_witness_schedule_check |
skip_authority_check);
}
}
_undo_db.enable();
Copy link
Member

Choose a reason for hiding this comment

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

This line need to be removed? We may have enabled it earlier. Also possible it hasn't been disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Strictly speaking yes, but it only sets a flag in undo_db. Doesn't hurt if it gets set more than once.

const auto last_block_num = last_block->block_num();
uint32_t flush_point = last_block_num - 10000;
uint32_t undo_point = last_block_num - 50;

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps need to check for Integer overflow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, but doesn't matter in practice IMO.
If last_block_num < 10000 then flush_point > MAX_INT-10000, which means we never flush. We don't lose much though, only the state from less than 10k blocks.
If last_block_num < 50 then undo_point > MAX_INT - 50, which means the fork_database isn't used during replay. But that is only a problem if your block_database ends in a fork, which is unlikely.

_undo_db.disable();
for( uint32_t i = 1; i <= last_block_num; ++i )
if( head_block_num() >= undo_point )
_fork_db.start_block( *fetch_block_by_number( head_block_num() ) );
Copy link
Member

Choose a reason for hiding this comment

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

This logic is a bit strange. I think we need to initialize _fork_db correctly before switching to push_block(). The start_block should be the block before the first push. Will it also be initialized in else?

Similar code in steem: abitmore/steem@77aaa00

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original code doesn't call _fork_db.start_block in all cases either. AFAICS fork_db uses the first pushed block as the start block if no start block has been set explicitly.

const auto last_block_num = last_block->block_num();
uint32_t flush_point = last_block_num - 10000;
uint32_t undo_point = last_block_num - 50;

ilog( "Replaying blocks..." );
Copy link
Member

Choose a reason for hiding this comment

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

Best if we have the start block number in the log.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add block number to the log message.

@wackou
Copy link
Contributor

wackou commented Jul 31, 2017

I cannot comment on the specifics of the code, but the logic seems sound and the importance of this cannot be understated. I especially like that you considered to add point 4., because I've had quite a few crashes when replaying (esp. towards the end), or had to ctrl+c a node replaying, and having to start replaying from scratch was really annoying. Great work!

@oxarbitrage oxarbitrage self-requested a review August 3, 2017 00:18
@oxarbitrage
Copy link
Member

reviewing this from the nodemaster point of view as i think it is a kick ass addition.

on an initial test i started to sync the chain and when it was starting 2017 i stopped it with 2 control-c. this will result in the tedious "unclean shutdown" that the patch is trying to avoid.

however when starting it back i am getting an error, pasting full output for reference:

root@NC-PH-1346-07:~/bitshares/issue339/bitshares-core# programs/witness_node/witness_node --data-dir data/my-blockprod --rpc-endpoint "127.0.0.1:8090" --max-ops-pe
r-account 100 --partial-operations true
1057725ms th_a       witness.cpp:88                plugin_initialize    ] witness plugin:  plugin_initialize() begin
1057725ms th_a       witness.cpp:99                plugin_initialize    ] Public Key: BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
1057725ms th_a       witness.cpp:117               plugin_initialize    ] witness plugin:  plugin_initialize() end
1057725ms th_a       object_database.cpp:101       open                 ] Opening object database from /root/bitshares/issue339/bitshares-core/data/my-blockprod/blo
ckchain ...
1066462ms th_a       object_database.cpp:107       open                 ] Done opening object database.
1066462ms th_a       db_management.cpp:59          reindex              ] reindexing blockchain
1066462ms th_a       db_management.cpp:65          reindex              ] Replaying blocks, starting at 1061499...
1066462ms th_a       db_management.cpp:175         open                 ] 3030007 insufficient_fee: insufficient fee
Insufficient Fee Paid
    {"core_fee_paid":3000000,"required":4000000}
    th_a  evaluator.hpp:156 evaluate

    {}
    th_a  evaluator.cpp:51 start_evaluate

    {"op":[0,{"fee":{"amount":3000000,"asset_id":"1.3.0"},"from":"1.2.91689","to":"1.2.22517","amount":{"amount":"5000000000","asset_id":"1.3.0"},"extensions":[]}]}
    th_a  db_block.cpp:645 apply_operation

    {"trx":{"ref_block_num":12922,"ref_block_prefix":3843669915,"expiration":"2015-11-19T18:05:51","operations":[[0,{"fee":{"amount":3000000,"asset_id":"1.3.0"},"fr
om":"1.2.91689","to":"1.2.22517","amount":{"amount":"5000000000","asset_id":"1.3.0"},"extensions":[]}]],"extensions":[],"signatures":["2027bda3e50585fca9d1726e153ec
2f37049daf9713d5b15852ccb6500ffee54e1716ba7d9aeb18b066c73417ad6e410fc14712aaf80a2712b209349599dc4dd56"]}}
    th_a  db_block.cpp:628 _apply_transaction

    {"next_block.block_num()":1061499}
    th_a  db_block.cpp:545 _apply_block

    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:123 reindex
1066462ms th_a       db_management.cpp:175         open                 ] data_dir: /root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain 
1066462ms th_a       application.cpp:400           startup              ] Caught exception 3030007 insufficient_fee: insufficient fee
Insufficient Fee Paid
    {"core_fee_paid":3000000,"required":4000000}
    th_a  evaluator.hpp:156 evaluate

    {}
    th_a  evaluator.cpp:51 start_evaluate

    {"op":[0,{"fee":{"amount":3000000,"asset_id":"1.3.0"},"from":"1.2.91689","to":"1.2.22517","amount":{"amount":"5000000000","asset_id":"1.3.0"},"extensions":[]}]}
    th_a  db_block.cpp:645 apply_operation

    {"trx":{"ref_block_num":12922,"ref_block_prefix":3843669915,"expiration":"2015-11-19T18:05:51","operations":[[0,{"fee":{"amount":3000000,"asset_id":"1.3.0"},"fr
om":"1.2.91689","to":"1.2.22517","amount":{"amount":"5000000000","asset_id":"1.3.0"},"extensions":[]}]],"extensions":[],"signatures":["2027bda3e50585fca9d1726e153ec
2f37049daf9713d5b15852ccb6500ffee54e1716ba7d9aeb18b066c73417ad6e410fc14712aaf80a2712b209349599dc4dd56"]}}
    th_a  db_block.cpp:628 _apply_transaction

    {"next_block.block_num()":1061499}
    th_a  db_block.cpp:545 _apply_block

    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:123 reindex
rethrow
    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:175 open in open(), you might want to force a replay
1066462ms th_a       application.cpp:444           startup              ] 3030007 insufficient_fee: insufficient fee
Insufficient Fee Paid
    {"core_fee_paid":3000000,"required":4000000}
    th_a  evaluator.hpp:156 evaluate

    {}
    th_a  evaluator.cpp:51 start_evaluate

    {"op":[0,{"fee":{"amount":3000000,"asset_id":"1.3.0"},"from":"1.2.91689","to":"1.2.22517","amount":{"amount":"5000000000","asset_id":"1.3.0"},"extensions":[]}]}
    th_a  db_block.cpp:645 apply_operation

    {"trx":{"ref_block_num":12922,"ref_block_prefix":3843669915,"expiration":"2015-11-19T18:05:51","operations":[[0,{"fee":{"amount":3000000,"asset_id":"1.3.0"},"fr
om":"1.2.91689","to":"1.2.22517","amount":{"amount":"5000000000","asset_id":"1.3.0"},"extensions":[]}]],"extensions":[],"signatures":["2027bda3e50585fca9d1726e153ec
2f37049daf9713d5b15852ccb6500ffee54e1716ba7d9aeb18b066c73417ad6e410fc14712aaf80a2712b209349599dc4dd56"]}}
    th_a  db_block.cpp:628 _apply_transaction

    {"next_block.block_num()":1061499}
    th_a  db_block.cpp:545 _apply_block

    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:123 reindex
rethrow
    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:175 open
1066463ms th_a       application.cpp:988           startup              ] 3030007 insufficient_fee: insufficient fee
Insufficient Fee Paid
    {"core_fee_paid":3000000,"required":4000000}
    th_a  evaluator.hpp:156 evaluate

    {}
    th_a  evaluator.cpp:51 start_evaluate

    {"op":[0,{"fee":{"amount":3000000,"asset_id":"1.3.0"},"from":"1.2.91689","to":"1.2.22517","amount":{"amount":"5000000000","asset_id":"1.3.0"},"extensions":[]}]}
    th_a  db_block.cpp:645 apply_operation

    {"trx":{"ref_block_num":12922,"ref_block_prefix":3843669915,"expiration":"2015-11-19T18:05:51","operations":[[0,{"fee":{"amount":3000000,"asset_id":"1.3.0"},"fr
om":"1.2.91689","to":"1.2.22517","amount":{"amount":"5000000000","asset_id":"1.3.0"},"extensions":[]}]],"extensions":[],"signatures":["2027bda3e50585fca9d1726e153ec
2f37049daf9713d5b15852ccb6500ffee54e1716ba7d9aeb18b066c73417ad6e410fc14712aaf80a2712b209349599dc4dd56"]}}
    th_a  db_block.cpp:628 _apply_transaction

    {"next_block.block_num()":1061499}
    th_a  db_block.cpp:545 _apply_block

    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:123 reindex
rethrow
    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:175 open
rethrow
    {}
    th_a  application.cpp:444 startup
1066463ms th_a       main.cpp:195                  main                 ] Exiting with error:
3030007 insufficient_fee: insufficient fee
Insufficient Fee Paid
    {"core_fee_paid":3000000,"required":4000000}
    th_a  evaluator.hpp:156 evaluate

    {}
    th_a  evaluator.cpp:51 start_evaluate

    {"op":[0,{"fee":{"amount":3000000,"asset_id":"1.3.0"},"from":"1.2.91689","to":"1.2.22517","amount":{"amount":"5000000000","asset_id":"1.3.0"},"extensions":[]}]}
    th_a  db_block.cpp:645 apply_operation

    {"trx":{"ref_block_num":12922,"ref_block_prefix":3843669915,"expiration":"2015-11-19T18:05:51","operations":[[0,{"fee":{"amount":3000000,"asset_id":"1.3.0"},"fr
om":"1.2.91689","to":"1.2.22517","amount":{"amount":"5000000000","asset_id":"1.3.0"},"extensions":[]}]],"extensions":[],"signatures":["2027bda3e50585fca9d1726e153ec
2f37049daf9713d5b15852ccb6500ffee54e1716ba7d9aeb18b066c73417ad6e410fc14712aaf80a2712b209349599dc4dd56"]}}
    th_a  db_block.cpp:628 _apply_transaction

    {"next_block.block_num()":1061499}
    th_a  db_block.cpp:545 _apply_block

    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:123 reindex
rethrow
    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:175 open
rethrow
    {}
    th_a  application.cpp:444 startup
1066463ms th_a       db_management.cpp:200         close                ] Database close unexpected exception: {"code":10,"name":"assert_exception","message":"Asser
t Exception","stack":[{"context":{"level":"error","file":"fork_database.cpp","line":41,"method":"pop_block","hostname":"","thread_name":"th_a","timestamp":"2017-08-
03T00:17:46"},"format":"_head: no blocks to pop","data":{}},{"context":{"level":"warn","file":"db_block.cpp","line":430,"method":"pop_block","hostname":"","thread_n
ame":"th_a","timestamp":"2017-08-03T00:17:46"},"format":"","data":{}}]}
1066952ms th_a       db_management.cpp:200         close                ] Database close unexpected exception: {"code":3070001,"name":"pop_empty_chain","message":"t
here are no blocks to pop","stack":[{"context":{"level":"error","file":"db_block.cpp","line":423,"method":"pop_block","hostname":"","thread_name":"th_a","timestamp"
:"2017-08-03T00:17:46"},"format":"there are no blocks to pop","data":{}},{"context":{"level":"warn","file":"db_block.cpp","line":430,"method":"pop_block","hostname"
:"","thread_name":"th_a","timestamp":"2017-08-03T00:17:46"},"format":"","data":{}}]}
root@NC-PH-1346-07:~/bitshares/issue339/bitshares-core# 

the only chance i had left was to remove the data dir and start over ...

@oxarbitrage
Copy link
Member

i think the previous msg(#339 (comment)) may be caused by the double ctrl-c because i did the same thing again but killed the process from another terminal. when running the program again it went straight to where i was left and continue sync.

more test to come but looking good :)

@oxarbitrage
Copy link
Member

i can confirm the kill with double ctrl-c cause the above problem, i think it may worth researching it as it is kind of a natural way to kill it if you need the terminal and can't wait for the clean shutdown specially on full node(no partial and max ops).

@pmconrad
Copy link
Contributor Author

pmconrad commented Aug 3, 2017

I suppose the first ctrl-c causes another flush which is then interrupted by the second ctrl-c. The patch should notice the inconsistent object_database in that case and start a full replay, though. Apparently that doesn't work, will check.

(IMO nobody should be running a node in a terminal window in the foreground, but that's not an excuse of course.)

@oxarbitrage
Copy link
Member

oxarbitrage commented Aug 4, 2017

I made a few tests of this pull, the last 2 cases failed but the rest worked as expected. i am wondering if we can know if the data is corrupted and launch a full replay for the last 2 cases.

  • tested stopping the node with single control-c(clean) - worked. no replay. as before. good.
  • tested killing the witness node with kill (SIGTERM) - worked. it made some replay starting at 97%. expected. good.
  • tested with double control-c. full replay. expected. good.
  • tested control-c while replaying. replay again. fair enough.
  • tested fill (SIGTERM) while replaying. replay again. fair enough.
  • tested control-c while replaying the 97%. start again at the same 97%. good.
  • tested SIGTERM while replaying the 97%. started even higher, at 98%. good.
  • tested by killing the witness with kill -9 (SIGKILL) fails. need to delete datadir to make it work again. not sure if this can happen in the real world.
  • tested by a forced shutdown. this can be an unexpected shutdown or reboot. failed. need to delete datadir.

logs for the 2 failing cases(sorry if they are too long, included everything from start to end of the restart):

  • for the kill - 9:
root@NC-PH-1346-07:~/bitshares/issue339/bitshares-core# programs/witness_node/witness_node --data-dir data/my-blockprod --rpc-endpoint "127.0.0.1:8090" --max-ops-
-per-account 100 --partial-operations true
1136747ms th_a       witness.cpp:88                plugin_initialize    ] witness plugin:  plugin_initialize() begin
1136747ms th_a       witness.cpp:99                plugin_initialize    ] Public Key: BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
1136747ms th_a       witness.cpp:117               plugin_initialize    ] witness plugin:  plugin_initialize() end
1136747ms th_a       object_database.cpp:101       open                 ] Opening object database from /root/bitshares/issue339/bitshares-core/data/my-blockprod/
blockchain ...
1145690ms th_a       object_database.cpp:107       open                 ] Done opening object database.
1145690ms th_a       db_management.cpp:59          reindex              ] reindexing blockchain
1145690ms th_a       db_management.cpp:65          reindex              ] Replaying blocks, starting at 2491367...
   70.5389%   2500000 of 3544145   
   70.821%   2510000 of 3544145   
   71.1032%   2520000 of 3544145   
1149311ms th_a       db_block.cpp:289              push_proposal        ] e
1149311ms th_a       db_update.cpp:185             clear_expired_propos ] Failed to apply proposed transaction on its expiration. Deleting it.
{"id":"1.10.52","expiration_time":"2016-01-10T03:00:00","review_period_time":"2016-01-10T02:59:00","proposed_transaction":{"ref_block_num":0,"ref_block_prefix":0
,"expiration":"2016-01-10T03:00:00","operations":[[22,{"fee":{"amount":4000001,"asset_id":"1.3.0"},"fee_paying_account":"1.2.1191","expiration_time":"2016-01-10T
12:00:00","proposed_ops":[{"op":[22,{"fee":{"amount":4000000,"asset_id":"1.3.0"},"fee_paying_account":"1.2.1191","expiration_time":"2016-01-10T12:00:00","propose
d_ops":[{"op":[24,{"fee":{"amount":200000,"asset_id":"1.3.0"},"fee_paying_account":"1.2.0","using_owner_authority":false,"proposal":"1.10.50","extensions":[]}]}]
,"review_period_seconds":3600,"extensions":[]}]}],"review_period_seconds":3600,"extensions":[]}]],"extensions":[]},"required_active_approvals":["1.2.1191"],"avai
lable_active_approvals":["1.2.1191"],"required_owner_approvals":[],"available_owner_approvals":[],"available_key_approvals":[]}
10 assert_exception: Assert Exception
_stack.size() >=2: 
    {}
    th_a  undo_database.cpp:130 merge

    {"proposal":{"id":"1.10.52","expiration_time":"2016-01-10T03:00:00","review_period_time":"2016-01-10T02:59:00","proposed_transaction":{"ref_block_num":0,"ref
_block_prefix":0,"expiration":"2016-01-10T03:00:00","operations":[[22,{"fee":{"amount":4000001,"asset_id":"1.3.0"},"fee_paying_account":"1.2.1191","expiration_ti
me":"2016-01-10T12:00:00","proposed_ops":[{"op":[22,{"fee":{"amount":4000000,"asset_id":"1.3.0"},"fee_paying_account":"1.2.1191","expiration_time":"2016-01-10T12
:00:00","proposed_ops":[{"op":[24,{"fee":{"amount":200000,"asset_id":"1.3.0"},"fee_paying_account":"1.2.0","using_owner_authority":false,"proposal":"1.10.50","ex
tensions":[]}]}],"review_period_seconds":3600,"extensions":[]}]}],"review_period_seconds":3600,"extensions":[]}]],"extensions":[]},"required_active_approvals":["
1.2.1191"],"available_active_approvals":["1.2.1191"],"required_owner_approvals":[],"available_owner_approvals":[],"available_key_approvals":[]}}
    th_a  db_block.cpp:295 push_proposal
1149348ms th_a       db_management.cpp:175         open                 ] 10 assert_exception: Assert Exception
maybe_found != nullptr: Unable to find Object
    {"id":"1.10.53"}
    th_a  index.hpp:111 get

    {"o":{"fee":{"amount":200000,"asset_id":"1.3.0"},"fee_paying_account":"1.2.1191","proposal":"1.10.53","active_approvals_to_add":["1.2.1191"],"active_approval
s_to_remove":[],"owner_approvals_to_add":[],"owner_approvals_to_remove":[],"key_approvals_to_add":[],"key_approvals_to_remove":[],"extensions":[]}}
    th_a  proposal_evaluator.cpp:146 do_evaluate

    {}
    th_a  evaluator.cpp:51 start_evaluate

    {"op":[23,{"fee":{"amount":200000,"asset_id":"1.3.0"},"fee_paying_account":"1.2.1191","proposal":"1.10.53","active_approvals_to_add":["1.2.1191"],"active_app
rovals_to_remove":[],"owner_approvals_to_add":[],"owner_approvals_to_remove":[],"key_approvals_to_add":[],"key_approvals_to_remove":[],"extensions":[]}]}
    th_a  db_block.cpp:645 apply_operation

    {"trx":{"ref_block_num":37188,"ref_block_prefix":4752196,"expiration":"2016-01-10T03:16:18","operations":[[23,{"fee":{"amount":200000,"asset_id":"1.3.0"},"fe
e_paying_account":"1.2.1191","proposal":"1.10.53","active_approvals_to_add":["1.2.1191"],"active_approvals_to_remove":[],"owner_approvals_to_add":[],"owner_appro
vals_to_remove":[],"key_approvals_to_add":[],"key_approvals_to_remove":[],"extensions":[]}]],"extensions":[],"signatures":["1f608d0ab505a2616432aa2c59c21f4118101
d03a680492d5d23efb70342e1b5cc469fffb4774983074feef02149e4b3e78424cf598d594cc5e5e2b93cb4605443"]}}
    th_a  db_block.cpp:628 _apply_transaction

    {"next_block.block_num()":2527557}
    th_a  db_block.cpp:545 _apply_block

    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:123 reindex
1149348ms th_a       db_management.cpp:175         open                 ] data_dir: /root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain 
1149348ms th_a       application.cpp:400           startup              ] Caught exception 10 assert_exception: Assert Exception
maybe_found != nullptr: Unable to find Object
    {"id":"1.10.53"}
    th_a  index.hpp:111 get

    {"o":{"fee":{"amount":200000,"asset_id":"1.3.0"},"fee_paying_account":"1.2.1191","proposal":"1.10.53","active_approvals_to_add":["1.2.1191"],"active_approval
s_to_remove":[],"owner_approvals_to_add":[],"owner_approvals_to_remove":[],"key_approvals_to_add":[],"key_approvals_to_remove":[],"extensions":[]}}
    th_a  proposal_evaluator.cpp:146 do_evaluate

    {}
    th_a  evaluator.cpp:51 start_evaluate

    {"op":[23,{"fee":{"amount":200000,"asset_id":"1.3.0"},"fee_paying_account":"1.2.1191","proposal":"1.10.53","active_approvals_to_add":["1.2.1191"],"active_app
rovals_to_remove":[],"owner_approvals_to_add":[],"owner_approvals_to_remove":[],"key_approvals_to_add":[],"key_approvals_to_remove":[],"extensions":[]}]}
    th_a  db_block.cpp:645 apply_operation

    {"trx":{"ref_block_num":37188,"ref_block_prefix":4752196,"expiration":"2016-01-10T03:16:18","operations":[[23,{"fee":{"amount":200000,"asset_id":"1.3.0"},"fe
e_paying_account":"1.2.1191","proposal":"1.10.53","active_approvals_to_add":["1.2.1191"],"active_approvals_to_remove":[],"owner_approvals_to_add":[],"owner_appro
vals_to_remove":[],"key_approvals_to_add":[],"key_approvals_to_remove":[],"extensions":[]}]],"extensions":[],"signatures":["1f608d0ab505a2616432aa2c59c21f4118101
d03a680492d5d23efb70342e1b5cc469fffb4774983074feef02149e4b3e78424cf598d594cc5e5e2b93cb4605443"]}}
    th_a  db_block.cpp:628 _apply_transaction

    {"next_block.block_num()":2527557}
    th_a  db_block.cpp:545 _apply_block

    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:123 reindex
rethrow
    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:175 open in open(), you might want to force a replay
1149349ms th_a       application.cpp:444           startup              ] 10 assert_exception: Assert Exception
maybe_found != nullptr: Unable to find Object
    {"id":"1.10.53"}
    th_a  index.hpp:111 get

    {"o":{"fee":{"amount":200000,"asset_id":"1.3.0"},"fee_paying_account":"1.2.1191","proposal":"1.10.53","active_approvals_to_add":["1.2.1191"],"active_approval
s_to_remove":[],"owner_approvals_to_add":[],"owner_approvals_to_remove":[],"key_approvals_to_add":[],"key_approvals_to_remove":[],"extensions":[]}}
    th_a  proposal_evaluator.cpp:146 do_evaluate

    {}
    th_a  evaluator.cpp:51 start_evaluate

    {"op":[23,{"fee":{"amount":200000,"asset_id":"1.3.0"},"fee_paying_account":"1.2.1191","proposal":"1.10.53","active_approvals_to_add":["1.2.1191"],"active_app
rovals_to_remove":[],"owner_approvals_to_add":[],"owner_approvals_to_remove":[],"key_approvals_to_add":[],"key_approvals_to_remove":[],"extensions":[]}]}
    th_a  db_block.cpp:645 apply_operation

    {"trx":{"ref_block_num":37188,"ref_block_prefix":4752196,"expiration":"2016-01-10T03:16:18","operations":[[23,{"fee":{"amount":200000,"asset_id":"1.3.0"},"fe
e_paying_account":"1.2.1191","proposal":"1.10.53","active_approvals_to_add":["1.2.1191"],"active_approvals_to_remove":[],"owner_approvals_to_add":[],"owner_appro
vals_to_remove":[],"key_approvals_to_add":[],"key_approvals_to_remove":[],"extensions":[]}]],"extensions":[],"signatures":["1f608d0ab505a2616432aa2c59c21f4118101
d03a680492d5d23efb70342e1b5cc469fffb4774983074feef02149e4b3e78424cf598d594cc5e5e2b93cb4605443"]}}
    th_a  db_block.cpp:628 _apply_transaction

    {"next_block.block_num()":2527557}
    th_a  db_block.cpp:545 _apply_block

    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:123 reindex
rethrow
    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:175 open
1149349ms th_a       application.cpp:988           startup              ] 10 assert_exception: Assert Exception
maybe_found != nullptr: Unable to find Object
    {"id":"1.10.53"}
    th_a  index.hpp:111 get

    {"o":{"fee":{"amount":200000,"asset_id":"1.3.0"},"fee_paying_account":"1.2.1191","proposal":"1.10.53","active_approvals_to_add":["1.2.1191"],"active_approval
s_to_remove":[],"owner_approvals_to_add":[],"owner_approvals_to_remove":[],"key_approvals_to_add":[],"key_approvals_to_remove":[],"extensions":[]}}
    th_a  proposal_evaluator.cpp:146 do_evaluate

    {}
    th_a  evaluator.cpp:51 start_evaluate

    {"op":[23,{"fee":{"amount":200000,"asset_id":"1.3.0"},"fee_paying_account":"1.2.1191","proposal":"1.10.53","active_approvals_to_add":["1.2.1191"],"active_app
rovals_to_remove":[],"owner_approvals_to_add":[],"owner_approvals_to_remove":[],"key_approvals_to_add":[],"key_approvals_to_remove":[],"extensions":[]}]}
    th_a  db_block.cpp:645 apply_operation

    {"trx":{"ref_block_num":37188,"ref_block_prefix":4752196,"expiration":"2016-01-10T03:16:18","operations":[[23,{"fee":{"amount":200000,"asset_id":"1.3.0"},"fe
e_paying_account":"1.2.1191","proposal":"1.10.53","active_approvals_to_add":["1.2.1191"],"active_approvals_to_remove":[],"owner_approvals_to_add":[],"owner_appro
vals_to_remove":[],"key_approvals_to_add":[],"key_approvals_to_remove":[],"extensions":[]}]],"extensions":[],"signatures":["1f608d0ab505a2616432aa2c59c21f4118101
d03a680492d5d23efb70342e1b5cc469fffb4774983074feef02149e4b3e78424cf598d594cc5e5e2b93cb4605443"]}}
    th_a  db_block.cpp:628 _apply_transaction

    {"next_block.block_num()":2527557}
    th_a  db_block.cpp:545 _apply_block

    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:123 reindex
rethrow
    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:175 open
rethrow
    {}
    th_a  application.cpp:444 startup
1149349ms th_a       main.cpp:195                  main                 ] Exiting with error:
10 assert_exception: Assert Exception
maybe_found != nullptr: Unable to find Object
    {"id":"1.10.53"}
    th_a  index.hpp:111 get

    {"o":{"fee":{"amount":200000,"asset_id":"1.3.0"},"fee_paying_account":"1.2.1191","proposal":"1.10.53","active_approvals_to_add":["1.2.1191"],"active_approval
s_to_remove":[],"owner_approvals_to_add":[],"owner_approvals_to_remove":[],"key_approvals_to_add":[],"key_approvals_to_remove":[],"extensions":[]}}
    th_a  proposal_evaluator.cpp:146 do_evaluate

    {}
    th_a  evaluator.cpp:51 start_evaluate

    {"op":[23,{"fee":{"amount":200000,"asset_id":"1.3.0"},"fee_paying_account":"1.2.1191","proposal":"1.10.53","active_approvals_to_add":["1.2.1191"],"active_app
rovals_to_remove":[],"owner_approvals_to_add":[],"owner_approvals_to_remove":[],"key_approvals_to_add":[],"key_approvals_to_remove":[],"extensions":[]}]}
    th_a  db_block.cpp:645 apply_operation

    {"trx":{"ref_block_num":37188,"ref_block_prefix":4752196,"expiration":"2016-01-10T03:16:18","operations":[[23,{"fee":{"amount":200000,"asset_id":"1.3.0"},"fe
e_paying_account":"1.2.1191","proposal":"1.10.53","active_approvals_to_add":["1.2.1191"],"active_approvals_to_remove":[],"owner_approvals_to_add":[],"owner_appro
vals_to_remove":[],"key_approvals_to_add":[],"key_approvals_to_remove":[],"extensions":[]}]],"extensions":[],"signatures":["1f608d0ab505a2616432aa2c59c21f4118101
d03a680492d5d23efb70342e1b5cc469fffb4774983074feef02149e4b3e78424cf598d594cc5e5e2b93cb4605443"]}}
    th_a  db_block.cpp:628 _apply_transaction

    {"next_block.block_num()":2527557}
    th_a  db_block.cpp:545 _apply_block

    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:123 reindex
rethrow
    {"data_dir":"/root/bitshares/issue339/bitshares-core/data/my-blockprod/blockchain"}
    th_a  db_management.cpp:175 open
rethrow
    {}
    th_a  application.cpp:444 startup
1149350ms th_a       db_management.cpp:200         close                ] Database close unexpected exception: {"code":10,"name":"assert_exception","message":"As
sert Exception","stack":[{"context":{"level":"error","file":"fork_database.cpp","line":41,"method":"pop_block","hostname":"","thread_name":"th_a","timestamp":"20
17-08-04T00:19:09"},"format":"_head: no blocks to pop","data":{}},{"context":{"level":"warn","file":"db_block.cpp","line":430,"method":"pop_block","hostname":"",
"thread_name":"th_a","timestamp":"2017-08-04T00:19:09"},"format":"","data":{}}]}
1149586ms th_a       db_management.cpp:200         close                ] Database close unexpected exception: {"code":3070001,"name":"pop_empty_chain","message"
:"there are no blocks to pop","stack":[{"context":{"level":"error","file":"db_block.cpp","line":423,"method":"pop_block","hostname":"","thread_name":"th_a","time
stamp":"2017-08-04T00:19:09"},"format":"there are no blocks to pop","data":{}},{"context":{"level":"warn","file":"db_block.cpp","line":430,"method":"pop_block","
hostname":"","thread_name":"th_a","timestamp":"2017-08-04T00:19:09"},"format":"","data":{}}]}
root@NC-PH-1346-07:~/bitshares/issue339/bitshares-core# 
  • for the unexpected shutdown:
alfredo@alfredo-Inspiron-5559 ~/CLionProjects/pull339/bitshares-core $ programs/witness_node/witness_node --data-dir data/my-blockprod --rpc-endpoint "127.0.0.1:8090" --max-ops-per-account 100 --partial-operations true
1666997ms th_a       witness.cpp:88                plugin_initialize    ] witness plugin:  plugin_initialize() begin
1666997ms th_a       witness.cpp:99                plugin_initialize    ] Public Key: BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
1666997ms th_a       witness.cpp:117               plugin_initialize    ] witness plugin:  plugin_initialize() end
1666997ms th_a       object_database.cpp:101       open                 ] Opening object database from /home/alfredo/CLionProjects/pull339/bitshares-core/data/my-blockprod/blockchain ...
1674420ms th_a       object_database.cpp:107       open                 ] Done opening object database.
1674439ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 104.236.144.84:1777
1674439ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 128.199.143.47:2015
1674439ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 23.92.53.182:1776
1674439ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 192.121.166.162:1776
1674439ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 51.15.61.160:1776
1675034ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 114.92.234.195:62015
1675954ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 144.76.29.248:4243
1681992ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 212.47.249.84:50696
1681992ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 51.15.42.228:50696
1682002ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 45.76.37.29:1776
1683015ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 71.197.2.119:1776
1684041ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 209.99.64.52:1777
1685073ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 149.56.17.159:1776
1685994ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 108.61.176.106:1776
1687222ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 188.241.58.128:1776
1688143ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 82.211.1.99:1776
1688956ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 45.32.117.94:1776
1689974ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 188.241.58.128:1776
1689974ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 108.61.176.106:1776
1689974ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 71.197.2.119:1776
1689974ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 139.162.183.240:1776
1689974ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 213.167.243.194:1776
1689974ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 116.62.226.52:1776
1689975ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 82.211.1.99:1776
1689975ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 173.233.75.2:1776
1689975ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 51.15.61.160:1776
1689975ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 209.105.239.13:1776
1689975ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 23.92.53.182:1776
1689975ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 81.89.101.133:1776
1689975ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 45.32.159.93:1776
1689975ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 149.56.17.159:1776
1689975ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 45.79.174.179:1776
1689975ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 192.121.166.162:1776
1689976ms th_a       application.cpp:189           reset_p2p_node       ] Adding seed node 94.130.15.169:1776
1689977ms th_a       application.cpp:204           reset_p2p_node       ] Configured p2p node to listen on 0.0.0.0:34945
1689980ms th_a       application.cpp:279           reset_websocket_serv ] Configured websocket rpc to listen on 127.0.0.1:8090
1689980ms th_a       witness.cpp:122               plugin_startup       ] witness plugin:  plugin_startup() begin
1689980ms th_a       witness.cpp:137               plugin_startup       ] No witnesses configured! Please add witness IDs and private keys to configuration.
1689980ms th_a       witness.cpp:138               plugin_startup       ] witness plugin:  plugin_startup() end
1689980ms th_a       main.cpp:179                  main                 ] Started witness node on a chain with 0 blocks.
1689980ms th_a       main.cpp:180                  main                 ] Chain ID is 4018d7844c78f6a6c41c6a552b898022310fc5dec06da467ee7905a8dad512c8
1784495ms th_a       db_block.cpp:145              _push_block          ] Switching to fork: 00078708c094ede03b69a0bce11fd2927d48b76e
1784572ms th_a       application.cpp:534           handle_block         ] Error when pushing block:
10 assert_exception: Assert Exception
second_branch_itr != _index.get<block_id>().end(): 
    {}
    th_a  fork_database.cpp:210 fetch_branch_from

    {"first":"00078708c094ede03b69a0bce11fd2927d48b76e","second":"0000000000000000000000000000000000000000"}
    th_a  fork_database.cpp:241 fetch_branch_from

    {"new_block":{"previous":"00078707a7d7fdaefe4660046e7a7f1a2ac2c909","timestamp":"2015-10-30T22:28:15","witness":"1.6.17","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"1f765e7afae6af1660a2215f99826889fc68a10b049a6a19029168427a644d2a730ccc7d06d258c7829a421bd379c775a1efadcc0f1a702bb31b1953abb6350580","transactions":[]}}
    th_a  db_block.cpp:208 _push_block
1784585ms th_a       db_block.cpp:145              _push_block          ] Switching to fork: 000787097c10964b6c5a9f44ff29ca77810a8f95
1784585ms th_a       application.cpp:534           handle_block         ] Error when pushing block:
10 assert_exception: Assert Exception
second_branch_itr != _index.get<block_id>().end(): 
    {}
    th_a  fork_database.cpp:210 fetch_branch_from

    {"first":"000787097c10964b6c5a9f44ff29ca77810a8f95","second":"0000000000000000000000000000000000000000"}
    th_a  fork_database.cpp:241 fetch_branch_from

    {"new_block":{"previous":"00078708c094ede03b69a0bce11fd2927d48b76e","timestamp":"2015-10-30T22:28:18","witness":"1.6.38","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"20735c764d12749916d039a0b8cc0fd09dfb515cbaea3fb075dc79d4076521a6bd0172066ce0ee8f5041dcc3bfca9131d6586a322a73d7e2cd45d49132a25d5094","transactions":[]}}
    th_a  db_block.cpp:208 _push_block
1784586ms th_a       db_block.cpp:145              _push_block          ] Switching to fork: 0007870af9a4c35f569ec1ec992839947e04a863
1784590ms th_a       application.cpp:534           handle_block         ] Error when pushing block:
10 assert_exception: Assert Exception
second_branch_itr != _index.get<block_id>().end(): 
    {}
    th_a  fork_database.cpp:210 fetch_branch_from

    {"first":"0007870af9a4c35f569ec1ec992839947e04a863","second":"0000000000000000000000000000000000000000"}
    th_a  fork_database.cpp:241 fetch_branch_from

    {"new_block":{"previous":"000787097c10964b6c5a9f44ff29ca77810a8f95","timestamp":"2015-10-30T22:28:21","witness":"1.6.43","transaction_merkle_root":"bce9d4f7f0c9bda298244aa7445034e576c005ac","extensions":[],"witness_signature":"2052f00d19eb9f90d00194f18c41637b7866d044e048bc35c34375709793d180164ad5636bfdcc8899336dd6565073ffbd729a0064e933ca3f0f93658dd39253dd","transactions":[{"ref_block_num":34569,"ref_block_prefix":1268125820,"expiration":"2015-10-30T22:28:48","operations":[[19,{"fee":{"amount":10000,"asset_id":"1.3.0"},"publisher":"1.2.277","asset_id":"1.3.102","feed":{"settlement_price":{"base":{"amount":53012,"asset_id":"1.3.102"},"quote":{"amount":100000,"asset_id":"1.3.0"}},"maintenance_collateral_ratio":1750,"maximum_short_squeeze_ratio":1100,"core_exchange_rate":{"base":{"amount":53012,"asset_id":"1.3.102"},"quote":{"amount":95000,"asset_id":"1.3.0"}}},"extensions":[]}]],"extensions":[],"signatures":["1f5653ac9f257ad6988e7f0a199f3208d96d33a226270c179fb0d3e2e2816b3b6c5826ae3bc69e0767be9b1ee501fb21d7646a546c45b6b1c805b83b2f51e9f92a"],"operation_results":[[0,{}]]},{"ref_block_num":34569,"ref_block_prefix":1268125820,"expiration":"2015-10-30T22:28:48","operations":[[19,{"fee":{"amount":10000,"asset_id":"1.3.0"},"publisher":"1.2.277","asset_id":"1.3.112","feed":{"settlement_price":{"base":{"amount":7042,"asset_id":"1.3.112"},"quote":{"amount":10000000,"asset_id":"1.3.0"}},"maintenance_collateral_ratio":1750,"maximum_short_squeeze_ratio":1100,"core_exchange_rate":{"base":{"amount":7042,"asset_id":"1.3.112"},"quote":{"amount":9500000,"asset_id":"1.3.0"}}},"extensions":[]}]],"extensions":[],"signatures":["1f20a295da0485e54195a47e5ffd0d9269d91b68a1a54392baf3041acc8a17913f3b3f41038ee31f7ad2a2b8b72ac943d313dfa18250c97eea75450725b55400ab"],"operation_results":[[0,{}]]},{"ref_block_num":34569,"ref_block_prefix":1268125820,"expiration":"2015-10-30T22:28:48","operations":[[19,{"fee":{"amount":10000,"asset_id":"1.3.0"},"publisher":"1.2.277","asset_id":"1.3.106","feed":{"settlement_price":{"base":{"amount":4177,"asset_id":"1.3.106"},"quote":{"amount":100000000,"asset_id":"1.3.0"}},"maintenance_collateral_ratio":1750,"maximum_short_squeeze_ratio":1100,"core_exchange_rate":{"base":{"amount":4177,"asset_id":"1.3.106"},"quote":{"amount":95000000,"asset_id":"1.3.0"}}},"extensions":[]}]],"extensions":[],"signatures":["1f5d7c31ffdec5e11dd1a723796aea41720e11da0d52a47dcc9d650dac1e923ae615636986f3ee34c6b486311bea1752e382832413e69006c3c1820526fc5d378c"],"operation_results":[[0,{}]]},{"ref_block_num":34569,"ref_block_prefix":1268125820,"expiration":"2015-10-30T22:28:48","operations":[[19,{"fee":{"amount":10000,"asset_id":"1.3.0"},"publisher":"1.2.277","asset_id":"1.3.114","feed":{"settlement_price":{"base":{"amount":7873,"asset_id":"1.3.114"},"quote":{"amount":1000000,"asset_id":"1.3.0"}},"maintenance_collateral_ratio":1750,"maximum_short_squeeze_ratio":1100,"core_exchange_rate":{"base":{"amount":7873,"asset_id":"1.3.114"},"quote":{"amount":950000,"asset_id":"1.3.0"}}},"extensions":[]}]],"extensions":[],"signatures":["206cca146c27ab3a1e9e1d64741a5416ce12522f6fabe86472b8ed50d989ed03571fcbf92800a2df399ab8009efe202de551e6675bdc9c820bef5193228107eeb9"],"operation_results":[[0,{}]]},{"ref_block_num":34569,"ref_block_prefix":1268125820,"expiration":"2015-10-30T22:28:48","operations":[[19,{"fee":{"amount":10000,"asset_id":"1.3.0"},"publisher":"1.2.277","asset_id":"1.3.115","feed":{"settlement_price":{"base":{"amount":6240,"asset_id":"1.3.115"},"quote":{"amount":10000000,"asset_id":"1.3.0"}},"maintenance_collateral_ratio":1750,"maximum_short_squeeze_ratio":1100,"core_exchange_rate":{"base":{"amount":6240,"asset_id":"1.3.115"},"quote":{"amount":9500000,"asset_id":"1.3.0"}}},"extensions":[]}]],"extensions":[],"signatures":["2043d919f203d1cff8ccb65fb6c1f6eb0aa919ecf68302296d57e8357c412db8600b1d923e5b15b6e87442e78eeac62baa09cabf0a42342e43ba931acc64ad2a86"],"operation_results":[[0,{}]]},{"ref_block_num":34569,"ref_block_prefix":1268125820,"expiration":"2015-10-30T22:28:48","operations":[[19,{"fee":{"amount":10000,"asset_id":"1.3.0"},"publisher":"1.2.277","asset_id":"1.3.103","feed":{"settlement_price":{"base":{"amount":1392,"asset_id":"1.3.103"},"quote":{"amount":100000,"asset_id":"1.3.0"}},"maintenance_collateral_ratio":1750,"maximum_short_squeeze_ratio":1100,"core_exchange_rate":{"base":{"amount":1392,"asset_id":"1.3.103"},"quote":{"amount":95000,"asset_id":"1.3.0"}}},"extensions":[]}]],"extensions":[],"signatures":["1f0e9aa816159f241ff58f197cca6a34a222a02c5bbaef11045505565b924013562ee3f909513b2b899219873c6376c66a1d182063f07e84ac13e2f6ea713bf7e6"],"operation_results":[[0,{}]]},{"ref_block_num":34569,"ref_block_prefix":1268125820,"expiration":"2015-10-30T22:28:48","operations":[[19,{"fee":{"amount":10000,"asset_id":"1.3.0"},"publisher":"1.2.277","asset_id":"1.3.120","feed":{"settlement_price":{"base":{"amount":4334,"asset_id":"1.3.120"},"quote":{"amount":10000000,"asset_id":"1.3.0"}},"maintenance_collateral_ratio":1750,"maximum_short_squeeze_ratio":1100,"core_exchange_rate":{"base":{"amount":4334,"asset_id":"1.3.120"},"quote":{"amount":9500000,"asset_id":"1.3.0"}}},"extensions":[]}]],"extensions":[],"signatures":["2064094c7ebf5ba2b7e30f89d7661191201a04d921ae2434440c6d38a23a3e04a739bcb17147d67d0f42482256bbba30b8f4107e9b2001f59281051710ef263792"],"operation_results":[[0,{}]]},{"ref_block_num":34569,"ref_block_prefix":1268125820,"expiration":"2015-10-30T22:28:48","operations":[[19,{"fee":{"amount":10000,"asset_id":"1.3.0"},"publisher":"1.2.277","asset_id":"1.3.117","feed":{"settlement_price":{"base":{"amount":6685,"asset_id":"1.3.117"},"quote":{"amount":10000000,"asset_id":"1.3.0"}},"maintenance_collateral_ratio":1750,"maximum_short_squeeze_ratio":1100,"core_exchange_rate":{"base":{"amount":6685,"asset_id":"1.3.117"},"quote":{"amount":9500000,"asset_id":"1.3.0"}}},"extensions":[]}]],"extensions":[],"signatures":["1f6ba16e4929911723e4b3529efa3ac61835290fec6afc596fce6724048915e1e03b3ccfc0dcd196882848bd4edbcb9dc1aa719971e4169136591d397872602400"],"operation_results":[[0,{}]]},{"ref_block_num":34569,"ref_block_prefix":1268125820,"expiration":"2015-10-30T22:28:48","operations":[[19,{"fee":{"amount":10000,"asset_id":"1.3.0"},"publisher":"1.2.277","asset_id":"1.3.113","feed":{"settlement_price":{"base":{"amount":3014,"asset_id":"1.3.113"},"quote":{"amount":1000000,"asset_id":"1.3.0"}},"maintenance_collateral_ratio":1750,"maximum_short_squeeze_ratio":1100,"core_exchange_rate":{"base":{"amount":3014,"asset_id":"1.3.113"},"quote":{"amount":950000,"asset_id":"1.3.0"}}},"extensions":[]}]],"extensions":[],"signatures":["2024ac434d378cdaa1d81511d3cb75bdd8138abbb7b586abdc833abcf6f816efed4ff2906c0d8c1a1876ad91b38859099135e85d3cda56e4416985782fd5555d8a"],"operation_results":[[0,{}]]},{"ref_block_num":34569,"ref_block_prefix":1268125820,"expiration":"2015-10-30T22:28:48","operations":[[19,{"fee":{"amount":10000,"asset_id":"1.3.0"},"publisher":"1.2.277","asset_id":"1.3.105","feed":{"settlement_price":{"base":{"amount":3065,"asset_id":"1.3.105"},"quote":{"amount":100000000,"asset_id":"1.3.0"}},"maintenance_collateral_ratio":1750,"maximum_short_squeeze_ratio":1100,"core_exchange_rate":{"base":{"amount":3065,"asset_id":"1.3.105"},"quote":{"amount":95000000,"asset_id":"1.3.0"}}},"extensions":[]}]],"extensions":[],"signatures":["200fb75350c087d3e10ee8140f66deeacc6de88ac1d6eb9b109189cbde8b6e2c44294cd5644a3387c997fdc2b76954d3c72549c43fa7c0ef0e20fe350b79546ce8"],"operation_results":[[0,{}]]},{"ref_block_num":34569,"ref_block_prefix":1268125820,"expiration":"2015-10-30T22:28:48","operations":[[19,{"fee":{"amount":10000,"asset_id":"1.3.0"},"publisher":"1.2.277","asset_id":"1.3.118","feed":{"settlement_price":{"base":{"amount":3092,"asset_id":"1.3.118"},"quote":{"amount":10000000,"asset_id":"1.3.0"}},"maintenance_collateral_ratio":1750,"maximum_short_squeeze_ratio":1100,"core_exchange_rate":{"base":{"amount":3092,"asset_id":"1.3.118"},"quote":{"amount":9500000,"asset_id":"1.3.0"}}},"extensions":[]}]],"extensions":[],"signatures":["2027853a355a7995f1416cfa01b2f229dd027c88eddac14a354c90036a44f4f3e361534b849d008bb96c3835fa727fcca3463c72be615d63d6292e91931338b949"],"operation_results":[[0,{}]]},{"ref_block_num":34569,"ref_block_prefix":1268125820,"expiration":"2015-10-30T22:28:48","operations":[[19,{"fee":{"amount":10000,"asset_id":"1.3.0"},"publisher":"1.2.277","asset_id":"1.3.119","feed":{"settlement_price":{"base":{"amount":5748,"asset_id":"1.3.119"},"quote":{"amount":10000000,"asset_id":"1.3.0"}},"maintenance_collateral_ratio":1750,"maximum_short_squeeze_ratio":1100,"core_exchange_rate":{"base":{"amount":5748,"asset_id":"1.3.119"},"quote":{"amount":9500000,"asset_id":"1.3.0"}}},"extensions":[]}]],"extensions":[],"signatures":["201e5653c97d48161497497baa5c7bdb710cce1094b0fa6f95a52bb23c6994016e76e26f9318963adcf1fce364722e04009579ea3151616e7e2fc22f560c535f9c"],"operation_results":[[0,{}]]},{"ref_block_num":34569,"ref_block_prefix":1268125820,"expiration":"2015-10-30T22:28:48","operations":[[19,{"fee":{"amount":10000,"asset_id":"1.3.0"},"publisher":"1.2.277","asset_id":"1.3.109","feed":{"settlement_price":{"base":{"amount":3698,"asset_id":"1.3.109"},"quote":{"amount":1000000,"asset_id":"1.3.0"}},"maintenance_collateral_ratio":1750,"maximum_short_squeeze_ratio":1100,"core_exchange_rate":{"base":{"amount":3698,"asset_id":"1.3.109"},"quote":{"amount":950000,"asset_id":"1.3.0"}}},"extensions":[]}]],"extensions":[],"signatures":["20322b70f804d57522369bceaa8b4d4633c479ed3d1abd3ace0c8af5965ec651e5090e2fa7f7a4170180817f30bfc245e3df04672ddb3921a4eef87bb28dfd1e91"],"operation_results":[[0,{}]]},{"ref_block_num":34569,"ref_block_prefix":1268125820,"expiration":"2015-10-30T22:28:48","operations":[[19,{"fee":{"amount":10000,"asset_id":"1.3.0"},"publisher":"1.2.277","asset_id":"1.3.121","feed":{"settlement_price":{"base":{"amount":4771,"asset_id":"1.3.121"},"quote":{"amount":10000000,"asset_id":"1.3.0"}},"maintenance_collateral_ratio":1750,"maximum_short_squeeze_ratio":1100,"core_exchange_rate":{"base":{"amount":4771,"asset_id":"1.3.121"},"quote":{"amount":9500000,"asset_id":"1.3.0"}}},"extensions":[]}]],"extensions":[],"signatures":["204861204b35a22cd7f9b60c64c7627ebe085c5b6d290bc528472e0d0dc6c317d24662ffb3de98ec477cd8578f38fc15adc2b3f40c164e6bbd1416c23fea6ad174"],"operation_results":[[0,{}]]},{"ref_block_num":34569,"ref_block_prefix":1268125820,"expiration":"2015-10-30T22:28:48","operations":[[19,{"fee":{"amount":10000,"asset_id":"1.3.0"},"publisher":"1.2.277","asset_id":"1.3.116","feed":{"settlement_price":{"base":{"amount":4712,"asset_id":"1.3.116"},"quote":{"amount":10000000,"asset_id":"1.3.0"}},"maintenance_collateral_ratio":1750,"maximum_short_squeeze_ratio":1100,"core_exchange_rate":{"base":{"amount":4712,"asset_id":"1.3.116"},"quote":{"amount":9500000,"asset_id":"1.3.0"}}},"extensions":[]}]],"extensions":[],"signatures":["20541c7bd28fd5554b4d0b879f47cd35983cd99fc8fc9331a968f1771f7a14bfe061179ebf38cedee89edaae2916c19cfe5118b8fa021f86fd182271d39736cdbc"],"operation_results":[[0,{}]]},{"ref_block_num":34569,"ref_block_prefix":1268125820,"expiration":"2015-10-30T22:28:48","operations":[[19,{"fee":{"amount":10000,"asset_id":"1.3.0"},"publisher":"1.2.277","asset_id":"1.3.108","feed":{"settlement_price":{"base":{"amount":6681,"asset_id":"1.3.108"},"quote":{"amount":10000000,"asset_id":"1.3.0"}},"maintenance_collateral_ratio":1750,"maximum_short_squeeze_ratio":1100,"core_exchange_rate":{"base":{"amount":6681,"asset_id":"1.3.108"},"quote":{"amount":9500000,"asset_id":"1.3.0"}}},"extensions":[]}]],"extensions":[],"signatures":["20031810c85f3f3aa2140a84214f949eddf29719117dca533a1c9ca832fd346f18540e2f24283ce8305086262959b7e09fa7963d1ef94db0b92c0cd9d4c9876081"],"operation_results":[[0,{}]]},{"ref_block_num":34569,"ref_block_prefix":1268125820,"expiration":"2015-10-30T22:28:48","operations":[[19,{"fee":{"amount":10000,"asset_id":"1.3.0"},"publisher":"1.2.277","asset_id":"1.3.107","feed":{"settlement_price":{"base":{"amount":1391,"asset_id":"1.3.107"},"quote":{"amount":1000000,"asset_id":"1.3.0"}},"maintenance_collateral_ratio":1750,"maximum_short_squeeze_ratio":1100,"core_exchange_rate":{"base":{"amount":1391,"asset_id":"1.3.107"},"quote":{"amount":950000,"asset_id":"1.3.0"}}},"extensions":[]}]],"extensions":[],"signatures":["1f3b69e48adb2d067e9e18e91098c9882b550aff05497a4e698b3a7e736ba342631853fd81c95dc6ecc266edd9d6a9cd5165dc78cc91b5097d57d557f0a6262a2e"],"operation_results":[[0,{}]]}]}}
    th_a  db_block.cpp:208 _push_block
1784591ms th_a       db_block.cpp:145              _push_block          ] Switching to fork: 0007870b62467ea1a9b773a845dd6f90a1711f15
1784591ms th_a       application.cpp:534           handle_block         ] Error when pushing block:
10 assert_exception: Assert Exception
second_branch_itr != _index.get<block_id>().end(): 
    {}
    th_a  fork_database.cpp:210 fetch_branch_from

    {"first":"0007870b62467ea1a9b773a845dd6f90a1711f15","second":"0000000000000000000000000000000000000000"}
    th_a  fork_database.cpp:241 fetch_branch_from

    {"new_block":{"previous":"0007870af9a4c35f569ec1ec992839947e04a863","timestamp":"2015-10-30T22:28:24","witness":"1.6.18","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"1f1af7e64fc0f7f4a87f1f1b39c677ec27037ad988e9c511d7bff7c87851e4f32940df214f3e3d802ce4d980cc7a1ffc7fdba5044594df19325c4c6875bfc370a0","transactions":[]}}
    th_a  db_block.cpp:208 _push_block
1784591ms th_a       db_block.cpp:145              _push_block          ] Switching to fork: 0007870c09aac6ec35d7deab4f282fadfd35cd7c
1784592ms th_a       application.cpp:534           handle_block         ] Error when pushing block:
10 assert_exception: Assert Exception
second_branch_itr != _index.get<block_id>().end(): 
    {}
    th_a  fork_database.cpp:210 fetch_branch_from

    {"first":"0007870c09aac6ec35d7deab4f282fadfd35cd7c","second":"0000000000000000000000000000000000000000"}
    th_a  fork_database.cpp:241 fetch_branch_from

    {"new_block":{"previous":"0007870b62467ea1a9b773a845dd6f90a1711f15","timestamp":"2015-10-30T22:28:27","witness":"1.6.15","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"1f4508fbd2805cafb0418353a25c930ca66bd70f5890c8ada09a72294ee36a5bfe7b786656f229871ad65d3d5de8b9ecbb21541908904370af6b218691cc9a68c8","transactions":[]}}
    th_a  db_block.cpp:208 _push_block
1784592ms th_a       db_block.cpp:145              _push_block          ] Switching to fork: 0007870d41a47ecbb5d2bd8c20fa28116161211e
1784592ms th_a       application.cpp:534           handle_block         ] Error when pushing block:
10 assert_exception: Assert Exception
second_branch_itr != _index.get<block_id>().end(): 
    {}
    th_a  fork_database.cpp:210 fetch_branch_from

    {"first":"0007870d41a47ecbb5d2bd8c20fa28116161211e","second":"0000000000000000000000000000000000000000"}
    th_a  fork_database.cpp:241 fetch_branch_from

    {"new_block":{"previous":"0007870c09aac6ec35d7deab4f282fadfd35cd7c","timestamp":"2015-10-30T22:28:30","witness":"1.6.49","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"1f5c6bac5f32368b91e40ebfac3e8e327858ff0749abd58bb1f1e69031b39c8eee681955621e49a027c9148188824e9c21fecba3baec097dfd2567778cdc9e3a80","transactions":[]}}
    th_a  db_block.cpp:208 _push_block
1784592ms th_a       db_block.cpp:145              _push_block          ] Switching to fork: 0007870e2def6d686c88b1604a39de85de38fad8
1784592ms th_a       application.cpp:534           handle_block         ] Error when pushing block:
10 assert_exception: Assert Exception
second_branch_itr != _index.get<block_id>().end(): 
    {}
    th_a  fork_database.cpp:210 fetch_branch_from

    {"first":"0007870e2def6d686c88b1604a39de85de38fad8","second":"0000000000000000000000000000000000000000"}
    th_a  fork_database.cpp:241 fetch_branch_from

    {"new_block":{"previous":"0007870d41a47ecbb5d2bd8c20fa28116161211e","timestamp":"2015-10-30T22:28:33","witness":"1.6.12","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"1f663a3044b6c5f1c64f6ec66a3c9e7eeea6f63c84c0113263f8f5bc612f77c394399547e357a58ce8955319f3b4242376bc09486b2dc80ae7d892809b020e521e","transactions":[]}}
    th_a  db_block.cpp:208 _push_block
1784593ms th_a       db_block.cpp:145              _push_block          ] Switching to fork: 0007870fa07f8de3c6cab33868a832b4be88f3e3
1784593ms th_a       application.cpp:534           handle_block         ] Error when pushing block:
10 assert_exception: Assert Exception
second_branch_itr != _index.get<block_id>().end(): 
    {}
    th_a  fork_database.cpp:210 fetch_branch_from

    {"first":"0007870fa07f8de3c6cab33868a832b4be88f3e3","second":"0000000000000000000000000000000000000000"}
    th_a  fork_database.cpp:241 fetch_branch_from

    {"new_block":{"previous":"0007870e2def6d686c88b1604a39de85de38fad8","timestamp":"2015-10-30T22:28:36","witness":"1.6.16","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"1f59d2545acb4721a52bdf38a981229524b6f87d52c89a8318f1f1865597333253718595d974611c42d97f6340a12e3b2e0caa614b945a5f2b0c3d16b3c50e0a5a","transactions":[]}}
    th_a  db_block.cpp:208 _push_block
1784597ms th_a       db_block.cpp:145              _push_block          ] Switching to fork: 00078710e71b7efdf9b276a55aae78481ef33508
1784598ms th_a       application.cpp:534           handle_block         ] Error when pushing block:
10 assert_exception: Assert Exception
second_branch_itr != _index.get<block_id>().end(): 
    {}
    th_a  fork_database.cpp:210 fetch_branch_from

    {"first":"00078710e71b7efdf9b276a55aae78481ef33508","second":"0000000000000000000000000000000000000000"}
    th_a  fork_database.cpp:241 fetch_branch_from

    {"new_block":{"previous":"0007870fa07f8de3c6cab33868a832b4be88f3e3","timestamp":"2015-10-30T22:28:39","witness":"1.6.44","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"1f4f1f8249b6ba76c6ac6833d2107b11ae4b2210f92e1abfd73324139ea574b434723cd194dc391f4debc8a3c415a49561c0089c97f5e45bf355eb5acb46449546","transactions":[]}}
    th_a  db_block.cpp:208 _push_block

... it just freezes here, no more output for more than 15 mins. data is corrupted.

@pmconrad
Copy link
Contributor Author

pmconrad commented Aug 4, 2017

Thanks for testing thoroughly. :-/ Will investigate more.

Did you send SIGKILL / shutdown during replay, during normal operation/sync, or after initiating normal shutdown (SIGTERM / CTRL-C)?

@pmconrad
Copy link
Contributor Author

pmconrad commented Aug 4, 2017

The problems you were seeing resulted from a corrupted block_log. I have improved the consistency checking in block_database.
I have also modified the object_db's flush() to operate in an almost atomic way, i. e. the database is first written to a temporary location, and then moved to its final path. Interrupting the write will leave an existing object_db untouched.

@oxarbitrage
Copy link
Member

hi Peter, i like where it is heading with the new commits however it still have some issues.
at some tests when control-c or killing with segterm(should be the same) i am getting a segfault. not all the cases but sometimes:

2206717ms th_a       application.cpp:502           handle_block         ] Got block: #18650000 time: 2017-07-28T02:24:48 latency: 745918716 ms from: delegate.free
dom  irreversible: 18649982 (-18)
2208142ms asio       main.cpp:175                  operator()           ] Caught SIGTERM attempting to exit cleanly
2208329ms th_a       main.cpp:183                  main                 ] Exiting from signal 15
2208541ms th_a       db_block.cpp:202              _push_block          ] Failed to push new block:
10 assert_exception: Assert Exception
Internal error: static_variant tag is invalid.
    {}
    th_a  static_variant.hpp:134 apply
2208544ms th_a       application.cpp:534           handle_block         ] Error when pushing block:
10 assert_exception: Assert Exception
Internal error: static_variant tag is invalid.
    {}
    th_a  static_variant.hpp:134 apply
2208544ms th_a       application.cpp:534           handle_block         ] Error when pushing block:
10 assert_exception: Assert Exception
Internal error: static_variant tag is invalid.
    {}
    th_a  static_variant.hpp:134 apply
Segmentation fault

another one:

    {"new_block":{"previous":"0012cbc566b1d183bddca1d07486cbe62092a04f","timestamp":"2015-11-25T16:24:42","witness":"1.6.21","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"1f0b49d9b70aa3137ed175850bccddc44c2f4c6225e71936f41332f107a916e6144f67493ca0551a4e7e530e137129d13323213027cceefb1b111a821f403c731a","transactions":[]}}
    th_a  db_block.cpp:208 _push_block
2338901ms th_a       fork_database.cpp:66          push_block           ] Pushing block to fork database that failed to link: 0012cbc7fc85eebf5bee69f66bc4d8db97bb88d4, 1231815
2338901ms th_a       fork_database.cpp:67          push_block           ] Head: 1231708, 0012cb5c8d439f7dba8246e291b84d4329240d5b
2338901ms th_a       application.cpp:531           handle_block         ] Error when pushing block:
3080000 unlinkable_block_exception: unlinkable block
block does not link to known chain
    {}
    th_a  fork_database.cpp:87 _push_block

    {"new_block":{"previous":"0012cbc6484fa150b96142903521167272874ba0","timestamp":"2015-11-25T16:24:45","witness":"1.6.38","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"1f6868e871da50228a9fdf4ef40c2b0e49af31509d83ce2b3ea535bda4cd63beef766a6b42e0efbabafa23b5fdb581408085dad9a77aab897142bc7011771fd636","transactions":[]}}
    th_a  db_block.cpp:208 _push_block
2338901ms th_a       fork_database.cpp:66          push_block           ] Pushing block to fork database that failed to link: 0012cbc88856a73b95254398b67d811affcda593, 1231816
2338901ms th_a       fork_database.cpp:67          push_block           ] Head: 1231708, 0012cb5c8d439f7dba8246e291b84d4329240d5b
2338901ms th_a       application.cpp:531           handle_block         ] Error when pushing block:
3080000 unlinkable_block_exception: unlinkable block
block does not link to known chain
    {}
    th_a  fork_database.cpp:87 _push_block

    {"new_block":{"previous":"0012cbc7fc85eebf5bee69f66bc4d8db97bb88d4","timestamp":"2015-11-25T16:24:48","witness":"1.6.16","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"1f4920dc01a7f652a85f81a678185d0b77cacde481f3e07ba7d1fe9aa52bdb97da3830a45f1cb9d338d79043e71654ee9802928ff82029cfd07e3770ed6119bda7","transactions":[]}}
    th_a  db_block.cpp:208 _push_block
2338901ms th_a       fork_database.cpp:66          push_block           ] Pushing block to fork database that failed to link: 0012cbc94241ea236f815c5c29ebc54433cef446, 1231817
2338901ms th_a       fork_database.cpp:67          push_block           ] Head: 1231708, 0012cb5c8d439f7dba8246e291b84d4329240d5b
2338901ms th_a       application.cpp:531           handle_block         ] Error when pushing block:
3080000 unlinkable_block_exception: unlinkable block
block does not link to known chain
    {}
    th_a  fork_database.cpp:87 _push_block

    {"new_block":{"previous":"0012cbc88856a73b95254398b67d811affcda593","timestamp":"2015-11-25T16:24:51","witness":"1.6.17","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"1f33f7e4348d4ea4eae4efa9ced31b9c93f7989e0c72601d16930dba38399cbfb623653d10c7d16cc9e60e6d2b4b10574d2fb4203ceac7a4ae715d17b00c515a7f","transactions":[]}}
    th_a  db_block.cpp:208 _push_block
2338902ms th_a       fork_database.cpp:66          push_block           ] Pushing block to fork database that failed to link: 0012cbca5b588dc7a3c32e47b6951814778246ba, 1231818
2338902ms th_a       fork_database.cpp:67          push_block           ] Head: 1231708, 0012cb5c8d439f7dba8246e291b84d4329240d5b
2338902ms th_a       application.cpp:531           handle_block         ] Error when pushing block:
3080000 unlinkable_block_exception: unlinkable block
block does not link to known chain
    {}
    th_a  fork_database.cpp:87 _push_block

    {"new_block":{"previous":"0012cbc94241ea236f815c5c29ebc54433cef446","timestamp":"2015-11-25T16:24:54","witness":"1.6.43","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"1f5ffe8254c8be9178a696e479e81461602468ca3d4b776f9a2fcd025e255936ff7f517ac00a59c6439233cc8ca530ad88a0f55d21ad3285b0247b8b4f982b60fd","transactions":[]}}
    th_a  db_block.cpp:208 _push_block
2338902ms th_a       fork_database.cpp:66          push_block           ] Pushing block to fork database that failed to link: 0012cbcb2216d910a34ea44a1fc3bcefb3d6df9b, 1231819
2338902ms th_a       fork_database.cpp:67          push_block           ] Head: 1231708, 0012cb5c8d439f7dba8246e291b84d4329240d5b
2338902ms th_a       application.cpp:531           handle_block         ] Error when pushing block:
3080000 unlinkable_block_exception: unlinkable block
block does not link to known chain
    {}
    th_a  fork_database.cpp:87 _push_block

    {"new_block":{"previous":"0012cbca5b588dc7a3c32e47b6951814778246ba","timestamp":"2015-11-25T16:24:57","witness":"1.6.40","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"206c97761313e606c658929f6ca33e6390e07cb87e31ea9dca9ea65aa7a99c7e9f4fcf56113623104c5af7f524108054dbf4dcd1e926572a4b7504401f349e2a09","transactions":[]}}
    th_a  db_block.cpp:208 _push_block
2338902ms th_a       fork_database.cpp:66          push_block           ] Pushing block to fork database that failed to link: 0012cbcc4082c522623e2ed71a06328ac7b81e72, 1231820
2338902ms th_a       fork_database.cpp:67          push_block           ] Head: 1231708, 0012cb5c8d439f7dba8246e291b84d4329240d5b
2338903ms th_a       application.cpp:531           handle_block         ] Error when pushing block:
3080000 unlinkable_block_exception: unlinkable block
block does not link to known chain
    {}
    th_a  fork_database.cpp:87 _push_block

    {"new_block":{"previous":"0012cbcb2216d910a34ea44a1fc3bcefb3d6df9b","timestamp":"2015-11-25T16:25:00","witness":"1.6.26","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"207677134313a901862ed02d4e112afd3617bf5e9befd74a74037fef6afab81cce02fda9efa7270110aca46775d74477a78d5009b3c23cc0deafeadf484afa97dc","transactions":[]}}
    th_a  db_block.cpp:208 _push_block
2338903ms th_a       fork_database.cpp:66          push_block           ] Pushing block to fork database that failed to link: 0012cbcdf8df325b27718f91435824053e275a17, 1231821
2338903ms th_a       fork_database.cpp:67          push_block           ] Head: 1231708, 0012cb5c8d439f7dba8246e291b84d4329240d5b
2338903ms th_a       application.cpp:531           handle_block         ] Error when pushing block:
3080000 unlinkable_block_exception: unlinkable block
block does not link to known chain
    {}
    th_a  fork_database.cpp:87 _push_block

    {"new_block":{"previous":"0012cbcc4082c522623e2ed71a06328ac7b81e72","timestamp":"2015-11-25T16:25:03","witness":"1.6.28","transaction_merkle_root":"0000000000000000000000000000000000000000","extensions":[],"witness_signature":"205d0b9953579a00595199d54c57ab8d8b5c7262e5cd1093ea91df95f810d48ef6670df4bd4b3a71b8858ee0b9ddc8c8aacb94a0909d3862155d6acdaf50cf9695","transactions":[]}}
    th_a  db_block.cpp:208 _push_block
Segmentation fault
alfredo@alfredo-Inspiron-5559 ~/CLionProjects/pull339/bitshares-core $ 

please note this were while chain was syncing and it was not all the times, sometimes it just exit clean as expected and no replay is needed. seems to be dependent on where on the chain the process is stopped.

when segfaulting at the exit on the restart at 1 time the replay was only on the last part of the chain while in other the data was corrupted and had to delete the datadir and startover.

during an unexpected shutdown i got a full replay, this is bettera than previous version where

@pmconrad
Copy link
Contributor Author

pmconrad commented Aug 6, 2017

I believe the errors when pushing blocks after ctrl-c/SIGTERM are unrelated to this PR, I have seen similar messages when terminating an unmodified node. It looks like the P2P code is still active while the database is being shut down. Note sure why this happens, application::shutdown closes the P2P layer before closing the database. Perhaps a race condition.

Still looking into the data corruption. I believe I have found a bug in the undo_database that is not triggered in the original code, but can be triggered during a partial replay. Did you try a full replay instead of deleting the datadir?

In the case of an unexpected shutdown, evil things can happen, especially when you pull the power plug. Disk buffers may not be flushed etc., which means you most likely have an inconsistent on-disk state.

@oxarbitrage
Copy link
Member

i am pretty sure the segfaults are related to the last commits of this pull but ill do some testing with nodes without this changes to confirm. the control-c or sigterm kill is always a clean shutdown if you have ram enough or using ram reducing node options. i don't remember this kind of segfaults when trying to exit clean from a node without the code in this pull request.

will confirm by comparing with a node without that code and get back here to update.

i understand what you mean about the unexpected shutdown, lets forget that case.

@pmconrad
Copy link
Contributor Author

pmconrad commented Aug 6, 2017

Found and fixed a bug in undo_database:

undo_database contains a stack of undo "frames", each of which should be tied to an undo session. The undo session can commit or undo (i. e. roll back) the top frame, or merge the two top frames on the stack.

The merge is used for a kind of sub-transaction: when a proposal is executed, a sub-session of the current session is created. If the proposal fails for some reason, the sub-session is undone. If the proposal executes successfully, the sub-session is merged with its "parent" session. Problem: during replay, a parent session does not exist, because undo is disabled, therefore the merge fails. In a full replay, this situation does not occur, most likely because a previous proposal failed, and the resulting undo creates an empty frame on the stack! https://github.com/cryptonomex/graphene/blob/master/libraries/db/undo_database.cpp#L121-L122

The latest commit resolves this problem by treating the merge as a no-op if the undo stack is empty. This is compatible with previous behaviour.

Regarding the segfaults, I have also seen these in an unmodified node.

@ThomasFreedman
Copy link

PC said: "Regarding the segfaults, I have also seen these in an unmodified node."

Yes, as have I. It's actually quite frequent, even with track-account / partial operations. Likelihood of a segfault with a ^C stop increases the longer the node has been running.

I don't stop with ^C in production, I use systemD, and coded a stop event using:
/usr/bin/pkill -SIGINT witness_node
Still, it crashes rather often from my observation.

I like this work and the quality I'm seeing in testing it. Great job guys, glad to see these issues being addressed. This also provides more reliability and is of immediate benefit to all witnesses.

@SahkanDesertHawk
Copy link
Contributor

Good work here team. Just like Tom, I use systemD to run the nodes and capture output into the logs. Stopping services of systemD crashes it every time and requires replay. The output varies, sometimes it will show a clean exit and sometimes it will show an error like this:

3107456ms th_a main.cpp:195 main ] Exiting with error:
11 eof_exception: End Of File
unexpected end of file
{}
th_a json.cpp:430 variant_from_stream
rethrow
{}
th_a application.cpp:480 startup
3107457ms th_a db_management.cpp:170 close ] Database close unexpected exception: {"code":10,"name":"assert_exception","message":"Assert Exception","stack":[{"context":{"level":"error","file":"fork_database.cpp","line":43,"method":"pop_block","hostname":"","thread_name":"th_a","timestamp":"2017-07-11T08:51:47"},"format":"prev: poping block would leave head block null","data":{}},{"context":{"level":"warn","file":"db_block.cpp","line":431,"method":"pop_block","hostname":"","thread_name":"th_a","timestamp":"2017-07-11T08:51:47"},"format":"","data":{}}]}
3108442ms th_a db_management.cpp:170 close ] Database close unexpected exception: {"code":3070001,"name":"pop_empty_chain","message":"there are no blocks to pop","stack":[{"context":{"level":"error","file":"db_block.cpp","line":423,"method":"pop_block","hostname":"","thread_name":"th_a","timestamp":"2017-07-11T08:51:48"},"format":"there are no blocks to pop","data":{}},{"context":{"level":"warn","file":"db_block.cpp","line":431,"method":"pop_block","hostname":"","thread_name":"th_a","timestamp":"2017-07-11T08:51:48"},"format":"","data":{}}]}

In both cases replay is required.

@pmconrad
Copy link
Contributor Author

pmconrad commented Sep 7, 2017

@oxarbitrage @abitmore it is important to get this into the next release too, please finish your reviews and merge

@@ -118,15 +118,19 @@ void undo_database::undo()
_db.insert( std::move(*item.second) );

_stack.pop_back();
if( _stack.empty() )
_stack.emplace_back();
Copy link

Choose a reason for hiding this comment

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

curious why we had this in the first place, and why we think these two lines should be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think these two lines were added as a workaround for the problem I describe here: #339 (comment)

4822c21 contains a better fix to the underlying problem, IMO.

Copy link

Choose a reason for hiding this comment

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

not sure I understand all the corner cases, but it looks better. thanks.

Copy link
Member

@abitmore abitmore left a comment

Choose a reason for hiding this comment

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

I'm OK with it.

Copy link
Member

@oxarbitrage oxarbitrage left a comment

Choose a reason for hiding this comment

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

definitely this is an improve, when killed and the node segfaults(happens often) the full chain will not be replayed, among other scenarios where the new code is helpful. it might not solve all the cases but it is still a time saver and smart way to reuse data saved before crash. looks good.

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.

None yet

8 participants