[database] Improve protocol template lookup for prototype
Rather than blindingly selecting the first protocol template found, look for the first valid one.
Rather than blindingly selecting the first protocol template found, look for the first valid one.