The specific parameters required by a backend is better left up to the
backend itself. For example memdb has no need for a database path, while
ldb does. This commit modifies the OpenDB and CreateDB functions to take
a arbitrary arguments which are passed along to the driver. The driver is
expected to verify the correct type and number of arguments and error
accordingly.
The existing backends have been updated accordingly.
This commit prunes several unused functions from the Db interface and the
underlying implementations. For the most part these are holdovers from
the original sqlite implementation. It also removes the types associated
with those functions since they are no longer needed. The following
functions and types have been removed:
- InvalidateCache
- InvalidateBlockCache
- InvalidateTxCache
- SetDBInsertMode
- InsertMode type and associated constants
- NewIterateBlocks
- BlockIterator interface
The reasons for removing these are broken out below.
- Neither of two current implementations implement these functions nor
does any of the fully functional code using the interface invoke them.
- After contemplating and testing caching of blocks and transactions at
this layer, it doesn't seem to provide any real benefit unless very
specific assumptions about the use case are made. Making those
assumptions can make other use cases worse. For example, assuming a
large cache is harmful to memory-constrained use cases. Leaving it up
to the caller to choose when to cache block and transactions allows much
greater flexibility.
- The DB insert mode was an artifact of the original sqlite implementation
and probably should have only been exposed specifically on the
implementation as opposed through generic interface. If a specific
implementation wishes to provide functionality such as special modes,
that should be done through type assertions.
This commit introduces two new functions to the btcdb.Db interface named
FetchBlockHeightBySha and FetchBlockHeaderBySha.
The FetchBlockHeightBySha function is useful since previously it was only
possible to get the height of block by fetching the entire block with
FetchBlockBySha and pulling the height out of the returned btcutil.Block.
The FetchBlockHeaderBySha function will ultimately make it much more
efficient to fetch block headers. Currently, due to the database design
in the ldb backend, the entire block has to be loaded anyways, so the only
current benefit is to avoid the deserialize on all of the transactions.
However, ultimately btcdb will gain a more efficient backend which can
also avoid reading all of the extra transaction data altogether.
The sqlite3 backend has been deprecated for quite some time. As a result,
it has not been updated with many of the more recent changes which means
the behavior no longer conforms to the interface contract.
This commit adds a new backend driver which conforms to the btcdb
interface to provide a memory only database. This is primarily useful for
testing purposes as normal operations require a persistent block storage
mechanism.
The btcutil code was recently changed to provide a new Tx type which
provides hash caching (among other things). As a result, the notion of
obtaining a transaction hashes via TxShas was deprecated as well. This
commit updates the tests and backend implementation code accordingly.
This commit optimizes InsertBlock slightly by using the cached transaction
hashes instead of recomputing them. Also, while here, use the
ShaHash.IsEqual function to do comparisons for consistency.
This is ongoing work towards conformal/btcd#25.
ok @drahn.
This commit adds the infrastructure needed to re-run the integrity tests
after calling the InvalidBlockCache, InvalidateTxCache, and
InvalidateCache functions. The tests intentially randomize the order the
invalidate functions are called in to increase the likelyhood of finding
in issues realted to ordering of the calls.
This commit changes the interface test errors to all report the block
height and hash prior to the failure. Test failures that transactions
also now report the transaction number and hash. The makes it much
easier to track down where a test failure occurs.
The idea here is that interface_test.go will be directly usable in each
implementation to increase test coverage there as well, but also works at
the top-most level to test arbitrary backends.
This is simply at start at providing generic interface tests. The only
thing is tests so far is the empty database conditions on NewestSha, but
it adds infrastructure for creating and opening databases with special
type handling based on the database and necessary logic to teardown so
multiple backends can be tested simultaneously.
This and the next series of commits all discussed with drahn@.