Commit graph

3510 commits

Author SHA1 Message Date
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
Dave Collins
b6e4ae4441 Optimize duplicate transaction input check.
Profiling showed the duplicate transaction input check was taking around
6% of the total CheckTransactionSanity processing time.  This was largely
due to using fmt.Sprintf to generate the map key.

This commit modifies the check instead to use the actual output as a map
key.

The following benchmark results show the difference:

Before: BenchmarkOldDuplicatInputCheck    100000     21787 ns/op
After:  BenchmarkNewDuplicatInputCheck   2000000       937 ns/op

Closes #2
2013-10-26 14:31:15 -05:00
Dave Collins
36bd4b8994 Revert "Enable memdb support."
This reverts commit 1fadf619c7.
2013-10-26 01:58:50 -05:00
Dave Collins
7b01074f5e Add simple benchmark for MruInventoryMap handling. 2013-10-26 01:57:00 -05:00
Dave Collins
261e61f8ee Vastly optimize the MRU inventory handling.
Profiling showed the MRU inventory handling was taking 5% of the total
block handling time.  Upon inspection this is because the original
implementation was extremely inefficient using iteration to find the
oldest node for eviction.

This commit reworks it to use a map and list in order to achieve close to
O(1) performance for lookups, insertion, and eviction.

The following benchmark results show the difference:

Before: BenchmarkMruInventoryList          100     1069168 ns/op
After:  BenchmarkMruInventoryList     10000000         152 ns/op

Closes #21
2013-10-26 01:39:53 -05:00
Dave Collins
1fadf619c7 Enable memdb support. 2013-10-25 21:41:17 -05:00
Dave Collins
24a5645fce Update for recent btcchain tx script val change.
The ValidateTransactionScripts was recently changed to accept script flags
which pass through to the script engine in order to control its validation
behavior.  This commit modifies the transaction memory pool script
validation code for this change and additionally adds the new flag to
perform canonical signtaure checking.
2013-10-25 15:36:31 -04:00
David Hill
8eead5217d Add flag bitmask to NewScript for canonical sig checks.
This removes the bip16 bool from NewScript and adds it to flags (with
the constant ScriptBip16), and also adds a new flag,
ScriptCanonicalSignatures, which will call btcec.ParseDERSignature
parsing a signature during an Execute.  This is needed to emulate
bitcoind behavior, as bitcoind performs canonical signature validation
(DER format) in some places (like mempool acceptance) but not others
(like block validation).

Updated tests and test coverage file to reflect changes.
2013-10-25 15:15:00 -04:00
Josh Rickmar
98ac46b37d Add ParseDERSignature.
This change adds an additional signature parsing function which
performs additional checks to verify the signature is serialized in a
valid DER (and thus, unique) format, instead of allowing the less
strict BER signatures that ParseSignature will happily accept.

Added additional tests and updated test coverage to reflect changes.
2013-10-25 15:09:48 -04:00
Owain G. Ainsworth
e396121192 More info commands. 2013-10-25 20:02:13 +01:00
Owain G. Ainsworth
711f229487 add getmininginfo to switch and move to alphabetical order.
more tests.
2013-10-25 19:50:39 +01:00
Owain G. Ainsworth
0daf04f9bd More get commands. 2013-10-25 19:42:25 +01:00
John C. Vernaleo
00382bed8d Adding to tests.
Fix typo in a test name.

Update coverage report.
2013-10-25 14:16:29 -04:00
Owain G. Ainsworth
020444906b Getblockhash and getblock template
Fix some type wranging in unmarshal for getblocktemplate
2013-10-25 19:00:33 +01:00
Owain G. Ainsworth
ebc4c17162 Add basic test for getbestblockhash.
And move the getblock/getblockcount so they are in order.
2013-10-25 18:36:27 +01:00
Owain G. Ainsworth
d1ac7b9384 getaddressesbyaccoutn and getbalance test.
and one bug in the marshalling code for getbalance
2013-10-25 18:32:51 +01:00
Owain G. Ainsworth
fedafbdd49 go fmt 2013-10-25 18:23:53 +01:00
Owain G. Ainsworth
b3b8b37855 test and fix bugs in getaddednodeinfo 2013-10-25 18:23:28 +01:00
Owain G. Ainsworth
77316a003a fix method for getaccountaddress.
and test dumpprivkey, dumpwallet, encryptwallet, getaccount and
getaccountaddress
2013-10-25 17:47:11 +01:00
Owain G. Ainsworth
bac5600145 basic functionality test for decoderawtransactioncmd 2013-10-25 17:22:07 +01:00
Owain G. Ainsworth
6227c446d3 Add a framewowrk for parsing and creating json commands.
Initial prototype for one command mostly from jrick, with discussion
with me and jcv.  Other commands mocked up in a couple of long boring days by
yours truly.

Code isn't fully tested yet so may well still be buggy in the type conversions.
Test will be added over the next few days to get this up to snuff.
2013-10-25 17:10:39 +01:00
Dave Collins
89d86d07ac ValidateTransactionScripts now accepts script flags.
This commit modifies the ValidateTransactionScripts API to accept the
recently added ScriptFlags from btcscript.  This provides flexibility to
the caller to choose validation behavior based on those new flags.
2013-10-25 10:49:06 -05:00
Dave Collins
bd297491b9 Make var length string overflow tests consistent.
This commit modifies the variable length string overflow tests slight to
make them consistent with the other overflow tests.
2013-10-25 09:55:27 -05:00
Dave Collins
a4c5c620c6 Finish a TODO in the message headers tests. 2013-10-25 09:00:05 -05:00
Dave Collins
d1edbf1f0b Add tests to exercise intential malicious overflow.
This commit adds several tests which intentionally attempt to feed
malicious data to the various deserialize functions.
2013-10-25 08:57:39 -05:00
Dave Collins
5cc32bbfc7 Add bounds checking to all variable length allocs.
Several of the bitcoin data structures contain variable length entries,
many of which have well-defined maximum limits.  However, there are still
a few cases, such as variable length strings and number of transactions
which don't have clearly defined maximum limits.  Instead they are only
limited by the maximum size of a message.

In order to efficiently decode messages, space is pre-allocated for the
slices which hold these variable length pieces as to avoid needing to
dynamically grow the backing arrays.  Due to this however, it was
previously possible to claim extremely high slice lengths which exceed
available memory (or maximum allowed slice lengths).

This commit imposes limits to all of these cases based on calculating
the maximum possible number of elements that could fit into a message
and using those as sane upper limits.

The variable length string case was found (and tests added to hit it) by
drahn@ which prompted an audit to find all cases.
2013-10-25 08:55:39 -05:00
Dale Rahn
70aa92bf0d Test some boundary conditions that exercise 'flaws' in the current
btcwire protocol.
2013-10-24 14:39:40 -04:00
Josh Rickmar
618b885e9e Notify wallets of mined transactions.
This change allows btcwallet to keep a pool of transactions that have
not yet been mined into a block, notifying wallet when transactions
are mined, as well as introducing a new way to send the
btcd:blockconnected notification with wallet-specific information as
part of the same notification.  When a transaction is sent using the
RPC call 'sendrawtransaction', a notification request will be
automatically registered with the connected wallet (if using
websockets) to notify the wallet when the transaction first appears in
a block.

To perform this notification, and to avoid requiring wallets from
waiting for seperate mined tx notifications (and resend after a
timeout) or from sending an additional tx mined request for every tx
in the pool after each new block, the blockconnected notification is
now created seperately for each wallet.  If the notified wallet has
sent a transaction, an additional JSON field "minedtxs" will include
an array of transaction IDs that the wallet has created and which are
included in the new block.

This new unique blockconnected notification can also be used for
additional notifications that may happen each new block in the future,
and to cut down on existing notification handlers in btcwallet, such
as for transactions to a watched address.
2013-10-23 18:13:03 -04:00
Dave Collins
2bb8c5d5cc Bring back default redirect for profiling.
Now that the RPC server uses its own mux, bring back the code which does
the automatic 303 redirect for the root of the profile server.
2013-10-23 10:48:17 -05:00
Dave Collins
5a4772bdc6 Change the RPC server to use it's own Muxer.
Rather than relying on the http package's DefaultServeMux for the RPC
server, create a unique mux specifically for the RPC server.  This ensures
things, such as the http profiling handlers, do not commingle.
2013-10-23 10:45:43 -05:00
Dave Collins
8970d4bf99 Revert "Add default redirect for profiling when enabled."
This reverts commit cc6cfdad9e.
2013-10-23 10:25:09 -05:00
Dave Collins
cc6cfdad9e Add default redirect for profiling when enabled.
This commit adds a simple 303 redirect for the root of profile server so
launching it without a path automatically goes to the debug profiling
page.
2013-10-23 09:39:02 -05:00
Dave Collins
7846b2f4e2 Update README.md TODO to remove 32-bit MSI.
32-bit MSIs will now be available for all future releases.
2013-10-22 17:05:43 -05:00
Dave Collins
1e93cdad6e Add 0.3.2 deps to deps.txt. 2013-10-22 16:45:19 -05:00
Dave Collins
3b025b2352 Prepare for release 0.3.2. 2013-10-22 16:40:51 -05:00