code: function readNextSpendableMcIndex(conn, type, address, arrConflictingUnits, handleNextSpendableMcIndex){
  	conn.query(
  		"SELECT to_main_chain_index FROM inputs CROSS JOIN units USING(unit) \n\
  		WHERE type=? AND address=? AND sequence='good' "+(
  			(arrConflictingUnits && arrConflictingUnits.length > 0) 
  			? " AND unit NOT IN("+arrConflictingUnits.map(function(unit){ return db.escape(unit); }).join(", ")+") " 
  			: ""
  		)+" \n\
  		ORDER BY to_main_chain_index DESC LIMIT 1", 
  		[type, address],
  		function(rows){
  			var mci = (rows.length > 0) ? (rows[0].to_main_chain_index+1) : 0;
  		//	readNextUnspentMcIndex(conn, type, address, function(next_unspent_mci){
  		//		if (next_unspent_mci !== mci)
  		//			throw Error("next unspent mci !== next spendable mci: "+next_unspent_mci+" !== "+mci+", address "+address);
  				handleNextSpendableMcIndex(mci);
  		//	});
  		}
  	);
  }
docs: Functions for reading headers commissions and witnessing outputs. In all functions below, type=(headers_commission|witnessing)