示例#1
0
class Issue2235Test(ConfluxTestFramework):
    def set_test_params(self):
        self.num_nodes = 1

    def setup_network(self):
        self.add_nodes(self.num_nodes)
        self.start_node(0, ["--archive"])
        self.rpc = RpcClient(self.nodes[0])

    def run_test(self):

        #                      ---
        #                  .- | A | <--- ...
        #           ---    |   ---
        # ... <--- | 0 | <-*
        #           ---    |   ---
        #                  .- | B | <--- ...
        #                      ---

        block_number_0 = int(self.rpc.block_by_epoch("latest_mined")['epochNumber'], 0)
        block_0 = self.rpc.block_by_epoch("latest_mined")['hash']

        block_a = self.rpc.generate_custom_block(parent_hash = block_0, referee = [], txs = [])
        block_b = self.rpc.generate_custom_block(parent_hash = block_0, referee = [], txs = [])

        # create pivot chain from 'A', make sure 'A' is executed
        parent_hash = block_a

        for _ in range(5):
            block = self.rpc.generate_custom_block(parent_hash = parent_hash, referee = [], txs = [])
            parent_hash = block

        block_after_0 = self.rpc.block_by_block_number(hex(block_number_0 + 1))["hash"]
        assert_equal(block_a, block_after_0)

        # switch pivot chain to 'B', make sure 'B' is executed
        parent_hash = block_b

        for _ in range(6):
            block = self.rpc.generate_custom_block(parent_hash = parent_hash, referee = [], txs = [])
            parent_hash = block

        block_after_0 = self.rpc.block_by_block_number(hex(block_number_0 + 1))["hash"]
        assert_equal(block_b, block_after_0)

        # switch pivot chain back to 'A', make sure 'A' is executed
        parent_hash = block_a

        for _ in range(7):
            block = self.rpc.generate_custom_block(parent_hash = parent_hash, referee = [], txs = [])
            parent_hash = block

        block_after_0 = self.rpc.block_by_block_number(hex(block_number_0 + 1))["hash"]
        assert_equal(block_a, block_after_0) # <<< (#2235)

        self.log.info("Pass")
示例#2
0
    print(start, end)
    logs = client.get_logs(filter=Filter(from_block=hex(start), to_block=hex(end), address=["0x0888000000000000000000000000000000000005"], networkid=1))
    print("logs=", logs)
    for log in logs:
        pos_identifier = log["topics"][1]
        if log["topics"][0] == REGISTER_TOPIC:
            bls_pub_key, vrf_pub_key = eth_abi.decode_abi(["bytes", "bytes"], decode_hex(log["data"]))
            pub_keys_map[pos_identifier] = (encode_hex_0x(bls_pub_key), encode_hex_0x(vrf_pub_key))
            print(pub_keys_map[pos_identifier])
        elif log["topics"][0] == INCREASE_STAKE_TOPIC:
            assert pos_identifier in pub_keys_map
            voting_power_map[pos_identifier] += parse_as_int(log["data"])
with open(os.path.join(cwd, "public_keys"), "w") as f:
    for pos_identifier in pub_keys_map.keys():
        f.write(",".join([pub_keys_map[pos_identifier][0][2:], pub_keys_map[pos_identifier][1][2:], str(voting_power_map[pos_identifier])]) + "\n")
cfx_block_hash = client.block_by_block_number(hex(end_block_number))["hash"]
initial_seed = encode_hex(keccak(hexstr=cfx_block_hash[2:]+bitcoin_block_hash))
tg_config_gen = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../target/release/pos-genesis-tool")
check_output([tg_config_gen, "frompub", "--initial-seed={}".format(initial_seed),"public_keys"], cwd=cwd)
waypoint = open(os.path.join(cwd, "waypoint_config"), "r").readlines()[0]
conf_file = open(os.path.join(cwd, "pos_config.yaml"), "w")
conf_file.write(f"""
base:
  #data_dir: ./pos_db
  role: validator
  waypoint:
    from_config: {waypoint}
consensus:
  round_initial_timeout_ms: 60000
  safety_rules:
    service: