bsc icon indicating copy to clipboard operation
bsc copied to clipboard

refactor: remove outdated prune-block/pruneancient tool, implement it by tail-deletion

Open galaio opened this issue 1 year ago • 3 comments

Description

This PR will remove prune-block/pruneancient tool, it can be replaced by tail-deletion, which is more easy & efficient for managing block history.

The PR will auto-detect the legacy offset metadata from db, and reset the tail metadata of freezer tables. So it's safe to run --history.blocks with the old pruneancient/prune-block feature.

Changes

Notable changes:

  • misc: remove outdated prune-block tools
  • chain: support new online prune block tool;
  • freezer: remove prunedfreezer;
  • freezer: support online prune by block history;

galaio avatar Dec 17 '24 09:12 galaio

validator which has used tool pruneBlock still can run their nodes?

NathanBSC avatar Dec 17 '24 10:12 NathanBSC

it would disable the prune-block tool, to avoid impacting the current users, better to be delivered in a separate maintenance release after Pascal hardfork.

zzzckck avatar Dec 19 '24 03:12 zzzckck

Good Job!

NathanBSC avatar Dec 30 '24 07:12 NathanBSC

Just FYI: https://github.com/bnb-chain/bsc/issues/2923

klim0v avatar Feb 27 '25 11:02 klim0v

I would like to ask one more question, we now have 3 flags (history.state, history.transactions, history.blocks) to clear historical data, what data do we still have that is not cleared and if so, is it possible to reduce that too?

klim0v avatar Mar 14 '25 12:03 klim0v

And I'd like to point out that we must avoid a situation where history.transactions > history.blocks. In such a case we will not be able to do indexTransactions/unindexTransactions, because there will be an error when getting the transaction hashes of the block. So TxIndexTail must be less than or equal to an existing block

https://github.com/bnb-chain/bsc/blob/87e622e51fab01204f6d57712f9d86192e7a9ac5/core/rawdb/chain_iterator.go#L150-L162

klim0v avatar Mar 14 '25 17:03 klim0v

I would like to ask one more question, we now have 3 flags (history.state, history.transactions, history.blocks) to clear historical data, what data do we still have that is not cleared and if so, is it possible to reduce that too?

Hi @klim0v , You can refer to the inspected data from 2024 bnbchain storage report. https://www.bnbchain.org/en/blog/bnb-smart-chain-annual-storage-report-2024 image

The most burden is state history, chain history, and Index data. These data has a way to prune now. There also has some proposal for live state expiry, but it's more difficult.

And if you have good suggestions, it's greate to create an issue/proposal or discuss it in forum/discord.

galaio avatar Mar 18 '25 03:03 galaio

And I'd like to point out that we must avoid a situation where history.transactions > history.blocks. In such a case we will not be able to do indexTransactions/unindexTransactions, because there will be an error when getting the transaction hashes of the block. So TxIndexTail must be less than or equal to an existing block

https://github.com/bnb-chain/bsc/blob/87e622e51fab01204f6d57712f9d86192e7a9ac5/core/rawdb/chain_iterator.go#L150-L162

Yeah, accepted, there is a corner case, when un-indexing & indexing again in node. Because the index and ancient data are saved in different ways, so they cannot generate or prune together. But it can be handled well to avoid bad behavior.

galaio avatar Mar 18 '25 03:03 galaio

The following tools will be removed after this PR:

./bsc snapshot prune-state --datadir <datadir> --triesInMemory <size>
./bsc snapshot prune-block --datadir <datadir> --datadir.ancient <ancientdir> --block-amount-reserved <reserveNum>

--pruneancient will be deprecated, it is replaced by --history.blocks 360000

zzzckck avatar Jul 01 '25 04:07 zzzckck