Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test for OpenRPC subscription methods on trace/debug modules #356

Conversation

ziogaschr
Copy link
Member

Resolves #345 (comment)

@ziogaschr ziogaschr requested a review from meowsbits April 12, 2021 11:32
@ziogaschr ziogaschr changed the title Merge/foundation release/1.10.1 resolved state diff openrpc Test for OpenRPC subscription methods on trace/debug modules Apr 12, 2021
@meowsbits
Copy link
Contributor

meowsbits commented Apr 12, 2021

Thanks for getting this going!
Have you tried generating docs with this and see if they are as expected? I haven't yet, but have a feeling there's going to be a mismatch; please correct me if I'm wrong.

Pub/Sub is not handled well automatically by the reflector; it's a "special" case for the way ethereum/go-ethereum does (or does not) do method reflection and mapping.

For example, eth_subscribe("newHeads") uses the method SubscribeNewHeads (or is it NewHeads? can't remember exactly); does trace_filter work the same (or use (api *TraceAPI) Filter(...))?

The current hack-around for eth_subscribe's weirdness is the RPCSubscription mocks in node/openrpc.go, where the subscription's basically-enum values (eg. newHeads, newSideHeads, newPendingTransactions...) are provided in hardcode as type-mappings (see rpcSubscriptionParamsNameD).

I think we may need to either provide a similar kind of mock pattern for debug_ and trace_ modules (as you have started), or get a little fancier with additional conditions to the catch-all pub/sub skip logic.

TL;DR: I don't think debug_subscribe and trace_subscribe exist.

	        // Exclude methods that handle subscriptions, but do so without adhering to the conventional code pattern.
		// Eg. *filters.PublicFiltersAPI.SubscribeNewHeads handles eth_subscribe("newHeads"), but there
		// isn't a method called `eth_subscribeNewHeads`. So we blacklist all these methods and use
		// the mock subscription receiver type RPCSubscription.
		// This pattern matches all strings that start with Subscribe and are suffixed with a non-zero
		// number of A-z characters.
		if isPubSub(method.Type) {
			// This catches MOST of them (except SubscribeSyncStatus)
			return false
		}

@ziogaschr
Copy link
Member Author

No I haven't generated the docs. I will.
I think I see what you mean now. Will have a look myself and I will ping you.

Thanks man

Base automatically changed from merge/foundation-release/1.10.1-resolved-stateDiff to merge/foundation-release/1.10.1-resolved April 13, 2021 13:23
@@ -329,7 +369,8 @@ var blockNumberOrHashD = fmt.Sprintf(`{
]
}`, blockNumberD, commonHashD, requireCanonicalD)

var rpcSubscriptionParamsNameD = `{
var rpcEthSubscriptionParamsNameD = `{
"title": "subscriptionName",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meowsbits added this, as it wasn't working for params without it even for eth_subscribe.

@@ -208,25 +210,59 @@ func newOpenRPCDocument() *go_openrpc_reflect.Document {
}

/*
The following struct RPCSubscription and RPCSubscription.Unsubscribe method
The following structs *RPCSubscription and *RPCSubscription.Unsubscribe method
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@meowsbits I want to play a bit in order to find a better way of merging those 3 duplicated implementations where only the subscriptionName type in subscribe changes.

Let me know if you have an idea.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you experimented at all with getting rid of or modifying the general "skip PubSub" case to be more permissive (even if only allowing debug and trace receivers through)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I haven't. I will give it a try. Thanks

Copy link
Member Author

@ziogaschr ziogaschr Apr 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried it here, which adds the trace_filter nicely, although it cancan't be used in the way documented, which leads to issues. What do you think? Did you mean something else @meowsbits?

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

X-linking: #364 (review)

node/openrpc.go Outdated
var rpcDebugSubscriptionParamsNameD = `{
"title": "subscriptionName",
"oneOf": [
{"type": "string", "enum": ["traceFilter"], "description": "Returns traces for the filtered transactions within a range of blocks."}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have to collect all the debug_* subscription based methods

@ziogaschr
Copy link
Member Author

Generated docs sample

image

@ziogaschr
Copy link
Member Author

@meowsbits I added generating docs for both *_subscribe, but also more accurate logs for the subscriptionable methods like trace_filter (in this case, I change the examples section).

  1. I still need to fix the examples...
  2. I am thinking if it makes sense in this case to add a new field per method Subscription: bool

@meowsbits
Copy link
Contributor

meowsbits commented Apr 27, 2021

Per this comment at OpenRPC/spec we could potentially use x-subscription: true (or similar) as a specification extension on the method annotations.

@ziogaschr
Copy link
Member Author

@meowsbits can you review it? To see what's done, check the trace_subscribe and trace_filter in trace.md file.

p.s.: At the moment I haven't enabled the same for the eth package, but we can do that there too. For example documenting the eth_newHeads.

Per this comment at OpenRPC/spec we could potentially use x-subscription: true (or similar) as a specification extension on the method annotations.

This is a great addon, but not straightforward to implement. As discussed, let's keep this for later.

Adapts the canonical list of methods that
should be provided by the document to meet
what the document says.

Date: 2021-04-30 06:13:54-05:00
Signed-off-by: meows <b5c6@protonmail.com>
Copy link
Contributor

@meowsbits meowsbits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this latest commit (ce80270) looks OK to you, everything LGTM!

(I've left the methods commented because that lists serves a duty both as a test case, but also as a "behind-the-scenes" developer reference.)

@ziogaschr ziogaschr merged commit 695c0a2 into merge/foundation-release/1.10.1-resolved May 4, 2021
@ziogaschr ziogaschr deleted the merge/foundation-release/1.10.1-resolved-stateDiff-openrpc branch May 4, 2021 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants