def test_primaries_in_ordered_from_audit_for_tree_txns(test_node):
    node_regs = {}
    replica = test_node.master_replica
    test_node.primaries = ["Alpha", "Beta"]
    node_reg = ["Alpha", "Beta", "Gamma", "Delta", "Eta"]
    for i in range(3):
        pp = create_pre_prepare_no_bls(state_root=generate_state_root(),
                                       pp_seq_no=i)
        key = (pp.viewNo, pp.ppSeqNo)
        replica._ordering_service.prePrepares[key] = pp
        replica._consensus_data.preprepared.append(preprepare_to_batch_id(pp))
        three_pc_batch = ThreePcBatch.from_pre_prepare(pre_prepare=pp,
                                                       state_root=pp.stateRootHash,
                                                       txn_root=pp.txnRootHash,
                                                       primaries=["Node{}".format(num)
                                                                  for num in range(i + 1)],
                                                       valid_digests=pp.reqIdr)
        three_pc_batch.node_reg = node_reg + ["Node{}".format(i + 10)]
        test_node.write_manager.audit_b_handler.post_batch_applied(three_pc_batch)
        node_regs[key] = three_pc_batch.node_reg

    for key in reversed(list(node_regs.keys())):
        replica._ordering_service._order_3pc_key(key)

    for ordered in replica.outBox:
        if not isinstance(ordered, Ordered):
            continue
        assert ordered.nodeReg == node_regs[(ordered.viewNo,
                                              ordered.ppSeqNo)]
示例#2
0
    def tryOrderAndAddTxns(self, commit):
        canOrder, _ = self.canOrder(commit)
        node = replica.node
        if not replica.added and canOrder:
            pp = self.getPrePrepare(commit.viewNo, commit.ppSeqNo)
            ledger_manager = node.ledgerManager
            ledger_id = DOMAIN_LEDGER_ID
            catchup_rep_service = ledger_manager._leechers[
                ledger_id].catchup_rep_service

            # simulate audit ledger catchup
            three_pc_batch = ThreePcBatch.from_pre_prepare(
                pre_prepare=pp,
                valid_txn_count=len(reqs),
                state_root=pp.stateRootHash,
                txn_root=pp.txnRootHash)
            node.audit_handler.post_batch_applied(three_pc_batch)
            node.audit_handler.commit_batch(ledger_id, len(reqs),
                                            pp.stateRootHash, pp.txnRootHash,
                                            pp.ppTime)

            ledger_manager.preCatchupClbk(ledger_id)
            pp = self.getPrePrepare(commit.viewNo, commit.ppSeqNo)
            for req in reqs:
                txn = append_txn_metadata(reqToTxn(req), txn_time=pp.ppTime)
                catchup_rep_service._add_txn(txn)
            ledger_manager.catchupCompleted(DOMAIN_LEDGER_ID,
                                            (node.viewNo, commit.ppSeqNo))

            replica.added = True

        return origMethod(commit)
    def post_batch_applied(self,
                           three_pc_batch: ThreePcBatch,
                           prev_handler_result=None):
        # Observer case:
        if not self.uncommitted_node_reg and three_pc_batch.node_reg:
            self.uncommitted_node_reg = list(three_pc_batch.node_reg)

        view_no = three_pc_batch.view_no if three_pc_batch.original_view_no is None else three_pc_batch.original_view_no

        # Update active_node_reg to point to node_reg at the end of last view
        if view_no > self._uncommitted_view_no:
            self.uncommitted_node_reg_at_beginning_of_view[view_no] = list(
                self._uncommitted[-1].uncommitted_node_reg) if len(
                    self._uncommitted) > 0 else list(self.committed_node_reg)
            self._uncommitted_view_no = view_no

        self._uncommitted.append(
            UncommittedNodeReg(list(self.uncommitted_node_reg), view_no))

        three_pc_batch.node_reg = list(self.uncommitted_node_reg)

        logger.debug("Applied uncommitted node registry: {}".format(
            self.uncommitted_node_reg))
        logger.debug(
            "Current committed node registry for previous views: {}".format(
                sorted(self.committed_node_reg_at_beginning_of_view.items())))
        logger.debug(
            "Current uncommitted node registry for previous views: {}".format(
                sorted(
                    self.uncommitted_node_reg_at_beginning_of_view.items())))
        logger.debug("Current active node registry: {}".format(
            self.active_node_reg))
def three_pc_batch():
    return ThreePcBatch(DOMAIN_LEDGER_ID, 0, 0, 1, time.time(),
                        randomString(),
                        randomString(),
                        ['a', 'b', 'c'],
                        ['d1', 'd2', 'd3'],
                        'pp_digest')
 def commit_batch(self, three_pc_batch, prev_handler_result=None):
     committed_txns = prev_handler_result
     token_state_root, token_txn_root, _ = self.token_tracker.commit_batch()
     committed_seq_nos_with_fees = [
         get_seq_no(t) for t in committed_txns
         if self._fees_tracker.has_deducted_fees(get_type(t), get_seq_no(t))
     ]
     if len(committed_seq_nos_with_fees) > 0:
         # This is a fake txn only for commit to token ledger
         token_fake_three_pc_batch = ThreePcBatch(
             ledger_id=TOKEN_LEDGER_ID,
             inst_id=three_pc_batch.inst_id,
             view_no=three_pc_batch.view_no,
             pp_seq_no=three_pc_batch.pp_seq_no,
             pp_time=three_pc_batch.pp_time,
             state_root=token_state_root,
             txn_root=txn_root_serializer.serialize(token_txn_root),
             primaries=three_pc_batch.primaries,
             valid_digests=[
                 i for i in range(len(committed_seq_nos_with_fees))
             ])
         committed_token_txns = super()._commit(self.token_ledger,
                                                self.token_state,
                                                token_fake_three_pc_batch)
         TokenStaticHelper.commit_to_utxo_cache(self.utxo_cache,
                                                token_state_root)
         i = 0
         # We are adding fees txn to the reply, so that client could get information about token transition
         for txn in committed_txns:
             if get_seq_no(txn) in committed_seq_nos_with_fees:
                 txn[FEES] = committed_token_txns[i]
                 i += 1
         self._fees_tracker.fees_in_current_batch = 0
     return committed_txns
def test_primaries_in_ordered_from_audit_for_tree_txns(test_node):
    primaries = {}
    replica = test_node.master_replica
    test_node.primaries = ["Alpha", "Beta"]
    for i in range(3):
        pp = create_pre_prepare_no_bls(state_root=generate_state_root(),
                                       pp_seq_no=i)
        key = (pp.viewNo, pp.ppSeqNo)
        replica.prePrepares[key] = pp
        three_pc_batch = ThreePcBatch.from_pre_prepare(
            pre_prepare=pp,
            state_root=pp.stateRootHash,
            txn_root=pp.txnRootHash,
            primaries=["Node{}".format(num) for num in range(i + 1)],
            valid_digests=pp.reqIdr)
        test_node.audit_handler.post_batch_applied(three_pc_batch)
        primaries[key] = three_pc_batch.primaries

    for key in reversed(list(primaries.keys())):
        replica.order_3pc_key(key)

    for ordered in replica.outBox:
        if not isinstance(ordered, Ordered):
            continue
        assert ordered.primaries != test_node.primaries
        assert ordered.primaries == primaries[(ordered.viewNo,
                                               ordered.ppSeqNo)]
def add_txns_to_audit(alh,
                      count,
                      ledger_id,
                      txns_per_batch,
                      view_no,
                      initial_pp_seq_no,
                      pp_time,
                      digest=''):
    db_manager = alh.database_manager
    for i in range(count):
        add_txns(db_manager, ledger_id, txns_per_batch, pp_time)
        three_pc_batch = ThreePcBatch(
            ledger_id=ledger_id,
            inst_id=0,
            view_no=view_no,
            pp_seq_no=initial_pp_seq_no + i,
            pp_time=pp_time,
            state_root=db_manager.get_state(ledger_id).headHash,
            txn_root=db_manager.get_ledger(ledger_id).uncommitted_root_hash,
            primaries=DEFAULT_PRIMARIES,
            node_reg=DEFAULT_NODE_REG,
            valid_digests=[],
            pp_digest=digest)
        alh._add_to_ledger(three_pc_batch)
    alh.ledger.commitTxns(count)
示例#8
0
def do_apply_audit_txn(alh,
                       txns_count,
                       ledger_id,
                       view_no,
                       pp_sq_no,
                       txn_time,
                       has_audit_txn=True,
                       original_view_no=None,
                       digest='',
                       nod_reg=DEFAULT_NODE_REG):
    db_manager = alh.database_manager
    add_txns(db_manager, ledger_id, txns_count, txn_time)
    three_pc_batch = ThreePcBatch(
        ledger_id=ledger_id,
        inst_id=0,
        view_no=view_no,
        pp_seq_no=pp_sq_no,
        pp_time=txn_time,
        state_root=db_manager.get_state(ledger_id).headHash,
        txn_root=db_manager.get_ledger(ledger_id).uncommitted_root_hash,
        primaries=DEFAULT_PRIMARIES,
        valid_digests=[],
        pp_digest=digest,
        node_reg=nod_reg,
        has_audit_txn=has_audit_txn,
        original_view_no=original_view_no)
    alh.post_batch_applied(three_pc_batch)
def test_fee_batch_handler_commit_batch(fee_batch_handler, fees_tracker):
    utxo_cache = fee_batch_handler.database_manager.get_store(UTXO_CACHE_LABEL)
    utxo_cache.set('1', '2')
    fee_batch_handler.database_manager.get_state(TOKEN_LEDGER_ID).set('1'.encode(), '2'.encode())
    fees_tracker.fees_in_current_batch = 1
    fee_batch_handler.post_batch_applied(None, None)

    fees_tracker.add_deducted_fees(NYM, 1, 1)
    prev_res = [{
        TXN_METADATA: {
            TXN_METADATA_SEQ_NO: 1
        },
        TXN_PAYLOAD: {
            TXN_PAYLOAD_TYPE: NYM
        }
    }]

    three_pc_batch = ThreePcBatch(0, 0, 0, 3, 1, 'state', 'txn',
                                  ['a', 'b', 'c'], ['a'], 0)

    fee_batch_handler.commit_batch(three_pc_batch, prev_res)
    assert not len(utxo_cache.current_batch_ops)
    assert not len(utxo_cache.un_committed)
    assert fee_batch_handler.token_ledger.committed_root_hash == fee_batch_handler.token_ledger.uncommitted_root_hash
    assert fee_batch_handler.token_state.headHash == fee_batch_handler.token_state.committedHeadHash
示例#10
0
def test_node_reg_in_ordered_from_audit_for_tree_txns(test_node):
    node_regs = {}
    replica = test_node.master_replica
    node_reg = ["Alpha", "Beta", "Gamma", "Delta", "Eta"]
    for i in range(3):
        pp = create_pre_prepare_no_bls(state_root=generate_state_root(),
                                       pp_seq_no=i)
        key = (pp.viewNo, pp.ppSeqNo)
        replica._ordering_service.prePrepares[key] = pp
        replica._consensus_data.preprepared.append(preprepare_to_batch_id(pp))
        three_pc_batch = ThreePcBatch.from_pre_prepare(
            pre_prepare=pp,
            state_root=pp.stateRootHash,
            txn_root=pp.txnRootHash,
            valid_digests=pp.reqIdr)
        three_pc_batch.node_reg = node_reg + ["Node{}".format(i + 10)]
        three_pc_batch.primaries = ["Alpha", "Beta"]
        test_node.write_manager.audit_b_handler.post_batch_applied(
            three_pc_batch)
        node_regs[key] = three_pc_batch.node_reg

    for key in reversed(list(node_regs.keys())):
        pp = replica._ordering_service.get_preprepare(*key)
        assert replica._ordering_service._get_node_reg_for_ordered(
            pp) == node_regs[key]
def test_future_primaries_replicas_increase(looper, txnPoolNodeSet, sdk_pool_handle,
                                            sdk_wallet_stewards, tdir, tconf, allPluginsPath):
    # Don't delete NodeStates, so we could check them.
    global old_commit
    old_commit = txnPoolNodeSet[0].write_manager.future_primary_handler.commit_batch
    for node in txnPoolNodeSet:
        node.write_manager.future_primary_handler.commit_batch = lambda three_pc_batch, prev_handler_result=None: 0

    initial_primaries = copy.copy(txnPoolNodeSet[0].primaries)
    last_ordered = txnPoolNodeSet[0].master_replica.last_ordered_3pc
    starting_view_number = checkViewNoForNodes(txnPoolNodeSet)

    # Increase replicas count
    add_new_node(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_stewards[0], tdir, tconf, allPluginsPath)

    new_view_no = checkViewNoForNodes(txnPoolNodeSet)
    assert new_view_no == starting_view_number + 1
    # "seq_no + 2" because 1 domain and 1 pool txn.

    node = txnPoolNodeSet[0]
    with delay_rules(node.nodeIbStasher, cDelay()):
        req = sdk_send_random_and_check(looper, txnPoolNodeSet,
                                        sdk_pool_handle,
                                        sdk_wallet_stewards[0], 1)[0][0]
        req = Request(**req)
        three_pc_batch = ThreePcBatch(DOMAIN_LEDGER_ID, 0, 0, 1, time.time(),
                                      randomString(),
                                      randomString(),
                                      ['a', 'b', 'c'], [req.digest], pp_digest='')
        primaries = node.write_manager.future_primary_handler.post_batch_applied(three_pc_batch)
        assert len(primaries) == len(initial_primaries) + 1
        assert len(primaries) == len(node.primaries)
def test_future_primaries_replicas_decrease(looper, txnPoolNodeSet, sdk_pool_handle,
                                            sdk_wallet_stewards, tdir, tconf, allPluginsPath):
    assert len(txnPoolNodeSet) == 7

    initial_primaries = copy.copy(txnPoolNodeSet[0].primaries)
    last_ordered = txnPoolNodeSet[0].master_replica.last_ordered_3pc
    starting_view_number = checkViewNoForNodes(txnPoolNodeSet)

    # Decrease replicas count
    demote_node(looper, sdk_wallet_stewards[-1], sdk_pool_handle, txnPoolNodeSet[-2])
    txnPoolNodeSet.remove(txnPoolNodeSet[-2])
    ensureElectionsDone(looper=looper, nodes=txnPoolNodeSet)

    new_view_no = checkViewNoForNodes(txnPoolNodeSet)
    assert new_view_no == starting_view_number + 1
    node = txnPoolNodeSet[0]
    with delay_rules(node.nodeIbStasher, cDelay()):
        req = sdk_send_random_and_check(looper, txnPoolNodeSet,
                                        sdk_pool_handle,
                                        sdk_wallet_stewards[0], 1)[0][0]
        req = Request(**req)
        three_pc_batch = ThreePcBatch(DOMAIN_LEDGER_ID, 0, 0, 1, time.time(),
                                      randomString(),
                                      randomString(),
                                      ['a', 'b', 'c'], [req.digest], pp_digest='')
        primaries = node.write_manager.future_primary_handler.post_batch_applied(three_pc_batch)
        assert len(primaries) + 1 == len(initial_primaries)
        assert len(primaries) == len(txnPoolNodeSet[0].primaries)

    for node in txnPoolNodeSet:
        node.write_manager.future_primary_handler.commit_batch = old_commit
def test_node_reg_in_ordered_from_audit_no_node_reg(test_node):
    replica = test_node.master_replica

    # run multiple times to have a situation when we write node reg to non-empty audit ledger
    for i in range(1, 4):
        uncommitted_node_reg = ['Alpha', 'Beta', 'Gamma', 'Node{}'.format(i)]
        test_node.write_manager.node_reg_handler.uncommitted_node_reg = uncommitted_node_reg

        pre_prepare = create_pre_prepare_no_bls(
            state_root=generate_state_root(), pp_seq_no=i)
        key = (pre_prepare.viewNo, pre_prepare.ppSeqNo)
        replica._ordering_service.prePrepares[key] = pre_prepare
        replica._consensus_data.preprepared.append(
            preprepare_to_batch_id(pre_prepare))
        test_node.primaries = ["Alpha", "Beta"]
        three_pc_batch = ThreePcBatch.from_pre_prepare(
            pre_prepare=pre_prepare,
            state_root=pre_prepare.stateRootHash,
            txn_root=pre_prepare.txnRootHash,
            primaries=["Alpha", "Beta", "Gamma"],
            valid_digests=pre_prepare.reqIdr)
        three_pc_batch.node_reg = None
        test_node.write_manager.audit_b_handler.post_batch_applied(
            three_pc_batch)

        replica._ordering_service._order_3pc_key(key)

        ordered = replica.outBox.pop()
        # we expect it equal to the current uncommitted node reg
        assert ordered.nodeReg == uncommitted_node_reg
