Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot delete blocks #24007

Closed
heliosVII-tech opened this issue Nov 28, 2021 · 3 comments
Closed

Cannot delete blocks #24007

heliosVII-tech opened this issue Nov 28, 2021 · 3 comments

Comments

@heliosVII-tech
Copy link

For a particular reason I want to delete blocks. But when I call rawdb.DeleteBlock it doesn't actually delete the old block. For example, the code below prints the same value for blockBefore and blockAfter (sans pointer differences). How do I actually delete blocks to save disk space?

func (bc *BlockChain) GetBlockByNumber(number uint64) *types.Block {
	hash := rawdb.ReadCanonicalHash(bc.db, number)
	if hash == (common.Hash{}) {
		return nil
	}

	if number == 1000 {
		blockBefore := bc.GetBlock(hash, number)

                 // clear from cache
		present := bc.blockCache.Remove(hash)
                 bc.blockCache.Purge()

                // try this way
		rawdb.DeleteBlock(bc.db, hash, number)

                // try using batches
		batch := bc.db.NewBatch()
		i := 0
		for _, hash := range rawdb.ReadAllHashes(bc.db, number) {
			i++
			rawdb.DeleteBlock(batch, hash, number)
		}
		if err := batch.Write(); err != nil {
			log.Error("Batch write got error", "err", err.Error())
		}

		blockAfter := bc.GetBlock(hash, number)
		log.Info("GetHeader", "number", number, "blockBefore", blockBefore, "blockAfter", blockAfter, "present", present, "i", i)
	}

	return bc.GetBlock(hash, number)
}

Is there something obvious missing here? I see that sidechains are deleted in a similar manner.

@s1na
Copy link
Contributor

s1na commented Nov 29, 2021

I'm guessing the block is somewhat old and hence stored in the freezer (not in leveldb). And right now freezer doesn't support deletion. But that feature is not far off: #23954

@karalabe
Copy link
Member

We don't support deleting blocks.

@maurodelazeri
Copy link

@karalabe I exported a range of blocks in an archive node with geth export and im trying to import this range in a read-only full node that I want to have this range of blocks with archive data... is this possible? while I import I get this message

INFO [12-05|02:35:21.235] Skipping batch as all blocks present batch=60 first=99299a..1a532a last=25ac15..f65ff1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants