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

[Malleability] Update herocache to use generics and implement BackData. #7151

Open
wants to merge 21 commits into
base: 6646-mempool-refactoring
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
483b10a
Changed heropool to work with generics
AndriiDiachuk Mar 5, 2025
4afef1c
Updated pool_test to work with generics
AndriiDiachuk Mar 5, 2025
932408b
Made Tracer, Pool and part of Cache as generics
AndriiDiachuk Mar 6, 2025
b8de6b9
Fixed backend_test by init HeroCache with generics, made more cache f…
AndriiDiachuk Mar 6, 2025
aba6016
Fixed part cache test
AndriiDiachuk Mar 6, 2025
ba53af4
Fixed rest of cache test
AndriiDiachuk Mar 7, 2025
c911b0b
Removed K from cache
AndriiDiachuk Mar 11, 2025
0f22c1a
Added invalidated field, cache now have only V and Identifier as key
AndriiDiachuk Mar 11, 2025
702c316
Fixed test check for nil and added also ckech for new flag invalidated
AndriiDiachuk Mar 11, 2025
66ac537
Renamed variables, added wasEjected, fixed cache tests
AndriiDiachuk Mar 12, 2025
d85947a
Merge branch '6646-mempool-refactoring' of github.com:onflow/flow-go …
AndriiDiachuk Mar 12, 2025
cae9371
Merge branch '6646-mempool-refactoring' of github.com:onflow/flow-go …
AndriiDiachuk Mar 14, 2025
34a6ad4
Using range instead of loop, using append instead of indexing
AndriiDiachuk Mar 17, 2025
f9e3058
applied suggestions for review
AndriiDiachuk Mar 17, 2025
b691317
Applied changes from review
AndriiDiachuk Mar 17, 2025
fa227a2
added documentation for returned values
AndriiDiachuk Mar 17, 2025
319cd52
checking wasEjected returned value in the tests of pool
AndriiDiachuk Mar 17, 2025
b444d67
Removed both Adjust methods
AndriiDiachuk Mar 17, 2025
2b0f4f9
Fixed distributor for heroCache
AndriiDiachuk Mar 17, 2025
a5315c3
fixed godoc
AndriiDiachuk Mar 18, 2025
e3d6b70
Returned Adjust methods back
AndriiDiachuk Mar 21, 2025
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: 8 additions & 15 deletions engine/common/follower/cache/distributor.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
package cache

import (
"github.com/onflow/flow-go/model/flow"
herocache "github.com/onflow/flow-go/module/mempool/herocache/backdata"
)

type OnEntityEjected func(ejectedEntity flow.Entity)
type OnEntityEjected[V any] func(ejectedEntity V)

// HeroCacheDistributor implements herocache.Tracer and allows subscribers to receive events
// for ejected entries from cache using herocache.Tracer API.
// This structure is NOT concurrency safe.
type HeroCacheDistributor struct {
consumers []OnEntityEjected
type HeroCacheDistributor[V any] struct {
consumers []OnEntityEjected[V]
}

var _ herocache.Tracer = (*HeroCacheDistributor)(nil)

func NewDistributor() *HeroCacheDistributor {
return &HeroCacheDistributor{}
func NewDistributor[V any]() *HeroCacheDistributor[V] {
return &HeroCacheDistributor[V]{}
}

// AddConsumer adds subscriber for entity ejected events.
// Is NOT concurrency safe.
func (d *HeroCacheDistributor) AddConsumer(consumer OnEntityEjected) {
func (d *HeroCacheDistributor[V]) AddConsumer(consumer OnEntityEjected[V]) {
d.consumers = append(d.consumers, consumer)
}

func (d *HeroCacheDistributor) EntityEjectionDueToEmergency(ejectedEntity flow.Entity) {
func (d *HeroCacheDistributor[V]) EntityEjectionDueToEmergency(ejectedEntity V) {
for _, consumer := range d.consumers {
consumer(ejectedEntity)
}
}

func (d *HeroCacheDistributor) EntityEjectionDueToFullCapacity(ejectedEntity flow.Entity) {
func (d *HeroCacheDistributor[V]) EntityEjectionDueToFullCapacity(ejectedEntity V) {
for _, consumer := range d.consumers {
consumer(ejectedEntity)
}
Expand Down
Loading