code: func (h *headerIndex) addHeaders(batch headerBatch) error {
  	// If we're writing a 0-length batch, make no changes and return.
  	if len(batch) == 0 {
  		return nil
  	}
  
  	// In order to ensure optimal write performance, we'll ensure that the
  	// items are sorted by their hash before insertion into the database.
  	sort.Sort(batch)
  
  	return walletdb.Update(h.db, func(tx walletdb.ReadWriteTx) error {
  		rootBucket := tx.ReadWriteBucket(indexBucket)
  
  		var tipKey []byte
  
  		// Based on the specified index type of this instance of the
  		// index, we'll grab the key that tracks the tip of the chain
  		// so we can update the index once all the header entries have
  		// been updated.
  		// TODO(roasbeef): only need block tip?
  		switch h.indexType {
  		case Block:
  			tipKey = bitcoinTip
  		case RegularFilter:
  			tipKey = regFilterTip
  		default:
  			return fmt.Errorf("unknown index type: %v", h.indexType)
  		}
  
  		var (
  			chainTipHash   chainhash.Hash
  			chainTipHeight uint32
  		)
  
  		for _, header := range batch {
  			var heightBytes [4]byte
  			binary.BigEndian.PutUint32(heightBytes[:], header.height)
  			err := rootBucket.Put(header.hash[:], heightBytes[:])
  			if err != nil {
  				return err
  			}
  
  			// TODO(roasbeef): need to remedy if side-chain
  			// tracking added
  			if header.height >= chainTipHeight {
  				chainTipHash = header.hash
  				chainTipHeight = header.height
  			}
  		}
  
  		return rootBucket.Put(tipKey, chainTipHash[:])
  	})
  }
docs: // addHeaders writes a batch of header entries in a single atomic batch