Browse Source

Add cache invalidation for reorg'd blocks

master
Aditya Kulkarni 5 years ago
parent
commit
8e6259b258
  1. 10
      common/cache.go

10
common/cache.go

@ -39,6 +39,16 @@ func (c *BlockCache) Add(height int, block *walletrpc.CompactBlock) error {
c.LastBlock = height - 1
}
// If we're adding a block in the middle of the cache, remove all
// blocks after it, since this might be a reorg, and we don't want
// Any outdated blocks returned
if height >= c.FirstBlock && height <= c.LastBlock {
for i := height; i <= c.LastBlock; i++ {
delete(c.m, i)
}
c.LastBlock = height - 1
}
// Don't allow out-of-order blocks. This is more of a sanity check than anything
// If there is a reorg, then the ingestor needs to handle it.
if c.m[height-1] != nil && !bytes.Equal(block.PrevHash, c.m[height-1].Hash) {

Loading…
Cancel
Save