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

Method ResetWithGenesisBlock

core/blockchain.go:544–563  ·  view source on GitHub ↗

ResetWithGenesisBlock purges the entire blockchain, restoring it to the specified genesis state.

(genesis *types.Block)

Source from the content-addressed store, hash-verified

542// ResetWithGenesisBlock purges the entire blockchain, restoring it to the
543// specified genesis state.
544func (bc *BlockChain) ResetWithGenesisBlock(genesis *types.Block) error {
545 // Dump the entire block chain and purge the caches
546 if err := bc.SetHead(0); err != nil {
547 return err
548 }
549 bc.mu.Lock()
550 defer bc.mu.Unlock()
551
552 // Prepare the genesis block and reinitialise the chain
553 rawdb.WriteBlock(bc.db, genesis)
554
555 bc.genesisBlock = genesis
556 bc.insert(bc.genesisBlock)
557 bc.currentBlock.Store(bc.genesisBlock)
558 bc.hc.SetGenesis(bc.genesisBlock.Header())
559 bc.hc.SetCurrentHeader(bc.genesisBlock.Header())
560 bc.currentFastBlock.Store(bc.genesisBlock)
561
562 return nil
563}
564
565// repair tries to repair the current blockchain by rolling back the current block
566// until one with associated state is found. This is needed to fix incomplete db

Callers 1

ResetMethod · 0.95

Calls 7

SetHeadMethod · 0.95
insertMethod · 0.95
LockMethod · 0.80
UnlockMethod · 0.80
SetGenesisMethod · 0.80
HeaderMethod · 0.80
SetCurrentHeaderMethod · 0.80

Tested by

no test coverage detected