def METHOD_NAME(chain_name):
    """Ensure that any REJECT rules are last, and any LOG rules are second-to-last"""
    table = iptc.Table(iptc.Table.FILTER)
    with iptables_txn(table):
        rules = list_chain(chain_name)
        chain = iptc.Chain(table, chain_name)
        # sort the rules by rule_key, which uses (RULE_TARGET_SORT_ORDER, idx)
        sorted_rules_with_indices = sorted(enumerate(rules), key=_rule_sort_key)
        for new_index, (old_index, rule) in enumerate(sorted_rules_with_indices):
            if new_index == old_index:
                continue
            log.debug(f"reordering chain {chain_name} rule {rule} to #{new_index}")
            chain.replace_rule(rule.to_iptc(), new_index)