                           peer-reactions)]
     (vector new-replica unapplied)))
 
-(defn apply-peer-queue-entry [{:keys [replica message-id entries peer-choices log]} next-peer] 
+(defn apply-peer-queue-entry 
+  "Applies the next log message in the selected peer's queue.
+  Effectively, the next peer that wrote its message to ZK"
+  [{:keys [replica message-id entries peer-choices log]} next-peer] 
   (let [peer-queue (entries next-peer)
         next-entry (first peer-queue)
         new-peer-queue (vec (rest peer-queue))

     :log (conj log message)
     :peer-choices (conj peer-choices next-peer)}))

(defn peer-gen [replica-state-gen]
  (gen/bind replica-state-gen 
            (fn [state]
              ; we only play back log messages from peers who have

(def messaging 
  (component/start (aeron/aeron {:opts peer-config})))

(defn bump-forward-immediates 
  "If peer hasn't finished joining yet, bump all their 
  log entries to the head of their queue. Order is otherwise stable."
  [entries peers peer-id]
  (if ((set peers) peer-id)
    entries
    (vec (concat (filter :immediate? entries)
                 (remove :immediate? entries)))))

(defn active-peers [replica entry]
  (cond-> (set (concat (:peers replica)
                       ; might not need these with the below entries
                       (vals (or (:prepared replica) {})) 
                       (vals (or (:accepted replica) {}))))
    (:id (:args entry)) (conj (:id (:args entry)))
    (:joiner (:args entry)) (conj (:joiner (:args entry)))))

(defn apply-entry [replica entries entry]
  (let [new-replica (extensions/apply-log-entry entry replica)
        diff (extensions/replica-diff entry replica new-replica)
        peers (active-peers replica entry)
        peer-reactions (keep (fn [peer-id] 
                               (if-let [reactions (extensions/reactions entry 
                                                                        replica 
