pokt-network / poktroll

The official Shannon upgrade implementation of the Pocket Network Protocol implemented using the Cosmos SDK
MIT License
15 stars 8 forks source link

[Proxy] Support middleware & factor out non-proxy concerns #160

Open bryanchriswhite opened 10 months ago

bryanchriswhite commented 10 months ago

Objective

Add a degree of freedom for proxy consumers to configure middleware functions which the proxy will call at appropriate stages in the request/response pipeline.

Origin Document

Currently, RelayServer implementations, which are responsible for the request/response pipeline, don't expose any control over the shape of or flow through it. I.e., a validation stage (function) is applied before the relay is serviced and a signing stage (function) is applied after servicing the relay but before returning the response. While the implementation of these functions may lie outside of the RelayServer implementation, it is still explicitly aware of which of them is called at what stage, with no opportunity for (re)configuration.

If we add a "middleare" concept to the RelayServer which provides sufficient hooks into significant stages of the request/response pipeline we would reduce RelayServers awareness of an unrelated concern; instead of "validate here" and "sign here", it becomes "run this [current stage]'s middleware".

We should consider whether it's necessary and/or appropriate to make the RelayerProxy aware of middleware as well. I could imagine use cases for both relayer-wide as well as RelayServer-specific middleware)

Goals

Stage Description
Pre-service Immediately after a relay request is received from an application and before taking any other action. (E.g.: relay, session, application accounting, etc. validation.)
Pre-response After servicing the relay and hydrating the response and immediately before sending the response back to the application. (E.g.: response validation and signing)

Deliverables

Non-goals / Non-deliverables

General deliverables


Creator: @bryanchriswhite Co-Owners: @red-0ne

Olshansk commented 10 months ago

@bryanchriswhite I like the initative of this refactor. I moved it into our TECHDEBT iteration but lmk if you think it should be tended to sooner.

Two additional thoughts/comments:

  1. Thought on naming this RelayerMiddleware under /pkg/relayer/middleware
  2. Once this is done, we'll need to add a requirement/delvierable to explicitly document that middleware is where gateways can add their own custom (e.g. quality-of-service) plugins
Olshansk commented 7 months ago

@red-0ne to review in iteration 9 and sync with @bryanchriswhite to decide if this is necessary or not.