Add bitswap_v1_get method#183
Conversation
|
|
||
|
|
||
| **Return value**: String containing the requested data chunk, hexadecimal-encoded. Always starts with | ||
| `0x...`. |
There was a problem hiding this comment.
When the CID maps to an empty block we return 0x?
There was a problem hiding this comment.
Yes, but in practice it is not possible to store empty indexed transaction.
| **Parameters**: | ||
|
|
||
| - `cid`: CID of the data chunk requested serialized in a [string format](https://github.com/multiformats/cid/blob/edb1c5294ad2d8257812d7ded4941c3e0fafccf3/README.md#variant---stringified-form). | ||
| Only CIDv1 version in `base32` multibase encoding (string starting from `b...`) is supported. |
There was a problem hiding this comment.
Do we plan to extend these in the near future?
There was a problem hiding this comment.
This is the default string representation of a CID and CIDv1 is the latest default as well, so we are free to define this as a requirement here and support nothing else.
| @@ -0,0 +1,8 @@ | |||
| # Introduction | |||
|
|
|||
| The functions with `bitswap` prefix allow fetching data chunks from the storage given their CID, | |||
There was a problem hiding this comment.
Nit: I would add a tiny mention, "For the implementation details of the bitswap implementation see... url-link"
There was a problem hiding this comment.
Not sure what implementation to include (litep2p / substrate / smoldot?), plus the implementation may change / get moved to another place and get outdated.
| - [archive_v1_storage](api/archive_v1_storage.md) | ||
| - [archive_v1_storageDiff](api/archive_v1_storageDiff.md) | ||
| - [bitswap](api/bitswap.md) | ||
| - [bitswap_v1_get](api/bitswap_v1_get.md) |
There was a problem hiding this comment.
@dmitry-markin what about the stream version we discussed before?
There was a problem hiding this comment.
It will go as a separate PR. Going to open it when the streaming version is added to smoldot to be sure we don't miss anything important.
There was a problem hiding this comment.
Meanwhile, the RPC endpoint in the full node gained the priority, so I will implement it first before going back to streaming in smoldot.
| ``` | ||
|
|
||
| Please note again that only the `code` and corresponding error retry categories in the table above | ||
| are stable. Everything else is provided for debugging purposes only, subject to change, and must not |
There was a problem hiding this comment.
In this case we could simplify the retur error code and incldue all details into the serialized message? I think chainHead follows a similar impl
There was a problem hiding this comment.
I would go a JSON-RPC standard way of returning the data on success and using standard JSON-RPC error codes like -3602 for "invalid params" already familiar to web app developers.
There was a problem hiding this comment.
Edit: I see what you mean, yep it makes sense
| | -32602 | `InvalidParams` | Invalid/unsupported CID was passed. Must not retry | | ||
| | -32810 | `Fail` | Permanent failure for this request, e.g. data not found | | ||
| | -32811 | `FailRetry` | Transient failure, can retry immediately | | ||
| | -32812 | `FailRetryBackoff` | Transient failure, can retry with a delay | |
There was a problem hiding this comment.
Only -32602 code here is standard JSON-RPC error code, and for application-defined error codes we can use something simple like -1, -2, -3. Unless we reserve "easy" codes for some common json-rpc-interface-spec errors — then we need to use unique codes per method to be consistent.
There was a problem hiding this comment.
Also, according to JSON-RPC 2.0 spec, the messages for standard codes (like InvalidParams in our case) seem to be standard ("Invalid params"). smoldot hardcodes a message for invalid params to "Invalid method parameter(s)." Theoretically, we can replace the hardcoded message with a human-readable description of a specific error — then we won't need to introduce a separate field data.details for a human-readable message in this particular case.
E.g., we can use a custom message Invalid params: {error} and remove data.details field completely.
There was a problem hiding this comment.
"E.g., we can use a custom message Invalid params: {error} and remove data.details field completely."
Yep, lets only keep the code + message, then we can extend the message with all the other datails from data
There was a problem hiding this comment.
The design intiiatly showed the data variant:
{"code": -32812, "message": "No Bitswap peers connected", "data": {"variant": "NoPeers"}}
It could be simplified such that we place all details into the serialized message:
{"code": -32812, "message": "No Bitswap peers connected: No peers"}
There was a problem hiding this comment.
The data.variant actually makes sense, because it is suitable for structured logging in grafana etc. It is synonymous to message, not supplementing it.
But let's get rid of data.details completely and put the human-readable info into message for consistency of InvalidParams case with other cases.
lexnv
left a comment
There was a problem hiding this comment.
LGTM! Thanks @dmitry-markin for spec here 🙏
This PR standardizes
bitswap_v1_getRPC used to download data from Polkadot Bulletin Chain. Calling this method is equivalent to downloading the data from a full node via Bitswap protocol. Both light & full nodes must provide this endpoint.Follow-ups
bitswap_v1_streammethod for requesting streaming of multiple Bitswap chunks (multiple CIDs) will be introduced in a separate PR.CC @ERussel