Commit Graph

268 Commits

Author SHA1 Message Date
David Hill
5fc31ca578 multi: fix misspell linter warnings 2018-02-18 12:26:52 -06:00
Dave Collins
1a62f72f40
blockchain/indexers: Allow interrupts.
This propagates the interrupt channel through to blockchain and the
indexers so that it is possible to interrupt long-running operations
such as catching up indexes.
2018-02-18 11:18:52 -06:00
Donald Adu-Poku
e48b9ab823 mempool: Rename RelayNonStd config option.
This renames the mempool.Config.RelayNonStd option to AcceptNonStd which
more accurately describes its behavior since the mempool was refactored
into a separate package.

The reasoning for this change is that the mempool is not responsible for
relaying transactions (nor should it be).  Its job is to maintain a pool
of unmined transactions that are validated according to consensus and
policy configuration options which are then used to provide a source of
transactions that need to be mined.

Instead, it is the server that is responsible for relaying transactions.
While it is true that the current server code currently only relays txns
that were accepted to the mempool, this does not necessarily have to
be the case.  It would be entirely possible (and perhaps even a good
idea as something do in the future), to separate the relay policy from
the mempool acceptance policy (and thus indirectly the mining policy).
2018-02-14 15:55:22 +00:00
David Hill
dce7e3f161 multi: various cleanups 2018-02-02 14:18:41 -06:00
Dave Collins
31f11b26b2
blockchain: Explicit block fetch semantics.
This makes the semantics of block fetching much more explicit by
introducing a new function named fetchMainChainBlockByHash which only
attempts to the load a block from the main chain block cache and then
falls back to the database.  While currently only blocks in the main
chain are in the database, the intention is for future commits to
allow the database to house side chain blocks as well, so having clearly
defined semantics will help make that transition easier to verify.

While here, it also renames {f,F}etchBlockFromHash to {f,F}etchBlockByHash
to be consistent with the naming used by the other existing functions
and updates the comments to better describe the function semantics.
2018-01-31 17:01:30 -06:00
Dave Collins
20a8ccc27b
blockchain: Use hash values in structs.
This modifies the BestState struct in the blockchain package to store
hashes directly instead of pointers to them and updates callers to deal
with the API change in the exported BestState struct.

In general, the preferred approach for hashes moving forward is to store
hash values in complex data structures, particularly those that will be
used for cache entries, and accept pointers to hashes in arguments to
functions.

Some of the reasoning behind making this change is:

- It is generally preferred to avoid storing pointers to data in cache
  objects since doing so can easily lead to storing interior pointers into
  other structs that then can't be GC'd
- Keeping the hash values directly in the structs provides better
  cache locality
2018-01-30 13:37:26 -06:00
Dave Collins
cac5c152ae
blockchain: Reconstruct headers from block nodes.
This modifies the block node structure to include extra fields needed to
be able to reconstruct the block header from a node, and exposes a new
function from chain to fetch the block headers which takes advantage of
the new functionality to reconstruct the headers from memory when
possible.  Finally, it updates both the p2p and RPC servers to make use
of the new function.

This is useful since many of the block header fields need to be kept in
order to form the block index anyways and storing the extra fields means
the database does not have to be consulted when headers are requested if
the associated node is still in memory.
2018-01-29 11:41:25 -06:00
Donald Adu-Poku
7f7894cf71 chaincfg: Introduce new type DNSSeed
DNSSeed defines a DNS Seed with a hostname and whether it supports
filtering by service flag bits.
2018-01-17 23:02:21 +00:00
David Hill
b13f5dfbda travis: add ineffassign linter 2017-12-01 09:14:04 -05:00
David Hill
20686cd775 travis: add gosimple linter 2017-11-20 18:49:55 -06:00
Josh Rickmar
6842aa006d Merge remaining dcrutil code into a dcrd package.
This merge commit adds the following code from the
github.com/decred/dcrutil package into a new
github.com/decred/dcrd/dcrutil package:

