Published on: 2014-06-07T00:57:04+00:00
According to Jeff Garzik, a Bitcoin core developer and open source evangelist, it is important to compile in as many cheap, compiler-predictable asserts as possible into the production runtime. Expensive diagnostics should be compiled in and disabled by default at runtime to avoid slowing down the system. Jannis Froese suggested changing the current use of asserts to a definition that is independent of NDEBUG and introducing a second class of debugging asserts exclusively for expensive, redundant checks. These changes would resolve most concerns about the current use of asserts. Jannis Froese also recommended that assertion errors be handled differently, such as proposing a -reindex instead of raising an assertion error in certain cases. The writer of an email exchange agrees with the kernel's policy of using lightweight assertions and suggests using the glog library's CHECK macros to make software more robust. The current assertion system in Bitcoin Core is designed to prevent incorrect behavior, but it comes at the cost of meeting performance requirements. Assertions are intended for checks like ensuring a hash hasn't changed or that data structures are in sync. There have been concerns about the current use of assertions, and some suggest introducing debugging asserts exclusively for expensive, redundant checks. It is common for professional codebases to require assertions to be enabled, and Bitcoin Core currently fails to build if assertions are disabled. In a conversation from June 2014, Mike Hearn discusses the use of assertions with side effects in code. He explains that the codebase no longer uses them, but still requires them to be enabled to catch errors. He recommends using the glog library's CHECK macros, which print stack traces when they fail. In another email conversation, it is revealed that Ron's email was being spamfoldered due to Yahoo's DMARC policy and broken SF.net mailing list software. It is suggested to move away from SF.net for hosting mailing lists. The use of assert() in code is discussed, and it is stated that assert() should have no side effects. Bitcoin Core currently requires assertions to be enabled in order to build. The issue with the Bitcoin code for 0.9.x regarding assertions has been addressed through a commit and code with all side effects removed. Unit tests are available, along with resources on building Bitcoind.exe and alternate coin-qt.exe. The problem with assert() having side effects is explained in a book titled "Gotcha #28 Side Effects". It is questioned why these coding practices were not fixed earlier.
Updated on: 2023-08-01T09:26:34.933676+00:00