<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ack(self, connection, frame, transaction=None):
 """ Acknowledge receipt of a message. If the `transaction` parameter is non-null, the frame being ack'd will be queued so that it can be requeued if the transaction is rolled back. @param connection: The connection that is acknowledging the frame. @type connection: L{coilmq.server.StompConnection} @param frame: The frame being acknowledged. """

        self.log.debug("ACK %s for %s" % (frame, connection))

        if connection in self._pending:
            pending_frame = self._pending[connection]
            # Make sure that the frame being acknowledged matches
            # the expected frame
            if pending_frame.headers.get('message-id') != frame.headers.get('message-id'):
                self.log.warning(
                    "Got a ACK for unexpected message-id: %s" % frame.message_id)
                self.store.requeue(pending_frame.destination, pending_frame)
                # (The pending frame will be removed further down)

            if transaction is not None:
                self._transaction_frames[connection][
                    transaction].append(pending_frame)

            del self._pending[connection]
            self._send_backlog(connection)

        else:
            self.log.debug("No pending messages for %s" % connection)