Currently all HTTP JSON API are served at port 30003, but this is not optimal. It’s beneficial from both architecture and security’s perspective to separate necessary and optional APIs and serve them using different ports, such that miners can choose to enable or disable the optional API.
The first step towards this goal is to define what is necessary
API that should be enabled by EVERY NKN node. The principles in my opinion are:
- Every NKN node should be able to serve as a seed node for other NKN
node
to join - Every NKN node should be able to serve as a seed node for other NKN
client
to find the designated NKN node that should be connected with the client - Every NKN node should be able to be the designated NKN node for a NKN
client
and transmit data for it - (optional) Every NKN node should be able to serve as a seed node for other NKN
wallet
to get necessary information (e.g. get nonce, get balance, get pk/address by name) and send transactions
Among the above principles, 1 and 2 help to achieve better decentralization, robustness and security; 3 is necessary for routing to worker properly. But we may need some discussion about whether we should try to achieve 4.
Next step is to list APIs to achieve each principle above.
To achieve 1 (node join), we need:
- get my ip address
- get id by public key
- get successor by id (optional)
To achieve 2 (client join), we need:
- get predecessor by id (get websocket address)
To achieve 3 (transmit data for client), we need:
- get subscribers by topic
- get public key by name
To achieve 4 (wallet), we need:
- get balance by address
- get nonce by address
- get address by name
- send transactions
Let’s call these APIs by class 1-4 for convenience.
For class 1, using http is easiest.
For class 2, using http is easiest, and we can also use websocket if really necessary. And it’s better to use https/wss for browser compatibility.
For class 3, using websocket or http should both work, although use http is a little bit easier since it’s naturally request-response model. It’s also better to use https/wss for browser compatibility.
For class 4, using http is the only option since there is no other transport layer between wallet and node yet. It’s also better to use https for browser compatibility.
All the rest APIs should use separate port so miners can choose to enable or disable them without affecting the functions of the network.