def get_3PC_batch(root_hash, ledger_id=1):
    return ThreePcBatch(ledger_id,
                        0,
                        0,
                        1,
                        5000,
                        root_hash,
                        "", ["Alpha", "Beta"], [],
                        pp_digest='')
def three_pc_batch():
    fp = ThreePcBatch(0,
                      0,
                      0,
                      3,
                      1,
                      'state',
                      'txn', ['a', 'b', 'c'], ['a'],
                      pp_digest='')
    return fp
def three_pc_batch(batch_handler):
    # Constant root hash is one which will be formed after applying txn
    return ThreePcBatch(LEDGER_ID,
                        0,
                        0,
                        1,
                        time.time(),
                        batch_handler.state.headHash,
                        FIXED_HASH, ['d1', 'd2', 'd3'],
                        'pp_digest',
                        primaries=['a', 'b', 'c'])
    def _do_apply_batch(self, batch):
        reqs = [Request(**req_dict) for req_dict in batch[f.REQUESTS.nm]]

        pp_time = batch[f.PP_TIME.nm]
        ledger_id = batch[f.LEDGER_ID.nm]
        state_root = batch[f.STATE_ROOT.nm]
        txn_root = batch[f.TXN_ROOT.nm]

        three_pc_batch = ThreePcBatch.from_batch_committed_dict(batch)
        self._node.apply_reqs(reqs, three_pc_batch)
        self._node.get_executer(ledger_id)(pp_time, reqs, state_root, txn_root)
    def _do_apply_batch(self, batch):
        reqs = [Request(**req_dict) for req_dict in batch[f.REQUESTS.nm]]

        ledger_id = batch[f.LEDGER_ID.nm]
        three_pc_batch = ThreePcBatch.from_batch_committed_dict(batch)
        self._node.apply_reqs(reqs, three_pc_batch)

        # We need hashes in apply and str in commit
        three_pc_batch.txn_root = Ledger.hashToStr(three_pc_batch.txn_root)
        three_pc_batch.state_root = Ledger.hashToStr(three_pc_batch.state_root)
        self._node.get_executer(ledger_id)(three_pc_batch)
示例#19
0
 def post_batch_applied(self,
                        three_pc_batch: ThreePcBatch,
                        prev_handler_result=None):
     node_reg = list(self.node.nodeReg.keys())
     number_of_inst = getMaxFailures(len(node_reg)) + 1
     view_no = self.node.viewNo if three_pc_batch.original_view_no is None else three_pc_batch.original_view_no
     validators = TxnPoolManager.calc_node_names_ordered_by_rank(
         node_reg, copy.deepcopy(self.node.nodeIds))
     three_pc_batch.primaries = self.node.primaries_selector.select_primaries(
         view_no=view_no,
         instance_count=number_of_inst,
         validators=validators)
     return three_pc_batch.primaries
示例#20
0
    def post_batch_applied(self,
                           three_pc_batch: ThreePcBatch,
                           prev_handler_result=None):
        view_no = self.node.viewNo if three_pc_batch.original_view_no is None else three_pc_batch.original_view_no
        primaries = self.get_primaries(view_no)
        if primaries is None:
            # In case of reordering after view_change
            # we can trust for list of primaries from PrePrepare
            # because this PrePrepare was validated on all the nodes
            primaries = three_pc_batch.primaries
            self.set_primaries(view_no, primaries)

        three_pc_batch.primaries = primaries
        return three_pc_batch.primaries
