コード例 #1
0
 def poolTxnReceived(self, msg: PoolLedgerTxns, frm):
     logger.debug("{} received pool txn {} from {}".format(self, msg, frm))
     txn = getattr(msg, t)
     seqNo = txn.pop(F.seqNo.name)
     if seqNo not in self.tempNodeTxns:
         self.tempNodeTxns[seqNo] = {}
     self.tempNodeTxns[seqNo][frm] = txn
     # If this is the next sequence number that should go into ledger, then
     # check if there are enough same transactions from different nodes
     if (seqNo - self.ledger.size) == 1:
         f = getMaxFailures(len(self.nodeReg))
         if len(self.tempNodeTxns[seqNo]) > f:
             # TODO: Shouldnt this use `checkIfMoreThanFSameItems`
             txns = [
                 item for item, count in collections.Counter([
                     json.dumps(t, sort_keys=True)
                     for t in self.tempNodeTxns[seqNo].values()
                 ]).items() if count > f
             ]
             if len(txns) > 0:
                 txn = json.loads(txns[0])
                 self.addToLedger(txn)
                 if self.config.UpdateGenesisPoolTxnFile:
                     # Adding sequence number field since needed for safely
                     # updating genesis file
                     txn[F.seqNo.name] = len(self.ledger)
                     updateGenesisPoolTxnFile(
                         self.config.baseDir,
                         self.config.poolTransactionsFile, txn)
                 self.tempNodeTxns.pop(seqNo)
             else:
                 logger.error("{} has not got enough similar node "
                              "transactions".format(self))
コード例 #2
0
ファイル: pool_manager.py プロジェクト: loxadim/plenum
    def onPoolMembershipChange(self, txn):
        if txn[TXN_TYPE] == NODE:
            nodeName = txn[DATA][ALIAS]
            nodeNym = txn[TARGET_NYM]

            def _updateNode(txn):
                if {NODE_IP, NODE_PORT, CLIENT_IP, CLIENT_PORT}. \
                        intersection(set(txn[DATA].keys())):
                    self.nodeHaChanged(txn)
                if VERKEY in txn:
                    self.nodeKeysChanged(txn)
                if SERVICES in txn[DATA]:
                    self.nodeServicesChanged(txn)

            if nodeName in self.nodeReg:
                # The node was already part of the pool so update
                _updateNode(txn)
            else:
                seqNos, info = self.getNodeInfoFromLedger(nodeNym)
                if len(seqNos) == 1:
                    # Since only one transaction has been made, this is a new
                    # node transaction
                    self.addNewNodeAndConnect(txn)
                else:
                    self.node.nodeReg[nodeName] = HA(info[DATA][NODE_IP],
                                                     info[DATA][NODE_PORT])
                    self.node.cliNodeReg[nodeName] = HA(
                        info[DATA][CLIENT_IP], info[DATA][CLIENT_PORT])
                    _updateNode(txn)

            self.node.sendPoolInfoToClients(txn)
            if self.config.UpdateGenesisPoolTxnFile:
                updateGenesisPoolTxnFile(self.config.baseDir,
                                         self.config.poolTransactionsFile, txn)
コード例 #3
0
ファイル: pool_manager.py プロジェクト: evernym/plenum
 def poolTxnReceived(self, msg: PoolLedgerTxns, frm):
     logger.debug("{} received pool txn {} from {}".format(self, msg, frm))
     txn = getattr(msg, t)
     seqNo = txn.pop(F.seqNo.name)
     if seqNo not in self.tempNodeTxns:
         self.tempNodeTxns[seqNo] = {}
     self.tempNodeTxns[seqNo][frm] = txn
     # If this is the next sequence number that should go into ledger, then
     # check if there are enough same transactions from different nodes
     if (seqNo - self.ledger.size) == 1:
         f = getMaxFailures(len(self.nodeReg))
         if len(self.tempNodeTxns[seqNo]) > f:
             # TODO: Shouldnt this use `checkIfMoreThanFSameItems`
             txns = [item for item, count in
                     collections.Counter(
                         [json.dumps(t, sort_keys=True)
                          for t in self.tempNodeTxns[seqNo].values()]
                     ).items() if count > f]
             if len(txns) > 0:
                 txn = json.loads(txns[0])
                 self.addToLedger(txn)
                 if self.config.UPDATE_GENESIS_POOL_TXN_FILE:
                     # Adding sequence number field since needed for safely
                     # updating genesis file
                     txn[F.seqNo.name] = len(self.ledger)
                     updateGenesisPoolTxnFile(self.config.baseDir,
                                              self.config.poolTransactionsFile,
                                              txn)
                 self.tempNodeTxns.pop(seqNo)
             else:
                 logger.error("{} has not got enough similar node "
                              "transactions".format(self))