Commit Graph

5107 Commits

Author SHA1 Message Date
Donald Adu-Poku
dcddbbabb4 multi: add SanityChecker interface.
This adds the sanity checker interface and update
the function signature of CheckBlockSanity.
Associated tests and mocks updated/added.
2020-07-25 19:17:27 -05:00
Dave Collins
f73d738c24
main: Simplify startup logic slightly.
This modifies the main startup logic to make use of the fact that the
server now has its lifecycle tied to the same context that is cancelled
when a shutdown signal is received.

The end result is that the separate goroutine it was running in before
and associated synchronization logic is no longer necessary.
2020-07-25 18:14:55 -05:00
Dave Collins
264df84ae6
docs: Update for removal of fees module. 2020-07-25 18:10:43 -05:00
Dave Collins
eb4a0a06ac
fees: Move to internal.
This makes the fees package an internal package such that it will no
longer be an exported module.  The only place its functionality is
really needed is for the internal implementation of dcrd itself and thus
having an unnecessary exported module significantly increases the
maintenance burden.

This is part of the overall effort to reduce the total number of modules
and eventually get to the point that it will be possible to follow
semver for the root module.

It is worth noting that there are a few constants, which will be listed
below, that were exported from this module that callers might have
previously relied upon.  However, due to previous discussions about the
goal of removing the module, a code search has revealed that there are
no known callers that rely on them.

The aforementioned constants are:

- DefaultMaxBucketFeeMultiplier
- DefaultMaxConfirmations
- DefaultFeeRateStep

Overview of the major changes:

- Move the following files from fees -> internal/fees:
  - README.md
  - cmd/dumpfeedb/dumpfeedb.go
  - doc.go
  - estimator.go
  - log.go
- Remove fees/go.mod and fees/go.sum
- Make the README.md and doc.go files match the new reality
- Update all import paths in the repository accordingly
- Remove the dependency from the root go.mod
- Run go mod tidy on all modules
2020-07-25 18:10:39 -05:00
Dave Collins
1f308b4cb2
rpcserver: Use func for semver string.
This constructs the RPC API semantic version string from the individual
major, minor, and path constants versus requiring updates in both
places.  This is something contributors have previously forgotten to
update, so it makes sense to avoid the need to do it altogether.
2020-07-25 17:54:10 -05:00
Ryan Staudt
61705d7501 rpcserver: Remove math/rand init and import.
This removes math/rand from rpcserver as it is being initialized but it
is not being used anywhere.
2020-07-24 23:29:59 -05:00
Ryan Staudt
09f74d9ea9 rpcserver: Rename RPCServer to Server.
This renames RPCServer to Server since this is now referenced as
rpcserver.Server from outside of the rpcserver package.
2020-07-24 23:29:59 -05:00
Ryan Staudt
ff79d17569 rpcserver: Rename NewRPCServer to New.
This renames NewRPCServer to New since this is now referenced as
rpcserver.New from outside of the rpcserver package.
2020-07-24 23:29:59 -05:00
Ryan Staudt
24daadf5b9 rpcserver: Rename RpcserverConfig to Config.
This renames RpcserverConfig to Config since this is now referenced as
rpcserver.Config from outside of the rpcserver package.
2020-07-24 23:29:59 -05:00
Ryan Staudt
c6881b3288 rpcserver: Move to internal.
This moves rpcserver from the main module to a standalone internal
package.

Overview of the major changes:

- Move the following files from the main module -> internal/rpcserver:
  - rpcserver.go
  - rpcserver_test.go
  - rpcserverhandlers_test.go
  - rpcserverhelp.go
  - rpcserverhelp_test.go
  - rpcwebsocket.go
- Update the README.md and doc.go files
- Update all import paths in the repository accordingly
- Update `testDataPath` in rpcserverhandlers_test.go
- Update all `rpcsLog` references to `log`
- Define the following convenience functions and vars in rpcserver.go:
    - `normalizeAddress`
    - `directionString`
    - `zeroHash`
2020-07-24 23:29:59 -05:00
Ryan Staudt
69227557e1 rpcserver: Move genCertPair to server.go.
This moves `genCertPair` from rpcserver.go to server.go.  `genCertPair`
is only used by server.go and is being moved there in anticipation of
rpcserver being moved to a separate internal package.

This is part of the effort to move rpcserver into a separate internal
package.
2020-07-24 23:29:59 -05:00
Ryan Staudt
c08d34ad2e rpcserver: Export rpcwebsocket Notify functions.
This adds the following exported RPCServer functions, which delegate to
the corresponding underlying rpcwebsocket notification functions:
  - NotifyWork
  - NotifyStakeDifficulty
  - NotifyNewTickets
  - NotifyBlockConnected
  - NotifySpentAndMissedTickets
  - NotifyBlockDisconnected
  - NotifyReorganization
  - NotifyWinningTickets

This is done so that blockmanager.go and server.go can still access
these functions after rpcserver is moved to a separate internal package.

This is part of the effort to move rpcserver into a separate internal
package.
2020-07-24 23:29:59 -05:00
Ryan Staudt
92ab26beb5 rpcserver: Export RPC server, config, and new.
This exports `rpcServer`, `rpcserverConfig`, and `newRPCServer` from
rpcserver.go and updates all references accordingly.

This is part of the effort to move rpcserver into a separate internal
package.
2020-07-24 23:29:59 -05:00
Ryan Staudt
e79cbef1e0 rpcserver: Remove PeerNotifier dependency.
This removes the dependency that rpcserver has on the PeerNotifier
interface defined in blockmanager.go.  It accomplishes this by removing
the call to AnnounceNewTransactions and instead calling the already
defined ConnMgr.RelayTransactions interface method, followed by directly
calling NotifyNewTransactions to notify websocket clients of the newly
accepted transactions.

This is part of the effort to move rpcserver into a separate internal
package.
2020-07-24 23:29:59 -05:00
Ryan Staudt
41e0d57315 rpcserver: Remove log config dependencies.
This removes the dependency that rpcserver has on the
supportedSubsystems and parseAndSetDebugLevels functions defined in
config.go.  It accomplishes this by creating and implementing a
rpcserver.LogManager interface.

This is part of the effort to move rpcserver into a separate internal
package.
2020-07-24 23:29:59 -05:00
Ryan Staudt
2afb586cc0 rpcserver: Remove server.go dependencies.
This removes the dependency that rpcserver has on the const
maxProtocolVersion and var userAgentVersion defined in server.go.  It
accomplishes this by passing these values through the rpcserverConfig
struct.

This is part of the effort to move rpcserver into a separate internal
package.
2020-07-24 23:29:59 -05:00
Ryan Staudt
254c66ca2c rpcserver: Remove global config dependency.
This removes the dependency that rpcserver has on the global config in
the main module.  It accomplishes this by passing the necessary config
information through the rpcserverConfig struct.  Additionally, this adds
a Lookup method to the rpcserver.ConnManager interface.

This is part of the effort to move rpcserver into a separate internal
package.
2020-07-24 23:29:59 -05:00
Dave Collins
a6feca22cd
cpuminer: Rework to use bg template generator.
This significantly reworks the CPU miner to make use of the background
block template generator that was introduced in the previous release as
well as to convert its lifecycle to use the expected pattern for running
subsystems based on contexts.

The switch to using the background block template generator provides all
the benefits it offers to miners such as:

- Intelligent vote propagation handling
- Improved handling of chain reorganizations necessary when the current
  tip is unable to obtain enough votes
- Current state synchronization
- Near elimination of stale templates when new blocks and votes are received

This is particularly important in testing scenarios, such as when using
the simulation network, since the difficulty is so low that the code
this is replacing is often able to mine blocks so fast it ends up mining
multiple alternative blocks while waiting for the votes to show up which
makes testing with it more difficult.

This is no longer an issue when requesting template updates since the
background block template generator has logic to provide the votes a
chance to arrive before building and notifying the template.

Another modification this makes is to also make use of template
notifications when mining blocks mined via the discrete mining mode and
to only count blocks if they successfully extend the main chain.  This
also significantly helps in testing scenarios since it means the testing
code and/or testers using the simulation test network can rely on the
requested number of blocks actually being added to the main chain even
if more need to be generated to make that happen.

Along similar lines, one area this change does not address, but does
pave the way to support and would be useful in the future for the
simulation test network is to add some additional logic to provide
ticket purchases a chance to arrive when prior to stake validation
height, since that is another area that often complicates testing.

In terms of the lifecycle changes, this replaces the Start, Stop, and
Wait methods with a single method named Run and arranges for it to block
until the provided context is cancelled.  This is more flexible for the
caller since it can easily turn blocking code into async code while the
reverse is not true.

The new Run method waits for all goroutines that it starts to shutdown
before returning to help ensure an orderly shutdown.

In addition, the semantics of Run are different from Start/Stop in that
the Start method launched the default number of mining worker goroutines
whereas Run only starts the CPU miner with the main infrastructure
goroutines and zero workers, meaning it will be idle until explicitly
requested to mine by the caller setting the number of workers to use.

Since there are exported methods that send messages to the CPU miner
infrastructure goroutines via a channel and those goroutines are stopped
during the shutdown process, all sends select across both the channel in
question as well as a quit channel which is closed when the context is
canceled.  This ensures callers can't end up blocking on send to a
goroutine that is no longer running without needing additional mutexes.

As part of the conversion, it improves a lot of the comments to better
describe the expected behavior and further integrates the context to
support cancellation where it previously was not supported.

Finally, all callers are updated to use the new API and the server is
modified to take advantage of the new lifecycle semantics by taking
ownership of the CPU miner code directly in its Run method where it more
logically makes sense and only creating the template generate and CPU
miner infrastructure if needed based on the configuration options.
2020-07-23 12:36:09 -05:00
Dave Collins
65da0cb422
cpuminer: Refactor code to its own package.
This does the minimum work necessary to refactor the CPU miner code into
its own internal 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 internal/mining/cpuminer.go -> internal/mining/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)
- Add exported BestSnapshot method to mining.BlkTmplGenerator
- Add exported TxSource method to mining.BlkTmplGenerator
- Update all references to the cpuminer to use the package
- Add a skeleton README.md
- Add a skeleton doc.go
2020-07-22 20:06:28 -05:00
Dave Collins
407d6dcbb4
mining: Improve comment for UpdateBlockTime. 2020-07-22 20:06:24 -05:00
Donald Adu-Poku
935467a868 rpcserver: add missed and live tickets rpc tests.
This adds tests for the missed and live ticket rpcs
as well as the validate address rpc.
2020-07-22 18:36:16 -05:00
David Hill
66807231ce build: golangci-lint v1.28.3 2020-07-21 12:33:51 -05:00
David Hill
fff10b5e09 wire: return detectable err from makeEmptyMessage. 2020-07-21 12:33:51 -05:00
David Hill
a927f2ace2 wire: formatting fixes - no functional change 2020-07-21 12:33:51 -05:00
Dave Collins
3a88a1ba65
docs: Update for removal of mining module. 2020-07-21 12:27:46 -05:00
Dave Collins
6ea800f516
mining: Move to internal.
This makes the mining package an internal package such that it will no
longer be an exported module.  The only place its functionality is
really needed is for the internal implementation of dcrd itself and thus
having an unnecessary exported module significantly increases the
maintenance burden.

This is part of the overall effort to reduce the total number of modules
and eventually get to the point it will be possible to follow semver for
the root module.

It is worth noting that there are a few constants, which will be listed
below, that were exported from this module that callers might have
previously relied upon.  However, due to previous discussions about the
goal of removing the module, a code search has revealed that there are
no known callers that still rely on them.

The aforementioned constants are:

- UnminedHeight
- MinHighPriority

Overview of the major changes:

- Move the following files from mining -> internal/mining:
  - README.md
  - cpuminer.go
  - doc.go
  - miningerror.go -> error.go
  - log.go
  - mining.go
  - mining_test.go
  - policy.go
  - policy_test.go
- Remove mining/go.mod and mining/go.sum
- Make the README.md and doc.go files match the new reality
- Update all import paths in the repository accordingly
- Remove the dependency from the root go.mod
- Run go mod tidy on all modules
2020-07-20 18:07:59 -05:00
Dave Collins
a524703265
docs: Update for removal of mempool module. 2020-07-20 14:09:48 -05:00
Dave Collins
3547f21f89
mempool: Move to internal.
This makes the mempool an internal package such that it will no longer
be an exported module.  The only place its functionality is really
needed is for the internal implementation of dcrd itself and thus having
an unnecessary exported module significantly increases the maintenance
burden.

This is part of the overall effort to reduce the total number of modules
and eventually get to the point it will be possible to follow semver for
the root module.

It is worth noting that there are a few constants, which will be listed
below, that were exported from this module that callers might have
previously relied upon.  However, due to previous discussions about the
goal of removing the module, a code search has revealed that there are
no known callers that still rely on them.

The aforementioned constants are:

- MaxStandardTxSize
- DefaultMinRelayTxFee
- BaseStandardVerifyFlags

Overview of the major changes:

- Move the following files from mempool -> internal/mempool:
  - README.md
  - doc.go
  - error.go
  - log.go
  - mempool.go
  - mempool_test.go
  - policy.go
  - policy_test.go
- Remove mempool/go.mod and mempool/go.sum
- Make the README.md and doc.go files match the new reality
- Update all import paths in the repository accordingly
- Remove the dependency from the root go.mod
- Run go mod tidy on all modules
2020-07-20 05:02:35 -05:00
Dave Collins
69a417232c
mempool: Remove deprecated DisableLog func.
This removes the deprecated DisableLog function since the major version
has been bumped since the last release.
2020-07-19 17:46:39 -05:00
Dave Collins
b99031ece8
mempool: Remove deprecated tx rule err reject code.
This removes the deprecated RejectCode from the TxRuleError struct and
updates all of the callers accordingly.
2020-07-19 17:46:39 -05:00
Dave Collins
175d7af5c8
mempool: Remove deprecated ErrToRejectErr func.
This removes the deprecated ErrToRejectErr function and also removes
extractRejectCode since it has no other callers.
2020-07-19 17:46:39 -05:00
Dave Collins
3b68646cf4
mempool: Don't use deprecated reject code in tests.
This updates the tests to use error codes instead of the deprecated
reject codes.
2020-07-19 17:46:38 -05:00
Youssef Boukenken
a1630f5af9 multi: Move mining code into mining package.
This contains the changes necessary to move the
mining code into the mining package.  The motivation
behind these changes is to decouple the block template
generation from other modules in the codebase to
simplify extending it with new features and tests.
2020-07-19 15:22:00 -05:00
Youssef Boukenken
b3e9529ad8 multi: Hide CPUMiner WaitGroup.
This change wraps the CPUMiner's
WaitGroup reference in preparation for
moving the CPUMiner under the mining
package.
2020-07-19 15:22:00 -05:00
Youssef Boukenken
285ea48bfb multi: Decouple blockManager from mining.
This removes coupling between the mining code,
blockManager, and the main configuration.

This change is a step towards moving
the mining code into its own package.
2020-07-19 15:22:00 -05:00
Ryan Staudt
bede6843c7 rpcserver: Add handleGetStakeVersionInfo test. 2020-07-18 21:11:24 -05:00
Ryan Staudt
fb7a30a800 rpcserver: Add handleGetStakeVersions test. 2020-07-18 21:11:24 -05:00
Ryan Staudt
c36a5bc815 rpcserver: Add handleGetTicketPoolValue test. 2020-07-18 21:11:24 -05:00
JoeGruff
97d2c01807 rpcserver: Add handleEstimateStakeDiff test.
Because handleEstimateStakeDiff calls chain.EstimateNextStakeDifficulty
up to four times, change testRPCChain.estimateNextStakeDifficulty to a
function so that handlers can specify more complex return values. In
TestHandleExtimateStakeDiff, have the test RPC chain return functions
that return results from a queue, allowing for multiple calls with
varying results.

Use go-spew to print test result equality errors so that values of
pointers are also printed.
2020-07-18 21:10:53 -05:00
JoeGruff
cdc897dcc2 rpcserver: Add handleEstimateSmartFee test.
Creates a new interface that fees.Estimator satisfies that can be used
with the rpcserver. Corrects some grammar issues and adds a TODO to use
the unused chainserver result type EstimateSmartFeeResult.
2020-07-15 10:59:19 -05:00
Dave Collins
fddd629fe0
rpcclient: Protect websocket connection with mutex.
This modifies the various places the websocket connection is accessed to
protect it with a mutex so that it can't race in reconnect scenarios.

While here, it also makes the retry count local to the only goroutine it
is accessed from.
2020-07-14 14:21:28 -05:00
Dave Collins
5b1b776406
secp256k1: Harden const time field normalization.
This updates the field normalization code to better secure against the
possibility of non-constant time operations due to branch prediction and
adds several tests to ensure the new logic is sound.

The following benchmark results show that this implementation is within
the margin of error for it to not be statistically relevant and thus has
no performance impact.

name             old time/op   new time/op   delta
----------------------------------------------------------------------
FieldNormalize   22.1ns ± 1%   22.1ns ± 1%   ~     (p=0.873 n=5+5)
2020-07-14 14:16:36 -05:00
Ryan Staudt
faec0f8280 rpcserver: Update error case handling in tests.
This updates the rpcserver handler tests to properly call Errorf in the
case that the test specifies wantErr, but err is nil.
2020-07-14 04:38:13 -05:00
Ryan Staudt
58b094f0fa rpcserver: Run tests in parallel.
This updates the rpcserver handler tests to run in parallel and ensure
that they are safe to be run concurrently.
2020-07-14 04:38:13 -05:00
Ryan Staudt
45fb202aeb rpcserver: Update tests to use default configs.
This updates the rpcserver handler tests to use the default
rpcserverConfig and override values only where necessary.  This
simplifies the tests and also ensures that the tests are first
duplicating the default config before overriding values.
2020-07-14 04:38:13 -05:00
Ryan Staudt
b0bfc77d2d rpcserver: Rework default configs for tests.
This updates the rpcserver handler tests to use a reasonable default
rpcserverConfig.  This allows for less of a need to provide mocks in
every test and instead only override where necessary.  It also reduces
the likelihood of the tests panicking if code is added to rpcserver
where an assumption of a non-nil value is being made.
2020-07-14 04:38:13 -05:00
Dave Collins
b0ea067acb
connmgr: Remain responsive with simul failed conns.
This modifies the connection manager handler for failed connections so
that it remains responsive to requests when there are multiple
simultaneous failed connections in the retry state and adds a test to
ensure proper functionality.

While here it also updates a few formatting nits in the server code.
2020-07-13 11:26:02 -05:00
Dave Collins
17d7750192
connmgr: Use t.Fatal when there are no params. 2020-07-13 11:26:02 -05:00
Dave Collins
f7e984b7e7
txscript: Optimize sig enc check with mod n scalar.
This modifies the signature encoding check function to use the new
secp256k1.ModNScalar type for the half order check instead of a big int.

The following benchmark shows a before and after comparison of a typical
signature encoding check:

benchmark                         old ns/op    new ns/op    delta
-------------------------------------------------------------------
BenchmarkCheckSignatureEncoding   79.0         46.9         -40.63%

benchmark                         old allocs   new allocs   delta
--------------------------------------------------------------------
BenchmarkCheckSignatureEncoding   1            0            -100.00%

benchmark                         old bytes    new bytes    delta
--------------------------------------------------------------------
BenchmarkCheckSignatureEncoding   64           0            -100.00%
2020-07-12 00:58:09 -05:00
Dave Collins
23ad58e77b
txscript: Add benchmark for CheckSignatureEncoding. 2020-07-12 00:58:06 -05:00