def add_txns_to_audit(alh, count, ledger_id, txns_per_batch, view_no,
                      initial_pp_seq_no, pp_time):
    db_manager = alh.database_manager
    for i in range(count):
        add_txns(db_manager, ledger_id, txns_per_batch, pp_time)
        three_pc_batch = ThreePcBatch(
            ledger_id=ledger_id,
            inst_id=0,
            view_no=view_no,
            pp_seq_no=initial_pp_seq_no + i,
            pp_time=pp_time,
            valid_txn_count=txns_per_batch,
            state_root=db_manager.get_state(ledger_id).headHash,
            txn_root=db_manager.get_ledger(ledger_id).uncommitted_root_hash)
        alh._add_to_ledger(three_pc_batch)
    alh.ledger.commitTxns(count)
示例#22
0
    def emulate_ordered_processing(self, msg: Ordered):
        three_pc_batch = ThreePcBatch.from_ordered(msg)
        three_pc_batch.txn_root = Ledger.hashToStr(three_pc_batch.txn_root)
        three_pc_batch.state_root = Ledger.hashToStr(three_pc_batch.state_root)
        self._write_manager.commit_batch(three_pc_batch)

        possible_added = set(three_pc_batch.node_reg) - set(self._previous_node_reg)
        possible_removed = set(self._previous_node_reg) - set(three_pc_batch.node_reg)
        if possible_added:
            for node_name in list(possible_added):
                self._internal_bus.send(NeedAddNode(node_name, self.name))
        if possible_removed:
            for node_name in list(possible_removed):
                self._internal_bus.send(NeedRemoveNode(node_name, self.name))
        if possible_added or possible_removed:
            self._previous_node_reg = three_pc_batch.node_reg
示例#23
0
    def post_batch_applied(self,
                           three_pc_batch: ThreePcBatch,
                           prev_handler_result=None):
        # Observer case:
        if not self.uncommitted_node_reg and three_pc_batch.node_reg:
            self.uncommitted_node_reg = list(three_pc_batch.node_reg)

        view_no = three_pc_batch.view_no if three_pc_batch.original_view_no is None else three_pc_batch.original_view_no
        self._uncommitted.append(
            UncommittedNodeReg(list(self.uncommitted_node_reg), view_no))

        three_pc_batch.node_reg = list(self.uncommitted_node_reg)

        logger.debug("Applied uncommitted node registry: {}".format(
            self.uncommitted_node_reg))
        logger.debug("Current node registry for previous views: {}".format(
            sorted(self.node_reg_at_beginning_of_view.items())))
    def post_batch_applied(self,
                           three_pc_batch: ThreePcBatch,
                           prev_handler_result=None):
        node_txn_count = 0
        last_state = None
        if len(self.node_states) == 0:
            last_state = self.create_node_state_from_current_node()
        else:
            last_state = copy.deepcopy(self.node_states[-1])

        for digest in three_pc_batch.valid_digests:
            if digest not in self.node.requests:
                raise LogicError('Request is absent when it is applying')
            request = self.node.requests[digest].request
            if request.operation.get(TXN_TYPE) == NODE \
                    and request.operation.get(DATA).get(SERVICES) is not None:
                node_txn_count += 1
                node_nym = request.operation.get(TARGET_NYM)
                node_name = request.operation.get(DATA).get(ALIAS)
                curName = last_state.node_ids.get(node_nym)
                if curName is None:
                    last_state.node_ids[node_nym] = node_name
                elif curName != node_name:
                    raise LogicError("Alias inconsistency")

                serv = request.operation.get(DATA).get(SERVICES)
                if VALIDATOR in serv and node_name not in last_state.node_reg:
                    last_state.node_reg.append(node_name)
                elif serv == [] and node_name in last_state.node_reg:
                    last_state.node_reg.remove(node_name)

                count = self.get_required_number_of_instances(
                    len(last_state.node_reg))
                if last_state.number_of_inst != count:
                    last_state.number_of_inst = count
                    new_validators = TxnPoolManager.calc_node_names_ordered_by_rank(
                        last_state.node_reg, last_state.node_ids)
                    last_state.primaries = self.node.primaries_selector.select_primaries(
                        view_no=self.node.viewNo,
                        instance_count=last_state.number_of_inst,
                        validators=new_validators)

        # We will save node state at every pool batch, so we could revert it correctly
        self.node_states.append(last_state)
        three_pc_batch.primaries = last_state.primaries
        return last_state.primaries
