Commit graph

794 commits

Author SHA1 Message Date
David Hill
765dbb443d Fix a bug in fetching the XML URL.
In Discover, the reponse was lowercased for comparison.  However,
this caused a 404 - Not found when fetching the url provided by
the location header if the url contained uppercase.

ok @owainga
2014-04-23 19:10:53 -04:00
Owain G. Ainsworth
4d44eeb877 Move to protecting all peer stats by the same mutex.
In practise the races caused by not protecting these quite simply didn't
matter, they couldn't actually cause any damage whatsoever. However, I
am sick of hearing about these essentially false positivies whenever
someone runs the race detector (yes, i know that race detector has no
false positives but this was effectively harmess).

verified to shut the detector up by dhill.
2014-04-23 17:38:14 +01:00
Owain G. Ainsworth
88ea84cf12 Addrman: only shuffle as much as we need.
If we switch the knuth shuffle to the version that swaps the element
with an element between it and the end of the array, then once we have
gotten to the amount of elements we need they won't change later in the
algorithm. Terminating here means that we only do 23% of the length of
the array worth of random swaps at most.
2014-04-23 17:38:13 +01:00
Owain G. Ainsworth
ec8d0e582c Attempt to create less garbage for getaddr calls.
We make ka.na immutable in the address manager. Whenever we would update
the structure we replace it with a new copy. This beats making a copy of
all addresses once per getaddr command (max is just over 23000 we would
be copying, compared to at most 2000 copies on a new getaddr that has
all addresses we know with newer dates).
2014-04-23 17:38:13 +01:00
David Hill
08377c21e2 Lower maxKnownInventory from 20000 to 1000.
ok @davecgh
2014-04-23 07:48:52 -04:00
David Hill
8a322e4792 Bypass rate limiter for sendrawtransaction.
ok @davecgh
2014-04-23 07:45:56 -04:00
David Hill
75bb52d715 In handleGetDataMsg, fix two unknown inv type bugs.
On unknown inventory types, handleGetDataMsg would loop forever.
After fixing that, if a getdata request only had unknown inventory
types, it would block forever.

ok @davecgh
2014-04-21 14:52:02 -04:00
Josh Rickmar
f88db561f1 Make rescan faster by avoiding hash copies.
Copying the RIPEMD160 after SHA256 hash result into a new stack array
to be used as a map lookup key can be quite expensive, and this should
be avoided if possible on intensive tasks such as rescans.  This
change takes advantage of the new Hash160 methods of the
AddressPubKeyHash and AddressScriptHash types to use the address's
underlying hash array directly, rather than creating a copy from the
ScriptAddress result.

Unfortunately, for AddressPubKey, ScriptAddress may return either a
byte slice of len 33 or 65 depending on whether the pubkey is
compressed or not, so no such straightforward optimization is
possible.

As a result of this change, I have seen rescans perform roughly 3.5x
faster than before.
2014-04-20 21:16:59 -05:00
Dave Collins
1e75ccc9b9 Update for recent btcwire AddUserAgent addition. 2014-04-20 17:46:32 -05:00
David Hill
88093cb838 Use NewMsgInvSizeHint since we know the size.
ok @davecgh
2014-04-19 20:05:35 -04:00
Dave Collins
a4673597bd Update for notifyallnewtxs rename.
The websocket extension command to register for notifications when a new
transaction has been accepted to the memory pool and the resulting
notifications have been renamed.  This commit catches up to the change.
2014-04-15 12:22:52 -05:00
Dave Collins
05a7979292 Update for notifynewtxs to notifyreceived rename.
The websocket extension command to register for notifications when an
address receives funds has been renamed.  This commit catches up to the
change.
2014-04-14 19:11:08 -05:00
Dave Collins
de51409185 Add debug print for chain verify.
Since a chain verification can take a long time depending on the
parameters, this commit adds a debug print to the RPC server at the info
level for how many blocks are being verified and at what level.

The logic was also slightly modified so the number of blocks being checked
can easily be calculated and shown.
2014-04-14 10:29:51 -05:00
David Hill
3937c1a67c This RPCS debug statement should be a trace. 2014-04-13 15:50:28 -04:00
Josh Rickmar
42061ebf87 Update for btcws API change. 2014-04-10 21:12:40 -05:00
Dave Collins
a0bfde8db0 Update btcctl for latest btcjson changes. 2014-04-10 21:12:40 -05:00
Josh Rickmar
1fd5cd2742 Use btcws.GetBestBlockResult. 2014-04-10 20:03:54 -05:00
David Hill
384a535f49 addmultisigaddress support for btcctl 2014-04-07 14:45:42 -04:00
David Hill
1b56cb291f add new dns seed, seed.bitnodes.io 2014-04-01 14:58:40 -04:00
Dave Collins
886281993a Use separate max protocol version.
This commit modifies peers to use a max protocol version that is specified
as a constant in the peer code as opposed to the btcwire.ProtocolVersion
constant.

This allows btcwire to be updated to support new protocol versions without
causing peers to claim they support a protocol version which they actually
don't.
2014-03-28 17:42:59 -05:00
Dave Collins
444d05eafc Run go fmt. 2014-03-28 14:49:48 -05:00
Josh Rickmar
d702e37141 Update websocket clients with rescan progress.
This change periodically (about every 10 seconds) notifies the
connected websocket client of the height of the last processed block
as part of the rescan.  This enables clients to listen for the
notification and keep track of how much progress a rescan has made
even without any results being found.  If the websocket connection is
lost during the rescan, on reconnect, clients may safely start over at
the last notified height.
2014-03-28 11:27:29 -05:00
Owain G. Ainsworth
5932cd5385 comments - shorten, simplify and make 80cols. 2014-03-28 00:19:53 +00:00
Owain G. Ainsworth
b7622c4e6c Correct type capitalisation in comment. 2014-03-28 00:03:45 +00:00
Owain G. Ainsworth
613f61ec59 simplify comment and fit into 80 cols. 2014-03-28 00:02:57 +00:00
Owain G. Ainsworth
3a03a03a92 Kill duff newline. 2014-03-28 00:01:46 +00:00
Dave Collins
35936c1f01 Don't discuss internals in exported func comments.
This commit cleans up and moves a couple of comments in the recent pull
request which implements a rebroadcast handler (#114) in order to avoid
discussing internal state in the exported function comment.

How a function actually accomplishes the stated functionality is not
something that a caller is concerned with.  The details about the internal
state are better handled with comments inside the function body.
2014-03-27 14:09:34 -05:00
mydesktop
ab002c90cc Implement a rebroadcast handler.
This commit implements a rebroadcast handler which deals with
rebroadcasting inventory at a random time interval between 0 and 30
minutes.  It then uses the new rebroadcast logic to ensure transactions
which were submitted via the sendrawtransaction RPC are rebroadcast until
they make it into a block.

Closes #99.
2014-03-27 14:09:33 -05:00
David Hill
5fcdfb040a add importwallet to btcctl 2014-03-24 15:52:40 -04:00
Dave Collins
2ae7cb8ee2 Update handleGetBlock to not use deprecated func.
Rather than using the deprecated TxShas function on a btcutil.Block,
convert handleGetBlock to use the newer preferred method of ranging over
the Transactions to obtain the cached hash of each transaction.

This is a little more efficient since it can avoid creating and caching an
extra slice to keep the hashes in addition to having the hash cached with
each transaction.
2014-03-24 13:19:32 -05:00
mydesktop
a55ea104c7 Bugfix for issue #101. 2014-03-24 12:28:54 -05:00
Dave Collins
049a545427 Switch RPC server to use fastsha256 package. 2014-03-23 00:49:37 -05:00
Dave Collins
e98db34ef2 Add infrastructure for creating a block template.
This commit adds a new function named NewBlockTemplate along with
supporting infrastructure which is part of the core functionality needed
to support mining.

In particular the function creates a new block template which contains a
fully populated block with a zero nonce that is ready to be solved as well
as additional information regarding the fees and number of signature
operations for each transaction included in the block.  The specific
transaction selection logic mirrors the reference implementation.

Various cleanup, optimizations, and comment suggestions provided by
@owainga.  Also contains some naming suggestions and comment fixes from
@flammit.
2014-03-22 11:47:38 -05:00
Dave Collins
ed45b717e0 Add options to control block creation settings.
This commit adds three new options which are intended to to be used by the
upcoming mining-related block template creation code.
2014-03-22 11:47:03 -05:00
Dave Collins
5e517a9116 Add new logging subsystem for mining related ops.
This commit adds a new logging subsystem named MINR which is used for
logging mining releated operations.
2014-03-22 11:47:02 -05:00
Josh Rickmar
29dd411457 Prevent blocking on RPC server messages after shutdown.
This change adds select statements to each channel write that may
occur from a non-RPCS goroutine to unblock once the server has begun
shutting down.  This prevents issues in clean shutdown where non-RPCS
goroutines may block indefinitely on message sends to the RPC server.
2014-03-21 18:07:36 -05:00
Josh Rickmar
715fd22de9 Bootstrap unspents with rescan request's outpoints. 2014-03-21 15:43:31 -05:00
Josh Rickmar
de31674a8d Optimize rescan.
This change adds rescan fast paths for all current implementations of
the btcutil.Address interface.  Rather than encoding a payment address
string from a txout script, the minimum number of bytes (which depends
on the address type) are copied into a stack array and used as a
lookup key to a map exclusive for that address type.  This performs
better than the previous implementation due to avoiding the base58
encoding and generating less garbage (so each GC cycle completes
faster).

If the address type switch falls into the default (unhandled) case,
the encoded payment address is used as a fallback.  This keeps the
intended rescan behavior even when new implementations of
btcutil.Address are added without a rescan fast path.

Benchmarks indicate that when a fast path is followed, for 20 byte
RIPEMD-160 hashes (such as P2PKH and P2SH), skipping the payment
address encoding (and thus bypassing the base58 encoding code) can
result in map lookups up to 60x faster.
2014-03-21 10:54:37 -05:00
Dave Collins
9d6dd6fa6b Don't fail RPC server create due to single iface.
Rather than returning an error when creating the RPC server an it can't
listen on any of the specified interfaces, only error when it can't listen
on all of the specified interfaces.
2014-03-20 21:54:50 -05:00
David Hill
eecea4180a Preallocate the tx serialization buffer.
Benchmarking shows this is slightly faster due to avoiding the extra
garbage collection in addition to less peak memory usage.

ok @davecgh
2014-03-20 15:33:09 -04:00
Dave Collins
f1a4dfb86d Update chain state with best block.
Rather than updating the new chain state with the hash and height of the
block that was just processed, query the database for the best block.
This is needed because the block that was just processed might be a side
chain block or have caused a reorg.
2014-03-20 14:08:46 -05:00
Dave Collins
1d674905e0 Introduce a chain state to block manager.
This commit introduces a chain state that is updated as blocks are
processed into the block chain instance associated with the block manager.

This has been done because btcchain is currently not safe for concurrent
access and the block manager is typically quite busy processing block and
inventory.  This approach allows fast access to most chain information in
a concurrent safe fashion.
2014-03-20 01:06:59 -05:00
Dave Collins
ee19fd79e4 Fix comment typo in addblock. 2014-03-20 00:37:35 -05:00
Dave Collins
9f1382f03c Use defaults in config struct for btcctl.
Rather than doing a lot of if/else in the configuration load for btcctl,
set the default for the RPC server to localhost and the RPC cert to the
btcd cert, then override them as needed depending on the --wallet and
--testnet flags.
2014-03-19 23:52:22 -05:00
David Hill
a94ca01cf4 add --testnet and --wallet options to btcctl.
Closes #112
2014-03-20 00:17:26 -04:00
Dave Collins
e3f3918242 Use increment on p.retryCount to make golint happy. 2014-03-19 17:58:58 -05:00
Dave Collins
ae89f7aa82 Expand btcctl RPC cert path to from config file.
This commit allows paths in the btcctl config file to use environment
variables and ~ as a shortcut for the home directory.

Closes #113.
2014-03-19 15:24:14 -05:00
Dave Collins
083f5e007c Correct the new addblock progress logging.
The code was not resetting the counters when logging a message, so the
stats kept increasing rather than showing the number of items processed
since the last log message.

This has been resolved by copying the log function directly from btcd and
modifying it slightly to work with the importer.
2014-03-19 15:11:50 -05:00
Dave Collins
0b73e14e79 Remove extraneous space and go fmt. 2014-03-19 09:47:49 -05:00
Jimmy Song
b12e2fc1db Issue #90: Improve addblock logging by reporting every 10 seconds instead of X number of blocks
blockImporter now has these new properties:

txProcessed - number of transactions processed by the importer
lastHeight - height of the last imported block
lastBlockTime - block time of the last imported block
lastLogTime - last timestamp of when a progress message was shown

the p/progress option in addblocks now indicates how often you want the progress message to appear
2014-03-19 09:35:19 -05:00