Commit Graph

1065 Commits

Author SHA1 Message Date
M. J. Fromberger
af96ef2fe4 rpc: set a minimum long-polling interval for Events (#8050)
Since the goal of reading events at the head of the event log is to satisfy a
subscription style interface, there is no point in allowing head polling with
no wait interval. The pagination case already bypasses long polling, so the
extra option is unneessary.

Set a minimum default long-polling interval for the head case.
Add a test for minimum delay.
2022-03-02 08:12:18 -08:00
M. J. Fromberger
ab32f5a9b6 rpc/client: add eventstream helper (#7987)
This allows the caller to stream events. It handles the bookkeeping for cursors
and pagination, and delivers items to a callback.

Handle missed items by reporting a structured error. The caller can use the
Reset method to "catch up" to head after this happens.

Add a manual test CLI to probe a running node. Requires the node to be
configured with the event log settings.

Add a unit test that scripts input to the stream to exercise it.
2022-02-25 12:37:01 -08:00
M. J. Fromberger
f795d3f360 rpc/client: rewrite the WaitForOneEvent helper (#7986)
Update usage in tests.
2022-02-24 11:21:40 -08:00
M. J. Fromberger
211b80a484 rpc/client: add Events method to the client interface (#7982)
- Update documentation to deprecate the old methods.
- Add Events methods to HTTP, WS, and Local clients.
- Add Events method to the light client wrapper.
- Rename legacy events client to SubscriptionClient.
2022-02-24 06:51:14 -08:00
Sam Kleinman
62a1cb8d17 testing: reduce usage of the MustDefaultLogger constructor (#7960)
* testing: reduce usage of the MustDefualtLogger constructor

* Apply suggestions from code review

Co-authored-by: M. J. Fromberger <michael.j.fromberger@gmail.com>

* cleanup tests

Co-authored-by: M. J. Fromberger <michael.j.fromberger@gmail.com>
2022-02-24 02:43:11 +00:00
M. J. Fromberger
5662bd12a8 rpc: implement the ADR 075 /events method (#7965)
This method implements the eventlog extension interface to expose ABCI metadata
to the log for query processing. Only the types that have ABCI events need to
implement this.

- Add an event log to the environment
- Add a sketch of the handler method
- Add an /events RPCFunc to the route map
- Implement query logic
- Subscribe to pubsub if confingured, handle termination
2022-02-23 15:22:40 -08:00
Sam Kleinman
61a81279bd abci: make tendermint example+test clients manage a mutex (#7978)
This is the first step in removing the mutex from ABCI applications:
making our test applications hold mutexes, which this does, hopefully
with zero impact. If this lands well, then we can explore deleting the
other mutexes (in the ABCI server and the clients.) While this change
is not user impacting at all, removing the other mutexes *will* be. 

In persuit of this, I've changed the KV app somewhat, to put almost
all of the logic in the base application and make the persistent
application mostly be a wrapper on top of that with a different
storage layer.
2022-02-23 22:39:47 +00:00
M. J. Fromberger
80186a9d9c Update OpenAPI docs. (#7974)
* Update OpenAPI docs.

- Add an Events tag for event methods.
- Add schema entries for event request/response types.
- Clarify the documentation for broadcast methods.
- Note that websocket will be deprecated in v0.36.
2022-02-23 06:42:29 -08:00
Sam Kleinman
2ffb262600 context: cleaning up context dead ends (#7963) 2022-02-22 20:04:16 +00:00
Sam Kleinman
cc18f87000 mempool: use checktx sync calls (#7868) 2022-02-18 14:17:45 -05:00
Sergio Mena
d3548eb706 Completed the existing FinalizeBlock PR and rebased to master (#7798)
* Rebased and git-squashed the commits in PR #6546

migrate abci to finalizeBlock

work on abci, proxy and mempool

abciresponse, blok events, indexer, some tests

fix some tests

fix errors

fix errors in abci

fix tests amd errors

* Fixes after rebasing PR#6546

* Restored height to RequestFinalizeBlock & other

* Fixed more UTs

* Fixed kvstore

* More UT fixes

* last TC fixed

* make format

* Update internal/consensus/mempool_test.go

Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>

* Addressed @williambanfield's comments

* Fixed UTs

* Addressed last comments from @williambanfield

* make format

Co-authored-by: marbar3778 <marbar3778@yahoo.com>
Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>
2022-02-14 23:41:28 +01:00
M. J. Fromberger
7e09c2ef43 Clean up temp files more thoroughly after testing. (#7815)
Our test cases spew a lot of files and directories around $TMPDIR.  Make more
thorough use of the testing package's TempDir methods to ensure these are
cleaned up.

In a few cases, this required plumbing test contexts through existing helper
code. In a couple places an explicit path was required, to work around cases
where we do global setup during a TestMain function. Those cases probably
deserve more thorough cleansing (preferably with fire), but for now I have just
worked around it to keep focused on the cleanup.
2022-02-14 06:32:07 -08:00
M. J. Fromberger
01262b8ca9 rpc: remove unused latency metric (#7810)
We have this one solitary metric from the go-metrics package.  In principle
this statistic could be useful, but the way we have it hooked up, nothing can
observe the value: We don't export it, we don't log it, and it does not auto
publish anywhere.

Given that this state of affairs has not changed since the metric was first
added in 2017 (c08618f), I think we can safely discard it. No one is now or has
ever gotten any data out of this metric.
2022-02-11 13:19:56 -08:00
M. J. Fromberger
4ba5a053de rpc: allow GET parameters that support encoding.TextUnmarshaler (#7800)
Extend the decoding rules for URL query parameters so that if the target type
implements encoding.TextUnmarshaler, the decoder will use it.

This is a non-breaking change.
2022-02-10 18:32:18 -08:00
M. J. Fromberger
205bfca66f types: add string format to 64-bit integer JSON fields (#7787)
This picks up a few remaining cases that I missed during my previous round of
adding these tags.
2022-02-09 13:34:23 +00:00
M. J. Fromberger
ce61abc038 rpc: remove the placeholder RunState type. (#7749)
* rpc/client: remove the placeholder RunState type.

I added the RunState type in #6971 to disconnect clients from the service
plumbing, which they do not need. Now that we have more complete context
plumbing, the lifecycle of a client no longer depends on this type: It serves
as a carrier for a logger, and a Boolean flag for "running" status, neither of
which is used outside of tests.

Logging in particular is defaulted to a no-op logger in all production use.
Arguably we could just remove the logging calls, since they are never invoked
except in tests. To defer the question of whether we should do that or make the
logging go somewhere more productive, I've preserved the existing use here.

Remove use of the IsRunning method that was provided by the RunState, and use
the Start method and context to govern client lifecycle.

Remove the one test that exercised "unstarted" clients. I would like to remove
that method entirely, but that will require updating the constructors for all
the client types to plumb a context and possibly other options. I have deferred
that for now.
2022-02-02 12:02:04 -08:00
mconcat
d2afb91e99 ABCI Vote Extension 2 (#6885)
* add proto, add boilerplates

* add canonical

* fix tests

* add vote signing test

* Update internal/consensus/msgs_test.go

* modify state execution in progress

* add extension signing

* add extension signing

* VoteExtension -> ExtendVote

* modify state execution in progress

* add extension signing

* verify in progress

* modify CommitSig

* fix test

* apply review

* update data structures

* Apply suggestions from code review

* Add comments

* fix test

* VoteExtensionSigned => VoteExtensionToSigned

* Apply suggestions from code review

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>

* *Signed -> *ToSign

* add Vote to RequestExtendVote

* add example VoteExtension

* apply reviews

* fix vote

* Apply suggestions from code review

Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>

* fix typo, modify proto

* add abcipp_kvstore.go

* add extension test

* fix test

* fix test

* fix test

* fit lint

* uncomment test

* refactor test in progress

* gofmt

* apply review

* fix lint

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Dev Ojha <ValarDragon@users.noreply.github.com>
2022-02-02 11:51:13 +01:00
M. J. Fromberger
8a684c1bb5 rpc: fix layout of endpoint list (#7742)
* rpc: fix layout of endpoint list

The output of the default endpoint-list query was not correctly segregating
methods with and without arguments. Fix this, and also clean up the output to
be easier to read (both in code and in generated source).

Fixes #3618.
2022-01-31 14:52:38 -08:00
M. J. Fromberger
75b1b1d6c5 rpc: simplify the handling of JSON-RPC request and response IDs (#7738)
* rpc: simplify the handling of JSON-RPC request and response IDs

Replace the ID wrapper interface with plain JSON. Internally, the client
libraries use only integer IDs, and the server does not care about the ID
structure apart from checking its validity.

Basic structure of this change:

- Remove the jsonrpcid interface and its helpers.
- Unexport the ID field of request and response.
- Add helpers for constructing requests and responses.
- Fix up usage and tests.
2022-01-31 12:11:42 -08:00
M. J. Fromberger
95158636cd rpc: clean up unmarshaling of batch-valued responses (#7728)
Update the interface of the batch decoder to match the type signature of the
single-response case. The caller provides the outputs, so there is no need to
return them as well.

No functional changes.
2022-01-31 06:16:10 -08:00
M. J. Fromberger
fbe86ea645 rpc: simplify and consolidate response construction (#7725)
Responses are constructed from requests using MakeResponse, MakeError, and
MakeErrorf. This ensures the response is always paired with the correct ID,
makes cases where there is no ID more explicit at the usage site, and
consolidates the handling of error introspection across transports.

The logic for unpacking errors and assigning JSON-RPC response types was
previously duplicated in three places. Consolidate it in the types package for
the RPC subsystem.

* update test cases
2022-01-28 13:33:02 -08:00
M. J. Fromberger
20886fdb39 rpc: clean up encoding of request and response messages (#7721)
Instead of having the exported Request and Response type expose the version
directly, delegate version injection to an unexported shim.  We already had the
shim; this just boosts it to the top level and does a bit more checking.

* Check JSON-RPC version marker.
2022-01-28 11:41:23 -08:00
M. J. Fromberger
6f6935a44b rpc: don't route websocket-only methods on GET requests (#7715) 2022-01-27 14:52:41 -08:00
M. J. Fromberger
557d86316b rpc: clean up unused non-default websocket client options (#7713)
These are only ever used with the defaults, except in our own tests.  A search
of cs.github.com shows no other callers.

The use in the test was solely to bug out the go-metrics package so its
goroutines don't trigger the leak checker. Use the package's own flag for that
purpose instead. Note that calling "Stop" on the metric helps, but is not
sufficient -- the Stop does not wait for its goroutine to exit.
2022-01-27 11:49:08 -08:00
M. J. Fromberger
e87d40719d rpc: remove unused websocket options (#7712)
These options are never set to anything but the defaults, so drop the options
and inline the defaults.
2022-01-27 10:15:56 -08:00
William Banfield
bd8726c784 Use proposer timestamp instead of genesis time for height 1 block time (#7711)
Merged to pbts branch in #7541
2022-01-27 17:04:55 +00:00
mempirate
db3044ff3c rpc: add application info to status call (#7701)
* rpc/coretypes: add `ApplicationInfo` to `ResultStatus`
* internal/rpc/core: return application version

Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>
Co-authored-by: M. J. Fromberger <michael.j.fromberger@gmail.com>
2022-01-27 07:24:01 -08:00
M. J. Fromberger
441ecbaeec types: rename and extend the EventData interface (#7687)
This is the interface shared by types that can be used as event data in, for
example, subscriptions via the RPC.

To be compatible with the RPC service, data need to support JSON encoding.
Require this as part of the interface.
2022-01-26 07:01:55 -08:00
M. J. Fromberger
f9c6cc9306 rpc: use encoding/json rather than tmjson (#7670)
The main change here is to use encoding/json to encode and decode RPC 
parameters, rather than the custom tmjson package. This includes:

- Update the HTTP POST handler parameter handling.
- Add field tags to 64-bit integer types to get string encoding (to match amino/tmjson).
- Add marshalers to struct types that mention interfaces.
- Inject wrappers to decode interface arguments in RPC handlers.
2022-01-21 15:10:28 -08:00
Jasmina Malicevic
d68d25dcd5 light: return light client status on rpc /status (#7536)
*light: rpc /status returns status of light client ; code refactoring
 light: moved lightClientInfo into light.go, renamed String to ID
test/e2e: Return light client trusted height instead of SyncInfo trusted height
test/e2e/start.go: Not waiting for light client to catch up in tests. Removed querying of syncInfo in start if the node is a light node

* light: Removed call to primary /status. Added trustedPeriod to light info
* light/provider: added ID function to return IP of primary and witnesses
* light/provider/http/http_test: renamed String() to ID()
2022-01-20 14:53:20 +01:00
Sam Kleinman
4e5c2b5e8f consensus: use delivertxsync (#7616) 2022-01-19 16:58:12 -05:00
Sam Kleinman
b10c74647f testing: use noop loger with leakteset in more places (#7604) 2022-01-18 09:08:20 -05:00
Kene
49153b753c rpc: paginate mempool /unconfirmed_txs endpoint (#7612)
This commit changes the behaviour of the /unconfirmed_txs endpoint by replacing limit with a page and perPage parameter for pagination.
The test case for unconfirmed_txs have been accommodated to properly test this change and the documentation for the API as well.
2022-01-18 10:58:32 +01:00
M. J. Fromberger
dbe2146d0a rpc: simplify the encoding of interface-typed arguments in JSON (#7600)
Add package jsontypes that implements a subset of the custom libs/json 
package. Specifically it handles encoding and decoding of interface types
wrapped in "tagged" JSON objects. It omits the deep reflection on arbitrary
types, preserving only the handling of type tags wrapper encoding.

- Register interface types (Evidence, PubKey, PrivKey) for tagged encoding.
- Update the existing implementations to satisfy the type.
- Register those types with the jsontypes registry.
- Add string tags to 64-bit integer fields where needed.
- Add marshalers to structs that export interface-typed fields.
2022-01-14 18:14:09 -08:00
M. J. Fromberger
1ff69361e8 rpc: remove dependency of URL (GET) requests on tmjson (#7590)
The parameters for RPC GET requests are parsed from query arguments in the
request URL. Rework this code to remove the need for tmjson. The structure of a
call still requires reflection, and still works the same way as before, but the
code structure has been simplified and cleaned up a bit.

Points of note:

- Consolidate handling of pointer types, so we only need to dereference once.
- Reduce the number of allocations of reflective types.
- Report errors for unsupported types rather than returning untyped nil.

Update the tests as well. There was one test case that checked for an error on
a behaviour the OpenAPI docs explicitly demonstrates as supported, so I fixed
that test case, and also added some new ones for cases that weren't checked.

Related:

* Update e2e base Go image to 1.17 (to match config).
2022-01-14 07:53:53 -08:00
M. J. Fromberger
ec59b1a1ae rpc: check RPC service functions more carefully (#7587)
Require that RPC functions take a context as their first argument, and return
an error as either their only result, or the second of two results.

This does not change how functions are dispatched, but will make it a little
easier to make more invasive changes in the near future.
2022-01-13 13:27:45 -08:00
M. J. Fromberger
b7c19a5cd4 rpc: clean up the RPCFunc constructor signature (#7586)
Instead of taking a comma-separated string of parameter names, take each
parameter name as a separate argument. Now that we no longer have an extra flag
for caching, this fits nicely into a variadic trailer.

* Update all usage of NewRPCFunc and NewWSRPCFunc.
2022-01-13 12:13:28 -08:00
M. J. Fromberger
5a89263dbe rpc: simplify panic recovery in the server middleware (#7578)
Rather than installing two separate panic handlers, defer the bookkeeping
separately from recovery, and lift the delegated handler call out to the top
level of the wrapper.

Also: Regularize the server middleware wrappers.
2022-01-13 07:02:21 -08:00
M. J. Fromberger
904957aaa9 rpc: rework how responses are written back via HTTP (#7575)
Add writeRPCResponse and writeHTTPResponse helpers, that handle the way RPC
responses are written to HTTP replies. These replace the exported helpers.

Visible effects:

- JSON results are now marshaled without indentation.
- HTTP status codes are now normalized.
- Cache control headers are no longer set.

Details:

- When writing a response to a URL (GET) request, do not marshal the whole
  JSON-RPC object into the body, only encode the result or the error object.
  This is a user-visible change.

- Do not change the HTTP status code for RPC errors. The RPC error already
  reports what went wrong, the HTTP status should only report problems with the
  HTTP transaction itself. This is a user-visible change.

- Encode JSON without indentation in POST response bodies. This is mainly cosmetic
  but saves quite a bit of response data. Indent is still applied to GET responses to make
  life easier for code examples.

- Remove an obsolete TODO about reporting an HTTP error on websocket upgrade.
  Nothing needed to change; the upgrader already reports an error.

- Report an HTTP error when starting the server loop fails.

- Improve logging for encoding errors.

- Log less aggressively.
2022-01-12 17:25:58 -08:00
Sam Kleinman
2a348cc1e9 logging: remove reamining instances of SetLogger interface (#7572) 2022-01-12 16:56:49 -05:00
Sam Kleinman
e07c4cdcf2 node: collapse initialization internals (#7567) 2022-01-12 15:32:22 -05:00
M. J. Fromberger
5c1399d803 rpc: fix mock test cases (#7571)
In two cases, we check for the content of an error right after asserting that
no error occurs. Fix the sense of those checks.

In one case, we check that there is no error with the diagnostic "expected
error". It's not clear whether this means "an error was expected" (which is
what I believe) or "we got the expected error". However, given the way the mock
plumbing is set up, the first interpretation seems right.
2022-01-12 20:17:53 +00:00
M. J. Fromberger
1f5e64e5b6 rpc: remove cache control settings from the HTTP server (#7568)
We should not set cache-control headers on RPC responses. HTTP caching
interacts poorly with resources that are expected to change frequently, or
whose rate of change is unpredictable.

More subtly, all calls to the POST endpoint use the same URL, which means a
cacheable response from one call may actually "hide" an uncacheable response
from a subsequent one. This is less of a problem for the GET endpoints, but
that means the behaviour of RPCs varies depending on which HTTP method your
client happens to use. Websocket requests were already marked statically
uncacheable, adding yet a third combination.

To address this:

- Stop setting cache-control headers.
- Update the tests that were checking for those headers.
- Remove the flags to request cache-control.

Apart from affecting the HTTP response headers, this change does not modify the
behaviour of any of the RPC methods.
2022-01-12 18:20:59 +00:00
M. J. Fromberger
50ac52e28d rpc: replace custom context-like argument with context.Context (#7559)
* Rename rpctypes.Context to CallInfo.

Add methods to attach and recover this value from a context.Context.

* Rework RPC method handlers to accept "real" contexts.

- Replace *rpctypes.Context arguments with context.Context.
- Update usage of RPC context fields to use CallInfo.
2022-01-11 11:47:56 -08:00
M. J. Fromberger
a4d0a43100 rpc: refactor the HTTP POST handler (#7555)
No functional changes.

- Pull out a some helper code to simplify the control flow within the body of
  the HTTP request handler.

- Front-load the URL path check so it does not get repeated for each request.
2022-01-11 11:04:55 -08:00
Sam Kleinman
5bf1bdcfb4 reactors: skip log on some routine cancels (#7556) 2022-01-11 12:56:52 -05:00
M. J. Fromberger
7f8b75e1ee rpc: replace anonymous arguments with structured types (#7552)
Instead of using anonymous maps, define tagged struct types for JSON argument
encoding. This allows us to have the encoding rules we want without tmjson.

This commit handles the "easy" cases. BroadcastEvidence is omitted here,
because it depends on the interface encoding rules from tmjson. I will address
that in a forthcoming change.
2022-01-11 06:37:38 -08:00
M. J. Fromberger
6291d22f46 rpc: simplify the JSON-RPC client Caller interface (#7549)
* Update Caller interface and its documentation.
* Rework MapToRequest as ParamsToRequest.

The old interface returned the result as well as populating it.  Nothing was
using this, so drop the duplicated value from the return signature. Clarify the
documentation on the Caller type.

Rework the MapToRequest helper to take an arbitrary value instead of only a
map. This is groundwork for getting rid of the custom marshaling code. For now,
however, the implementation preserves the existing behaviour for the map, until
we can replace those.
2022-01-10 13:56:43 -08:00
M. J. Fromberger
8e58c564c0 rpc: collapse Caller and HTTPClient interfaces. (#7548)
These two interfaces are identical, and besides HTTPClient being confusingly
named, all but one location uses Caller. Update that one location, and drop the
redundant interface.
2022-01-10 11:52:52 -08:00
M. J. Fromberger
211d755aca rpc: remove positional parameter encoding from clients (#7545)
Apart from the tests for the websocket client, positional parameters are not
used by RPC clients. The server supports both arrays and objects, but the
client only needs to provide one or the other.
2022-01-10 11:20:30 -08:00