Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

feat: implement @dcl/rpc#308

Merged
leanmendoza merged 83 commits into
mainfrom
feat/implement-@dcl-rpc
Jun 15, 2022
Merged

feat: implement @dcl/rpc#308
leanmendoza merged 83 commits into
mainfrom
feat/implement-@dcl-rpc

Conversation

@leanmendoza
Copy link
Copy Markdown
Contributor

@leanmendoza leanmendoza commented May 25, 2022

What?

decentraland/sdk#313
Replace the decentraland-rpc usage with @dcl/rpc in scenes.

Why?

decentraland-rpc doesn't support binary messages, an important feature to optimize the protocol and to implement the new ECS7.

How to test

It's possible to test in every environment, just add &kernel-branch=feat/implement-@dcl-rpc in the URL. The behavior should be the same as if the query parameter isn't added.

The overhead added (temporary) is:

  • JSON.stringify and JSON.parse in the events payload, the most case used is the position report and avatar scenes.
  • Each engine scene message was JSON-serialized, now it's JSON-serialized and then protocolbuffer-serialized. In other words, one layer of serialization is temporary added, so this can introduce some delays or make it heavier.

Some environment examples:

You have two paths in each environment, as a guest and with a wallet.

How the code was changed

@dcl/rpc host implementation

Path: packages/world

In the previous implementation, kernel fed the APIs with system.getAPIInstance(XXXX) getting the class implemented and modifying some variable members.

Now, the SceneWorker creates the context with all the data before starting the system. This context is passed in all service methods and it can be patched by accessing the SceneWorker object and modifying the rpcContext member.

Scene runtime implementation

Path: packages/scene-system
The SceneRuntime.ts was rewritten, now the scene runtime consumes event from the EngineAPI with a pushable channel, instead of native on-emit messages from the worker (decentraland-rpc really).

APIs

  • Path: packages/shared/apis
    The changed line counter is significant because of this.
  1. All APIs were transcribed to .proto as RPC services.
  2. All API calls were modified because the request and response data are only one object instead of multiple parameters, undefined responses or void responses, etc.
  3. To maintain the backward compatibility, most of the API-clients preserved the response and request data structure except EngineAPI (now the events are pushed to the channel, and this channel streamed)
    a. The event payloads now have JSON.stringify on the host-side and JSON.parse on the worker-side, this can introduce some delays
  4. SignedFetch is another modified API, the request object was trimmed to only method, body, and headers.

Known issues (X indicates that it's solved)

  • Delayed event receiving: sometimes it seems some events are enqueued and the delivery delays
  • When close the worker, the host throw the error that is expecting the ACK message:
    Screenshot_20220606_191024
  • Fix avatar tests
  • Fix circular dependency (With StatefulWorker)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 25, 2022

Test this pull request

Comment thread packages/shared/apis/EnvironmentAPI/server.ts Outdated
Comment thread packages/scene-system/sdk/NewSceneRuntime.ts Outdated
Comment thread packages/scene-system/stateful-scene/RendererStatefulActor.ts Outdated
Comment thread packages/scene-system/stateful-scene/RendererStatefulActor.ts Outdated
Comment thread packages/shared/apis/IEngineAPI.ts
Comment thread packages/shared/apis/client/EthereumController.ts
Comment thread packages/shared/apis/client/ParcelIdentity.ts
Comment thread packages/shared/apis/client/index.ts Outdated
Comment thread packages/shared/apis/host/EngineAPI.ts Outdated
Comment thread packages/shared/apis/host/Permissions.ts Outdated
Comment thread packages/shared/apis/host/PortableExperiences.ts Outdated
Comment thread packages/shared/apis/host/SignedFetch.ts
kuruk-mm
kuruk-mm previously approved these changes Jun 15, 2022
Copy link
Copy Markdown
Member

@kuruk-mm kuruk-mm left a comment

Choose a reason for hiding this comment

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

Great work! I tested it on Desktop and Web, and it's working smoothly! Congrats!

@leanmendoza leanmendoza merged commit 6af9c3b into main Jun 15, 2022
@leanmendoza leanmendoza deleted the feat/implement-@dcl-rpc branch June 15, 2022 20:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants