-
Notifications
You must be signed in to change notification settings - Fork 192
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
feat(torii): subscribe to token updates (metadata etc.) #2990
base: main
Are you sure you want to change the base?
Conversation
WalkthroughOhayo, sensei! This PR extends token-related functionality in the gRPC service. It adds a new Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant WorldService
participant Service
participant TokenManager
Client->>WorldService: SubscribeTokens(RetrieveTokensRequest)
WorldService->>Service: Create Subscription
Service->>TokenManager: add_subscriber(contract_addresses)
TokenManager-->>Service: Confirm Registration
loop Token Update
TokenManager-->>Service: Notify Token Update
Service->>Client: Stream SubscribeTokensResponse
end
Possibly related PRs
Suggested reviewers
Tip 🌐 Web search-backed reviews and chat
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
crates/torii/grpc/src/server/subscriptions/token.rs (4)
34-59
: Ohayo sensei! Consider using a globally unique subscription ID generator.Storing subscription IDs generated with a random u64 may risk collisions over a large number of subscriptions. Using a time-based or atomic counter-based ID might reduce the already small probability of collisions.
60-60
: Ohayo sensei! Fix Rust formatting to pass CI.The CI pipeline indicates code formatting issues on lines 60, 98, and 135. Please run Rust’s built-in formatter (
cargo fmt
) to comply with the project formatting guidelines.Also applies to: 98-98, 135-135
🧰 Tools
🪛 GitHub Actions: ci
[warning] 60-60: Code formatting issues detected. Please adhere to the Rust formatting guidelines.
111-120
: Ohayo sensei! Consider graceful shutdown forpublish_updates
.When shutting down, the infinite loop in
publish_updates
may continue receiving from the channel until it empties or indefinitely if no complete signal is sent. You could add a cancellation mechanism or a select statement that also listens for a shutdown request to ensure a clean exit.
122-162
: Ohayo sensei! Confirm the performance ofprocess_balance_update
under high load.Looping over all subscribers in
process_balance_update
may become costly if there are many subscribers. Consider using a more scalable data structure or partitioning subscriptions by contract address to avoid iterating the entire map.🧰 Tools
🪛 GitHub Actions: ci
[warning] 135-135: Code formatting issues detected. Please adhere to the Rust formatting guidelines.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
crates/torii/grpc/proto/types.proto
(1 hunks)crates/torii/grpc/proto/world.proto
(2 hunks)crates/torii/grpc/src/server/mod.rs
(3 hunks)crates/torii/grpc/src/server/subscriptions/mod.rs
(1 hunks)crates/torii/grpc/src/server/subscriptions/token.rs
(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- crates/torii/grpc/src/server/subscriptions/mod.rs
🧰 Additional context used
🪛 GitHub Actions: ci
crates/torii/grpc/src/server/subscriptions/token.rs
[warning] 60-60: Code formatting issues detected. Please adhere to the Rust formatting guidelines.
[warning] 98-98: Code formatting issues detected. Please adhere to the Rust formatting guidelines.
[warning] 135-135: Code formatting issues detected. Please adhere to the Rust formatting guidelines.
crates/torii/grpc/src/server/mod.rs
[warning] 56-56: Code formatting issues detected. Please adhere to the Rust formatting guidelines.
[warning] 1256-1256: Code formatting issues detected. Please adhere to the Rust formatting guidelines.
🔇 Additional comments (6)
crates/torii/grpc/src/server/subscriptions/token.rs (1)
91-110
: Ohayo sensei! Verify concurrency in theService::new
method.Spawning a new task to run
publish_updates
might lead to potential race conditions if other tasks modify shared states unexpectedly. Ensure that the references tosubs_manager
remain valid for the duration of the spawned task, and confirm that the manager’s concurrency design is robust (e.g. no risk of partial updates or deadlocks).🧰 Tools
🪛 GitHub Actions: ci
[warning] 98-98: Code formatting issues detected. Please adhere to the Rust formatting guidelines.
crates/torii/grpc/src/server/mod.rs (2)
59-59
: Ohayo sensei! Great job consolidating these imports.All relevant
proto::world
entities are neatly grouped. This improves readability and maintainability.
1246-1247
: Ohayo sensei! Confirm consistent naming for token subscription streams.The introduction of
SubscribeTokensResponseStream
and aliasing it withSubscribeTokensStream
is appropriate. Just ensure a consistent naming convention throughout the codebase so it’s easy to locate references.Also applies to: 1258-1259
crates/torii/grpc/proto/types.proto (1)
165-165
: Ohayo sensei! Validate the usage oftoken_id
in upstream logic.Adding this field is helpful to distinguish tokens, but ensure that instrumentation code and any references to
Token
in logic or tests properly handletoken_id
so we don’t accidentally break backward compatibility.crates/torii/grpc/proto/world.proto (2)
43-45
: Ohayo sensei: New RPC method for token updates!The addition of the
SubscribeTokens
RPC method correctly follows the structure of existing subscription RPCs. This new method enhances the service's token handling capability by providing a stream of token updates. Please ensure that client documentation and integration tests are updated accordingly to include this new branch of functionality.
91-95
: Ohayo sensei: Clean and clear SubscribeTokensResponse message!The new
SubscribeTokensResponse
message neatly encapsulates atypes.Token
, aligning well with the new RPC. Do verify that theToken
message in the importedtypes.proto
includes thetoken_id
field as per the overarching PR objectives, to guarantee that token updates carry the correct metadata.
Summary by CodeRabbit