def client_new_node_obj(global_running_env, staking_cfg): """ Get a new node Client object list """ normal_node = global_running_env.get_a_normal_node() for noconsensus_node in global_running_env.normal_node_list: msg = noconsensus_node.ppos.getCandidateInfo(noconsensus_node.node_id) log.info(noconsensus_node.node_id) if msg["Code"] == 301204: log.info("Current linked node: {}".format(noconsensus_node.node_mark)) return Client(global_running_env, noconsensus_node, staking_cfg) log.info('noconsensus node has been staked, restart the chain') global_running_env.deploy_all() log.info("Current linked node: {}".format(normal_node.node_mark)) return Client(global_running_env, normal_node, staking_cfg)
def client_noconsensus_obj(global_running_env, staking_cfg): """ Get a noconsensus node Client object """ noconsensus_node_obj = global_running_env.get_a_normal_node() client_noconsensus_obj = Client(global_running_env, noconsensus_node_obj, staking_cfg) return client_noconsensus_obj
def param_governance_verify(client, module, name, newvalue, effectiveflag=True): """ effectiveflag indicates whether it takes effect """ if isinstance(client, Client): pip = client.pip else: raise Exception("client must Client class") if pip.is_exist_effective_proposal_for_vote(pip.cfg.param_proposal) or \ pip.is_exist_effective_proposal_for_vote(pip.cfg.version_proposal): raise Exception( 'There is effective param proposal or version proposal') result = pip.submitParam(pip.node.node_id, str(time.time()), module, name, newvalue, pip.node.staking_address, transaction_cfg=pip.cfg.transaction_cfg) log.info('submit param proposal result : {}'.format(result)) assert_code(result, 0) proposalinfo = pip.get_effect_proposal_info_of_vote(pip.cfg.param_proposal) log.info('param proposalinfo : {}'.format(proposalinfo)) all_clients = [] for node_obj in pip.economic.env.get_all_nodes(): all_clients.append( Client( pip.economic.env, node_obj, StakingConfig("externalId", "nodeName", "website", "details"))) client = get_client_by_nodeid(pip.node.node_id, all_clients) verifier_list = get_pledge_list(client.ppos.getVerifierList) log.info('verifierlist : {}'.format(verifier_list)) clients_verifier = get_clients_by_nodeid(verifier_list, all_clients) if effectiveflag: blocknum = 0 for client in clients_verifier: if client.node.block_number < blocknum and blocknum != 0: wait_block_number(client.node, blocknum) result = client.pip.vote( client.node.node_id, proposalinfo.get('ProposalID'), client.pip.cfg.vote_option_yeas, client.node.staking_address, transaction_cfg=client.pip.cfg.transaction_cfg) log.info('Node {} vote proposal result : {}'.format( client.node.node_id, result)) blocknum = client.node.block_number wait_block_number(pip.node, proposalinfo.get('EndVotingBlock')) if effectiveflag: assert pip.get_status_of_proposal(proposalinfo.get('ProposalID')) == 2 log.info("blockNumber {}, the {} has become {}".format( proposalinfo.get('EndVotingBlock'), name, newvalue)) else: assert pip.get_status_of_proposal(proposalinfo.get('ProposalID')) == 3 log.info("{} retains the original value".format(name))
def get_clients(env, cfg=None): if cfg is None: cfg = StakingConfig("externalId", "nodeName", "website", "details") all_clients = [] all_nodes = env.get_all_nodes() for node_obj in all_nodes: all_clients.append(Client(env, node_obj, cfg)) return all_clients
def client_noconsensus(global_running_env, staking_cfg) -> Client: """ Get a noconsensus node Client object """ noconsensus_node = global_running_env.get_a_normal_node() client_noconsensus = Client(global_running_env, noconsensus_node, staking_cfg) return client_noconsensus
def param_governance_verify_before_endblock(client_obj, module, name, newvalue, effectiveflag=True): """ effectiveflag indicates whether it takes effect :param client_obj: :param module: :param name: :param newvalue: :param effectiveflag: :return: the EndVotingBlock of the param proposal """ if isinstance(client_obj, Client): pip_obj = client_obj.pip else: raise Exception("client must Client class") if pip_obj.is_exist_effective_proposal_for_vote(pip_obj.cfg.param_proposal) or \ pip_obj.is_exist_effective_proposal_for_vote(pip_obj.cfg.version_proposal): raise Exception('There is effective param proposal or version proposal') result = pip_obj.submitParam(pip_obj.node.node_id, str(time.time()), module, name, newvalue, pip_obj.node.staking_address, transaction_cfg=pip_obj.cfg.transaction_cfg) log.info('submit param proposal result : {}'.format(result)) assert_code(result, 0) proposalinfo = pip_obj.get_effect_proposal_info_of_vote(pip_obj.cfg.param_proposal) log.info('param proposalinfo : {}'.format(proposalinfo)) client_obj_list = [] for node_obj in pip_obj.economic.env.get_all_nodes(): client_obj_list.append(Client(pip_obj.economic.env, node_obj, StakingConfig("externalId", "nodeName", "website", "details"))) client_obj = get_client_obj(pip_obj.node.node_id, client_obj_list) verifier_list = get_pledge_list(client_obj.ppos.getVerifierList) log.info('verifierlist : {}'.format(verifier_list)) client_verifier_obj_list = get_client_obj_list(verifier_list, client_obj_list) if effectiveflag: for client_obj in client_verifier_obj_list: result = client_obj.pip.vote(client_obj.node.node_id, proposalinfo.get('ProposalID'), client_obj.pip.cfg.vote_option_yeas, client_obj.node.staking_address, transaction_cfg=client_obj.pip.cfg.transaction_cfg) log.info('Node {} vote proposal result : {}'.format(client_obj.node.node_id, result)) log.info('The proposal endvoting block is {}'.format(proposalinfo.get('EndVotingBlock'))) return proposalinfo.get('EndVotingBlock')
def get_client_consensus_obj(env, cfg): consensus_node_obj = env.get_rand_node() client_consensus_obj = Client(env, consensus_node_obj, cfg) return client_consensus_obj
def get_client_noconsensus_list(env, cfg): client_noc_list_obj = [] noconsensus_node_obj_list = env.normal_node_list for node_obj in noconsensus_node_obj_list: client_noc_list_obj.append(Client(env, node_obj, cfg)) return client_noc_list_obj
def get_con_list_list(env, cfg): client_con_list_obj = [] consensus_node_obj_list = env.consensus_node_list for node_obj in consensus_node_obj_list: client_con_list_obj.append(Client(env, node_obj, cfg)) return client_con_list_obj
def get_client_list_obj(env, cfg): client_list_obj = [] node_obj_list = env.get_all_nodes() for node_obj in node_obj_list: client_list_obj.append(Client(env, node_obj, cfg)) return client_list_obj
def get_client_consensus(env, cfg): consensus_node = env.get_rand_node() client_consensus = Client(env, consensus_node, cfg) return client_consensus
def get_clients_noconsensus(env, cfg): client_noconsensus = [] noconsensus_nodes = env.normal_node_list for node_obj in noconsensus_nodes: client_noconsensus.append(Client(env, node_obj, cfg)) return client_noconsensus
def get_consensus_clients(env, cfg): clients_consensus = [] consensus_nodes = env.consensus_node_list for node in consensus_nodes: clients_consensus.append(Client(env, node, cfg)) return clients_consensus