code: func (bc *BlockChain) repair(head **types.Block) error {
  	for {
  		// Abort if we've rewound to a head block that does have associated state
  		if _, err := state.New((*head).Root(), bc.stateCache); err == nil {
  			log.Info("Rewound blockchain to past state", "number", (*head).Number(), "hash", (*head).Hash())
  			return nil
  		}
  		// Otherwise rewind one block and recheck state availability there
  		block := bc.GetBlock((*head).ParentHash(), (*head).NumberU64()-1)
  		if block == nil {
  			return fmt.Errorf("missing block %d [%x]", (*head).NumberU64()-1, (*head).ParentHash())
  		}
  		*head = block
  	}
  }
docs: // 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 header and current
  // fast block are left intact.