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.
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
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.
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`
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.
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.
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.
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.
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.
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.
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.
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.
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
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
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
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.
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.
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.
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.
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.
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)
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.
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.
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.
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%