Commit graph

3531 commits

Author SHA1 Message Date
Olaoluwa Osuntokun
e8f63bc295
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.
2016-11-10 11:22:36 -08:00
Olaoluwa Osuntokun
c6e1d711da review: fix typos 2016-11-09 11:13:10 -08:00
Olaoluwa Osuntokun
01050a2f82
add support for getblockchaininfo 2016-11-06 16:07:47 -08:00
Dave Collins
df33d4340e
server: Ensure callbacks use the server peer.
This modifies the signatures of all serverPeer callbacks that are
provided as peer.Listeners to use _ for the first parameter name which
ensures the passed peer can't be used within the function and updates
all references to the server peer.

This helps ensure any overridden methods that might be defined on a
serverPeer will be invoked where directly calling methods on the passed
peer would not.

Also, while here, add a comment to the OnFeeFilter function.
2016-11-04 13:38:13 -05:00
Dave Collins
b65881c137
connmgr: Add tests for new inbound listener logic. 2016-11-04 13:14:50 -05:00
Dave Collins
d98430d8ca
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.
2016-11-04 13:14:44 -05:00
Dave Collins
ea9bf748bb
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.
2016-11-04 13:14:39 -05:00
Dave Collins
2c6f864b55
wire: Change NewNetAddress to accept a *net.TCPConn.
Rather than accepting a net.Addr interface and returning an error when
it's not specifically a *net.TCPConn, just accept a *net.TCPConn
directly so the compiler will assert it.  Also, remove the error return
since it can no longer occur.
2016-11-04 11:06:07 -05:00
Javed Khan
a041b4349b server: Use Disconnect in handleDonePeerMsg 2016-11-04 00:36:13 -05:00
Javed Khan
b320129e9b server: Check max peers before connecting 2016-11-04 00:36:13 -05:00
Javed Khan
d8a6de461f connmgr: Retry only if below target outbound conns 2016-11-04 00:36:13 -05:00
Javed Khan
aca9fc040c connmgr: Rename max outbound to target outbound 2016-11-04 00:36:13 -05:00
Dave Collins
6bb8d297a6
wire: Remove unused NewMsgVersionFromConn.
This function is a legacy function from way back during initial
development.  Nothing actually uses it and it's not very useful anyways
since it requires the connection to be a specific type (net.TCPConn) and
therefore doesn't work right with things that typically provide their
own net.Conn implementation like proxies.
2016-11-03 20:14:16 -05:00
David Hill
2510baac35 btcd: support feefilter requests.
This only adds support for handling remote peer requests.
2016-11-03 14:47:30 -04:00
Dave Collins
fbb49ae349
build: Add unconvert linter to goclean.sh.
This modifies the goclean.sh script to include the unconvert lint tool
in the gometalinter configuration.

It also bumps the deadline to 45 seconds to give slower TravisCI
build servers more breathing room.
2016-11-03 13:32:35 -05:00
Dave Collins
c180551348
build: Add gosimple linter to goclean.sh.
This modifies the goclean.sh script to include the gosimple lint tool to
the gometalinter configuration.
2016-11-03 13:24:06 -05:00
Dave Collins
915fa6639b
multi: Simplify code per gosimple linter.
This simplifies the code based on the recommendations of the gosimple
lint tool.
2016-11-03 13:00:35 -05:00
Dave Collins
af524fb3e7
multi: Remove unnecessary convs found by unconvert.
This removes all unnecessary typecast conversions as found by the
unconvert linter.
2016-11-03 11:59:38 -05:00
Dave Collins
aa53c14a19
addrmgr/btcd: Updates for staticcheck results.
This makes two modifications based on the results of staticcheck.

The first is to use a simplified zero value for the time in the addrmgr
package tests.

The second is check any errors when opening a directory while attempting
to perform old version upgrades.
2016-11-03 11:29:08 -05:00
Dave Collins
82cba61bad
bmgr: Remove unused struct fields.
Found by structcheck.
2016-11-02 18:50:35 -05:00
Dave Collins
e320330d29
multi: Remove unused code found by deadcode. 2016-11-02 17:37:31 -05:00
John C. Vernaleo
1e38d7fd4b Switch to gometalint in goclean
This switches `goclean` to use `gometalint` instead of running each checking tool one at a time.  The `gometalint` tool runs them concurrently.

More importantly it will allow us to easily add additional linters as desired.
2016-11-02 17:36:32 -05:00
Javed Khan
d1c39edee8 server: Cap max outbound in connmgr cfg at max peers 2016-11-02 15:10:14 -05:00
David Hill
6951d8e235 connmgr: unexport the DynamicBanScore mutex. 2016-11-01 14:53:15 -05:00
Jonathan Gillham
83432785f3 peer: Separate ping ticker functionality from outHandler.
This is part of a series of commits to make the internals of the peer
package more modular, testable and tunable. No functionality has changed.
2016-10-29 23:28:12 +01:00
Dave Collins
760c5299c7
mempool: Modify default orphan tx policy.
The current max orphan transaction size causes problems with dependent
transaction relay due to its artificially small size in relation to the
max standard transaction size.

Consequently, this modifies the orphan transaction policy by increasing
the max size of each orphan to the same value allowed for standard
non-orphan transactions and reducing the default max allowed number of
orphans to 100.

From a memory usage standpoint, the worst case max mem usage prior to
this change was 5MB plus structure and tracking overhead (1000 max
orphans * 5KB max each).  With this, that is raised to 10MB (100 max
orphans * 100KB max each) in the worst case.

It is important to note that the values were originally implemented as a
naive means to control the size of the orphan pool before several of the
recent enhancements which more aggressively remove orphans from the
orphan pool were added, so they needed to be evaluated again.

For a very long time prior to recent changes, the orphan pool would
quickly reach the max allowed worst-case usage and effectively stay
there forever whereas with more recent changes, the actual run-time
orphan pool usage is usually much smaller.

Finally, as another point in favor of this change, as the network has
evolved, nodes have generally become better about orphan management and
as such missing ancestors will typically either be broadcast or mined
fairly quickly resulting in fewer overall orphans.
2016-10-28 15:41:59 -05:00
Dave Collins
6d5714e1b7
server/mempool: Evict orphans on peer disconnect.
This removes any remaining orphan transactions that were sent by a peer
when it disconnects since it is extremely unlikely that the missing
parents will ever materialize from elsewhere.
2016-10-28 15:27:57 -05:00
Dave Collins
2124accf62
mempool: Expose RemoveOrphansByTag function. 2016-10-28 15:27:57 -05:00
Dave Collins
e992d55822
mempool: Associated tag with orphan txns.
This allows a caller-provided tag to be associated with orphan
transactions.  This is useful since the caller can use the tag for
purposes such as keeping track of which peers orphans were first seen
from.

Also, since a parameter is required now anyways, it associates the peer
ID with processed transactions from remote peers.
2016-10-28 15:27:57 -05:00
David Hill
2615fa0849 mempool: Return type TxDesc instead of type btcutil.Tx
This will provide callers more information on the accepted transaction.
2016-10-28 14:52:31 -04:00
Dave Collins
1a69eb0617
cpuminer: Refactor code to its own package.
This does the minimum work necessary to refactor the CPU miner code into
its own package.  The idea is that separating this code into its own
package will improve its testability and ultimately be useful to other
parts of the codebase such as the various tests which currently
effectively have their own stripped-down versions of this code.

The API will certainly need some additional cleanup and changes to make
it more usable outside of the specific circumstances it was originally
designed to support (namely the generate RPC), however it is better to
do that in future commits in order to keep the changeset as small as
possible during this refactor.

Overview of the major changes:

