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

Method repair

core/blockchain.go:571–583  ·  view source on GitHub ↗

repair tries to repair the current blockchain by rolling back the current block until one with associated state is found. This is needed to fix incomplete db writes caused either by crashes/power outages, or simply non-committed tries. This method only rolls back the current block. The current head

(head **types.Block)

Source from the content-addressed store, hash-verified

569// This method only rolls back the current block. The current header and current
570// fast block are left intact.
571func (bc *BlockChain) repair(head **types.Block) error {
572 for {
573 // Abort if we've rewound to a head block that does have associated state
574 if _, err := state.New((*head).StateRoot(), bc.stateCache); err == nil {
575 if _, err = state.New(GetPrivateStateRoot(bc.db, (*head).StateRoot()), bc.privateStateCache); err == nil {
576 log.Info("Rewound blockchain to past state", "number", (*head).Number(), "hash", (*head).Hash().Hex())
577 return nil
578 }
579 }
580 // Otherwise rewind one block and recheck state availability there
581 *head = bc.GetBlock((*head).ParentHash(), (*head).NumberU64()-1)
582 }
583}
584
585// Export writes the active chain to the given writer.
586func (bc *BlockChain) Export(w io.Writer) error {

Callers 1

loadLastStateMethod · 0.95

Calls 8

GetBlockMethod · 0.95
GetPrivateStateRootFunction · 0.85
StateRootMethod · 0.80
ParentHashMethod · 0.80
NumberU64Method · 0.80
InfoMethod · 0.65
HashMethod · 0.65
NumberMethod · 0.45

Tested by

no test coverage detected