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

refactor(store): decouple waku store public api types from rpc types #1350

Merged
merged 1 commit into from
Nov 9, 2022

Conversation

LNSD
Copy link
Contributor

@LNSD LNSD commented Nov 7, 2022

The Waku Store protocol wire format will be reworked in the next release. To avoid having to refactor the whole codebase because the RPC types are used everywhere, decoupling the public-facing types from the internal implementation details is a good practice. This should apply to any public-facing API (e.g., c-bindings, REST, JSON-RPC, etc.).

  • Define a new set of types for the waku store and the message store API in the common module (common to the protocol handler and client)
  • Add the corresponding type mappings between the RPC and the API types
  • Add a wrapper for the Waku Store protocol results/errors
  • Remove RPC types exports. If needed, RPC types should be imported explicitly

@LNSD LNSD requested a review from rymnc November 7, 2022 17:38
@LNSD LNSD self-assigned this Nov 7, 2022
@LNSD LNSD changed the title refactor(queue_store): rename queue_store module and simplify api refactor(store): decouple waku store public api types from rpc types Nov 7, 2022
Comment on lines +67 to +104
HistoryErrorKind* {.pure.} = enum
UNKNOWN = uint32(000)
PEER_DIAL_FAILURE = uint32(200)
BAD_RESPONSE = uint32(300)
BAD_REQUEST = uint32(400)
SERVICE_UNAVAILABLE = uint32(503)

HistoryError* = object
case kind*: HistoryErrorKind
of PEER_DIAL_FAILURE:
address*: string
of BAD_RESPONSE, BAD_REQUEST:
cause*: string
else:
discard

HistoryResult* = Result[HistoryResponse, HistoryError]


proc parse*(T: type HistoryErrorKind, kind: uint32): T =
case kind:
of 000, 200, 300, 400, 503:
HistoryErrorKind(kind)
else:
HistoryErrorKind.UNKNOWN

proc `$`*(err: HistoryError): string =
case err.kind:
of HistoryErrorKind.PEER_DIAL_FAILURE:
"PEER_DIAL_FAILURE: " & err.address
of HistoryErrorKind.BAD_RESPONSE:
"BAD_RESPONSE: " & err.cause
of HistoryErrorKind.BAD_REQUEST:
"BAD_REQUEST: " & err.cause
of HistoryErrorKind.SERVICE_UNAVAILABLE:
"SERVICE_UNAVAILABLE"
of HistoryErrorKind.UNKNOWN:
"UNKNOWN"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rymnc This is, more or less, how I am envisioning error management in the nwaku codebase, in case we need to differentiate between error causes. Note the enum and the object variants type (this might remember you Rust's io:Error 🙂 )

Copy link
Contributor

Choose a reason for hiding this comment

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

very clean!!

@LNSD LNSD marked this pull request as draft November 7, 2022 21:09
@LNSD LNSD force-pushed the feat-store-decouple-types branch 2 times, most recently from 6d5995b to d4a2398 Compare November 8, 2022 16:14
@status-im-auto
Copy link
Collaborator

status-im-auto commented Nov 8, 2022

Jenkins Builds

Click to see older builds (8)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ d4a2398 #2 2022-11-08 16:28:23 ~13 min macos 📦bin
✔️ d4a2398 #2 2022-11-08 16:32:21 ~17 min linux 📦bin
✔️ 7e9e0d6 #3 2022-11-08 23:12:43 ~15 min linux 📦bin
✔️ 7e9e0d6 #3 2022-11-08 23:14:06 ~17 min macos 📦bin
✔️ 49299c8 #4 2022-11-09 09:10:24 ~15 min macos 📦bin
✔️ 49299c8 #4 2022-11-09 09:11:58 ~17 min linux 📦bin
✔️ 0bed6ce #5 2022-11-09 09:17:13 ~16 min macos 📦bin
✔️ 0bed6ce #5 2022-11-09 09:18:42 ~18 min linux 📦bin
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 517d4c5 #6 2022-11-09 09:28:27 ~15 min macos 📦bin
517d4c5 #6 2022-11-09 09:35:26 ~22 min linux 📄log
✔️ 517d4c5 #7 2022-11-09 10:34:42 ~22 min linux 📦bin
✔️ c36dbbb #8 2022-11-09 16:26:08 ~18 min linux 📦bin
✔️ c36dbbb #7 2022-11-09 17:01:52 ~54 min macos 📦bin

@LNSD LNSD marked this pull request as ready for review November 8, 2022 22:56
Copy link
Contributor

@rymnc rymnc left a comment

Choose a reason for hiding this comment

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

LGTM, minor nits!

tests/v2/test_waku_store.nim Show resolved Hide resolved
waku/v2/protocol/waku_store/client.nim Show resolved Hide resolved
waku/v2/protocol/waku_store/protocol.nim Outdated Show resolved Hide resolved
waku/v2/protocol/waku_store/protocol.nim Show resolved Hide resolved
@LNSD LNSD force-pushed the feat-store-decouple-types branch from 0bed6ce to 517d4c5 Compare November 9, 2022 09:12
@LNSD LNSD requested review from jm-clius and alrevuelta November 9, 2022 10:16
Copy link
Contributor

@jm-clius jm-clius left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@LNSD LNSD force-pushed the feat-store-decouple-types branch from 517d4c5 to c36dbbb Compare November 9, 2022 16:07
@LNSD LNSD merged commit b07cdb1 into master Nov 9, 2022
@LNSD LNSD deleted the feat-store-decouple-types branch November 9, 2022 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants