Skip to content
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

notification: send notifications in blocks received on sync reset for… #2285

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions core/node/events/notifications_stream_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,6 @@ func (ts *TrackedNotificationStreamView) applyBlock(
miniblock *MiniblockInfo,
cfg *crypto.OnChainSettings,
) error {
if lastBlock := ts.view.LastBlock(); lastBlock != nil {
if miniblock.Ref.Num <= lastBlock.Ref.Num {
return nil
}
}

view, _, err := ts.view.copyAndApplyBlock(miniblock, cfg)
if err != nil {
return err
Expand All @@ -134,7 +128,10 @@ func (ts *TrackedNotificationStreamView) applyBlock(
return nil
}

func (ts *TrackedNotificationStreamView) addEvent(ctx context.Context, event *ParsedEvent) error {
func (ts *TrackedNotificationStreamView) addEvent(
ctx context.Context,
event *ParsedEvent,
) error {
if ts.view.minipool.events.Has(event.Hash) || event.Event.GetMiniblockHeader() != nil {
return nil
}
Expand Down Expand Up @@ -163,6 +160,18 @@ func (ts *TrackedNotificationStreamView) addEvent(ctx context.Context, event *Pa
return nil
}

return ts.SendEventNotification(ctx, event)
}

func (ts *TrackedNotificationStreamView) SendEventNotification(
ctx context.Context,
event *ParsedEvent,
) error {
view := ts.view
if view == nil {
return nil
}

// otherwise for each member that is a member of the stream, or for anyone that is mentioned
members, err := ts.view.GetChannelMembers()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/node/notifications/event_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ func (p *MessageToNotificationsProcessor) sendNotification(

subscriptionExpired, err := p.sendWebPushNotification(ctx, channelID, sub.Sub, event, webPayload)
if err == nil {
p.log.Debugw("Successfully sent web push notification",
p.log.Infow("Successfully sent web push notification",
"user", user,
"event", event.Hash,
"channelID", channelID,
Expand Down
1 change: 0 additions & 1 deletion core/node/notifications/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ func (n *MessageNotifications) SendWebPushNotification(
n.webPushSent.With(prometheus.Labels{"status": fmt.Sprintf("%d", res.StatusCode)}).Inc()

if res.StatusCode == http.StatusCreated {
logging.FromCtx(ctx).Infow("Web push notification sent", "event", eventHash)
return false, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func (s *StreamTrackerConnectGo) Run(
if reset {
trackedStream, err = events.NewNotificationsStreamTrackerFromStreamAndCookie(
syncCtx, streamID, onChainConfig, update.GetStream(), listener, userPreferences)

if err != nil {
syncCancel()
log.Errorw("Unable to instantiate tracked stream", "err", err)
Expand All @@ -276,11 +277,19 @@ func (s *StreamTrackerConnectGo) Run(
continue
}

justAllocated = false

for _, block := range update.GetStream().GetMiniblocks() {
if err := trackedStream.ApplyBlock(block, onChainConfig.Get()); err != nil {
log.Errorw("Unable to apply block", "stream", streamID, "err", err)
if !reset {
if err := trackedStream.ApplyBlock(block, onChainConfig.Get()); err != nil {
log.Debugw("Unable to apply block", "stream", streamID, "err", err)
}
}
if justAllocated {
// send notifications for all events in all blocks
for _, event := range block.GetEvents() {
if parsedEvent, err := events.ParseEvent(event); err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

@bas-vk, is there a bug here where memberships from the current block are applied before the events are sent instead of after?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah Austin is clarifying, nevermind

_ = trackedStream.SendEventNotification(syncCtx, parsedEvent)
}
}
}
}

Expand All @@ -290,6 +299,8 @@ func (s *StreamTrackerConnectGo) Run(
}
}

justAllocated = false

case protocol.SyncOp_SYNC_DOWN:
log.Debugw("Stream reported as down")
metrics.SyncDown.Inc()
Expand Down
Loading