code: func openDB(dbPath string, network wire.BitcoinNet, create bool) (database.DB, error) {
  	// Error if the database doesn't exist and the create flag is not set.
  	metadataDbPath := filepath.Join(dbPath, metadataDbName)
  	dbExists := fileExists(metadataDbPath)
  	if !create && !dbExists {
  		str := fmt.Sprintf("database %q does not exist", metadataDbPath)
  		return nil, makeDbErr(database.ErrDbDoesNotExist, str, nil)
  	}
  
  	// Ensure the full path to the database exists.
  	if !dbExists {
  		// The error can be ignored here since the call to
  		// leveldb.OpenFile will fail if the directory couldn't be
  		// created.
  		_ = os.MkdirAll(dbPath, 0700)
  	}
  
  	// Open the metadata database (will create it if needed).
  	opts := opt.Options{
  		ErrorIfExist: create,
  		Strict:       opt.DefaultStrict,
  		Compression:  opt.NoCompression,
  		Filter:       filter.NewBloomFilter(10),
  	}
  	ldb, err := leveldb.OpenFile(metadataDbPath, &opts)
  	if err != nil {
  		return nil, convertErr(err.Error(), err)
  	}
  
  	// Create the block store which includes scanning the existing flat
  	// block files to find what the current write cursor position is
  	// according to the data that is actually on disk.  Also create the
  	// database cache which wraps the underlying leveldb database to provide
  	// write caching.
  	store := newBlockStore(dbPath, network)
  	cache := newDbCache(ldb, store, defaultCacheSize, defaultFlushSecs)
  	pdb := &db{store: store, cache: cache}
  
  	// Perform any reconciliation needed between the block and metadata as
  	// well as database initialization, if needed.
  	return reconcileDB(pdb, create)
  }
docs: // openDB opens the database at the provided path.  database.ErrDbDoesNotExist
  // is returned if the database doesn't exist and the create flag is not set.