* Address handling
* Amount type
* AppDataDir func
* bitflags functions
* Block wrapper type
* Hash160 func
* Tx wrapper type
* WIF type

as well as all tests for this code.

The old github.com/decred/dcrutil/hdkeychain package has also been
merged and moved to github.com/decred/dcrd/dcrutil/hdkeychain.

dcrd packages have been updated to use the new packages and the dep
files have been updated for this change.
2017-10-11 22:06:36 -04:00
Josh Rickmar
c394c7bd19 Copy github.com/decred/dcrutil/bloom to bloom package.
Use this new bloom package rather than relying on the bloom package
from the dcrutil repo.

Some minor source code changes have been made to conform to the dcrd
linter requirements.
2017-10-11 15:36:57 -04:00
Dave Collins
855305962a
multi: Enable vote for DCP0002 and DCP0003.
This implements the agenda for voting on the LN features as defined in
DCP0002 and DCP0003 along with consensus tests to ensure its correctness.

The following is an overview of the changes:

- Generate new version blocks and reject old version blocks after a
  super majority has been reached
  - New block version on mainnet is version 5
  - New block version on testnet is version 6
- Introduce a convenience function for determining if the vote passed
  and is now active
- Introduce a new function for getting the consensus script verification
  flags and setting the appropriate flags to enforce the new consensus
  semantics in accordance with the state of the vote
- Enforce transaction finality checks based on the past median time in
  accordance with the state of the vote
- Enforce relative time locks via sequence numbers in accordance with
  the state of the vote
- Modify the more strict standardness checks (acceptance to the mempool
  and relay) to enforce DCP0002 in accordance with the state of the vote
  - It should be noted that the flag for DCP0003 is always set for
    the more strict standardness checks because it is a soft fork while
    the DCP0002 enforcement must depend on the result of the vote
    because it is a hard fork
- Add tests for determining consensus script verification flags for both
  mainnet and testnet
- Add tests for determining if the agenda is active for both mainnet and
  testnet
2017-09-22 11:43:58 -05:00
Dave Collins
636d94a3dc
mempool: Enforce relative sequence locks.
This adds enforcement of the newly introduced relative time locks via
transaction sequence numbers when considering candidate transactions for
acceptance to the mempool, relaying, and inclusion into block templates.
It also raises the maximum standard transaction version to 2
accordingly.  This is acceptable because it is a soft forking change and
the aforementioned areas only enforce policy.

The following is an overview of the changes:

- Modify mempool to consider version 2 transactions standard
- Introduce a new callback to the mempool config for obtaining the
  sequence lock for block after the current best chain tip so it can
  remain decoupled from the chain
- Update mempool to enforce relative locks on all candidate transactions
- Update the mock chain in the mempool test harness accordingly
2017-09-21 15:58:45 -05:00
Dave Collins
ecf5f0a00e
mempool: Use median time for tx finality checks.
This modifies the mempool transaction finality checks to use the past
median time instead of the adjusted network time.  This ensures the
standardness rules match the upcoming consensus rules which reject
transactions that are not after the median time of the last several
blocks.  Without this change, it is possible for transactions which can
never make it into a block to be admitted to the mempool thereby wasting
memory.

The following is an overview of the changes:

- Introduce a new callback to the mempool config named PastMedianTime
  for obtaining the median time for the current best chain so it can
  remain decoupled from the chain
- Update the tx finality standardness check to use the callback
- Remove the now unused TimeSource mempool config parameter
- Update the mempool test harness and mock chain to use a mock median time
- Update server to provide a closure for the mempool config that uses
  the cached median time for the current best chain to negate any
  additional performance impact the new calculations would otherwise
  cause from recalculating the median time for every new candidate tx
  validation
2017-09-20 04:13:29 -05:00
Dave Collins
1955bb1bf1
multi: Abstract standard verification flags.
This modifies the way standard verification flags are handled so that it
is possible to selectively enable them based on the result of agenda
votes.

