-
Notifications
You must be signed in to change notification settings - Fork 129
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
dot/rpc implement state_subscribeStorage RPC WebSocket method #983
Conversation
I see that code climate is complaining, let me know if you want me to refactor. |
dot/rpc/modules/state.go
Outdated
// TODO implement change storage trie so that block hash parameter works (See issue #834) | ||
// SubscribeStorage Storage subscription. If storage keys are specified, it creates a message for each block which | ||
// changes the specified storage keys. If none are specified, then it creates a message for every block. | ||
// This endpoint communicates over the Websockt protocol, but this func should remain here so it's added to rpc_methods list |
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.
*websocket
// SubscribeStorage Storage subscription. If storage keys are specified, it creates a message for each block which | ||
// changes the specified storage keys. If none are specified, then it creates a message for every block. | ||
// This endpoint communicates over the Websockt protocol, but this func should remain here so it's added to rpc_methods list | ||
func (sm *StateModule) SubscribeStorage(r *http.Request, req *StateStorageQueryRangeRequest, res *StorageChangeSetResponse) error { |
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.
I'm also wondering, is there an unsubscribe method corresponding to the subscribe methods? if so, it would be nice to return the subscription ID
dot/rpc/websocket.go
Outdated
wss := &WebSocketSubscription{ | ||
WSConnection: conn, | ||
SubscriptionType: subscriptionType, | ||
Filter: filter, | ||
} | ||
wssub[sub] = wss | ||
h.serverConfig.WSSubscriptions = wssub |
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.
the WSSubscriptions should be stored in the HTTPServer struct (or in a separate wsServer struct) not in the config
dot/rpc/websocket.go
Outdated
if change != nil { | ||
for i, sub := range h.serverConfig.WSSubscriptions { | ||
if sub.SubscriptionType == SUB_STORAGE { | ||
// check it change key is in subscription filter |
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.
check if*
dot/state/storage.go
Outdated
Key: key, | ||
Value: value, | ||
} | ||
//fmt.Printf("SetStorage Key: %x Value: %x\n", key, value) |
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.
remove?
dot/state/storage.go
Outdated
Value: value, | ||
} | ||
//fmt.Printf("SetStorage Key: %x Value: %x\n", key, value) | ||
// TODO ed add channel notify here |
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.
is this done?
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.
should also be added to ClearStorage
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.
Yes
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.
overall looking good, a few comments!
dot/rpc/websocket.go
Outdated
for change := range h.storageChan { | ||
|
||
if change != nil { | ||
for i, sub := range h.serverConfig.WSSubscriptions { |
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.
I'm wondering if it would be simpler to start a goroutine for each subscription, what do you think?
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.
Yes, I've refactor websockets to better handle this.
I've updated this, it's ready for another look. Let me know your thoughts. |
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.
great work! i have a few smaller comments but overall looks good :)
dot/rpc/http.go
Outdated
type WSConn struct { | ||
wsconn *websocket.Conn | ||
mu sync.Mutex | ||
serverConfig *HTTPServerConfig |
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.
does this need the whole server config? or just the state interfaces?
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.
No just BlockAPI and StorageAPI, I've updated.
dot/rpc/http.go
Outdated
wsconn *websocket.Conn | ||
mu sync.Mutex | ||
serverConfig *HTTPServerConfig | ||
logger log.Logger |
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.
might be nice to make the logger global to the rpc package
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.
good idea.
dot/rpc/websocket.go
Outdated
// Listen implementation of Listen interface to listen for channel changes | ||
func (l *StorageChangeListener) Listen() { | ||
for change := range l.channel { | ||
if change != nil { |
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.
nitpick but it might be nice to do
if change == nil {
continue
}
// check if change key ....
same for below
Changes
Tests
OR connect a websocket client to node and send request:
Checklist
Issues