1bf713cb0a
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
31 lines
524 B
Go
31 lines
524 B
Go
package chain
|
|
|
|
import (
|
|
"github.com/filecoin-project/lotus/build"
|
|
lru "github.com/hashicorp/golang-lru"
|
|
"github.com/ipfs/go-cid"
|
|
)
|
|
|
|
type BadBlockCache struct {
|
|
badBlocks *lru.ARCCache
|
|
}
|
|
|
|
func NewBadBlockCache() *BadBlockCache {
|
|
cache, err := lru.NewARC(build.BadBlockCacheSize)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return &BadBlockCache{
|
|
badBlocks: cache,
|
|
}
|
|
}
|
|
|
|
func (bts *BadBlockCache) Add(c cid.Cid) {
|
|
bts.badBlocks.Add(c, nil)
|
|
}
|
|
|
|
func (bts *BadBlockCache) Has(c cid.Cid) bool {
|
|
return bts.badBlocks.Contains(c)
|
|
}
|