Commit graph

3244 commits

Author SHA1 Message Date
Owain G. Ainsworth
e8321441af add a stringer for ScriptClass 2013-11-06 00:11:14 +00:00
Owain G. Ainsworth
56a62309ae Add some error messages to be used by btcd.
ok jcv
2013-11-05 22:35:06 +00: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
John C. Vernaleo
b72f0c6474 Make peerinfo output match bitcoind a bit better.
Add long option for username in btcctl.
2013-11-04 16:25:13 -05:00
David Hill
a97fd5fe2c add test for testing IsOnCurve 2013-11-04 14:42:21 -05:00
Josh Rickmar
1f087adf15 Separate ws command handlers into separate funcs. 2013-11-04 14:15:05 -05:00
Josh Rickmar
53e1c2d6bd Stringify the address hash for txRequests map.
This change allows map lookups using address hashes (which are
returned as []byte) instead of either copying the hash into an array,
or doing a bytes.Equal().

A stupid range over a map until the right key is found was also just
changed to a single map lookup.
2013-11-04 14:11:39 -05:00
Josh Rickmar
506c3eacac Add padding for pubkey numbers.
This change pads serialized (big endian) pubkey numbers to a length of
32 bytes.  Previously, because serialized pubkey numbers are read
MSB-first, if a number could be serialized in less than 31 bytes, the
deserialized number would be incorrect.
2013-11-04 10:11:11 -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
John C. Vernaleo
815a0b0a84 Improve test coverage. 2013-11-01 15:27:17 -04:00
Josh Rickmar
2511fee152 Complete rescan extension.
This adds to the initial rescan implementation, but switches it to
rescan based on a group of addresses, rather than just one.  Due to
how expensive database lookups are during a rescan, wallets should
take advantage of this to rescan once for all needed addresses for all
accounts.
2013-11-01 09:35:52 -04:00
John C. Vernaleo
3f33e419a9 Improve test coverage and fix bug found by tests.
Spell receive the same way all the time so things work.
2013-10-31 14:51:35 -04:00
Dave Collins
5a46de5103 Add support for min required fees in tx mempool.
This commit adds checks to the memory pool to restrict allowed
transactions based on minimum required fees.
2013-10-31 12:24:28 -05:00
Dave Collins
a4794798d4 Make use of new btcwire SerializeSize API.
This commit changes the various cases that were serializing transactions
into a buffer and taking the length to use the new faster SerializeSize
API.  It also completes a TODO since the serialized size of a transaction
output is now available.
2013-10-31 00:28:37 -05:00
Dave Collins
b7b700fd5a Add tests for the new SerializeSize functions.
This commit adds tests for the new SerializeSize functions for variable
length integers and transactions (and indirectly transaction inputs and
outputs).
2013-10-31 00:20:41 -05:00
Dave Collins
26cb71d805 Expose new SerializeSize API for transactions.
This commit adds a new function named SerializeSize to the public API for
MsgTx, TxOut, and TxIn which can be used to determine how many bytes the
serialized data would take without having to actually serialize it.

The following benchmark shows the difference between using the new
function to get the serialize size for a typical transaction and
serializing into a temporary buffer and taking the length of it:

Bufffer: BenchmarkTxSerializeSizeBuffer     200000           7050 ns/op
New:     BenchmarkTxSerializeSizeNew     100000000             18 ns/op

This is part of the ongoing effort to optimize serialization as noted in
conformal/btcd#27.
2013-10-31 00:20:14 -05:00
Dave Collins
cbf648a02f Slightly optimize writeVarInt for the normal case.
Most variable length integers are smaller numbers, so this commit reverses
the order of the if checks in the writeVarInt to assume smaller numbers
are more common.

This is part of the ongoing effort to optimize serialization as noted in
conformal/btcd#27
2013-10-30 21:11:10 -05:00
Dave Collins
470ef8c58e Use correct calls to tx.Sha() in RPC server. 2013-10-30 18:40:55 -05:00
John C. Vernaleo
e1dd773e7c Improve test coverage and fix some bugs found by tests.
Fix move need to convert amount to btc from satoshi

Fix settxfee need to convert amount to btc from satoshi

Fix for optional arg off by one in move.

Fix for gettxout in optional args along with typo in error message.

And lots of new tests.
2013-10-30 17:22:56 -04:00
Dave Collins
70094fcee8 Minor cleanup.
Fix a couple of comments and call tx.Sha directly in a couple of places.
2013-10-30 14:13:29 -05:00
Dave Collins
b866e9f14c Improve RPC server log of rejected transactions.
Rather than showing all errors from ProcessTransaction as an error, check
if the error is a TxRuleError meaning the transaction was rejected as
opposed to something actually going wrong and log it accordingly.
2013-10-30 14:11:45 -05:00
Dave Collins
e76fada2d2 Optimize NotifyNewTxListener.
Looking up transactions from the database is an expensive operation.
This commit modifies the NotifyNewTxListener code to simply iterate the
transactions in the block instead of looking them up from the db.

Currently the wallet code needs a spent flag which ultimately shouldn't be
required.  For now, the spent data is simply created on the fly which is
still significantly faster than doing database transaction lookups.

Closes #24.
2013-10-30 10:54:03 -05:00
John C. Vernaleo
07de6ea013 Add additional tests for jsoncmd code.
Test stop, signrawtransaction, setaccount, sendtoaddress, and a few
others.

Fix off by one error in the optional arguments for sendtoaddress.

Rename occurances of Minconf to MinConf for constitancy.
2013-10-30 08:29:59 -04:00
Josh Rickmar
d7d2385fb0 Return JSON id with errors when possible.
This change unbreaks the case where an unknown command is sent to the
RPC server.  Instead of replying back with a nil JSON id, if the
initial unmarshal was successful (and thus, the message was valid
JSON-RPC), the unmarshaled id will be used in the error reply.
2013-10-29 23:23:22 -04:00
Josh Rickmar
334a1c1f20 Return basic Cmd from ParseMarshaledCmd when possible.
This changes the behavior of ParseMarshaledCmd to always return a
non-nil Cmd whenever unmarshaling a valid JSON-RPC message succeeds.
This is needed for RPC server code to reply back with detailed errors
to clients using the Method and Id methods of the Cmd interface.
2013-10-29 23:22:16 -04:00
Dave Collins
9442d96929 Convert errors in RPC server to new btcjson consts. 2013-10-29 19:42:21 -05:00
Owain G. Ainsworth
231efa35f5 Provide useragent in getpeerinfo now we know it. 2013-10-29 23:00:23 +00:00
Owain G. Ainsworth
c4be414921 Make ParseMarshaledCmd return a known error if the type isn't known. 2013-10-29 22:33:44 +00:00
David Hill
4f25d45e77 Grab the remote peer's user agent. 2013-10-29 21:45:45 +00:00
Owain G. Ainsworth
59e2b204a3 Add doc comments. 2013-10-29 20:30:16 +00:00
Owain G. Ainsworth
da2901a4fd Add support for the addnode command
Currently this acts on the list of all peers, and not just the list of
permanent peers. this will be changed shortly.
2013-10-29 20:30:07 +00:00
David Hill
36941cc427 Remove the satoshi consts and use them from btcutil instead. 2013-10-29 16:08:12 -04:00
David Hill
8271a11808 add SatoshiPerBitcent constant and export SatoshiPerBitcoin and
MaxSatoshi
2013-10-29 14:57:31 -04:00
Owain G. Ainsworth
b1f14732b1 Implement getpeerinfo and getconnectedcount
We have a channel for queries and commands in server, where we pass in
args and the channel to reply from, let rpcserver use these interfaces
to provide the requistie information.

So far not all of the informaation is 100% correct, the syncpeer
information needs to be fetched from blockmanager, the subversion isn't
recorded and the number of bytes sent and recieved needs to be obtained
from btcwire. The rest should be correct.
2013-10-29 17:05:12 +00:00
Owain G. Ainsworth
d647eea2b7 update statistics for the time we last send/recieved a message. 2013-10-29 17:02:04 +00:00
Owain G. Ainsworth
d26b8b2d43 Set peer.timeConnected when we are actualy connected. 2013-10-29 17:02:04 +00:00
Owain G. Ainsworth
c242d75866 Split the massive switch statement in rpcserver into a map of handlers.
Cleans up a the code a lot and removes the need to be careful about
shadowing err.

Much rejoicing from jcv, jrick and davec.
2013-10-29 17:00:25 +00:00
Owain G. Ainsworth
b96cb4317a Alphabetise command handlers. 2013-10-29 17:00:25 +00:00
Owain G. Ainsworth
975640c6b3 Switch rpcserver.go over to using the jsoncmd apis. 2013-10-29 16:59:19 +00:00
Owain G. Ainsworth
3c405563bd Add missing return; avoids panic. 2013-10-29 16:42:26 +00:00
Owain G. Ainsworth
9f96e59392 Rough and ready cut over of btcctl to use the btcjson command api. 2013-10-29 16:42:11 +00:00
Dave Collins
08fc3050a3 Convert to use new btcutil.Tx and btcchain APIs.
This commit updates btcd to work with the new btcchain APIs which now
accept btcutil.Tx instead of raw btcwire.MsgTx.  It also modifies the
transaction memory pool to store btcutil.Tx.

This is part of the ongoing transaction hash optimization effort noted in
conformal/btcd#25.
2013-10-28 15:47:24 -05:00
Dave Collins
6165e9b95b Convert API to use new btcutil.Tx.
This is part of the ongoing transaction hash optimization effort noted in
conformal/btcd#25.
2013-10-28 15:17:53 -05:00
Josh Rickmar
b0899204d9 Update NewScript example after API change.
This change updates the doc.go documentation file with the correct use
of the new (since 8eead5217d) API used
for passing additional options when creating new script engines.

Spotted by davec@
2013-10-27 19:45:07 -04: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
7d8bb5ab4c Add --cpuprofile option.
This commit provides a new --cpuprofile flag that can be used to specify a
file path to write CPU profile data into.  The resulting profile can then be
consumed by the 'go tool pprof' command.
2013-10-26 16:13:50 -05:00
Dave Collins
1aa65e6863 Correct and improve SIGINT (Ctrl+C) handling.
Since the main SIGINT handler is running as a goroutine, the main
goroutine must be kept active long enough for it to finish or it will be
nuked when the main goroutine exits.  This commit makes that happen by
slightly modifying how it waits for shutdown.

Rather than having the main goroutine only wait for the server to
shutdown, there is now a shutdown channel that is used to signal the main
goroutine to shutdown for all cases such as a graceful shutdown, a
scheduled shutdown, an RPC stop, or a SIGINT.

While here, also add a few prints to indicate a SIGINT was received and
the shutdown progress.
2013-10-26 16:10:04 -05:00