Skip to content

feat: add node rpc & subscription feature#911

Open
weigen393 wants to merge 2 commits into
mainfrom
774-jip-2-node-rpc-server
Open

feat: add node rpc & subscription feature#911
weigen393 wants to merge 2 commits into
mainfrom
774-jip-2-node-rpc-server

Conversation

@weigen393
Copy link
Copy Markdown
Contributor

No description provided.

@weigen393 weigen393 self-assigned this Mar 1, 2026
@weigen393 weigen393 added the feat new feature for the user, not a new feature for build script label Mar 1, 2026
@YCC3741 YCC3741 requested a review from yu2C March 1, 2026 13:08
}

type ServiceEvent struct {
ServiceID string `json:"service_id"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use number? u32

t.Fatalf("First subscribe request returned error: %v", resp1.Error)
}
subID1 = uint64(resp1.Result.(float64))
t.Logf("First subscription ID: %s", subID1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

%d

t.Fatalf("Second subscribe request returned error: %v", resp2.Error)
}
subID2 = uint64(resp2.Result.(float64))
t.Logf("Second subscription ID: %s", subID2)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

%d

Method: sub.MethodName,
Params: NotificationParams{
Subscription: sub.ID,
Result: result,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need error handling?

Comment thread cmd/node/main.go
SetupJAMProtocol(chainPath)

ctx, cancel := context.WithCancel(ctx)
defer cancel()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Blocker — RPC server lifecycle vs process exit

The RPC server is started in a goroutine with go func() { ... rpcServer.Start(ctx) }, while the main goroutine returns immediately after cancel() (triggered by signal) without waiting for the server goroutine to finish shutting down.

context.Cancel + http.Server.Shutdown (inside Start) is asynchronous with respect to the node() return. The process can exit while connections are still open or ListenAndServe / Shutdown is still in progress, leading to unclean termination and lost in-flight work.

Suggestion: use a sync.WaitGroup (or a dedicated done channel) so that after cancel() the main path waits until Start has returned (or until a bounded timeout), matching the 5s shutdown in Start.

Comment thread cmd/node/main.go

go func() {
chainState := blockchain.GetInstance()
eventBus := eventbus.NewEventBus()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Architecture — EventBus must be a shared process dependency

eventbus.NewEventBus() is created inside the RPC goroutine and only passed to NewRPCServer. The rest of the node (e.g. blockchain, sync, block import) has no way to Publish on the same bus, so real chain events cannot drive RPC subscribers without duplicating the bus or resorting to polling (e.g. ChainWatcher only).

Suggestion: construct a single EventBus (or EventPublisher / EventSubscriber interfaces) at the node composition root (node() or immediately after SetupJAMProtocol), and inject it into both the RPC server and any component that should emit JIP-2–relevant events, so Publish and Subscribe use the same instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat new feature for the user, not a new feature for build script

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants