Ejemplo n.º 1
0
def checkHeight(private_client, public_client, timeout=TIMEOUT):
    result_private = private_client.send(
        jsonrpcclient.Request("getRootBlockByHeight"),
        timeout=timeout,)
    result_public = public_client.send(
        jsonrpcclient.Request("getRootBlockByHeight"),
        timeout=timeout,)
    return {
        "height": int(result_private["height"], 16),
        "currentHeight": int(result_public["height"], 16),
    }
def check_routing_table(timeout=TIMEOUT):
    result = PRIVATE_CLIENT.send(jsonrpcclient.Request("getKadRoutingTable"),
                                 timeout=timeout)
    if len(result) == 0:
        print("Bootstrap node can not provide the routing table for a while!")
        subject = "Boostrap Node Alert!"
        msg = "Bootstrap node can not provide the routing table for a while!" + now(
        )
        send_email(subject, msg)
    print(len(result))
Ejemplo n.º 3
0
def get_highest() -> int:
    global fetcher
    assert isinstance(fetcher, Fetcher)

    res = fetcher.cli.send(
        jsonrpcclient.Request("getRootBlockByHeight"), timeout=TIMEOUT
    )
    if not res:
        raise RuntimeError("Failed to get latest block height")
    return int(res["height"], 16)
Ejemplo n.º 4
0
 def count_total_balance(self, block_id: str, root_block_id: str,
                         token_id: int, start: str) -> Tuple[int, str]:
     res = self.cli.send(
         jsonrpcclient.Request("getTotalBalance", block_id, root_block_id,
                               hex(token_id), start),
         timeout=self.timeout,
     )
     if not res:
         raise RuntimeError("Failed to count total balance")
     return int(res["totalBalance"], 16), res["next"]
Ejemplo n.º 5
0
 def _get_root_block(self, root_block_height: int) -> Dict[str, Any]:
     res = self.cli.send(
         jsonrpcclient.Request("getRootBlockByHeight",
                               hex(root_block_height)),
         timeout=self.timeout,
     )
     if not res:
         raise RuntimeError("Failed to query root block at height" %
                            root_block_height)
     return res
Ejemplo n.º 6
0
def scf_blockHeight(args):
    block_ip_list=args.blockHeightIpList.strip().split(",")
    peer_ip_list=args.peerIpList.strip().split(",")

    block_fetchers = {}
    ip_fetchers = {}
    block_height_gauge=Gauge("GoQKCBeijingData","block_heitht_by_ip",("ip","type"))
    for ip in block_ip_list:
        block_fetchers[ip] = Fetcher(ip, TIMEOUT)
    for ip in peer_ip_list:
        ip_fetchers[ip]=Fetcher(ip,TIMEOUT)

    while True:
        try:
            print("start---")
            for ip,f in block_fetchers.items():
                res = f.cli.send(
                    jsonrpcclient.Request("getRootBlockByHeight",None), timeout=TIMEOUT
                )
                if not res:
                    raise RuntimeError("Failed to get latest block height-115")
                data=int(res["height"], 16)
                print("height_ip",ip,"data",data)
                block_height_gauge.labels(ip,"height").set(data)

            for ip,f in ip_fetchers.items():
                res=f.cli.send(
                    jsonrpcclient.Request("getPeers"), timeout=TIMEOUT
                )
                if not res:
                    raise RuntimeError("fdadsadsadsa")
                data=len(res["peers"])
                print("peer_ip", ip, "data", data)
                block_height_gauge.labels(ip,"peer_nubmer").set(data)
        except Exception as e:
            print("failed to get latest root block height---", e)
            # Rpc not ready, wait and try again.
            time.sleep(3)
            continue
        time.sleep(args.interval)
Ejemplo n.º 7
0
def get_work_rpc(shard: Optional[int],
                 host: str = "localhost",
                 jrpc_port: int = 38391,
                 timeout=3) -> MiningWork:
    json_rpc_url = "http://{}:{}".format(host, jrpc_port)
    cli = jsonrpcclient.HTTPClient(json_rpc_url)
    header_hash, height, diff = cli.send(
        jsonrpcclient.Request("getWork",
                              hex(shard) if shard is not None else None),
        timeout=timeout,
    )
    return MiningWork(bytes.fromhex(header_hash[2:]), int(height, 16),
                      int(diff, 16))
Ejemplo n.º 8
0
def submit_work_rpc(
    shard: Optional[int],
    res: MiningResult,
    host: str = "localhost",
    jrpc_port: int = 38391,
    timeout=3,
) -> bool:
    json_rpc_url = "http://{}:{}".format(host, jrpc_port)
    cli = jsonrpcclient.HTTPClient(json_rpc_url)
    success = cli.send(
        jsonrpcclient.Request(
            "submitWork",
            hex(shard) if shard is not None else None,
            "0x" + res.header_hash.hex(),
            hex(res.nonce),
            "0x" + res.mixhash.hex(),
        ),
        timeout=timeout,
    )
    return success