Commit graph

3531 commits

Author SHA1 Message Date
Josh Rickmar
1a23feb53e Fix hang on new request receives after shutdown.
Previously, requests could still be sent to a shutdown client and
added to the client's internal data structures, without ever
responding to the future with an error for a shutdown client (causing
hangs when blocking on the future receive).  This change fixes this by
performing a non-blocking read of the client's shutdown channel before
adding a request, and responding with the shutdown error if the client
has begun or completed its shutdown.

ok @davecgh
2014-07-07 19:11:50 -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
16dc2cf2d0 Add errors to all interface methods.
This commit adds error returns to all of the Db interface methods except
for FetchTxByShaList and FetchUnSpentTxByShaList since they expose the
errors on each individual transaction.

It also updates all tests and code for both the leveldb and memdb drivers
for the changes.

Closes #5.

ok @drahn
2014-07-07 12:55:46 -05:00
Dave Collins
07bdbd9e3d Update for recent btcdb API changes. 2014-07-07 12:37:30 -05:00
Dave Collins
73228aaebe Update for recent btcdb API changes.
Since the underlying database driver can now return an error when looking
up if blocks and transactions exist, the HaveBlock function now includes
an error return to allow any underlying errors to be exposed.
2014-07-07 11:48:41 -05:00
David Hill
d31183ff19 go fmt 2014-07-07 11:07:30 -04:00
David Hill
879d69d040 use strconv.FormatInt which is much faster than fmt.Sprintf 2014-07-07 11:07:07 -04:00
David Hill
0dd81ad003 Use NewReader instead of NewBuffer.
NewReader is slightly faster than NewBuffer, but more importantly,
ensures the data is read-only.
2014-07-07 11:05:02 -04:00
David Hill
e2628dfc0d convert binary Read/Write to Uint/PutUint and copy 2014-07-07 11:05:00 -04:00
Dave Collins
fbb17fd35a Update TODO section of README.md.
This ability for multiple database backends has been available for a long,
long time.  Looks like this was simply not updated when the interface was
added.
2014-07-07 09:34:41 -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
dd41a4a233 Remove unneeded functions from memdb.
This commit removes some functions from memdb which only existed to satify
the btcdb.Db interface, but have since been removed from the interface.
2014-07-06 21:11:44 -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
David Hill
2e0a243383 Support gettxout 2014-07-04 10:46:21 -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
Dave Collins
1a866200e3 Improve websocket connection error handling.
This commit modifies the error handling for websocket connections to fall
back to returning the status text returned from the server if the
handshake fails and it's not due to an authentication or invalid endpoint.
2014-07-03 12:31:53 -05:00
Tomás Senart
77fdb1011b Handle non successfull HTTP responses
This change set equips the RPC client with handling of non successful
HTTP responses. An HTTP response is considered non successful when its
status code is not in the range 200..299
2014-07-03 18:54:50 +02: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
Dave Collins
efb92fcc99 goimports -w . 2014-07-02 19:47:24 -05:00
Dave Collins
1acb4b8151 goimports -w . 2014-07-02 19:44:43 -05:00
Dave Collins
3a1009529f goimports -w . 2014-07-02 19:43:33 -05:00
Dave Collins
d7e4789eda goimports -w . 2014-07-02 19:42:29 -05:00
Dave Collins
6aa6bec7fc goimports -w . 2014-07-02 19:41:28 -05:00
Dave Collins
22014931d4 goimports -w . 2014-07-02 19:39:37 -05:00
Dave Collins
5beafbd2d8 goimports -w . 2014-07-02 19:37:49 -05:00
Dave Collins
79b6e51dff Update tests for recent btcutil.Address API change. 2014-07-02 19:36:41 -05:00
Dave Collins
0e463baf95 goimports -w . 2014-07-02 19:34:05 -05:00
Tomás Senart
4772d4a1a4 goimports -w . 2014-07-02 19:14:27 -05: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
73ed07bd85 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 18:00:47 +02:00
Tomás Senart
e29f40274d Replace map[a]bool with map[a]struct{}
The later uses no memory storage for values and provides the same
functionality.
2014-07-02 17:56:22 +02:00
Tomás Senart
84fa553b65 Split imports into logical groups 2014-07-02 15:56:41 +02:00
Dave Collins
767caaa6ae Make hex decoding consistent in RPC handlers.
The hex package requires an even number of characters in hex encoded
strings.  Some of the handlers already prepended a zero if necessary to
make this condition true, however other did not.  This commit extends this
functionality to all handlers and also makes the error return consistent.

ok @jrick
2014-07-01 20:39:31 -05:00
Dave Collins
933cdf50e8 Export constant for the maximum time offset.
This commit creates and exports a new constant, MaxTimeOffsetSeconds,
which is the maximum number of seconds a block timestamp is allowed to be
ahead of the current time.

Previously this value was hard coded into the consensus rule path, however
it is useful better to have it defined as a constant and exported so other
callers can access it.

No consensus rules have been changed with this commit.
2014-06-30 12:14:58 -05:00
Dave Collins
2d32ed6ba7 Add MaxTime field support from BIP0023 mutations. 2014-06-30 10:38:15 -05:00
Josh Rickmar
130edaec65 Add ListLockUnspent support.
Closes #11.

ok @davecgh
2014-06-30 10:30:11 -05:00
Josh Rickmar
4c045cc1ec Add LockUnspent support.
Closes #10.

ok @davecgh
2014-06-30 10:30:10 -05:00
Dave Collins
dbca1d59c3 Add a new behavior flag to provide a dry run.
This commit adds a new behavior flag, BFDryRun which allows the caller
to indicate all checks should be performed against the block as normal
except it will not modify any state.  This is useful to test that a block
is valid without actually modifying the current chain or memory state.

This commit also adds a few additional checks which were elided before
since they are implicitly handled by btcwire.  However, with the ability
to propose blocks which didn't necessarily come through the btcwire path,
these checks need to be enforced in the chain code as well.

As a part of adding the checks, three new error codes named
ErrBlockTooBig, ErrTooManyTransactions, and ErrTxTooBig have been
introduced.

Closes #5.
2014-06-29 17:49:16 -05:00
Dave Collins
5032b07c66 Rename blockHashLen to blockHeaderLen.
The old name no longer makes sense because the hash length is the same as
the header length.
2014-06-29 17:45:46 -05:00
Dave Collins
843e71515a Expose new SerializeSize API for blocks.
This commit adds a new function named SerializeSize to the public API for
MsgBlock which can be used to determine how many bytes the serialized data would
take without having to actually serialize it.  In addition, it makes the
exported BlockVersion an untyped constant as well as changes the block and
tx versions to a signed integer to more closely match the protocol.

Finally, this commit also adds tests for the new function.

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

Bufffer: BenchmarkBlockSerializeSizeBuffer     200000          27050 ns/op
New:     BenchmarkBlockSerializeSizeNew     100000000             34 ns/op

Closes #19.
2014-06-29 17:43:54 -05:00
Dave Collins
1db0eb4fec Update for recent btcjson changes.
This commit updates the types to match the recent changes to the btcjson
result types.
2014-06-29 16:37:21 -05:00
Dave Collins
e2e688e3d6 Make a compatibility pass.
This commit modifies some of the types of the values to better match the
reference client JSON-RPC API.
2014-06-29 16:35:53 -05:00