def test_get_msgs_from_rxMsgs_queue(create_node_and_not_start, looper):
    node = create_node_and_not_start
    node.view_changer = create_view_changer(node)
    node.view_changer.pre_vc_strategy = VCStartMsgStrategy(view_changer, node)
    node.view_changer.view_no = 0
    """pre_view_change stage"""
    node.view_changer.start_view_change(1)
    assert node.view_changer.view_no == 0
    prepare = Prepare(
        0,
        0,
        1,
        get_utc_epoch(),
        'f99937241d4c891c08e92a3cc25966607315ca66b51827b170d492962d58a9be',
        'CZecK1m7VYjSNCC7pGHj938DSW2tfbqoJp1bMJEtFqvG',
        '7WrAMboPTcMaQCU1raoj28vnhu2bPMMd2Lr9tEcsXeCJ')
    inst_change = InstanceChange(1, 25)
    m = node.nodeInBox.popleft()
    assert isinstance(m[0], ViewChangeStartMessage)
    node.nodestack.addRemote('someNode', genHa(), b'1DYuELN<SHbv1?NJ=][4De%^Hge887B0I!s<YGdD', 'pubkey')
    node.nodestack.rxMsgs.append((json.dumps(prepare._asdict()), 'pubkey'))
    node.nodestack.rxMsgs.append((json.dumps(inst_change._asdict()), 'pubkey'))
    node.msgHasAcceptableViewNo = lambda *args, **kwargs: True
    """While processing ViewChangeStartMessage from nodeInBox queue, should be:
    - move msgs from rxMsgs queue to nodeInBox queue
    - process all 3PC msgs (for Prepare msg it should be moved to inBox queue of master_replica)
    - add ViewChangeContinue msg into master_replica's inBox queue
    - all not 3PC msgs will be stashed in strategy queue"""
    looper.run(node.process_one_node_message(m))
    m = node.master_replica.inBox.popleft()
    assert isinstance(m[0], Prepare)
    m = node.master_replica.inBox.popleft()
    assert isinstance(m, ViewChangeContinueMessage)
    m = node.view_changer.pre_vc_strategy.stashedNodeInBox.popleft()
    assert isinstance(m[0], InstanceChange)
def test_accept_all_3PC_msgs(create_node_and_not_start, looper):
    node = create_node_and_not_start
    preprepare = PrePrepare(
        0, 0, 1, get_utc_epoch(),
        ['f99937241d4c891c08e92a3cc25966607315ca66b51827b170d492962d58a9be'],
        '[]',
        'f99937241d4c891c08e92a3cc25966607315ca66b51827b170d492962d58a9be',
        DOMAIN_LEDGER_ID, 'CZecK1m7VYjSNCC7pGHj938DSW2tfbqoJp1bMJEtFqvG',
        '7WrAMboPTcMaQCU1raoj28vnhu2bPMMd2Lr9tEcsXeCJ', 0, True)
    prepare = Prepare(
        0, 0, 1, get_utc_epoch(),
        'f99937241d4c891c08e92a3cc25966607315ca66b51827b170d492962d58a9be',
        'CZecK1m7VYjSNCC7pGHj938DSW2tfbqoJp1bMJEtFqvG',
        '7WrAMboPTcMaQCU1raoj28vnhu2bPMMd2Lr9tEcsXeCJ')
    commit = Commit(0, 0, 1)
    node.view_changer = node.newViewChanger()
    node.view_changer.pre_vc_strategy = VCStartMsgStrategy(
        node.view_changer, node)
    node.view_changer.view_no = 0
    node.master_replica.primaryName = 'Alpha'
    """Initiate view_change procedure"""
    node.view_changer.startViewChange(1)
    assert len(node.nodeInBox) == 1
    m = node.nodeInBox[0]
    assert isinstance(m[0], ViewChangeStartMessage)
    """
    Imitate that nodestack.service was called and 
    those of next messages are put into nodeInBox queue
    """
    node.nodeInBox.append((preprepare, 'some_node'))
    node.nodeInBox.append((prepare, 'some_node'))
    node.nodeInBox.append((commit, 'some_node'))
    assert len(node.master_replica.inBox) == 0
    """Imitate looper's work"""
    looper.run(node.serviceReplicas(None))
    """
    Next looper's task must be processNodeInBox and 
    all of 3PC messages must be moved to replica's inBox queue
    """
    looper.run(node.processNodeInBox())
    """3 3PC msgs and 1 is ViewChangeContinuedMessage"""
    assert len(node.master_replica.inBox) == 4
    """Check the order of msgs"""
    m = node.master_replica.inBox.popleft()
    assert isinstance(m[0], PrePrepare)
    m = node.master_replica.inBox.popleft()
    assert isinstance(m[0], Prepare)
    m = node.master_replica.inBox.popleft()
    assert isinstance(m[0], Commit)
    m = node.master_replica.inBox.popleft()
    assert isinstance(m, ViewChangeContinueMessage)
def pre_vc_strategy(view_changer, fake_node):
    strategy = VCStartMsgStrategy(view_changer, fake_node)
    strategy.view_changer.pre_vc_strategy = strategy
    return strategy
Beispiel #4
0
def pre_vc_strategy(view_changer):
    strategy = VCStartMsgStrategy(view_changer)
    strategy.view_changer.pre_vc_strategy = strategy
    return strategy