Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

discover_runners: keep livepeer/node price_usd exact

Đang mở
#88 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
62/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
api

Hướng nghiên cứu

Start with request_json and get_json in src/livepeer_gateway/http.py, then discover_runners in discovery.py, which should pass parse_float=Decimal. Write the failing test first in tests/test_discovery.py, patching http._request_body with a 36-digit price_usd and an integer price, and assert price_usd equals Decimal and price stays int. Done when the test passes, other responses still return floats, and the Decimal price is accepted in _live_runner_price_info_from_json in live_runner.py.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Problem

livepeer/node now sends price_info.price_usd in runner discovery, and discover_runners does not return it as sent. The SDK rounds it to a float, so callers see a different price from the one the node advertises.

The orchestrator computes price_usd as an exact fraction, writes up to 36 decimal places and trims trailing zeros (orchestrator/registry.go#L238-L242). It serves the result from GET /discovery (orchestrator/http.go#L63). The signer passes the field through as a json.Number, so the digits are not changed there either (signer/service.go#L238). For example, a runner that registers at 0.01 USD/hour is advertised at 0.0000027777777777777777777777777777 USD per second.

discover_runners reads the body through get_json and request_json, which calls json.loads(raw) (http.py#L223-L224). That turns any JSON number with a fraction into a float, which holds about 16 significant digits:

>>> json.loads("0.0000027777777777777777777777777777")
2.777777777777778e-06
>>> json.loads("0.0000027777777777777777777777777777", parse_float=Decimal)
Decimal('0.0000027777777777777777777777777777')

price is unaffected: the node sends it in wei as a JSON integer, and json.loads keeps integers exact.

Change

The goal is parity: discover_runners should return the price exactly as the node advertised it.

  1. Add a parse_float keyword to request_json and get_json and pass it to json.loads (http.py#L201-L228, #L312-L321). It defaults to None, which is also json.loads's default (float). Signer and runner responses also go through request_json, and their callers expect floats, so they must not change.

    async def request_json(
        url: str,
        *,
        ...,
        timeout: float = 5.0,
        parse_float: Callable[[str], Any] | None = None,
    ) -> Any:
        ...
        return json.loads(raw, parse_float=parse_float)
    
  2. Pass parse_float=Decimal in discover_runners only (discovery.py#L161):

    data = await get_json(discovery_endpoint, headers=request_headers, parse_float=Decimal)
    

    discover_orchestrators reads only addresses, so it can stay as it is.

The return type is still list[dict[str, Any]]. The value type of price_usd changes from float to Decimal, so add a line about it to the release notes.

Callers in this repo that need updating

  • _live_runner_price_info_from_json (live_runner.py#L1082-L1094) accepts price only as an int, float or str. After this change, a price with a fraction would arrive as a Decimal. The function would then return None, and the session would be reserved with no max_price.
    • The node sends price as a wei integer today, so this does not happen yet.
    • Fix: add Decimal to that check and to LiveRunnerPriceInfo.price (#L264-L267).
    • _pad_runner_price already works through Decimal and needs no change.
  • examples/select_runner.py#L86 calls json.dumps(runner.raw, indent=2). That raises TypeError: Object of type Decimal is not JSON serializable for any runner that has price_usd. Fix: pass default=str.
  • The _get_json test fake (tests/test_discovery.py#L102-L104) accepts only headers. It needs a parse_float parameter too.

Callers outside the SDK that serialize discovery entries, or that do arithmetic with price_usd as a float, need to handle Decimal, for example with str(value) or json.dumps(..., default=str).

Tests

Write each test first and check that it fails on main.

  • price_usd stays exact.
    • Patch http._request_body to return a discovery body with the 36-digit price_usd and an integer price. Do not patch get_json: that would skip json.loads.
    • Assert that price_usd == Decimal("0.0000027777777777777777777777777777") and that price is still an int.
    • On main, price_usd is a float, which never equals that Decimal.
  • Other responses still return floats. request_json with no parse_float still returns a float for a number with a fraction.
  • A Decimal price is accepted. _live_runner_price_info_from_json({"price": Decimal("0.5"), ...}) returns price info, not None.

Not this

  • Do not convert wei to USD in the SDK. price_usd is the node's own figure.
  • Do not fill in a missing currency or unit. That is handled elsewhere (_pad_runner_price and call_runner).
  • Do not change how JSON is parsed in every request_json call.
Ngôn ngữ chính
Python
Star
1
Fork
10
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
7

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của livepeer/livepeer-python-gateway

Tất cả issue của livepeer/livepeer-python-gateway

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.