Commit graph

3509 commits

Author SHA1 Message Date
Owain G. Ainsworth
3c1bcb86ee add newsize parameter to keypoolrefill 2014-01-22 16:20:08 +00:00
Owain G. Ainsworth
99fdcf5d09 Add allowhighfees to SendRawTransactionCmd 2014-01-22 16:20:08 +00:00
Owain G. Ainsworth
5619604c21 Add addresses member to ListUnspentCmd 2014-01-22 16:20:08 +00:00
Owain G. Ainsworth
b677a421d0 Add an interface to provide help text for supported commands.
This changes the api to register new commands to also pass in the help
text.
2014-01-22 16:20:08 +00:00
Owain G. Ainsworth
7e1c44369c Adapt to btcjson api changes.
Add placeholder help text for all the json types that btcws adds. Jrick will
fill them in when he adds documentation.
2014-01-22 16:19:39 +00:00
Josh Rickmar
e745fffb83 Fix slice index for parameter. 2014-01-22 10:13:34 -05:00
Josh Rickmar
e321b6bdc7 Rename exportwatchingwallet zip option to download. 2014-01-22 10:08:09 -05:00
Josh Rickmar
8fb5c9f0e6 Return the actual id value, not func. 2014-01-21 15:10:12 -05:00
Josh Rickmar
f471d2b336 Add ExportWatchingWalletCmd. 2014-01-21 14:23:36 -05:00
Josh Rickmar
d3e4bcdcf5 Fix sendrawtransaction for websockets.
This fixes two issues: first, the sendrawtransaction handler had an
extra character in the key in the websocket handler map, preventing
the handler from never running.  Second, a nil pointer dereference was
removed from the handler.

This change fixes the minedtx notifications for btcwallet, since the
websocket-handler now runs instead of falling back to the legacy RPC
handler.
2014-01-20 18:27:27 -05:00
Dave Collins
d0d74b4e3e Add checkpoint at block height 279000. 2014-01-20 11:03:11 -06:00
Dave Collins
0a86df4a16 Correct test print found by go vet. 2014-01-19 21:41:52 -06:00
Dave Collins
f12ca20372 Enable memdb support.
This commit adds the btcdb memdb backend as a supported database type.
Note that users will NOT want to run in this mode because, being memory
only, it obviously does not persist the database when shutdown.

It is being added for testing purposes to help prevent constant abuse to
developer's hard drive when churning the block database multiple times a
day.
2014-01-19 20:44:06 -06:00
Dave Collins
e2dba2a074 Update for recent btcdb API changes. 2014-01-19 20:13:53 -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
583406ee51 Use block headers to generate node index.
This commit changes the node index creation to use block headers instead
of full blocks.  This speeds up the initial node index generation since it
doesn't require loading a bunch of full blocks at startup.
2014-01-19 13:04:07 -06:00
Dave Collins
1626994433 Avoid copying block headers in convenience locals.
This commit modifies local variables that are used for more convenient
access to a block's header to use pointers.  This avoids copying the
header multiple times.
2014-01-19 12:42:45 -06:00
Dave Collins
be277b7230 Update for recent btcwire API changes. 2014-01-19 12:32:30 -06:00
Dave Collins
f309e899f3 Make use of the new btcdb functions.
This commit switches the handleGetHeadersMsg function to make use of the
new FetchBlockHeightBySha and FetchBlockHeaderBySha functions in btcdb.

Also, while here, nuke the header copy which is no longer required due to
the recent btcwire changes.
2014-01-19 03:05:02 -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
6672f71d68 Add tests for new Serialize/Deserialize functions. 2014-01-18 21:43:11 -06:00
Dave Collins
06d1236d49 Add Serialize/Deserialize for BlockHeader.
This commit introduces two new functions for Blockheader named Serialize
and Deserialize.  The functions provide a stable mechanism for serializing
and deserializing block headers to and from disk.  The main benefit here
is deserialization of the header since typically only full blocks are
serialized to disk.  Then when a header is needed, only the header portion
of the block is read and deserialized.
2014-01-18 21:42:43 -06:00
Dave Collins
33bb455365 Update for recent btcwire API changes. 2014-01-18 21:15:09 -06:00
Dave Collins
0696c757fa Update ldb/dbtest to latest goleveldb API. 2014-01-18 21:06:10 -06:00
Dave Collins
d6aea22adb Remove deprecated InvType_* constants.
This closes #13.
2014-01-18 20:53:50 -06:00
Dave Collins
144822d4bf Remove BlockHeader.TxnCount field.
This commit removes the TxnCount field from the BlockHeader type and
updates the tests accordingly.  Note that this change does not affect the
actual wire protocol encoding in any way.

The reason the field has been removed is it really doesn't belong there
even though the wire protocol wiki entry on the official bitcoin wiki
implies it does.  The implication is an artifact from the way the
reference implementation serializes headers (MsgHeaders) messages.  It
includes the transaction count, which is naturally always 0 for headers,
along with every header.  However, in reality, a block header does not
include the transaction count.  This can be evidenced by looking at how a
block hash is calculated.  It is only up to and including the Nonce field
(a total of 80 bytes).

From an API standpoint, having the field as part of the BlockHeader type
results in several odd cases.

For example, the transaction count for MsgBlocks (the only place that
actually has a real transaction count since MsgHeaders does not) is
available by taking the len of the Transactions slice.  As such, having
the extra field in the BlockHeader is really a useless field that could
potentially get out of sync and cause the encode to fail.

Another example is related to deserializing a block header from the
database in order to serve it in response to a getheaders (MsgGetheaders)
request.  If a block header is assumed to have the transaction count as a
part of it, then derserializing a block header not only consumes more than
the 80 bytes that actually comprise the header as stated above, but you
then need to change the transaction count to 0 before sending the headers
(MsgHeaders) message.  So, not only are you reading and deserializing more
bytes than needed, but worse, you generally have to make a copy of it so
you can change the transaction count without busting cached headers.

This is part 1 of #13.
2014-01-18 20:53:20 -06:00
Dave Collins
7ad6e235ad Reduce the initial idle timeout to 30 seconds.
This commit reduces the initial idle timeout before version negotiation
has happened on a new peer to 30 seconds.  Previously it could take 5
minutes due to the general idle timeout.
2014-01-18 01:44:34 -06:00
Dave Collins
8c7d44c8dc Add authentication deadline to RPC server cnxns.
Previously it was possible to open a connection to the RPC server, never
authenticate, and idle forever.

This is work toward #68.
2014-01-18 00:08:39 -06:00
Josh Rickmar
b90c6c61ba Fix previous. 2014-01-17 18:38:26 -05:00
Dave Collins
0fbd962f8a Use our own websocket.Server instance.
The websocket.Server used the by websocket.Handler type automatically adds
a handshake function which prevents connections when the Origin header is
not set.  Not all clients send this information and we already require
authentication headers as the auth mechanism anyways.
2014-01-17 16:30:29 -06:00
Dave Collins
737e69594b Don't spend time on txout ntfns when no listeners. 2014-01-17 16:30:01 -06:00
Dave Collins
9474ef29d7 Use strings in websocket send/receive.
The websocket package assumes binary blobs if []byte is used.  Since we're
using JSON-RPC for all the websocket communications, it should be text
based.

This commit changes the websocket Send/Receive and associated channels to
strings accordingly.
2014-01-17 15:48:00 -06:00
Dave Collins
75554fab09 Fix merge conflict. 2014-01-17 15:45:23 -06:00
Josh Rickmar
ed8812f340 Add NotifyBlocksCmd. 2014-01-17 16:44:58 -05:00
Dave Collins
f089853d4d Move RPC websocket init code to rpcwebsocket.go. 2014-01-17 15:44:36 -06:00
Josh Rickmar
20e56d6eda Ask for block(dis)connected updates.
This removes the last notification that was being sent unsolicited.
Since it is no longer needed, the code to duplicate notifications to
all clients has been removed.
2014-01-17 16:38:16 -05:00
Dave Collins
1b54badde1 Improve efficiency of checkpoint tracking.
Previously the code performed a database query for every checkpoint (going
backwards) to find the latest known checkpoint on every block.  This was
particularly noticabled near the beginning of the block chain when there
are still several checkpoints that haven't been reached yet.

