Rollback is designed to remove a chain of links from the database that aren't certain enough to be valid.
(chain []common.Hash)
| 892 | // Rollback is designed to remove a chain of links from the database that aren't |
| 893 | // certain enough to be valid. |
| 894 | func (bc *BlockChain) Rollback(chain []common.Hash) { |
| 895 | bc.mu.Lock() |
| 896 | defer bc.mu.Unlock() |
| 897 | |
| 898 | for i := len(chain) - 1; i >= 0; i-- { |
| 899 | hash := chain[i] |
| 900 | |
| 901 | currentHeader := bc.hc.CurrentHeader() |
| 902 | if currentHeader.Hash() == hash { |
| 903 | bc.hc.SetCurrentHeader(bc.GetHeader(currentHeader.ParentHash, currentHeader.Number.Uint64()-1)) |
| 904 | } |
| 905 | if currentFastBlock := bc.CurrentFastBlock(); currentFastBlock.Hash() == hash { |
| 906 | newFastBlock := bc.GetBlock(currentFastBlock.ParentHash(), currentFastBlock.NumberU64()-1) |
| 907 | bc.currentFastBlock.Store(newFastBlock) |
| 908 | rawdb.WriteHeadFastBlockHash(bc.db, newFastBlock.Hash()) |
| 909 | } |
| 910 | if currentBlock := bc.CurrentBlock(); currentBlock.Hash() == hash { |
| 911 | newBlock := bc.GetBlock(currentBlock.ParentHash(), currentBlock.NumberU64()-1) |
| 912 | bc.currentBlock.Store(newBlock) |
| 913 | rawdb.WriteHeadBlockHash(bc.db, newBlock.Hash()) |
| 914 | } |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | // SetReceiptsData computes all the non-consensus fields of the receipts |
| 919 | func SetReceiptsData(config *configs.ChainConfig, block *types.Block, receipts types.Receipts) error { |
nothing calls this directly
no test coverage detected