Commit Graph

5030 Commits

Author SHA1 Message Date
Dave Collins
e2d77e4e7e
rpcclient: Reregister work ntfns on reconnect.
This ensures the rpcclient automatically reregisters for work
notifications on reconnect if it had previously registered for them.
2020-06-23 12:48:22 -05:00
degeri
3baf1f590c
docs: Fix chaingen broken markdown link. 2020-06-16 13:28:40 -05:00
Ryan Staudt
d31d9305a4
multi: go mod tidy cleanup and run in CI.
This updates run_tests.sh to run `go mod tidy` in CI and fail if go.mod
and/or go.sum changes.
2020-06-15 08:49:38 -05:00
Ryan Staudt
8559b8742d
rpcserver: Create Chain and UtxoEntry interfaces.
This creates rpcserver.Chain and rpcserver.UtxoEntry interfaces and
respective rpcChain and rpcUtxoEntry adaptors that implement those
interfaces.

This starts to decouple rpcserver from the concrete BlockChain
implementation and allows for mocking those interfaces when testing
rpcserver handlers.
2020-06-15 01:56:43 -05:00
Marco Peereboom
4c5825cf90 standalone: Start v2 module dev cycle 2020-06-11 15:48:38 -05:00
Dave Collins
b2f67c2dc4
multi: Use latest base58 module.
This updates the main, dcrutil, and hdkeychain modules to use the latest
base58 module.

The updated direct dependency is as follows:

- github.com/decred/base58@v1.0.3
2020-06-08 07:40:04 -05:00
Josh Rickmar
62fa0661bd secp256k1: Remove Encrypt/Decrypt functions
The Encrypt and Decrypt functions implemented an encryption and
ciphering scheme using secp256k1 for ECDH key exchange and AES-256-CBC
for ciphering of message plaintext, combined with HMAC-SHA256 for
message authentication (as the CBC block mode is otherwise vulnerable
to message tampering).

This change removes these functions because they are unused within the
Decred project, and we wish to discourage their use.  Instead, we
recommend callers to derive a shared key using secp256k1 for use with
a modern symmetric encryption scheme.  This remains possible through
the ECDH function GenerateSharedSecret (which is not being removed at
this time) and using this key with an AEAD cipher such as AES-256-GCM
or ChaCha20-Poly1305.

Examples which demonstrated use of the Encrypt/Decrypt functions have
been replaced with an example demonstrating usage of
GenerateSharedSecret to encrypt a message using AES-256-GCM.

While here, the doc comment for GenerateSharedSecret has been updated
to reflect that the function has been changed to correctly conform to
RFC 5903.
2020-06-06 23:17:02 -05:00
Dave Collins
3f43437d13
rpcserver: Limit getstakeversioninfo count.
This modifies the RPC server handler for getstakeversioninfo to limit
any provided interval counts to the maximum number of intervals that are
actually available for retrieval and improves a couple of error
messages while here.
2020-06-04 16:13:34 -05:00
Dave Collins
04a107e7c5
rpcserver: Correct JSON-RPC request unmarshal.
This reworks the JSON-RPC unmarshalling logic to correct some error
handling cases as well as optimize the normal path.

It accomplishes this as follows:

- Removes the custom, and incorrect, unmarshalling code in favor of just
  unmarshalling into the Request struct directly
- Allows the Params to be nil (unspecified) per the spec
- Corrects the per-entry batch unmarshal logic such that it first
  unmarshals into an array of json.RawMessage and then unmarshals each
  individual entry into the Request struct
- No longer attempts to process non-batched requests that fail to
  unmarshal properly
2020-06-03 01:58:29 -05:00
Dave Collins
335f6344fa
docs: Update JSON-RPC spec link to latest. 2020-06-02 11:00:03 -05:00
Wisdom Arerosuoghene
a2771b8ce6
rpcserver: Internal err on gettxout utxo fetch err.
Replace noTxInfoError with rpcInternalError when fetching utxo
entry errors in gettxout cmd handler. `gettxout` should never return
`noTxInfoError` because `gettxout` is about tx outputs not txs.

Update code comment and json-rpc docs to more clearly describe the
semantics of the gettxout method, particularly that JSON null is
returned if the requested txout cannot be found either because it
never existed or because it is spent (and possibly pruned).
2020-05-28 14:19:43 -05:00
Josh Rickmar
1a0a3dc5e4 rpcserver: Avoid panic during hash decode
The input hex string must be exactly 64 bytes, else an error will be
returned.  The input validation previously checked that the length
following decoding was correct, but was missing a check that the
destination slice was not smaller than half the source's length.
Moving the length check first keeps the existing short source check
while also preventing a panic with a long input string.
2020-05-28 13:51:46 -05:00
Dave Collins
6fc98347d9
txscript: Add support for errors.Is/As.
This updates the txscript package to provide support for the errors.Is
and errors.As functions introduced in Go 1.13 per the recently
documented best practices.

The following is an overview of the changes:

- Rename the ErrorCode type to ErrorKind and make it a string
- Implement the error interface on ErrorKind
- Update all error code definitions to the new type
- Remove error code string map that is no longer required
- Remove unused ErrInternal definition
- Change the error code field of the Error type to Err
- Implement Unwrap on the Error type to support unwrapping via
  errors.Is/As
- Remove the IsErrorCode function since it is no longer needed due to
  errors.Is
- Update IsDERSigError to cope with the changes
- Modify various comments to refer to error kinds instead of codes
- Update all test code to use the new ErrorKind directly along with
  errors.Is for detecting the expect errors
- Add full test coverage to ensure the new error definitions work as
  intended
- Update the doc.go errors section accordingly
2020-05-26 21:50:17 -05:00
David Hill
2caadbde3f build: use golangci-lint v1.27.0 2020-05-26 21:43:10 -05:00
David Hill
f5718dd3bd rpc: Add AddrIndex and TxIndex bools to getinfo.
These reflect if the dcrd indexes are enabled.
2020-05-26 21:43:10 -05:00
JoeGruff
b4eea1d59a rpcclient: Add a lifetime to requests.
Store the initial context in result types and stop waiting on context
done with ErrRequestCanceled by giving all result types a context field
and having receiveFuture stop waiting on context done with an
ErrRequestCanceled. Result types have been changed from a channel of
*response to a new cmdRes type that can hold the context.

Remove duplicate function futureError and unused sendCmdAndWait.
2020-05-26 20:32:30 -05:00
JoeGruff
464ed4abfa rpcclient: Stop client on ctx done.
The passed context was ignored until a reconnect. This kills the client
when the passed context is done. This is much more useful for consumers
who need the client to shut down when their context if finished.
2020-05-26 20:32:30 -05:00
JoeGruff
0c6c7ca85d stakeext: Fix comments on concurrency.
Both LiveTickets and MissedTickets were incorrectly tagged as not
concurrent safe. However, as these methods work on an immutable tree on
the tip's stake node, there is no way they will be changed at the time
of reading, as only older nodes are pruned.
2020-05-25 22:01:55 -05:00
Dave Collins
0c7cbb5368
connmgr: Finish recent connmgr err type additions.
This continues the work which switched the errors in the connmgr package
to be compatible with errors.Is/As introduced in go 1.13 to make it
match the best practices.

The following is a high level overview of the changes:

- Change the name of the error kind type to ErrorKind
- Make error definitions constant
- Add comments to all exported functions and types as required by the
  code contribution guidelines and various linters
- Add a MakeError function to create the errors instead of creating the
  structs with unnamed fields which goes against standard Go
  recommendations
- Add full test coverage to ensure the definitions work as intended
2020-05-22 13:22:28 -05:00
Donald Adu-Poku
3c5edc5355 connmgr: define connmgr error types.
This defines the connmgr error types compatible with
errors.Is/As introduced in go 1.13. This also removes
the tor success state from the status error set.
2020-05-22 02:02:05 -05:00
Josh Rickmar
ac2481195b
rpcclient: Resurrect validateaddress/verifymessage.
These methods were accidentally removed from the client type when the
dcrwallet method support was removed from the package.  However, dcrd
also implements verifymessage and a less-featureful version of the
validateaddress method, so the client ought to provide direct support
for these.

Compared to the earlier version of this the validateaddress methods,
these reintroduced methods use dcrd's defined type rather than depending
on the dcrwallet definition.
2020-05-20 15:56:54 -05:00
Ryan Staudt
c4751ba728
blocklogger: Always log when sync height reached. 2020-05-19 23:06:32 -05:00
David Hill
6ade944868
dcrutil: Add VerifyMessage API 2020-05-17 16:31:04 -05:00
Ryan Staudt
1f2b1ac7a5 docker: Update image to golang:1.14 2020-05-15 07:02:39 -05:00
matthawkins90
d08cb3f72b docs: Update links to avoid redirects
When linking to Decred.org, pages should end in / to avoid redirects.
Updated docs to use https://decred.org/community/
Updated docs to use https://decred.org/downloads/
2020-05-11 12:55:20 -05:00
Marco Peereboom
c441b41d7d Add debug and trace facility to rpctest.
The rpctest suite is useful however it is impossible to debug in its
current state. This diff adds debug and tracing facilities to the test
that are worth keeping.

It adds two global flags debug and trace that can be enabled when
additional output is required. In addition it sends the test object
around so that segregated parts of the code use the same logging
facility. And lastly, it will always print dcrd panics to the console.
2020-05-11 12:28:03 -05:00
Dave Collins
f5fdd95eb5
server: Actively prevent regnet network discovery.
This modifies the various aspects that deal with making nodes
discoverable and making outbound connections to disable them when
running in regression network test mode in the same way it is done for
the simulation network test mode.
2020-05-08 11:33:54 -05:00
Dave Collins
94fd8fb38c
mining: Prevent potential shutdown hang.
This modifies the background block template generator to ensure all
regen even sends respect the context shutdown state to prevent a
potential hang on shutdown when the underlying goroutines go away.
2020-05-08 11:32:17 -05:00
Dave Collins
639bec0fae
connmgr: Convert lifecycle to context.
This modifies the lifecycle of the connection manager to use the
expected pattern for running subsystems based on contexts.

In particular, 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.

Since there are exported methods that send messages to the connection
handler goroutine via a channel and that goroutine is 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 it 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, this adds various comments to better describe
the expected behavior and modifies timeout functions to select across
the quit channel as well to support cancellation.

Finally, all tests and 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 connection manager and seeding code directly in
its Run method where it more logically makes sense.
2020-05-08 06:05:09 -05:00
Dave Collins
4c3b04a2a6
connmgr: Cleanup TestCancelIgnoreDelayedConnection.
This modifies the TestCancelIgnoreDelayedConnection test to address a
few nits and switches to using a time.After for testing the timeout
condition to ensure proper behavior regardless of the presence of a
context timeout.
2020-05-07 20:07:06 -05:00
Dave Collins
ca4309baed
connmgr: Tighten TestRemovePendingConnection.
This reworks the TestRemovePendingConnection test to more accurately
test the intended condition without dialer sleep hacks.

It does this by signaling exactly when a dial attempt has been made and
responding to that signal by removing the the pending connection while
the dialer is intentionally blocking and ensuring the connection request
is marked as canceled.

It also adds a timeout to the initial dial to prevent a test timeout in
the case the connection were to fail.
2020-05-07 20:07:06 -05:00
Dave Collins
59af821030
connmgr: Tighten TestStopFailed.
This reworks the TestStopFailed test to more accurately test the
intended condition without sleep hacks.  It does this by setting the
retry timeout to a known value, signaling exactly when a dial attempt
has been made, and responding to that signal by shutting down the
connection manager after precisely half the duration of the retry
timeout has elapsed.

Finally, it renames the test to TestShutdownFailedConns to more
accurately reflect what it is testing.
2020-05-07 20:07:06 -05:00
Dave Collins
bef3a4c6af
connmgr: Tighten TestNetworkFailure.
This reworks the TestNetworkFailure test to more accurately test the
intended condition by signaling once the max number of failed attempts
has been reached prior to shutting down the connection manager and
checking the expected number of total dials attempted.

It also tightens the number of expected dials to a more accurate value
to better ensure an accurate result.
2020-05-07 20:07:05 -05:00
Dave Collins
31323ba0e9
connmgr: Shore up TestMaxRetryDuration.
This modifies TestmaxRetryDuration to assert the configured max retry
duration is the expected value since the test relies on that and also
switches to using a time.After for testing the timeout condition to
ensure proper behavior regardless of the presence of a context timeout.
2020-05-07 20:07:05 -05:00
Dave Collins
be9d4854ad
connmgr: Increase timeout in TestTargetOutbound.
This increases the timeout when ensuring there are no additional
connections to actually provide enough time to test the intended
condition.
2020-05-07 20:07:05 -05:00
Dave Collins
2e0ca46c6f
connmgr: Improve TestConnectMode robustness.
This reworks the TestConnectMode test a bit to ensure the connection was
received within a certain timeout and that only one connection was
made.  This prevents a test timeout in the case the connection were to
fail.

It also corrects the improper use of context while here.
2020-05-07 20:07:04 -05:00
Dave Collins
c858ca55ca
connmgr: Update tests to ensure clean shutdown.
This updates all of the tests which create a connection manager
instances to wait for clean shutdown to ensure it works properly with
the various states.
2020-05-07 20:07:04 -05:00
Dave Collins
40743875b7
connmgr: Refactor conn req ID/state test asserts.
This refactors the various checks which ensure a connection request has
the expected ID and state into test helpers to improve the readability
and reduce the amount of redundant code.
2020-05-07 20:07:01 -05:00
Donald Adu-Poku
2e07bdcff1 server: ban peers on wire protocol errors.
This bans peers, mostly non-whitelisted
peers, for not conforming to the wire protocol.
2020-05-07 19:57:12 -05:00
matthawkins90
c8e3fec516 docs: Update Code Contribution Guidelines
Added clarity about multi-line commit messages, as well as defined rules
regarding linking to other issues or PRs.
2020-05-06 15:51:09 -05:00
Wisdom Arerosuoghene
bb830e670f
multi: CancelPending error for no pending conns.
This modifies the CancelPending method of the connection manager to
return an error when there are no pending connections for the provided
address or the connection manager is already shutting down.

This change, in turn, ensures that attempts to remove a pending
connection that doesn't exist via RPC returns an error as expected.
2020-05-06 13:30:43 -05:00
Dave Collins
50fe5b7ad3
connmgr: Rework HTTPS seeding.
This reworks the HTTPS seeding in the connmgr package and server to make
it easier to use properly and to make use of a couple of the new
capabilities it offers.

The current implementation of the SeedAddrs function is basically a
carbon copy of the older DNS seeding function with some slight
modifications and, as a result, its API is geared more towards the older
functionality which is not the most ideal for the new functionality.

First, since the SeedAddrs function is synchronous, as opposed
to the older async DNS seeder version, an OnSeed callback adds
unnecessary complexity since the addresses can simply be returned from
the function instead.

Next, this existing function does not make it very clear how to use the
additional filtering parameters and it also always sets them in the
query string which unnecessarily imposes a specific implementation on
the seeding server.  More desirable behavior is to only set the specific
query parameters when the caller wishes to apply specific filters.

Finally, the code in the server that consumes the returned seeds
currently still contains a quirk that was required by the old DNS
seeding semantics which no longer apply where it attributes the source
of the addresses to the first returned address.

This addresses all of those issues and a couple of other minor nits.
The following is an overview of the changes:

- Modify the SeedAddrs func signature to return the addresses directly
  instead of using an OnSeed callback
- Introduce a new HttpsSeederFilters struct along with exported
  functions that allow the caller to selectively specify seed filters
- Modify the SeedAddrs func signature to accept a variable number of
  filters specified via the aforementioned functions
  - This allows only the specific filters the caller desires to be
    specified and is easily extensible to support more filters with no
    breaking API changes in the future should it be necessary
- Modify the implementation of the SeedAddrs func to only set the query
  params for the various filter options if the caller provided them
- Improve the logging to properly handle any invalid addresses returned
  from the seeder
- Improve the readability of the random time offset code in SeedAddrs
- Update the server code in accordance with the API changes
- Modify the server code that adds the discovered addresses to the
  address manager to look up the IP address of the HTTPS seeder and use
  that as the source address
  - Fall back to the first returned address in the extremely rare event
    the HTTPS seeder IP lookup fails
2020-05-04 22:10:59 -05:00
Dave Collins
ce2195fbc3
main: Update go.mod for recent rpcclient bumps.
This updates the main go.mod direct dependencies to account for the
recent rpcclient bumps as follows:

- github.com/decred/dcrd/dcrutil/v3@v3.0.0-20200503044000-76f6906e50e5
- github.com/decred/dcrd/rpc/jsonrpc/types/v2@v2.0.1-0.20200503044000-76f6906e50e5
- github.com/gorilla/websocket@v1.4.2
2020-05-04 21:47:38 -05:00
Dave Collins
984af9b0c9
connmgr: Rename TorLookupIPContext to TorLookupIP.
Now that the deprecated non-context version of TorLookupIP has been
removed, this renames the version that accepts a context to take its
place.
2020-05-04 21:34:01 -05:00
Dave Collins
7c02293c4f
connmgr: Add test for connect context cancel.
This adds a test to ensure the Connect method works as intended when
provided with a context that times out before a dial attempt succeeds.
2020-05-04 21:25:44 -05:00
Dave Collins
0f3ef4dec3
connmgr: Add test for dial timeout.
This adds a test to ensure the dial timeout configuration option works
as intended.
2020-05-04 21:25:41 -05:00
Dave Collins
26c088aee0
connmgr: Remove deprecated TorLookupIP func.
This removes the deprecated TorLookupIP function since the major version
has been bumped since the last release.
2020-05-04 14:50:14 -05:00
Dave Collins
fba0da4c1b
connmgr: Remove deprecated SeedFromDNS func.
This removes the deprecated SeedFromDNS function and associated
LookupFunc type since the major version has been bumped since the last
release.
2020-05-04 14:50:14 -05:00
Dave Collins
93060bdb8d
connmgr: Remove deprecated DisableLog func.
This removes the deprecated DisableLog function since the major version
has been bumped since the last release.
2020-05-04 14:50:10 -05:00
Dave Collins
9480b9aaf5
server: Remove unused interrupt chan param.
This removes the interrupt channel parameter from the newServer function
since it is no longer used due to the use of contexts instead.
2020-05-04 14:01:17 -05:00