aboutsummaryrefslogtreecommitdiffstats
path: root/core/block_cache.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-04-04 22:33:12 +0800
committerobscuren <geffobscura@gmail.com>2015-04-04 22:33:12 +0800
commit29f120206e16f80176a0cb309162cc7f889be0b0 (patch)
tree500188b663719000ead9bde79a2d1493539d7de3 /core/block_cache.go
parent0d1a9ce64847775b19ab1f0bbb7b2cc7771e862a (diff)
downloadgo-tangerine-29f120206e16f80176a0cb309162cc7f889be0b0.tar.gz
go-tangerine-29f120206e16f80176a0cb309162cc7f889be0b0.tar.zst
go-tangerine-29f120206e16f80176a0cb309162cc7f889be0b0.zip
Added block cache delete method
Diffstat (limited to 'core/block_cache.go')
-rw-r--r--core/block_cache.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/core/block_cache.go b/core/block_cache.go
index ea39e78e8..768d3bf19 100644
--- a/core/block_cache.go
+++ b/core/block_cache.go
@@ -56,6 +56,23 @@ func (bc *BlockCache) Push(block *types.Block) {
bc.hashes[len(bc.hashes)-1] = hash
}
+func (bc *BlockCache) Delete(hash common.Hash) {
+ bc.mu.Lock()
+ defer bc.mu.Unlock()
+
+ if _, ok := bc.blocks[hash]; ok {
+ delete(bc.blocks, hash)
+ for i, h := range bc.hashes {
+ if hash == h {
+ bc.hashes = bc.hashes[:i+copy(bc.hashes[i:], bc.hashes[i+1:])]
+ // or ? => bc.hashes = append(bc.hashes[:i], bc.hashes[i+1]...)
+
+ break
+ }
+ }
+ }
+}
+
func (bc *BlockCache) Get(hash common.Hash) *types.Block {
bc.mu.RLock()
defer bc.mu.RUnlock()