code: func (bi *blockIndex) flushToDB() error {
  	bi.Lock()
  	if len(bi.dirty) == 0 {
  		bi.Unlock()
  		return nil
  	}
  
  	err := bi.db.Update(func(dbTx database.Tx) error {
  		for node := range bi.dirty {
  			err := dbStoreBlockNode(dbTx, node)
  			if err != nil {
  				return err
  			}
  		}
  		return nil
  	})
  
  	// If write was successful, clear the dirty set.
  	if err == nil {
  		bi.dirty = make(map[*blockNode]struct{})
  	}
  
  	bi.Unlock()
  	return err
  }
docs: // flushToDB writes all dirty block nodes to the database. If all writes
  // succeed, this clears the dirty set.