Skip to content

Commit

Permalink
cr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
timwu20 committed Jan 22, 2025
1 parent 24469bf commit 630534b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 48 deletions.
2 changes: 1 addition & 1 deletion internal/client/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func NewFinalityNotificationFromSummary[
Hash: hash,
Header: summary.Header,
TreeRoute: summary.Finalized,
StaleHeads: summary.StateHeads,
StaleHeads: summary.StaleHeads,
unpinHandle: NewUnpinHandle[H](hash, unpin),
}
}
89 changes: 46 additions & 43 deletions internal/client/api/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,62 +272,65 @@ func (r *registry[H]) trigger( //nolint:gocyclo

// Trigger the events
for subsID, sink := range r.sinks {
if _, ok := subscribers[subsID]; ok {
sink.wasTriggered = true
r.sinks[subsID] = sink
_, ok := subscribers[subsID]
if !ok {
continue
}

var (
filteredChanges []StorageChange
filteredChildChanges []StorageChildChange
)
sink.wasTriggered = true
r.sinks[subsID] = sink

if sink.keys != nil {
for _, change := range changes {
_, ok := sink.keys[string(change.StorageKey)]
if ok {
filteredChanges = append(filteredChanges, change)
}
var (
filteredChanges []StorageChange
filteredChildChanges []StorageChildChange
)

if sink.keys != nil {
for _, change := range changes {
_, ok := sink.keys[string(change.StorageKey)]
if ok {
filteredChanges = append(filteredChanges, change)
}
} else {
filteredChanges = changes
}
} else {
filteredChanges = changes
}

if sink.childKeys != nil {
for _, childChange := range childChanges {
filter, ok := sink.childKeys[string(childChange.StorageKey)]
if ok {
filteredChildChange := StorageChildChange{
StorageKey: childChange.StorageKey,
ChangeSet: nil,
}
for _, change := range childChange.ChangeSet {
if filter == nil {
if sink.childKeys != nil {
for _, childChange := range childChanges {
filter, ok := sink.childKeys[string(childChange.StorageKey)]
if ok {
filteredChildChange := StorageChildChange{
StorageKey: childChange.StorageKey,
ChangeSet: nil,
}
for _, change := range childChange.ChangeSet {
if filter == nil {
filteredChildChange.ChangeSet = append(filteredChildChange.ChangeSet, change)
} else {
_, ok := filter[string(change.StorageKey)]
if ok {
filteredChildChange.ChangeSet = append(filteredChildChange.ChangeSet, change)
} else {
_, ok := filter[string(change.StorageKey)]
if ok {
filteredChildChange.ChangeSet = append(filteredChildChange.ChangeSet, change)
}
}
}
filteredChildChanges = append(filteredChildChanges, filteredChildChange)
}
filteredChildChanges = append(filteredChildChanges, filteredChildChange)
}
}
}

storageChangeSet := StorageChangeSet{
Changes: filteredChanges,
ChildChanges: filteredChildChanges,
Filter: sink.keys,
ChildFilters: sink.childKeys,
}

notification := StorageNotification[H]{
Block: hash,
StorageChangeSet: storageChangeSet,
}
storageChangeSet := StorageChangeSet{
Changes: filteredChanges,
ChildChanges: filteredChildChanges,
Filter: sink.keys,
ChildFilters: sink.childKeys,
}

dispatch(subsID, notification)
notification := StorageNotification[H]{
Block: hash,
StorageChangeSet: storageChangeSet,
}

dispatch(subsID, notification)
}
}
8 changes: 4 additions & 4 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,20 +315,20 @@ func (c *Client[H, Hasher, N, E, Header]) notifyImported(
triggerStorageChangesNotification()
c.importNotificationChansMtx.Lock()
defer c.importNotificationChansMtx.Unlock()
notifyChans(*notification, c.importNotificationChans, notifyBlockImportTimout)
notifyChans(*notification, c.importNotificationChans, notifyBlockImportTimeout)

c.everyImportNotificationChansMtx.Lock()
defer c.everyImportNotificationChansMtx.Unlock()
notifyChans(*notification, c.everyImportNotificationChans, notifyBlockImportTimout)
notifyChans(*notification, c.everyImportNotificationChans, notifyBlockImportTimeout)
case api.RecentBlockImportNotificationAction:
triggerStorageChangesNotification()
c.importNotificationChansMtx.Lock()
defer c.importNotificationChansMtx.Unlock()
notifyChans(*notification, c.importNotificationChans, notifyBlockImportTimout)
notifyChans(*notification, c.importNotificationChans, notifyBlockImportTimeout)
case api.EveryBlockImportNotificationAction:
c.everyImportNotificationChansMtx.Lock()
defer c.everyImportNotificationChansMtx.Unlock()
notifyChans(*notification, c.everyImportNotificationChans, notifyBlockImportTimout)
notifyChans(*notification, c.everyImportNotificationChans, notifyBlockImportTimeout)
case api.NoneBlockImportNotificationAction:
// This branch is unreachable in fact because the block import notification must be
// not nil (it's already handled at the beginning of this function) at this point.
Expand Down

0 comments on commit 630534b

Please sign in to comment.