Skip to content

Commit

Permalink
Joshua comments
Browse files Browse the repository at this point in the history
  • Loading branch information
marcopeereboom committed Jan 8, 2025
1 parent ca32e24 commit 9f05309
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 13 additions & 4 deletions database/tbcd/level/headercache.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,24 @@ func (l *lowIQMap) Get(k *chainhash.Hash) (*tbcd.BlockHeader, bool) {
}

func (l *lowIQMap) Purge(k *chainhash.Hash) {
l.mtx.RLock()
defer l.mtx.RUnlock()
l.mtx.Lock()
defer l.mtx.Unlock()

delete(l.m, *k)
}

func (l *lowIQMap) PurgeBatch(ks []*chainhash.Hash) {
l.mtx.Lock()
defer l.mtx.Unlock()

for v := range ks {
delete(l.m, *ks[v])
}
}

func lowIQMapNewCount(count int) (*lowIQMap, error) {
if count <= 0 {
return nil, fmt.Errorf("invalid count %v", count)
return nil, fmt.Errorf("invalid count: %v", count)
}
return &lowIQMap{
count: count,
Expand All @@ -73,7 +82,7 @@ func lowIQMapNewCount(count int) (*lowIQMap, error) {
// (~819200 items).
func lowIQMapNewSize(size int) (*lowIQMap, error) {
if size <= 0 {
return nil, fmt.Errorf("invalid size %v", size)
return nil, fmt.Errorf("invalid size: %v", size)
}
// approximate number of headers
return lowIQMapNewCount(size / blockHeaderSize)
Expand Down
1 change: 0 additions & 1 deletion database/tbcd/level/level.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ func New(ctx context.Context, cfg *Config) (*ldb, error) {
if cfg.blockheaderCacheSize > 0 {
l.headerCache, err = lowIQMapNewSize(cfg.blockheaderCacheSize)
if err != nil {
panic(spew.Sdump(cfg))
return nil, fmt.Errorf("couldn't setup block header cache: %w", err)
}
log.Infof("blockheader cache: %v",
Expand Down

0 comments on commit 9f05309

Please sign in to comment.