def msg_prepare_adopted(self, conn, msg):
        """MSG_PREPARE_ADOPTED is handled only if it belongs to an outstanding MSG_PREPARE,
        otherwise it is discarded.
        When MSG_PREPARE_ADOPTED is received, the corresponding ResponseCollector is retrieved
        and its state is updated accordingly.

        State Updates:
        - message is added to the received dictionary
        - the pvalue with the ResponseCollector's commandnumber is added to the possiblepvalueset
        - if naccepts is greater than the quorum size PREPARE STAGE is successful.
        -- Start the PROPOSE STAGE:
        --- create the pvalueset with highest ballotnumbers for distinctive commandnumbers
        --- update own proposals dictionary according to pmax dictionary
        --- remove the old ResponseCollector from the outstanding prepare set
        --- run the PROPOSE STAGE for each pvalue in proposals dictionary
        ---- create ResponseCollector object for PROPOSE STAGE: ResponseCollector keeps
        the state related to MSG_PROPOSE
        ---- add the new ResponseCollector to the outstanding propose set
        ---- create MSG_PROPOSE: message carries the corresponding ballotnumber, commandnumber and the proposal
        ---- send MSG_PROPOSE to the same Replica nodes from the PREPARE STAGE
        """
        if msg.inresponseto in self.outstandingprepares:
            prc = self.outstandingprepares[msg.inresponseto]
            prc.receivedcount += 1
            prc.receivedfrom.add(conn.peerid)
            if self.debug: self.logger.write("Paxos State",
                                             "got an accept for ballotno %s "\
                                             "commandno %s proposal %s with %d/%d"\
                                             % (prc.ballotnumber, prc.commandnumber, prc.proposal,
                                                prc.receivedcount, prc.ntotal))
            assert msg.ballotnumber == prc.ballotnumber, "[%s] MSG_PREPARE_ADOPTED cannot have non-matching ballotnumber" % self
            # add all the p-values from the response to the possiblepvalueset
            if msg.pvalueset is not None:
                prc.possiblepvalueset.union(msg.pvalueset)

            if prc.receivedcount >= prc.nquorum:
                if self.debug: self.logger.write("Paxos State", "suffiently many accepts on prepare!")
                # take this response collector out of the outstanding prepare set
                del self.outstandingprepares[msg.inresponseto]
                # choose pvalues with distinctive commandnumbers and highest ballotnumbers
                pmaxset = prc.possiblepvalueset.pmax()
                for commandnumber,proposal in pmaxset.iteritems():
                    self.add_to_proposals(commandnumber, proposal)
                # If the commandnumber we were planning to use is overwritten
                # we should try proposing with a new commandnumber
                if self.proposals[prc.commandnumber] != prc.proposal:
                    self.pick_commandnumber_add_to_pending(prc.proposal)
                    self.issue_pending_commands()
                for chosencommandnumber,chosenproposal in self.proposals.iteritems():
                    # send proposals for every outstanding proposal that is collected
                    if self.debug: self.logger.write("Paxos State", "Sending PROPOSE for %d, %s"
                                                     % (chosencommandnumber, chosenproposal))
                    newprc = ResponseCollector(prc.quorum, prc.ballotnumber,
                                               chosencommandnumber, chosenproposal)
                    self.outstandingproposes[chosencommandnumber] = newprc
                    propose = create_message(MSG_PROPOSE, self.me,
                                             {FLD_BALLOTNUMBER: prc.ballotnumber,
                                              FLD_COMMANDNUMBER: chosencommandnumber,
                                              FLD_PROPOSAL: chosenproposal,
                                              FLD_SERVERBATCH: isinstance(chosenproposal,
                                                                          ProposalServerBatch)})
                    self.send(propose, group=newprc.quorum)
                # As leader collected all proposals its state is up-to-date
                # and it is done initializing
                self.leader_initializing = False
                self.stateuptodate = True
                # become active
                self.active = True
dataset/ETHPy150Open denizalti/concoord/concoord/replica.py/Replica.msg_prepare_adopted/original