<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def subdomain_try_insert(self, cursor, subdomain_rec, history_neighbors):
 """ Try to insert a subdomain record into its history neighbors. This is an optimization that handles the "usual" case. We can do this without having to rewrite this subdomain's past and future if (1) we can find a previously-accepted subdomain record, and (2) the transition from this subdomain record to a future subdomain record preserves its acceptance as True. In this case, the "far" past and "far" future are already consistent. Return True if we succeed in doing so. Return False if not. """

        blockchain_order = history_neighbors['prev'] + history_neighbors['cur'] + history_neighbors['fut']

        last_accepted = -1
        for i in range(0, len(blockchain_order)):
            if blockchain_order[i].accepted:
                last_accepted = i
                break

            if blockchain_order[i].n > subdomain_rec.n or (blockchain_order[i].n == subdomain_rec.n and blockchain_order[i].parent_zonefile_index > subdomain_rec.parent_zonefile_index):
                # can't cheaply insert this subdomain record,
                # since none of its immediate ancestors are accepted.
                log.debug("No immediate ancestors are accepted on {}".format(subdomain_rec))
                return False

        if last_accepted < 0:
            log.debug("No immediate ancestors or successors are accepted on {}".format(subdomain_rec))
            return False

        # one ancestor was accepted.
        # work from there.

        chain_tip_status = blockchain_order[-1].accepted

        dirty = []  # to be written
        for i in range(last_accepted+1, len(blockchain_order)):
            cur_accepted = blockchain_order[i].accepted
            new_accepted = self.check_subdomain_transition(blockchain_order[last_accepted], blockchain_order[i])
            if new_accepted != cur_accepted:
                blockchain_order[i].accepted = new_accepted
                log.debug("Changed from {} to {}: {}".format(cur_accepted, new_accepted, blockchain_order[i]))
                dirty.append(blockchain_order[i])

            if new_accepted:
                last_accepted = i

        if chain_tip_status != blockchain_order[-1].accepted and len(history_neighbors['fut']) > 0:
            # deeper reorg
            log.debug("Immediate history chain tip altered from {} to {}: {}".format(chain_tip_status, blockchain_order[-1].accepted, blockchain_order[-1]))
            return False

        # localized change.  Just commit the dirty entries
        for subrec in dirty:
            log.debug("Update to accepted={}: {}".format(subrec.accepted, subrec))
            self.subdomain_db.update_subdomain_entry(subrec, cur=cursor)

        return True