First, it moves the StandardVerifyFlags constant from the txscript
package to the mempool/policy code and rename it to
BaseStandardVerifyFlags.  As the TODO in the comment of the moved
constant indicated, these flags are policy related and thus really
belong in policy.  Ideally there would be a completely separate policy
package, but since the policy code currently lives in mempool/policy.go,
the constant has been moved there.

Next, it introduces a new function named standardScriptVerifyFlags,
which accepts the chain as an argument and, for now, just returns the
BaseStandardVerifyFlags along with a nil error.  This will allow
additional flags to be selectively enabled depending on the result of an
agenda vote.

Finally, it updates the mempool policy struct to require a closure for
obtaining the flags so it can remain decoupled from the chain which in
turn allows easier and more robust unit testing of mempool functionality
since it allows a mocks to be used.
2017-09-15 12:58:21 -05:00
Dave Collins
dee4231e01
mempool/wire: Don't make policy decisions in wire.
This removes the function IsSupportedMsgTxVersion function from wire
since that is a policy decision and does not belong in wire.

It also updates the mempool standard transaction checks to be more
inline with the upstream code such that the maximum supported
transaction version is specified via a field in the mempool policy
configuration struct.

Finally, it adds a new test to the standard transaction tests to ensure
transactions that are not serialized with the full seriaization type are
considered nonstandard.
2017-08-05 15:49:55 -05:00
Dave Collins
9c59171c79
multi: Optimize by removing defers
Upstream commit b1621332cc.
2017-08-02 10:35:21 -05:00
Dave Collins
3d5ceb1788
peer: Strictly enforce bloom filter service bit.
Upstream commit 8965d88893.
2017-07-26 18:08:07 -05:00
David Hill
486271413e config: Add --whitelist option 2017-07-24 15:39:23 -04:00
Dave Collins
6dbb5aa627
config: new flags to accept/reject non-std txns.
This contains the following upstream commits:
- dc5486a579
- 815ded348e
- c6d50b7abf

The merge commit also includes the contains necessary Decred-specific
alterations.
2017-07-21 13:51:47 -05:00
Dave Collins
0a76122ef3
mempool: Break dependency on chain instance.
Upstream commit 641182b2ad.

In addition, the merge commit also adds two more functions to the
config, named BlockByHash and BestHash, along with an additional field
for the SubsidyCache in order to maintain the spirit of the upstream
commit breaking the dependency on a specific chain instance.
2017-07-20 13:54:59 -05:00
David Hill
ecd27f0d4d rpcserver: Support larger block sizes. 2017-04-28 21:48:27 -05:00
David Hill
bb51d32f69 Log the actual error as well. (#676) 2017-04-28 21:09:42 -04:00
David Hill
6c1a2a6beb peer: bump max protocol to wire.MaxBlockSizeVersion 2017-04-28 10:33:33 -05:00
dskloet
c58b7577e1 addrmgr: Remove unused param from GetAddress()
addrmgr.GetAddress() had a parameter `class string` originally intended
to support looking up addresses according to some type of filter such as
IPv4, IPv6, and only those which support specific wire.ServiceFlags
(full nodes, nodes that support bloom filters, nodes that support
segwit, etc). But currently the parameter is unused and also has an
inappropriate type `string`.

If it would ever be used, it's easy to add back and should then get an
appropriate type such as something that allows bitflags to be set so
that the caller could request combinations such as peers that support
IPv6, are full nodes, and support bloom filters.
2017-03-24 17:06:43 -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
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
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
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
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
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
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
David Hill
caa57df468 travis: enable gometalinter (#603)
* Hook up gometalinter

* travis: enable unconvert

* travis: enable gosimple
2017-03-08 15:44:15 -05:00
Dave Collins
e9acb1d35b
mempool: Refactor mempool code to its own package.
Upstream commit 7fac099bee.

Also, the merge commit contains the necessary decred-specific
alterations, adds a new policy parameter for AllowOldVotes to keep with
the spirit of the merged commit, modifies the RawMempoolVerbose to
accept an optional filter type to retain that functionality, and various
other cleanup intended to bring the code bases more in line with one
another.
2016-11-29 15:32:22 -06:00
Dave Collins
3ff0cf8afe
mempool: Decouple mining-specific logic.
This splits the mining-specific code that deals with sorting blocks
according to the number of votes available for it in the mempool into
mining.go.

This is being done for a couple of reasons:

1) Mining-specific code does not belong directly in the mempool
2) It is required to be able to split the mempool into a separate
   package which an upcoming upstream sync does

In order to accomplish this, a new function named VotesForBlocks has been
exposed on the mempool and the SortParentsByVotes code has been moved to
mining.go and modified to no longer return errors.  The reasoning for
this is the same as the recent change to VoteHashesForBlock.  That is to
say it is not the responsibility of a sorting function to dictate
caller-specific block eligibility logic.
2016-11-23 10:18:27 -06:00
Dave Collins
bfb9ca95b7
mempool: Rename GetVoteHashesForBlock & remove err.
This renames the GetVoteHashesForBlock on the mempool type to
VoteHashesForBlock so it is named according to Effective Go guidelines
as required by the project's code contribution guidelines and removes
the error return and paths from the function.

The error has been removed since the function should not be assuming how
the caller wishes to use the data.  Consequently, now when there are no
votes for a given block hash, the function simply returns a nil slice to
reflect that.  The caller can then decide if the lack of vote hashes for
a block is an error or not.

Also, the error path regarding an unset vote hash in the metadata is an
impossible condition because the mempool has full control over the vote
insertion and thus will never insert vote metadata without it.
2016-11-22 13:12:58 -06:00
Dave Collins
3526f520e4
server: Optimize get mining state code.
This slightly optimizes the code which is invoked to provide the current
mining state to remote peers.

First, rather than creating copies of all of the hashes into a new slice
while limiting them in the OnGetMiningState function, just subslice
the hashes to the max length when there are too many.

Second, make the slices []chainhash.Hash which has better cache
locality and only requires a single allocation as opposed to one per
hash.

Finally, convert the pushMiningState function to accept []chainhash.Hash
slices for the block hashes and vote hashes and use the hashes directly
in the slices to build the final wire message.
2016-11-21 23:20:45 -06:00
Dave Collins
8bd9101d7b
server: Remove superfluous check in OnMemPool.
Contains the following upstream commits:
- 05ab7141d3
  - Reverted because Travis is already at a more recent version
- 87b3756c8c
2016-11-18 13:19:35 -06:00
Dave Collins
c162fbde71
multi: Upstream chainhash abstraction sync
Contains the following commits:

- 711f33450c
- b6b1e55d1e
  - Reverted because Travis is already at a more recent version
- bd4e64d1d4

Also, the merge commit contains the necessary decred-specific
alterations, converts all other references to sha to hash to keep with
the spirit of the merged commits, and various other cleanup intended to
bring the code bases more in line with one another.
2016-11-16 12:48:40 -06:00
Dave Collins
cf7fbc0406
peer: Extract protocol negotiation from main loops.
Contains the following upstream commits:
- 5cbd1f85bf
- 777ccdade3
- f3d759d783
- 1ffc3dc18d

Also the merge commit updates the code to use the correct Decred
protocol versions and contains a few style-related changes.
2016-11-11 14:57:30 -06:00
Dave Collins
26e22790cd
mempool: Rename RelayNonStd config option.
This renames the mempool.Config.RelayNonStd option to AcceptNonStd which
more accurately describes its behavior since the mempool was refactored
into a separate package.

The reasoning for this change is that the mempool is not responsible for
relaying transactions (nor should it be).  Its job is to maintain a pool
of unmined transactions that are validated according to consensus and
policy configuration options which are then used to provide a source of
transactions that need to be mined.

Instead, it is the server that is responsible for relaying transactions.
While it is true that the current server code currently only relays txns
that were accepted to the mempool, this does not necessarily have to
be the case.  It would be entirely possible (and perhaps even a good
idea as something do in the future), to separate the relay policy from
the mempool acceptance policy (and thus indirectly the mining policy).
2016-10-23 20:41:54 -05:00