Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

discover_runners: keep livepeer/node price_usd exact

Aperta
#88 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
api

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
Python
Stelle
1
Fork
10
Merge medio
1g 9h
PR unite (30g)
7

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di livepeer/livepeer-python-gateway

Tutte le issue di livepeer/livepeer-python-gateway

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.