2019-10-09 08:50:57 +00:00
|
|
|
package chain
|
|
|
|
|
|
|
|
import (
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
2019-10-09 12:23:45 +00:00
|
|
|
lru "github.com/hashicorp/golang-lru"
|
2019-10-09 08:50:57 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
)
|
|
|
|
|
|
|
|
type BadBlockCache struct {
|
2019-10-09 12:23:45 +00:00
|
|
|
badBlocks *lru.ARCCache
|
2019-10-09 08:50:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewBadBlockCache() *BadBlockCache {
|
2019-10-09 12:55:27 +00:00
|
|
|
cache, err := lru.NewARC(build.BadBlockCacheSize)
|
2019-10-09 12:23:45 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2019-10-09 08:50:57 +00:00
|
|
|
return &BadBlockCache{
|
2019-10-09 12:23:45 +00:00
|
|
|
badBlocks: cache,
|
2019-10-09 08:50:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bts *BadBlockCache) Add(c cid.Cid) {
|
2019-10-09 12:23:45 +00:00
|
|
|
bts.badBlocks.Add(c, nil)
|
2019-10-09 08:50:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (bts *BadBlockCache) Has(c cid.Cid) bool {
|
2019-10-09 12:23:45 +00:00
|
|
|
return bts.badBlocks.Contains(c)
|
2019-10-09 08:50:57 +00:00
|
|
|
}
|