MCPcopy Create free account
hub / github.com/CPChain/chain / Rollback

Method Rollback

core/blockchain.go:894–916  ·  view source on GitHub ↗

Rollback is designed to remove a chain of links from the database that aren't certain enough to be valid.

(chain []common.Hash)

Source from the content-addressed store, hash-verified

892// Rollback is designed to remove a chain of links from the database that aren't
893// certain enough to be valid.
894func (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
919func SetReceiptsData(config *configs.ChainConfig, block *types.Block, receipts types.Receipts) error {

Callers

nothing calls this directly

Calls 12

GetHeaderMethod · 0.95
CurrentFastBlockMethod · 0.95
GetBlockMethod · 0.95
CurrentBlockMethod · 0.95
LockMethod · 0.80
UnlockMethod · 0.80
SetCurrentHeaderMethod · 0.80
Uint64Method · 0.80
ParentHashMethod · 0.80
NumberU64Method · 0.80
CurrentHeaderMethod · 0.65
HashMethod · 0.65

Tested by

no test coverage detected