github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/alsp/cache.go (about) 1 package alsp 2 3 import ( 4 "github.com/onflow/flow-go/model/flow" 5 "github.com/onflow/flow-go/network/alsp/model" 6 ) 7 8 // SpamRecordCache is a cache of spam records for the ALSP module. 9 // It is used to keep track of the spam records of the nodes that have been reported for spamming. 10 type SpamRecordCache interface { 11 // Adjust applies the given adjust function to the spam record of the given origin id. 12 // Returns the Penalty value of the record after the adjustment. 13 // It returns an error if the adjustFunc returns an error or if the record does not exist. 14 // Assuming that adjust is always called when the record exists, the error is irrecoverable and indicates a bug. 15 AdjustWithInit(originId flow.Identifier, adjustFunc model.RecordAdjustFunc) (float64, error) 16 17 // Identities returns the list of identities of the nodes that have a spam record in the cache. 18 Identities() []flow.Identifier 19 20 // Remove removes the spam record of the given origin id from the cache. 21 // Returns true if the record is removed, false otherwise (i.e., the record does not exist). 22 Remove(originId flow.Identifier) bool 23 24 // Get returns the spam record of the given origin id. 25 // Returns the record and true if the record exists, nil and false otherwise. 26 // Args: 27 // - originId: the origin id of the spam record. 28 // Returns: 29 // - the record and true if the record exists, nil and false otherwise. 30 // Note that the returned record is a copy of the record in the cache (we do not want the caller to modify the record). 31 Get(originId flow.Identifier) (*model.ProtocolSpamRecord, bool) 32 33 // Size returns the number of records in the cache. 34 Size() uint 35 }