Get all ledger IDs for which
          A) not updated for more than Freshness Timeout
          B) hasn't been attempted to update (returned from this method) for more than Freshness Timeout
        Should be called whenever we need to decide if ledgers need to be updated.

        :param ts: the current time check the freshness against
        :return: an ordered dict of outdated ledgers sorted by the time from the last update (from oldest to newest)
         and then by ledger ID (in case of equal update time)

def check_freshness(self, ts):
        '''
        Get all ledger IDs for which
          A) not updated for more than Freshness Timeout
          B) hasn't been attempted to update (returned from this method) for more than Freshness Timeout
        Should be called whenever we need to decide if ledgers need to be updated.

        :param ts: the current time check the freshness against
        :return: an ordered dict of outdated ledgers sorted by the time from the last update (from oldest to newest)
         and then by ledger ID (in case of equal update time)
        '''
        outdated_ledgers = {}
        for ledger_id, freshness_state in self._ledger_freshness.items():
            if ts - freshness_state.last_updated <= self.freshness_timeout:
                continue
            if ts - freshness_state.last_marked_as_outdated <= self.freshness_timeout:
                continue

            outdated_ledgers[ledger_id] = ts - freshness_state.last_updated
            freshness_state.last_marked_as_outdated = ts

        # sort by last update time and then by ledger_id
        return OrderedDict(
            sorted(
                outdated_ledgers.items(),
                key=lambda item: (-item[1], item[0])
            )
        )