New returns a BlockChain instance using the provided configuration details.

New is referenced in 2 repositories



		checkpointsByHeight = make(map[int32]*chaincfg.Checkpoint)
		for i := range params.Checkpoints {
			checkpoint := &params.Checkpoints[i]
			checkpointsByHeight[checkpoint.Height] = checkpoint

	targetTimespan := int64(params.TargetTimespan)
	targetTimePerBlock := int64(params.TargetTimePerBlock)
	adjustmentFactor := params.RetargetAdjustmentFactor
	b := BlockChain{
		checkpointsByHeight: checkpointsByHeight,
		db:                  config.DB,
		chainParams:         params,
		timeSource:          config.TimeSource,
		notifications:       config.Notifications,
		sigCache:            config.SigCache,
		indexManager:        config.IndexManager,
		minRetargetTimespan: targetTimespan / adjustmentFactor,
		maxRetargetTimespan: targetTimespan * adjustmentFactor,
		blocksPerRetarget:   int32(targetTimespan / targetTimePerBlock),
		minMemoryNodes:      int32(targetTimespan / targetTimePerBlock),
		bestNode:            nil,
		index:               make(map[chainhash.Hash]*blockNode),
		depNodes:            make(map[chainhash.Hash][]*blockNode),
		orphans:             make(map[chainhash.Hash]*orphanBlock),
		prevOrphans:         make(map[chainhash.Hash][]*orphanBlock),
		blockCache:          make(map[chainhash.Hash]*btcutil.Block),

	// Initialize the chain state from the passed database.  When the db
	// does not yet contain any chain state, both it and the chain state
	// will be initialized to contain only the genesis block.
	if err := b.initChainState(); err != nil {
		return nil, err

	// Initialize and catch up all of the currently active optional indexes
	// as needed.
	if config.IndexManager != nil {
		if err := config.IndexManager.Init(&b); err != nil {
			return nil, err

	log.Infof("Chain state (height %d, hash %v, totaltx %d, work %v)",
		b.bestNode.height, b.bestNode.hash, b.stateSnapshot.TotalTxns,

	return &b, nil