erigon-pulse/cl/pool/operation_pool.go
Giulio rebuffo 72ba18bd36
Beacon: Added basic operations pool (#8309)
Added operation pools for beacon chain. operations are the equivalent of
txs for eth2

Added operation pools for:

* Attester Slashings
* Proposer Slashings
* VoluntaryExits
* BLSExecutionToChange
* Postponed to later: Attestations (or maybe not)
2023-09-29 23:42:07 +02:00

36 lines
928 B
Go

package pool
import (
"github.com/ledgerwatch/erigon/cl/phase1/core/state/lru"
)
var operationsMultiplier = 20 // Cap the amount of cached element to max_operations_per_block * operations_multiplier
type OperationPool[K comparable, T any] struct {
pool *lru.Cache[K, T] // Map the Signature to the underlying object
}
func NewOperationPool[K comparable, T any](maxOperationsPerBlock int, matricName string) *OperationPool[K, T] {
pool, err := lru.New[K, T](matricName, maxOperationsPerBlock*operationsMultiplier)
if err != nil {
panic(err)
}
return &OperationPool[K, T]{pool: pool}
}
func (o *OperationPool[K, T]) Insert(k K, operation T) {
o.pool.Add(k, operation)
}
func (o *OperationPool[K, T]) DeleteIfExist(k K) (removed bool) {
return o.pool.Remove(k)
}
func (o *OperationPool[K, T]) Has(k K) (hash bool) {
return o.pool.Contains(k)
}
func (o *OperationPool[K, T]) Raw() []T {
return o.pool.Values()
}