示例#25
0
    def post_batch_applied(self,
                           three_pc_batch: ThreePcBatch,
                           prev_handler_result=None):
        # Observer case:
        if not self.uncommitted_node_reg and three_pc_batch.node_reg:
            self.uncommitted_node_reg = list(three_pc_batch.node_reg)

        view_no = three_pc_batch.view_no if three_pc_batch.original_view_no is None else three_pc_batch.original_view_no
        self._uncommitted.append(
            UncommittedNodeReg(list(self.uncommitted_node_reg), view_no))

        if view_no > self._uncommitted_view_no:
            self.node_reg_at_beginning_of_view[view_no] = list(
                self.uncommitted_node_reg)
            self._uncommitted_view_no = three_pc_batch.view_no

        three_pc_batch.node_reg = self.uncommitted_node_reg
示例#26
0
def test_node_reg_in_ordered_from_audit(test_node):
    pre_prepare = create_pre_prepare_no_bls(state_root=generate_state_root(),
                                            pp_seq_no=1)
    replica = test_node.master_replica
    key = (pre_prepare.viewNo, pre_prepare.ppSeqNo)
    replica._ordering_service.prePrepares[key] = pre_prepare
    replica._consensus_data.preprepared.append(
        preprepare_to_batch_id(pre_prepare))
    three_pc_batch = ThreePcBatch.from_pre_prepare(
        pre_prepare=pre_prepare,
        state_root=pre_prepare.stateRootHash,
        txn_root=pre_prepare.txnRootHash,
        valid_digests=pre_prepare.reqIdr)
    three_pc_batch.node_reg = ["Alpha", "Beta", "Gamma", "Delta", "Eta"]
    three_pc_batch.primaries = ["Alpha", "Beta"]
    test_node.write_manager.audit_b_handler.post_batch_applied(three_pc_batch)

    assert replica._ordering_service._get_node_reg_for_ordered(
        pre_prepare) == three_pc_batch.node_reg
示例#27
0
def do_apply_audit_txn(alh,
                       txns_count,
                       ledger_id,
                       view_no,
                       pp_sq_no,
                       txn_time,
                       has_audit_txn=True):
    db_manager = alh.database_manager
    add_txns(db_manager, ledger_id, txns_count, txn_time)
    three_pc_batch = ThreePcBatch(
        ledger_id=ledger_id,
        inst_id=0,
        view_no=view_no,
        pp_seq_no=pp_sq_no,
        pp_time=txn_time,
        valid_txn_count=txns_count,
        state_root=db_manager.get_state(ledger_id).headHash,
        txn_root=db_manager.get_ledger(ledger_id).uncommitted_root_hash,
        has_audit_txn=has_audit_txn)
    alh.post_batch_applied(three_pc_batch)
def test_primaries_in_ordered_from_audit(test_node):
    pre_prepare = create_pre_prepare_no_bls(state_root=generate_state_root(),
                                            pp_seq_no=1)
    replica = test_node.master_replica
    key = (pre_prepare.viewNo, pre_prepare.ppSeqNo)
    replica.prePrepares[key] = pre_prepare
    test_node.primaries = ["Alpha", "Beta"]
    three_pc_batch = ThreePcBatch.from_pre_prepare(
        pre_prepare=pre_prepare,
        state_root=pre_prepare.stateRootHash,
        txn_root=pre_prepare.txnRootHash,
        primaries=["Alpha", "Beta", "Gamma"],
        valid_digests=pre_prepare.reqIdr)
    test_node.audit_handler.post_batch_applied(three_pc_batch)

    replica.order_3pc_key(key)

    ordered = replica.outBox.pop()
    assert ordered.primaries != test_node.primaries
    assert ordered.primaries == three_pc_batch.primaries
示例#29
0
 def post_batch_applied(self,
                        three_pc_batch: ThreePcBatch,
                        prev_handler_result=None):
     view_no = three_pc_batch.original_view_no if three_pc_batch.original_view_no is not None else three_pc_batch.view_no
     three_pc_batch.primaries = self.primaries_selector.select_primaries(
         view_no)