Commit graph

123 commits

Author SHA1 Message Date
Dale Rahn
dd41d71a31 If data for tx is not present, return error. 2014-04-15 10:47:25 -04:00
Dale Rahn
4d63076526 All external entry points into the database must be locked. 2014-04-15 10:17:37 -04:00
David Hill
1b51d58e55 In FetchHeightRange, preallocate the hash array.
Change FetchBlockByHeight to do the database lookup itself instead of
calling getBlkByHeight.  This saves an allocation of the entire block,
which it wasn't using.

In OpenDB, use fetchBlockShaByHeight instead of getBlkByHeight since it
only needs the sha.  This saves memory on startup.

ok drahn@
2014-03-20 16:10:52 -04:00
Dave Collins
c570830104 Update README.md example to use leveldb.
SQLite is now fully deprecated and has been removed.  Spotted and reported
by @jolan.

Closes #3.
2014-03-17 12:58:22 -05:00
Dave Collins
0a86df4a16 Correct test print found by go vet. 2014-01-19 21:41:52 -06:00
Dave Collins
2aca924514 Allow the Open/CreateDB funcs to take any params.
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.
2014-01-19 20:13:21 -06:00
Dave Collins
2eea55ae1d Prune the btcddb.Db interface.
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.
2014-01-19 18:01:05 -06:00
Dave Collins
8c34084e24 Add interface tests for new Fetch functions. 2014-01-19 02:55:07 -06:00
Dave Collins
d6c2492c7f Add FetchBlockHeightBySha/FetchBlockHeaderBySha.
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.
2014-01-19 02:54:47 -06:00
Dave Collins
845aedf103 Remove deprecated sqlite3.
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.
2014-01-19 02:36:54 -06:00
Dave Collins
27bc18ba2e Switch test coverage tool to new 'go tool cover'.
Also, make the coverage report test ldb and memdb instead of just sqlite3.
2014-01-19 02:35:41 -06:00
Dave Collins
0696c757fa Update ldb/dbtest to latest goleveldb API. 2014-01-18 21:06:10 -06:00
Marco Peereboom
6578e7345f catch up to new goleveldb 2014-01-09 13:11:37 -06:00
Dave Collins
6b18796af7 Add 2014 to copyright dates. 2014-01-08 23:54:52 -06:00
Dave Collins
472c998c0d Add support for TravisCI.
Also add TravisCI build status badge to README.md.
2013-12-10 19:17:59 -06:00
David Hill
01b6ad7196 Reset batch on error 2013-11-26 16:42:55 -05:00
David Hill
ca502abbf2 Two fixes
fix returning error on insertTx and doSpend.
clear the batch on failures as well.
2013-11-26 15:58:13 -05:00
Dave Collins
fc11da9ca0 Gofmt. 2013-11-21 09:48:57 -06:00
Dave Collins
3bc401fed1 Use btclog for logging. 2013-11-21 09:48:16 -06:00
Dave Collins
d226968472 Add a new memory database backend named memdb.
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.
2013-11-08 02:48:59 -06:00
Dave Collins
ec70b6d1b3 Add comments which describe what is spent where. 2013-11-07 18:05:46 -06:00
Dale Rahn
e10cb732fd Fix. 2013-11-07 18:24:27 -05:00
Dale Rahn
13ef0e2be9 Rework leveldb support for duplicate tx.
This separates fully spent tx from tx containing unspent TxOut
This handles duplicate tx and Ideally should be faster.
2013-11-05 13:44:36 -05:00
Dale Rahn
078fb4d38e Delete obsolete API functions. 2013-11-05 13:44:36 -05:00
Dale Rahn
b406ca7ae7 If ExistsTx fails try looking up the tx, it may be fully spent. 2013-11-05 13:44:35 -05:00
Dave Collins
80981b4696 Update to no longer use deprecated TxShas.
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.
2013-11-01 21:17:06 -05:00
David Hill
83b1e74d6c Remove explicit garbage collection. 2013-10-26 20:38:27 -05:00
Dave Collins
19880b177e Optimize InsertBlock with cached tx hashes.
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.
2013-10-26 20:21:30 -05:00
Dave Collins
998682ec83 Remove sqlitedb from the common tests.
The sqlite db backend is now deprecated.
2013-10-22 15:28:32 -05:00
Dave Collins
5eee027f92 Correct leveldb package documenation.
The leveldb package documentation still referred to sqlite from
original copy/paste.
2013-10-22 15:26:44 -05:00
Dave Collins
3b56ccaff7 Add interface test for NewestSha. 2013-10-15 10:22:46 -05:00
Dave Collins
0c8a15a9d5 Add tests to verify integrity after clearing cache.
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.
2013-10-14 20:37:58 -05:00
Dave Collins
54ad820133 Combine two test functions used to fetch tx lists.
The two functions are nearly identical, so rather than repeating the
test code, refactor it into a separate function that takes a flag.
2013-10-14 19:26:23 -05:00
Dave Collins
a9d719f0c4 Separate interface integrity tests.
This paves the way for executing the integrity tests multiple times.
2013-10-14 18:31:01 -05:00
Dave Collins
9ec86518ac Improve interface test error messages.
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.
2013-10-14 18:27:12 -05:00
Dave Collins
c99416c121 Include db type in interface tests loading message. 2013-10-14 14:35:10 -05:00
Dave Collins
01af05c8ac Add interface tests for FetchUnSpentTxByShaList. 2013-10-14 13:56:21 -05:00
Dave Collins
2ab3e0a382 Add interface tests for FetchTxByShaList. 2013-10-14 13:49:52 -05:00
Dave Collins
fb5f9c0b5a Separate interface tests and add test context.
Rather than having one mammoth interface test function, create a test
context and several helper functions that accept the context.
2013-10-14 12:26:43 -05:00
Dave Collins
06cb2ec817 Add interface test for FetchTxBySha.
This commit adds an interface test for FetchTxBySha to ensure it returns
the same MsgTx that was part of an inserted block.
2013-10-14 12:26:43 -05:00
Dave Collins
6a3824b8aa Add interface test for ExistsTxSha.
This commit adds an interface test for ExistsTxSha to ensure all
transactions inserted as a part of a block are available.
2013-10-14 12:26:42 -05:00
Dave Collins
f37fabb855 Add negative tests for FetchBlockShaByHeight.
This commit adds tests to ensure FetchBlockShaByHeight returns expected
errors when invalid heights are specified.
2013-10-14 12:26:41 -05:00
Dave Collins
06d6e5fce8 Add db type to test error outputs. 2013-10-14 12:26:40 -05:00
Dave Collins
6eebf02183 Add interface test for FetchBlockShaByHeight.
This commit adds an interface test for FetchBlockShaByHeight to ensure it
returns the same expected hash for each block inserted block height.
2013-10-14 12:26:40 -05:00
Dave Collins
670d83a74e Improve error message for FetchBlockBySha test.wq 2013-10-14 12:26:39 -05:00
Dave Collins
396d1b056d Add interface test for FetchBlockBySha.
This commit adds an interface test for FetchBlockBySha to ensure it
returns the same MsgBlock and raw bytes that were inserted.
2013-10-14 12:26:38 -05:00
Dave Collins
2d84623493 Move non-interface specific tests into db_test.go.
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.
2013-10-14 12:26:37 -05:00
Dave Collins
ff429203c4 Start interface tests that require state. 2013-10-14 12:26:37 -05:00
Dave Collins
82d1898b12 Add interface test for unsupported dbtype failures.
This commit adds an interface test to ensure that the interface returns
the expected error when trying to open or create an unsupported database
type.
2013-10-14 12:26:36 -05:00
Dave Collins
d4c1214496 Add interface test for create and open failures.
This commit adds an interface test to ensure that failures which occur
while creating or opening a database are properly handled.
2013-10-14 12:26:35 -05:00