This commit modifies the way initial database creation is handled.
Previously, the genesis for the main chain was inserted automatically upon
creation of the database. However, that approach caused an issue since
other networks such as the test network don't use the same genesis block
as the main network.
The new approach introduced by this commit is to leave it up to the caller
to insert the desired genesis block. In order to support this, the
InsertBlock function has been modified to allow the first (and only the
first) block to be inserted without having an existing parent. Also, the
NewestSha function has been modified to return a zero hash, -1 for the
height, and no error when the database does not yet have any blocks. This
allows the caller to determine the difference between no blocks and only
the genesis block (in which case the return values would be the genesis
hash and 0 for the height).
The Db interface is intended to work with block heights as opposed to
specific database ids which may or may not be the same as the block
height. This commits changes the function names to make that distinction
a little more clear.
This commit makes several changes to the operation tests as follows:
- Ensure the database is closed between each operational mode test as
otherwise the database is locked when trying to reopening it which
makes it unusable
- Make the insert tests error after a single failure since every test
afterwards is guaranteed to fail as well
- Remove some of the logging statements which cluttered up the failed test
prints making it harder to see why a given test failed
- Make a couple of the log messages more descriptive
The function is being added back in since the tests rely on it, but it is
marked as DEPRECATED since it really should not be a part of the public
generic db interface.