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)
| 569 | // This method only rolls back the current block. The current header and current |
| 570 | // fast block are left intact. |
| 571 | func (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. |
| 586 | func (bc *BlockChain) Export(w io.Writer) error { |
no test coverage detected