31 lines
530 B
Go
31 lines
530 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) // ok
|
|
}
|
|
|
|
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)
|
|
}
|