- Create the new package
- Move cpuminer.go -> cpuminer/cpuminer.go
- Update mining logging to use the new cpuminer package logger
- Rename cpuminerConfig to Config (so it's now cpuminer.Config)
- Rename newCPUMiner to New (so it's now cpuminer.New)
- Update all references to the cpuminer to use the package
- Add a skeleton README.md
2016-10-28 11:06:11 -05:00
Dave Collins
a755305a2e
rpcserver: Move error check for generate RPC.
This moves the error check for an attempt to call the generate RPC when
on a network that there is virtually no chance of mining a block with
the CPU into the RPC server where it more naturally belongs.  The caller
of the CPU should be the one to determine if it wants to allow mining or
not.  While here, use a more accurate RPC error code of ErrDifficulty
instead of ErrInternal.

This change is a step towards being able to separate the CPU mining code
into its own subpackage.
2016-10-28 10:58:51 -05:00
Dave Collins
05126f6034
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.
2016-10-28 10:49:00 -05:00
Dave Collins
214d975adf
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.
2016-10-28 10:49:00 -05:00
Dave Collins
a1f014c9e1
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.
2016-10-28 10:15:38 -05:00
Dave Collins
14b51fc5f8
multi: Correct misspellings detected by misspell. 2016-10-28 09:43:38 -05:00
Dave Collins
55e2c5da2f
btcd: Remove deps.txt.
Now that glide is used for version management the deps.txt file is no
longer needed.  It will still be available in the git history if it is
ever needed.
2016-10-28 09:33:27 -05:00
Dave Collins
51a6309cdd
blockchain: Run gofmt -s.
Also compress some definitions a bit while simplifying.
2016-10-27 23:20:25 -05:00
Dave Collins
f3c442deb2
server: Remove unused wakeup channel.
This channel is no longer used since the outgoing connection logic is
handled by the connmgr package now.
2016-10-27 20:04:58 -05:00
Dave Collins
f6ad7eb2c9
wire: Make NewMsgTx accept the tx version.
This modifies the NewMsgTx function to accept the transaction version as
a parameter and updates all callers.

The reason for this change is so the transaction version can be bumped
in wire without breaking existing tests and to provide the caller with
the flexibility to create the specific transaction version they desire.
2016-10-27 14:09:29 -05:00
Dave Collins
58a98630e7
mining: Add basic priority calculation tests.
This adds some basic tests for the priority calculation code in the
mining policy.
2016-10-27 13:13:37 -05:00
Dave Collins
61ca40e0e9
mining: Refactor template code into mining package.
This does the minimum work necessary to refactor the block template
generation code into the mining package.  The idea is that separating
this code into the mining package will greatly improve its testability,
allow independent benchmarking and profiling, and open up some
interesting opportunities for future development related to mining.

There are some areas related to policy and other configuration that
could be further refactored, however it is better to do that in future
commits in order to keep the changeset as small as possible during this
refactor.

Overview of the major changes:

- Move mining.go -> mining/mining.go
- Move mining_test.go -> mining/mining_test.go
- Add logger to mining package
- Update the MINR subsystem to use the new mining package logger
- Export CoinbaseFlags from the mining package
- BlkTmplGenerator is now mining.BlkTmplGenerator
- Update all references to the mining code to use the package
2016-10-27 11:48:48 -05:00
Dave Collins
a952a3a148
mining: Use generator state versus local state.
This change is a step towards being able to separate the mining code
into its own subpackage.  No functional change.
2016-10-27 11:48:42 -05:00
Dave Collins
a18f883c1f
mining/mempool: Export MinHighPriority from mining.
This move the export for MinHighPriority from the mempool package to the
mining package.  This should have been done when the priority
calculation code was moved to the mining package.
2016-10-27 11:48:37 -05:00
Dave Collins
660467259e
mining: Break dependency on block manager instance.
This modifies the block template generate for the mining code such that
it takes chain instance and params instead of requiring a fully
initialized blockManager instance.

Also, in preparation for being able to more easily separate the code, it
exposes and makes use of two new functions:
- BestSnapshot which returns the state snapshot from the underlying
  chain instance
- TxSource which returns the underlying transaction source

This is a step towards being able to separate the mining code into its
own package.  No functional change.
2016-10-27 11:48:32 -05:00
Dave Collins
671901486c
cpuminer: Introduce cpuminerConfig.
This introduces a cpuminerConfig type which contains the necessary
information to break the direct dependency on the main server instance.

This change is a step towards being able to separate the cpu miner into
its own subpackage.  No functional change.
2016-10-27 09:37:30 -05:00
Olaoluwa Osuntokun
e3eeb4a34a
mempool: add policy config option for transaction version
This commit adds a new option to the mempool’s policy configuration
which determines which transaction versions should be accepted as
standard.

The default version set by the policy within the server is 2; this
allows accepting transactions which have version 2 enabled in order to
utilize the new sequence locks feature.
2016-10-26 21:49:14 -07:00
Olaoluwa Osuntokun
6cd8955498
mempool: enforce relative lock-time semantics
This commit introduces behavior which enforces sequence num based
relative lock-time semantics when accepting transaction to the mempool.
2016-10-26 21:49:07 -07:00
Olaoluwa Osuntokun
7eb0ab5f8d
mempool: add function to config for computing sequence locks 2016-10-26 21:49:04 -07:00
Olaoluwa Osuntokun
ecdaf9726c
blockchain: add basic tests for SequenceLockActive 2016-10-26 21:49:00 -07:00