This commit changes the logic to cache the latest known checkpoint while
keeping track of when it needs to be updated once a new later known
checkpoint has been reached.

While here, also add a log message when a checkpoint has been reached and
verified.
2014-01-17 09:59:52 -06:00
Dave Collins
b11f1620e2 Remove warnings for errors that are returned.
ok @owainga.
2014-01-17 09:40:34 -06:00
Dave Collins
4c13410e62 Update README.md TODO. 2014-01-17 00:51:42 -06:00
Dave Collins
03394d6309 Bring README.md and doc.go examples up to date.
Since sqlite is now deprecated, update the examples to use levelb.  Also,
add false to the ProcessBlock calls for the fastAdd parameter.
2014-01-17 00:48:32 -06:00
Dave Collins
84f6089bc9 Rework and improve async script validation logic.
The previous script validation logic entailed starting up a hard-coded
number of goroutines to process the transaction scripts in parallel.  In
particular, one goroutine (up to 8 max) was started per transaction in a
block and another one was started for each input script pair in the
each transaction.  This resulted in 64 goroutines simultaneously running
scripts and verifying cryptographic signatures.  This could easily lead to
the overall system feeling sluggish.

Further the previous design could also result in bursty behavior since the
number of inputs to a transaction as well as its complexity can vary
widely between transactions.  For example, starting 2 goroutines (one to
process the transaction and one for actual script pair validation) to
verify a transaction with a single input was not desirable.

Finally, the previous design validated all transactions and inputs
regardless of a failure in one of the other scripts.  This really didn't
have a big impact since it's quite rare that blocks with invalid
verifications are being processed, but it was a potential way DoS vector.

This commit changes the logic in a few ways to improve things:

- The max number of validation goroutines is now based on the number of
  cores in the system
- All transaction inputs from all transactions in the block are collated
  into a single list which is fed through the aforementioned validation
  goroutines
- The validation CPU usage is much more consistent due to the collation of
  inputs
- A validation error in any goroutine immediately stops validation of all
  remaining inputs
- The errors have been improved to include context about what tx script
  pair failed as opposed to showing the information as a warning

This closes conformal/btcd#59.
2014-01-16 20:02:30 -06:00
David Hill
871481ce1b Implement submitblock.
Closes #61.
2014-01-15 15:07:43 -06:00
Dave Collins
e3122c1b1d Remove extra parnethesis in previous. 2014-01-15 10:19:51 -06:00
Dave Collins
fcdddd499f Use a more specific license adjective in README.md.
This was proposed by @apotheon.
2014-01-15 10:17:22 -06:00
Josh Rickmar
bd98836a2b Fix several bugs in the RPC server shutdown.
The RPC server was performing some of the shutdown logic in the wrong
order, that is, logging the the server has shut down, waiting for all
server goroutines to finish, and then closing a channel to notify
server goroutines to stop.  These three items have been reversed to
fix a hang where goroutines currently being waited on had not shut
down because they did not receive the notification.

While here, the server waitgroup was incremented for a goroutine that
was running without it, another select statement was added to stop a
duplicate close (which never occured last commit when I added the
select statements), and the "stopping rescan" logging was moved to
debug to make the ^C shutdown logging nicer.
2014-01-14 22:53:07 -05:00
Josh Rickmar
d8227c2751 Only close websocket disconnected chan if still open.
A channel cannot be closed multiple times, so use a select statement
to only close the channel if it can not be read from.
2014-01-14 21:47:27 -05:00