-
Notifications
You must be signed in to change notification settings - Fork 42
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: storenode cycle #1223
base: master
Are you sure you want to change the base?
feat: storenode cycle #1223
Conversation
d9361e5
to
3988fc6
Compare
s.Lock() | ||
defer s.Unlock() | ||
|
||
for _, subs := range s.subscriptions { |
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.
This should be sub
.
m.host = h | ||
m.failedRequests = make(map[peer.ID]uint) | ||
m.peers = make(map[peer.ID]peerStatus) | ||
|
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 we connect the store node first with some strategy before actually verify the status?
} else { | ||
m.peers[m.activeStorenode] = peerStatus{ | ||
status: disconnected, | ||
canConnectAfter: time.Now().Add(backoffDuration), |
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.
Another strategy is have a blacklist of unreachable store nodes, and periodically check if the node should be kept in the list.
m.logger.Info("Automatically switching storenode") | ||
|
||
if m.activeStorenode != "" { | ||
m.disconnectActiveStorenode(graylistBackoff) |
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.
Wondering why this is needed and the intention of this graylistBackoff?
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.
Hm. Looking at the existing code in status-go, i believe it is so we dont connect again to this storenode for 3 minutes.
|
||
m.activeStorenode = peerID | ||
|
||
m.StorenodeChangedEmitter.Emit(m.activeStorenode) |
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 can't find the Subscriber of this emitter, do we still need it?
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.
waku/v2/api/history/cycle.go
Outdated
return peer.status | ||
} | ||
|
||
func (m *StorenodeCycle) connect(peerID peer.ID) 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.
How about rename it setActiveStoreNode
?
defer m.peersMutex.Unlock() | ||
pInfo, ok := m.peers[id] | ||
if !ok { | ||
pInfo.status = disconnected |
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.
This will panic if no peer id found in the map.
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.
pInfo
is not a pointer. Should be fine: https://go.dev/play/p/iCnMyu-hZpt
waku/v2/api/history/cycle.go
Outdated
} | ||
|
||
func (m *StorenodeCycle) verifyStorenodeStatus(ctx context.Context) { | ||
ticker := time.NewTicker(1 * time.Second) |
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.
This can be a constant.
m.logger.Info("trying performing history requests", zap.Uint("try", tries), zap.Stringer("peerID", peerID)) | ||
|
||
// Peform request | ||
err := fn() |
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 not familiar with this programming model, do see it in our codebase from time to time.
I'm thinking that will it be better if we use channels to communicate for the composing?
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.
Perhaps. I'd like to do this change in a separate PR if you agree!
b2d0226
to
b852a92
Compare
b852a92
to
f29ce5f
Compare
This PR contains the storenode cycle code from status-go.
I tried to simplify it a bit but most of the heavy refactoring should be done on a separate PR since this one is already complex enough.
@plopezlpz, @kaichaosun @igor-sirotin @chaitanyaprem:
I'm still working on the unit tests, but so far, while testing status-im/status-go#5857 with Desktop, it looks promising. Reviews are appreciated!