Commit Graph

2834 Commits

Author SHA1 Message Date
Dave Collins
3ce4b02e4e
dcrd: Remove unused old chainindexer file.
The chainindexer.go file is completely commented out and has been
replaced by a new indexing infrastructure.  This removes the entire file
since it is no longer required.
2017-03-23 02:21:02 -05:00
Josh Rickmar
3a61f8c61f Add example service files.
This adds example service files to run dcrd as a system service for systemd and
illumos SMF.

Waiting on an rc.d before this is merged...

Closes #561.
2017-03-23 02:07:08 -05:00
John C. Vernaleo
68deca1fe3 Add warning on startup about old testnet data.
Done in a loop so future testnets can be added in as needed.
2017-03-22 13:39:10 -04:00
Dave Collins
9b76b78168
server: Return error on address lookup fails.
This corrects an issue introduced by commit
e8f63bc29550705268b533032ccc2ea24f8c86ba where a failure to lookup a
hostname could lead to a panic in certain circumstances.  An error is
now returned in that case as expected.
2017-03-21 19:43:28 -05:00
Olaoluwa Osuntokun
c31eb4549d connmgr: switch to using net.Addr interface throughout for addresses
This commit modifies the `ConnManager` to use the `net.Add` interface
through the package instead of a plain string to represent and
manipulate addresses. This change makes the package much more general as
users of the package can possibly utilize custom implementations of the
`net.Addr` interface to establish connections.

More precisely, the `ConnReq` struct has been modified to use a net.Addr
instance explicitly, and the `DialFunc` type has also been modified to
take a `net.Addr` directly. This latter change gives functions that
adhere to the `DialFunc` type more flexibility as to exactly how the
connection is established.

Additionally, the `connmgr.Config.GetNewAddress` configuration option
now directly returns a `net.Addr. This change allows the `connmgr` to be
decoupled from all DNS queries which allows callers to preferentially
select more secure methods like performing DNS lookups over a Tor proxy.
2017-03-21 19:43:25 -05:00
Dave Collins
cb4a6452e0
connmgr: Add tests for new inbound listener logic. 2017-03-21 19:43:21 -05:00
Dave Collins
1be83e5319
connmgr: Implement inbound connection handling.
This modifies the connection manager to provide support for accepting
inbound connections on a caller-provided set of listeners and notify the
caller via a callback.

This is only the minimum work necessary to get inbound support into the
connection manager.  The intention for future commits is to move more
connection-related logic such as limiting the maximum number of overall
connections and banned peer tracking into the connection manager.
2017-03-21 19:43:15 -05:00
Dave Collins
3b187d3817
connmgr: Remove type defs for callbacks.
This removes the type definitions for the callback functions in favor of
declaring them directly in the Config struct.  This is more consistent
with the rest of the code base and is preferred since it means callers
reviewing the documentation don't have to follow another level of
indirection to figure out the signature.
2017-03-21 19:43:08 -05:00
Javed Khan
628c9e8b2d server: Use Disconnect in handleDonePeerMsg 2017-03-21 19:43:05 -05:00
Javed Khan
56da31dec5 server: Check max peers before connecting 2017-03-21 19:43:05 -05:00
Javed Khan
ea0238ec44 connmgr: Retry only if below target outbound conns 2017-03-21 19:43:04 -05:00
Javed Khan
a5487a01de connmgr: Rename max outbound to target outbound 2017-03-21 19:43:03 -05:00
Javed Khan
c05ef678b7 server: Cap max outbound in connmgr cfg at max peers 2017-03-21 19:43:03 -05:00
David Hill
0eea64362c connmgr: unexport the DynamicBanScore mutex. 2017-03-21 19:43:02 -05:00
Dave Collins
9e9dd98d94
peer: Use debug log for inability to start peer.
The inability for a peer to negotiate is not something that should be a
warning which implies something is wrong.  On the contrary, it is quite
expected that various peers will connect (or be connected to) that are
unable to properly negotiate for a variety of reasons.  One example would
be a peer that is too old.

Also, while here take care of a few style nits.
2017-03-21 19:42:57 -05:00
Dave Collins
1f9a89bebe
server: Notify connmgr if server peer assoc fails.
This corrects a few issues introduced with the connection manager where
the server was not notifying the connection manager when a connection
request is available again.

The cases resolved are:
- Unable to initialize a server peer instance in response to the connection
- Failure to associate the connection with the server peer instance
- Disconnection of a non-persistent outbound peer

It also changes the log message to a debug in the former case because
it's not something that should be shown to the user as an error given
it's not due to anything the user has misconfigured nor is it even
unexpected if an invalid address is provided.
2017-03-21 19:42:50 -05:00
Dave Collins
918fe7c4c5
peer: Track and return advertised protocol version
This adds a new field to the peer struct which stores the protocol
version advertised by the remote peer and updates the StatsSnapshot to
return the advertised version instead of the negotiated version.
2017-03-21 19:42:41 -05:00
Dave Collins
58ece81431
server: Remove unused wakeup channel.
This channel is no longer used since the outgoing connection logic is
handled by the connmgr package now.
2017-03-21 19:42:32 -05:00
David Hill
462c432cd2 peer: BestLocalAddress config option is no longer used. 2017-03-21 19:42:28 -05:00
David Hill
ab541dd587 peer: Stop setting AddrMe in the version message.
Older nodes previously added the IP and port information to the address
manager which proved to be unreliable as an inbound connection from a
peer didn't necessarily mean the peer itself accepted inbound
connections.

This also fixes a bug where the peer package was incorrectly sending
the peer's services as its own.
2017-03-21 19:42:27 -05:00
David Hill
82dcbf807b Do not add inbound peers to the address manager. 2017-03-21 19:42:26 -05:00
Javed Khan
25c93e46e6 connmgr: Refactor connection management into pkg
This commit introduces package connmgr which contains connection
management related functionality.

The following is an overview of the features the package provides:

- Maintain fixed number of outbound connections
- Optional connect-only mode
- Retry persistent connections with increasing back-off
- Source peers from DNS seeds
- Use Tor to resolve DNS
- Dynamic ban scores
- Test coverage

In addition, btcd has been refactored to make use of the new package by
extending the connection manager to work with the server to source and
maintain peer connections. The following is a broad overview of the
changes to integrate the package:

- Simplify peer state by removing pending, retry peers
- Refactor to remove retries which are now handled by connmgr
- Use callback to add addresses sourced from the  DNS seed

Finally the following connection-related things have been improved as a
part of this refactor:

- Fixes 100% cpu usage when network is down
- Fixes issues with max peers
- Simplify outbound peer connections management
2017-03-21 19:42:19 -05:00
Javed Khan
e3fd2f015c peer: rename peer.Connect to AssociateConnection 2017-03-21 19:42:17 -05:00
David Hill
99d04eea40 Preallocate the exact number of bytes if known. 2017-03-20 21:46:33 -05:00
David Hill
7cb68f472a dcrctl: Be smarter about automatic configuration.
dcrctl does not require dcrd so it should not keep complaining about
it missing.  Just skip automatic configuration if dcrd's configuration
is missing, but still set it up in the future if one appears and dcrctl
is still lacking a configuration file.
2017-03-20 14:17:06 -04:00
David Hill
6d9c4b360e gometalinter: use --vendor to skip ./vendor/
While here, clean up gosimple and unconvert rules, leaving gosimple
disabled due to API changes between go 1.7 and 1.8.
2017-03-18 14:22:53 -04:00
Dave Collins
83c65fe7b0
wire: Lower MaxUserAgentLen to 256.
Upstream commit 763f731c5c.

This updates wire to enforce a limit of 256 instead of the existing 2000
to coincide with the upstream btcd project, and consequently includes a
wire version bump to 0.2.1 in the merge commit.
2017-03-18 01:06:28 -05:00
Dave Collins
3b99f52a59
rpcserver: Make function definitions consistent.
This modifies the rpcserver.go file to make the function definitions
consistent with one another.  Not only is this good for consistency, but
it also makes the upstream syncs easier since there are less merge
conflicts due to superfluous changes.
2017-03-18 00:43:12 -05:00
Dave Collins
efe8260850
rpcserver/chain: Bounds check getstakeversions.
This adds bounds check for the RPC parameters for the getstakeversions
command to both the handler and the chain function itself which provides
the data.

Also, while here simplify the for loop in GetStakeVersions to check
prevNode in the for loops condition instead of in a separate if block,
return more appropriate error types for RPC parameter type errors, and
use a naked type cast of the command to be consistent with all of the
other handlers.
2017-03-17 22:03:27 -05:00
David Hill
a9a1ec181c server: send some vote hashes
If there are more vote hashes than wire.MaxMSBlocksAtHeadPerMsg, send
the max instead of none.  Also, add a missing error check for safety.
2017-03-17 11:08:56 -05:00
Dave Collins
8644a8c732
txscript: Update signing tests to use params var.
This updates the script signing test code to use a single chain params
variable instead of repeatedly referring to a specific network.  This
makes it much easier to change in the future such as future testnet
resets.
2017-03-16 19:46:03 -05:00
John C. Vernaleo
ef71103c95 Remove variables for testnet v1. 2017-03-16 20:19:07 -04:00
Dave Collins
01a0d76fd7
TravisCI: Remove a couple of linters.
The linters take quite a while to run in the TravisCI environment which
causes the deadline to be exceeded.

While here, also increase the allowed deadline for the remaining linters
to 10 minutes and also update Travis to use a new ubuntu distribution.
2017-03-16 14:07:53 -05:00
Dave Collins
7e57dbe093
chaincfg: Allow non-std transactions on testnet2.
The test network should allow any scripts and transaction types that are
valid according to consensus rules as opposed to the more strict
standardness rules that apply to mainnet.  This allows new script forms
and types to be tested before they go to mainnet.

Also, this is the same setting as the previous test network.
2017-03-16 12:54:20 -05:00
jolan
6a2ab3bc6a fix StakeBaseSigScript and a comment (#625) 2017-03-16 11:42:08 -05:00
John C. Vernaleo
9f58376efc Testnet Reset
This adds a new testnet2 network with new genesis block, premine
address, magic number, etc.

Corrected some testnet related comments while there.
2017-03-15 19:34:21 -04:00
Marco Peereboom
98af7c78ce chaincfg: strictly enforce agendas assumptions.
Agendas require some complicated and not always obvious assumptions.  In
order to prevent bad agendas from making it into the code we validate
them at init time and panic if an agenda violates assumptions.  This
will not adversely impact the user experience but will force developers
to properly design dcrd agendas.

These are the required tests to ensure vote integrity:
* All choices shall be consecutive and enumerated.
* Mask only contains consecutive 1 bits set.
* Ensure IsIgnore and IsNo are never both set to true.
* Ensure there is one and only one IsNo choice set to true.
* Ensure there is one and only one IsIgnore choice set to true.
* Ensure that the abstain choice is 0.
* Ensure that the number of choices does not exceed the mask bits
  permissible size.
* Ensure that choice bits match the mask bits.
* Ensure there are no duplicate choice ids.
* Ensure there are no duplicate vote ids.
2017-03-15 18:28:50 -05:00
Marco Peereboom
624f2d9ba7 blockchain: add expiration test during voting.
Add a test where the expiration time is roughly at the half of the
voting window.  We do that by spoofing the ExpireTime to be half of the
required RCI window.  The synthetics use a second per block time stamp
so we simply set ExpireTime to RCI/2 seconds.
2017-03-15 18:24:59 -05:00
Marco Peereboom
02d024be5a blockchain: use next block stake version.
Modify threshold state to use the stake version that will be used in the
next block. That removes a full interval before voting can start and it
makes all voting intervals consistent.

Fixes #595
Requires #596
2017-03-15 18:12:16 -05:00
Marco Peereboom
9b2dcda49c rpcserver: Confirmations -1 when a block is orphan
Make GetBlockHeaderVerboseResult and GetBlockVerboseResult return
Confirmations as -1 when we are dealing with an orphan block.

While here fix confirmations in the createTxRawResult call as well.

Every user of GetBlockHeaderVerboseResult, GetBlockVerboseResult and
TxRawResult MUST change the Confirmations field to int64!

The RPCs that are affected are getblock, getblockheader and
getrawtransaction.
2017-03-14 14:47:39 -05:00
Josh Rickmar
d8c9b45fbe Display Go version next to application versions. (#616) 2017-03-14 09:22:40 -04:00
jolan
43bf940cb6 remove walletinfo fields related to stakemining purchaser (#612) 2017-03-10 14:49:26 -05:00
jolan
10adc627c8 add more walletinfo fields (#610) 2017-03-08 16:24:49 -05:00
David Hill
caa57df468 travis: enable gometalinter (#603)
* Hook up gometalinter

* travis: enable unconvert

* travis: enable gosimple
2017-03-08 15:44:15 -05:00
John C. Vernaleo
72673d94d3 Switch to upstream golang.org/x/crypto (#608)
* Switch to upstream golang.org/x/crypto

* Update dcrutil to move to upstream crypto there too
2017-03-08 11:22:02 -05:00
Dave Collins
f7d188297f
chaingen: Allow 32-bit compile.
The go compiler treats the math.MaxUint32 constant as an integer in the
error print which causes a compile error.  This casts the constant to
avoid that thus allows the code to compile on 32-bit architectures.
2017-03-07 10:42:27 -06:00
Dave Collins
306cbf944c
blockchain: Make node creation in tests consistent.
This modifies all invocations of newBlockNode in the tests to use the
already existing zeroHash instance and nil for all unused fields versus
creating an empty object for them.  This is more consistent with
existing code and avoids needlessly creating objects.
2017-02-27 14:46:27 -06:00
Marco Peereboom
0f4b4333fd blockchain: Optimize stake and vote lookups.
The functions that are used to keep stake version and vote versions
humming along are relatively expensive due to repeated chain walks.
This commit removes the most egregious sinners by memoizing the answer.
It should be noted that we can not memoize the walk to the prior
interval because that would require one to memoize all blocks up to the
prior interval.  This is in practice not a big issue because relatively
new blockNodes are in memory.  The real savings happen when a block does
not need to be loaded from disk.

Here are some figures from a quad core Xeon 2.66GHz.
stakeversion_test.go:930: running: shallow no cache with 20160 nodes
stakeversion_test.go:1000:   run time (setup 0) 712.273µs
stakeversion_test.go:1000:   run time (run 1) 576.898µs
stakeversion_test.go:1000:   run time (run 2) 571.683µs
stakeversion_test.go:1000:   run time (run 3) 571.424µs
stakeversion_test.go:1000:   run time (run 4) 570.918µs
stakeversion_test.go:930: running: shallow cache with 20160 nodes
stakeversion_test.go:1000:   run time (setup 0) 775.044µs memory cost: 116
stakeversion_test.go:1000:   run time (run 1) 74.316µs memory cost: 116
stakeversion_test.go:1000:   run time (run 2) 57.283µs memory cost: 116
stakeversion_test.go:1000:   run time (run 3) 57.235µs memory cost: 116
stakeversion_test.go:1000:   run time (run 4) 57.068µs memory cost: 116
stakeversion_test.go:930: running: deep no cache with 201600 nodes
stakeversion_test.go:1000:   run time (setup 0) 700.987µs
stakeversion_test.go:1000:   run time (run 1) 571.4µs
stakeversion_test.go:1000:   run time (run 2) 569.362µs
stakeversion_test.go:1000:   run time (run 3) 569.154µs
stakeversion_test.go:1000:   run time (run 4) 569.319µs
stakeversion_test.go:930: running: deep cache with 201600 nodes
stakeversion_test.go:1000:   run time (setup 0) 723.686µs memory cost: 116
stakeversion_test.go:1000:   run time (run 1) 57.565µs memory cost: 116
stakeversion_test.go:1000:   run time (run 2) 55.698µs memory cost: 116
stakeversion_test.go:1000:   run time (run 3) 55.478µs memory cost: 116
stakeversion_test.go:1000:   run time (run 4) 56.046µs memory cost: 116
2017-02-27 14:15:13 -06:00
Dave Collins
9807f9ece0
blockchain: Always run fullblock tests.
Now that the chaingen code has been optimized, don't skip the fullblock
tests when in the short testing mode.
2017-02-21 15:49:22 -06:00
Dave Collins
50848a645b
TravisCI: Only run tests once.
This modifies the goclean.sh script that is executed on Travis to
only run the tests once.

While it is nice to see coverage reports in the log, unfortunately it
appears that both the -race and -cover flags can't be used together, and
the tests have grown in complexity such that they are starting to get
close to TravisCI time limits.
2017-02-21 15:40:29 -06:00