Skip to content

Commit

Permalink
Don't generate acceptedTransactionIDs if they were not requested by a…
Browse files Browse the repository at this point in the history
…nyone
  • Loading branch information
svarogg committed May 3, 2022
1 parent 696e651 commit 5119172
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
15 changes: 13 additions & 2 deletions app/rpc/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,20 @@ func (m *Manager) notifyVirtualSelectedParentChainChanged(virtualChangeSet *exte
onEnd := logger.LogAndMeasureExecutionTime(log, "RPCManager.NotifyVirtualSelectedParentChainChanged")
defer onEnd()

if m.context.NotificationManager.DoesAnyListenerPropagateVirtualSelectedParentChainChanged() {
listenersThatPropagateSelectedParentChanged :=
m.context.NotificationManager.AllListenersThatPropagateVirtualSelectedParentChainChanged()
if len(listenersThatPropagateSelectedParentChanged) > 0 {
// Generating acceptedTransactionIDs is a heavy operation, so we check if it's needed by any listener.
includeAcceptedTransactionIDs := false
for _, listener := range listenersThatPropagateSelectedParentChanged {
if listener.IncludeAcceptedTransactionIDsInVirtualSelectedParentChainChangedNotifications() {
includeAcceptedTransactionIDs = true
break
}
}

notification, err := m.context.ConvertVirtualSelectedParentChainChangesToChainChangedNotificationMessage(
virtualChangeSet.VirtualSelectedParentChainChanges, true)
virtualChangeSet.VirtualSelectedParentChainChanges, includeAcceptedTransactionIDs)
if err != nil {
return err
}
Expand Down
15 changes: 11 additions & 4 deletions app/rpc/rpccontext/notificationmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,16 @@ func (nm *NotificationManager) NotifyVirtualSelectedParentChainChanged(
return nil
}

// DoesAnyListenerPropagateVirtualSelectedParentChainChanged returns true if there's any listener that is
// AllListenersThatPropagateVirtualSelectedParentChainChanged returns true if there's any listener that is
// subscribed to VirtualSelectedParentChainChanged notifications.
func (nm *NotificationManager) DoesAnyListenerPropagateVirtualSelectedParentChainChanged() bool {
func (nm *NotificationManager) AllListenersThatPropagateVirtualSelectedParentChainChanged() []*NotificationListener {
var listenersThatPropagate []*NotificationListener
for _, listener := range nm.listeners {
if listener.propagateVirtualSelectedParentChainChangedNotifications {
return true
listenersThatPropagate = append(listenersThatPropagate, listener)
}
}
return false
return listenersThatPropagate
}

// NotifyFinalityConflict notifies the notification manager that there's a finality conflict in the DAG
Expand Down Expand Up @@ -277,6 +278,12 @@ func newNotificationListener() *NotificationListener {
}
}

// IncludeAcceptedTransactionIDsInVirtualSelectedParentChainChangedNotifications returns true if this listener
// includes accepted transaction IDs in it's virtual-selected-parent-chain-changed notifications
func (nl *NotificationListener) IncludeAcceptedTransactionIDsInVirtualSelectedParentChainChangedNotifications() bool {
return nl.includeAcceptedTransactionIDsInVirtualSelectedParentChainChangedNotifications
}

// PropagateBlockAddedNotifications instructs the listener to send block added notifications
// to the remote listener
func (nl *NotificationListener) PropagateBlockAddedNotifications() {
Expand Down

0 comments on commit 5119172

Please sign in to comment.