Iroha API for Clients
Status | IN PROGRESS |
|---|---|
Stakeholders | 武宮誠 Egor Ivkov Yuriy Vinogradov Vladislav Markushin |
Outcome |
|
Due date | Sep 11, 2020 |
Owner | Nikita Puzankov |
Background
Previous assumptions about Iroha Network and Web API in general were usage of iroha-client with encapsulation of underlying (plain TCP) protocols.
New needs from dependent projects require discussion of these assumptions and decision how to work with iroha network.
Iroha Bridge module provides an ability to connect different blockchains together and needs an ability to communicate between both sides via web interface.
Current Iroha approach is a proprietary TCP based protocol encapsulated inside `iroha_network` crate. `iroha_client` crate uses `iroha_network` inside and should be used itself by other applications including other blockchain solutions like `Polkadot`.
It turns out that `Substrate's` off chain workers provides only HTTP (more high level) API for communications with external resources (like Iroha Peer).
Requirements from Yuriy Vinogradov
HTTP compatible Iroha Peer API
HTTP client library for Instructions, Queries, Events
Rust client library (for Substrate's Off-chain workers)
JS Client library
Problem
Different clients environments have different restrictions - the strictest one is Substrate's Off-chain worker runtime which only supports HTTP 1.
Also DevOps team and Client side developers prefer to use JSON as a client-peer communication format. Some scenarios require to have an ability to combine Instructions API with Events API (send transaction and start consuming updates on it).
Solution
As a solution we propose this high-level design. HTTP and WebSocket protocols will be used for communication between Clients and Iroha Peers.
Iroha should provide HTTP API.
Endpoints:
Iroha Special Instructions
Iroha Queries
Iroha Events (under consideration - needed for Substrate)
MIME type of the HTTP API will be `application/json`
Clients build their own functionality or use 3rd party clients to establish HTTP connection, sign and construct transactions
JSON RPC or RESTfull approach should be discussed
Additionally Iroha should provide WebSocket API.
Endpoints:
Iroha Events
Iroha Special Instructions (under consideration - was requested by client-side developers)
Iroha Queries (under consideration - was requested by client-side developers)
JSON RPC can be used as high level protocol over WebSocket
Decisions
Iroha will provide HTTP and WebSocket API for clients
JSON format for messages encoding/decoding will be used
Alternatives
Stay with TCP and use middle ware for protocol and messages transformations - not user friendly
Use HTTP 2.0 - will not work with Substrate
Concerns
WebSocket connections should have configuration options to prevent bad performance of Iroha peers under high load
Assumptions
Bridge clients will use Substrate's Off-chain Workers with an ability to communicate over HTTP only
Risks
Performance regress `[8; 5]`
> Iroha Bridge has an additional application as a proxy on top of Iroha API (as a standalone app or service mesh)
I think the standalone app is not an Iroha approach. Might be implemented as a module on iorha2. We also can expect that some blockchains which use other protocols like Protobuf might be interested to connect iroha2, so the module approach seems someway better because it allows to add/exclude networking protocols.
> Iroha Bridge module provides HTTP wrapper on top of Iroha API (on the Peer side)
If the bridge will provide only bridging functions HTTP interface then another HTTP server might be needed if we will need to provide HTTP API for other functions. So the Iroha HTTP server is better to be decoupled from concrete functionality to have the ability to support all need functions for other possible cases.
So my vote is for the dedicated HTTP server module on Iorha2 not included in the core but has an ability to proxy all ISI and queries if needed.