Example #1
0
    def sendNomination(self, name: str, instId: int, viewNo: int,
                       lastOrderedSeqNo: int):
        """
        Broadcast a nomination message with the given parameters.

        :param name: node name
        :param instId: instance id
        :param viewNo: view number
        """
        self.send(Nomination(name, instId, viewNo, lastOrderedSeqNo))
def testBlacklistNodeOnMultipleNominations(looper, txnPoolNodeSet, ready):
    """
    A node that sends multiple nominations must be blacklisted by other nodes
    """
    A, B, C, D = txnPoolNodeSet

    # B sends more than 2 nominations
    for i in range(3):
        B.send(Nomination(D.name, 0, B.viewNo))

    # B should be blacklisted by A, C, D
    def chk():
        for node in A, C, D:
            assert node.isNodeBlacklisted(B.name)

    timeout = waits.expectedPoolNominationTimeout(len(txnPoolNodeSet))
    looper.run(eventually(chk, retryWait=1, timeout=timeout))
 def getElectionMsgsForInstance(self, instId: int) -> \
         Sequence[Union[Nomination, Primary]]:
     """
     Get nomination and primary messages for instance with id `instId`.
     """
     msgs = []
     replica = self.replicas[instId]
     # If a primary for this instance has been selected then send a
     # primary declaration for the selected primary
     if replica.isPrimary is not None:
         msgs.append(Primary(replica.primaryName, instId, self.viewNo,
                             replica.last_ordered_3pc[1]))
     else:
         # If a primary for this instance has not been selected then send
         # nomination and primary declaration that this node made for the
         # instance with id `instId`
         if self.didReplicaNominate(instId):
             nm, seqNo = self.nominations[instId][replica.name]
             msgs.append(Nomination(nm, instId, self.viewNo, seqNo))
         if self.didReplicaDeclarePrimary(instId):
             nm, seqNo = self.primaryDeclarations[instId][replica.name]
             msgs.append(Primary(nm, instId, self.viewNo, seqNo))
     return msgs
Example #4
0
def nominationByNode(name: str, byNode: TestNode, instId: int):
    return Nomination(name, instId, byNode.viewNo,
                      byNode.replicas[instId].lastOrderedPPSeqNo[1])