Bitcoin full node and query server

Nov 16, 2018

View in context in the libbitcoin Slack #general mirror.

jungly22:36
Hi @evoskuil, I have a small question about how asserts are used and how that interacts with NDEBUG flag enabled by default in the makefiles. Consider the update_confirmation_state method in bitcoin_database. https://github.com/libbitcoin/libbitcoin-database/blob/a0f64d2f904ec1e53e1b5b93eb8ede4102a8198f/src/databases/block_database.cpp#L361 If asserts are disabled, say NDEBUG is enabled, which is default in the libbitcoin Makefiles, then asserts will not get triggered. Even if an invariant fails, a block’s state will get updated. This could result in a not yet validated block being marked as confirmed, if data_base incorrectly calls the index method with such args. In fact, I was doing so in my first rewrites of the block database tests. I might be missing a detail somewhere. But I wanted to ask if it will make sense to convert the asserts to a simple condition and a return in case of the invariants failing. Or, do we expect production builds to disable NDEBUG? I have now set up my environment to always use --disable-ndebug so I can catch any similar bad situations from my code.
4 replies · evoskuil, jungly · last Nov 19, 2018
evoskuil13:28
Keep in mind that assertions are not error handling, so it matters not whether the assertions are enabled of disabled by default or otherwise.
evoskuil13:30
The database methods are public but not safe. libbitcoin-database is intended for use by libbitcoin-blockchain, which should provide safety to its public methods. This is a performance tradeoff, as making the database methods safe generally would have a material cost.
(edited)
evoskuil13:32
Since tests are verified in both debug and ndebug environments unsafe calls will be caught by our CI environment.
(edited)
jungly13:35
OK. That makes sense. I didn't realise that my local setup had ndebug enabled. I was thinking I was doing something bad with the locks and all this while I had a bad call to unindex that was passing on my machine but failing on travis in one of the test configs 🙂