Commit graph

806 commits

Author SHA1 Message Date
Josh Rickmar
da993eb034 Fix sending of next item in notification queue.
The notification queue used for websocket client notifications had a
bug which caused the next queued item in some situations to not be
sent, but instead send a previously sent item.  This change fixes this
by setting the 'next' variable to the next item which must be
dequeued, if the queue length is non-zero.

This bug did not always manifest itself as if the receiving goroutine
was ready, a queued item could be sent directly to it rather than
waiting in the queue to be sent at a later time.
2014-07-25 08:20:58 -05:00
Josh Rickmar
790a4f5a6e Return nil for some spent gettxout outputs.
This change modifies the behavior of the gettxout RPC to match the
behavior of the reference client.  If a transaction output is spent by
a mined transaction, the handler will now return nil (JSON null).

While here, avoid indexing some slices multiple times, by creating a
local variable instead.
2014-07-24 15:02:07 -05:00
Dave Collins
764893c400 Ensure vars used atomically in peer are aligned.
The sync.atomic requires alignment of variables used atomically on ARM.
This commit moves the connected and disconnect variables in the peer
struct up so they are aligned.

Fixes #157.
2014-07-23 14:12:49 -05:00
Javed Khan
458a996ae6 updated utils to handle regtest, simnet
handle active network assignment in the same if-else
instead of having another switch-case
2014-07-22 08:28:33 -05:00
Dave Collins
1184a4d8d1 Prevent hang on shutdown race.
This commit prevents a race that could happen on shutdown if a sigint was
received between adding the first the interrupt handler and and future
handlers.  This code is loosely based on initial pull request #154 which
was not accepted due to introducing a race of its own.

Thanks to @tuxcanfly for the intial pull request and finding the issue.
2014-07-22 08:21:58 -05:00
Olaoluwa Osuntokun
293d71e9c3 Implement gettxout rpc.
Use new error type defined in Roasbeef/btcjson@4dc9db809
2014-07-19 13:01:59 -05:00
Josh Rickmar
8a7b73e62b Fix logging: Warn -> Warnf.
ok @davecgh
2014-07-17 11:45:58 -05:00
Dave Collins
08c01f08b1 Only show parse errors and command to invoke usage.
Rather than showing the usage when an error is encounted during options
parsing, show a message that describes how to invoke help instead.  This
is useful because the help is long enough now that the error is often
overlooked since it scrolls out of view.

ok @jrick
2014-07-14 20:43:54 -05:00
Dave Collins
000691dc9e Implement BIP0061 reject handling (pver 70002).
This commit implements reject handling as defined by BIP0061 and bumps the
maximum supported protocol version to 70002 accordingly.

As a part of supporting this a new error type named RuleError has been
introduced which encapsulates and underlying error which could be one of
the existing TxRuleError or btcchain.RuleError types.

This allows a single high level type assertion to be used to determine if
the block or transaction was rejected due to a rule error or due to an
unexpected error.  Meanwhile, an appropriate reject error can be created
from the error by pulling the underlying error out and using it.

Also, a check for minimum protocol version of 209 has been added.

Closes #133.
2014-07-14 12:25:11 -05:00
David Hill
2f0cab1a48 Log accepted blocks via submitblock.
ok @davecgh
2014-07-14 11:08:07 -04:00
Josh Rickmar
e495dcbc2f Fix off-by-one making rescanfinished notification.
Fixes #150.

ok @davecgh
2014-07-12 09:43:53 -05:00
Dave Collins
be7923a4ed Update to account for recent btcchain API changes. 2014-07-11 09:57:03 -05:00
Dave Collins
a261436e1b Use chan struct{} for throttling related chans.
The done and wait channels used to throttle outgoing data are being used
as semaphores.  As mentioned in the previous commit, it's more efficient
to use a 0-byte type and allow compiler optimizations for the specific use
case.
2014-07-10 22:42:27 -05:00
Dave Collins
83cffc5d27 Use chan struct{} for tx/blockProcessed chans.
These channels are being used as semaphores, so it's more efficient to use
a 0-byte type and allow compiler optimizations for the specific use case.
2014-07-10 22:29:07 -05:00
Dave Collins
1483b92dcf Remove outdated comment. 2014-07-10 22:20:10 -05:00
Dave Collins
c7a6645ebe Correct pushGetMerkleBlock throttling.
This commit corrects the check which sends in the done channel when
pushing merkle blocks that have no transactions to go with them.
2014-07-10 21:45:45 -05:00
David Hill
06d2707744 We only care about the peers.json file... 2014-07-10 19:28:30 -05:00
David Hill
d269887c56 Put mutexes in exported functions. 2014-07-10 19:23:31 -05:00
David Hill
36e8b4c82e organize.
no objections from @davecgh
2014-07-10 19:03:34 -05:00
David Hill
ba937630d0 each goroutine needs its own random source.
caught by the race detector.
2014-07-10 14:52:02 -04:00
Dave Collins
bd7a100ebb Address a few more comments. 2014-07-10 09:43:03 -05:00
Dave Collins
ffe0b09890 Seed random generator in RPC server during init.
Rather than reseeding the PRNG used throughout the RPC server on each
call, do it once during init.

Suggested by @jrick
2014-07-10 09:43:02 -05:00
Dave Collins
180f4ac0a2 Implement some BIP0023 getblocktemplate mutations.
This commit implements a portion of the mutations section of BIP0023.
In particular, it adds the mutable, mintime, maxtime, and noncerange keys
to the returned block template along with indicating support for the time,
transactions/add, prevblock, and coinbase/append mutations.  Also, the
addition of the mintime and maxtime fields imply support for the
time/decrement and time/increment mutations.  Further, if the caller
indicates the coinbasevalue capability, the coinbasetxn field will be
omitted thereby implying support for the coinbase and generation
mutations.

Closes #124.
2014-07-10 09:43:01 -05:00
Dave Collins
21050b4751 Implement BIP0023 getblocktemplate block proposals.
This commit implements block proposals as defined by BIP0023.

This is work towards #124.
2014-07-10 09:43:00 -05:00
Dave Collins
db20f25ff7 Implement BIP0023 basic pool extensions support.
This commit implements the basic pool extension portion of the getblocktemplate
RPC as defined by BIP0023.

This is work towards #124.
2014-07-10 09:42:59 -05:00
Dave Collins
fc5656894d Implement getblocktemplate long poll support.
This commit implements the long polling portion of the getblocktemplate
RPC as defined by BIP0022.  Per the specification, each block template is
returned with a longpollid which can be used in a subsequent
getblocktemplate request to keep the connection open until the server
determines the block template associated with the longpollid should be
replaced with a new one.

This is work towards #124.
2014-07-10 09:42:58 -05:00
Dave Collins
eb7ecdcc22 Implement basic getblocktemplate BIP0022 support.
This commit implements the non-optional and template tweaking support for
the getblocktemplate RPC as defined by BIP0022.  This implementation does
not yet include long polling support.

This is work towards #124.
2014-07-10 09:42:57 -05:00
David Hill
3a45ec1058 Change AddAddressByIP to return an error. 2014-07-09 21:24:06 -04:00
David Hill
f7ce37f8c1 Switch btcctl to use btcutil.Amount. 2014-07-09 16:28:45 -04:00
David Hill
e68d46f556 Add full support for BIP0037 bloom filters.
This commit implements full support for filtering based on the filterload,
filteradd, filterclear, and merkleblock messages introduced by BIP0037.

This allows btcd to work seamlessly with SPV wallets such as BitcoinJ.

Original code by @dajohi.  Cleanup, bug fixes, and polish by @davecgh.
2014-07-09 13:33:42 -05:00
Dave Collins
307c52f25b Add new DNS seed for seeds.bitcoin.open-nodes.org. 2014-07-09 09:20:40 -05:00
Dave Collins
6a8b806a20 Correct QueueNotification comment.
This comment incorrectly said QueueMessage instead of QueueNotification.
2014-07-09 01:37:55 -05:00
Dave Collins
6248dd5e5d Don't return a double pointer.
This commit has no effect on the effective functionality since Go
automatically deferences pointers, but there is no reason to have a
double indirection when returning the reply for getmininginfo.
2014-07-09 01:34:56 -05:00
Josh Rickmar
9e60210f18 Update for untyped btcutil consts.
ok @davecgh
2014-07-08 11:14:46 -05:00
Tomás Senart
2afc5a0af2 Use lighter atomic counters instead of mutexes
Where appropriate, it makes sense to use lighter weight atomic counters
instead of mutexes.
2014-07-07 13:04:39 -05:00
Dave Collins
07bdbd9e3d Update for recent btcdb API changes. 2014-07-07 12:37:30 -05:00
David Hill
6f5a43d6c8 First round of address manager package refactor
These changes are a joint effort between myself and @dajohi.

- Separate IP address range/network code into its own file
- Group all of the RFC range declarations together
- Introduces a new unexported function to simplify the range declarations
- Add comments for all exported functions
- Use consistent variable casing in refactored code
- Add initial doc.go package overview
- Bump serialize interval to 10 minutes
- Correct GroupKey to perform as intended
- Make AddLocalAddress return error instead of just a debug message
- Add tests for AddLocalAddress
- Add tests for GroupKey
- Add tests for GetBestLocalAddress
- Use time.Time to improve readability
- Make address manager code golint clean
- Misc cleanup
- Add test coverage reporting
2014-07-07 09:04:22 -05:00
Dave Collins
62f21d3600 Move address manager to its own package.
This commit does just enough to move the address manager into its own
package.  Since it was not originally written as a package, it will
require a bit of refactoring and cleanup to turn it into a robust
package with a friendly API.
2014-07-06 01:06:38 -05:00
David Hill
ebc5db2710 Lookup each DNS seed in its own go routine.
By putting each DNS seed in its own go routine, btcd can start connecting
to nodes as they are found instead of waiting for all seeds to respond.  This
significantly speeds up startup time.

Additionally, logging was added to show how many addresses were fetched from
each seed.
2014-07-04 16:27:32 -04:00
David Hill
2e029b1c3d Add gettxout to btcctl. 2014-07-04 10:50:57 -04:00
Dave Collins
29a3bb6e69 Remove disconnect on unrequested transaction.
BitcoinJ, and possibly other wallets, don't follow the spec of sending an
inventory message and allowing the remote peer to decide whether or not
they want to request the transaction via a getdata message.  Unfortuantely
the reference implementation permits unrequested data, so it has allowed
wallets that don't follow the spec to proliferate.

While this is not ideal, this commit removes the functionality which
disconnects peers for sending unsolicited transactions to provide
interoperability.
2014-07-03 20:59:41 -05:00
Dave Collins
a546fa1b2a Correct getdata throttling.
This commit corrects an issue where the data requested by getdata was not
being properly throttled which could lead to higher than desired memory
usage on large requests.
2014-07-03 16:58:36 -05:00
David Hill
79fe7aadd6 Log an error when json encoding of peers.json fails. 2014-07-03 14:33:56 -04:00
Josh Rickmar
5966a5230d Don't log error if getrawtransaction finds no tx.
ok @davecgh
2014-07-03 10:37:37 -05:00
David Hill
6f17ebc8cb Implement validateaddress.
validateaddress will simply return whether the given address is
valid or not.  For the full implementation, one should query
btcwallet instead.
2014-07-02 23:52:34 -04:00
Tomás Senart
f439dece37 Use chan struct{} for semaphores
With semaphores we don't actually care about the value passed in. It
makes sense to use a 0 bytes type in these cases.
There is also the added benefit of compiler optimisations for this
specific use case as described here:
https://docs.google.com/document/d/1yIAYmbvL3JxOKOjuCyon7JhW4cSv1wy5hC0ApeGMV9s/pub
2014-07-02 19:06:32 -05:00
Tomás Senart
cc2c486791 Replace map[a]bool with map[a]struct{}
The later uses no memory storage for values and provides the same
functionality.
2014-07-02 19:06:29 -05:00
Tomás Senart
76d258e2a1 Avoid reallocs in removeDuplicateAddresses 2014-07-02 11:01:57 -05:00
Tomás Senart
a0f20007c5 golint -min_confidence=0.3 .
This commits removes a number of golint warnings. There is a class of
warnings which I can't fix due to unsufficient knowledge of the domain
at this point. These are listed here:

addrmanager.go:907:1: comment on exported method AddrManager.Attempt
should be of the form "Attempt ..."
addrmanager.go:1048:1: exported function RFC1918 should have comment or
be unexported
addrmanager.go:1058:1: exported function RFC3849 should have comment or
be unexported
addrmanager.go:1065:1: exported function RFC3927 should have comment or
be unexported
addrmanager.go:1073:1: exported function RFC3964 should have comment or
be unexported
addrmanager.go:1081:1: exported function RFC4193 should have comment or
be unexported
addrmanager.go:1089:1: exported function RFC4380 should have comment or
be unexported
addrmanager.go:1097:1: exported function RFC4843 should have comment or
be unexported
addrmanager.go:1105:1: exported function RFC4862 should have comment or
be unexported
addrmanager.go:1113:1: exported function RFC6052 should have comment or
be unexported
addrmanager.go:1121:1: exported function RFC6145 should have comment or
be unexported
addrmanager.go:1128:1: exported function Tor should have comment or be
unexported
addrmanager.go:1143:1: exported function Local should have comment or be
unexported
addrmanager.go:1228:2: exported const InterfacePrio should have comment
(or a comment on this block) or be unexported
discovery.go:26:2: exported var ErrTorInvalidAddressResponse should have
comment or be unexported
limits/limits_unix.go:19:1: exported function SetLimits should have
comment or be unexported
limits/limits_windows.go:7:1: exported function SetLimits should have
comment or be unexported
util/dropafter/dropafter.go:22:6: exported type ShaHash should have
comment or be unexported
util/dropafter/dropafter.go:38:2: exported const ArgSha should have
comment (or a comment on this block) or be unexported
util/dropafter/dropafter.go:128:5: exported var ErrBadShaPrefix should
have comment or be unexported
util/dropafter/dropafter.go:129:5: exported var ErrBadShaLen should have
comment or be unexported
util/dropafter/dropafter.go:130:5: exported var ErrBadShaChar should
have comment or be unexported
util/showblock/showblock.go:24:6: exported type ShaHash should have
comment or be unexported
util/showblock/showblock.go:46:2: exported const ArgSha should have
comment (or a comment on this block) or be unexported
util/showblock/showblock.go:163:1: exported function DumpBlock should
have comment or be unexported
util/showblock/showblock.go:211:5: exported var ErrBadShaPrefix should
have comment or be unexported
util/showblock/showblock.go:212:5: exported var ErrBadShaLen should have
comment or be unexported
util/showblock/showblock.go:213:5: exported var ErrBadShaChar should
have comment or be unexported
2014-07-02 11:01:56 -05:00
Tomás Senart
84fa553b65 Split imports into logical groups 2014-07-02 15:56:41 +02:00