klaim: math jendela UTC-naive (V49/B13): _utcnow() di step/poll_claim/_try_claim_once konsisten dgn last_claim_time chain — ⊥ datetime.now() lokal (TZ Asia/Jakarta) yang menggeser jendela ~7 jam → poll prematur ditolak chain → retry tanpa henti ; oracle UTC + image claim rebuild + push

This commit is contained in:
proitlab committed 2026-08-07 22:34:57 +07:00
1 parent 0e83137b5a
commit 642822989c
4 files changed
+48 -22

No files matched your search

+18 -6
View File
@@ -1,7 +1,8 @@
"""Klaim reward BP + transfer fee harian: `vexcore::claimrewards` utk TARGET_BP.
Setiap siklus (V32..V34): tentukan jendela klaim = `last_claim_time` (tabel
`producers`) + 24 jam, tidur sampai mendekatinya, lalu poll `claimrewards`
`producers`) + 24 jam (math UTC-naive via `_utcnow`, konsisten dgn stempel
chain; V49/B13), tidur sampai mendekatinya, lalu poll `claimrewards`
tiap `CLAIM_RETRY_SECONDS` sampai diterima chain. Jendela yang sudah lewat
(≥24 jam sejak last) → klaim dikejar segera (recovery, ⊥ spin-timeout
selamanya). Landing dikonfirmasi via Hyperion `executed` ATAU `last_claim_time`
@@ -22,7 +23,7 @@ Modul logika (⊥ CLI) — `claim_loop.py` yang menjalankan loop tak-berhenti.
"""
import time
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from decimal import Decimal, ROUND_FLOOR, InvalidOperation
import db
@@ -37,6 +38,16 @@ SETTLE_SECONDS = 10 # tunggu finalitas sebelum baca saldo setelah klaim
POLL_SPAN_SECONDS = 7200 # batas poll sekali jendela (2 jam)
def _utcnow():
"""UTC-naive `datetime.now()` — konsisten dgn `last_claim_time` chain
(Vexanium mengembalikan UTC) & `get_voters`/`dashboard` (V49).
Memakai waktu lokal (`datetime.now()`, TZ container Asia/Jakarta) untuk
math jendela 24 jam membuat jendela maju ~7 jam lebih awal → poll ditolak
chain → retry tanpa henti (B13)."""
return datetime.now(timezone.utc).replace(tzinfo=None)
def _post_json(url, payload, max_retries=3, timeout=30):
"""POST JSON dengan retry (node publik flaky) — pola `get_voters`."""
for attempt in range(max_retries):
@@ -88,7 +99,8 @@ def next_window(now):
Pembacaan `last_claim_time` node flaky di-retry: bila SEMUA pembacaan
gagal/kosong → raise (loop catch-and-sleep, ⊥ clamp ke now prematur yang
memicu percobaan klaim sebelum jendela → ditolak chain). `now` hanya utk
pembacaan yang BENAR-BENAR berhasil tanpa klaim sebelumnya (BP baru)."""
pembacaan yang BENAR-BENAR berhasil tanpa klaim sebelumnya (BP baru).
`now` & `last_claim_time` sama-sama UTC-naive (V49/B13)."""
raw = None
for _ in range(3):
try:
@@ -241,7 +253,7 @@ def _try_claim_once():
'— retry (⊥ catat sukses)', flush=True)
return 'retry'
reward = _measure_reward(txid, before)
now = datetime.now()
now = _utcnow()
now_iso = now.isoformat(timespec='seconds')
txid_label = txid[:16] + '...' if txid else '?'
if reward is None:
@@ -267,7 +279,7 @@ def poll_claim(deadline):
Return `claimed` | `timeout` (deadline lewat — jadwal dihitung ulang).
"""
while datetime.now() < deadline:
while _utcnow() < deadline:
status = _try_claim_once()
if status == 'claimed':
return 'claimed'
@@ -315,7 +327,7 @@ def step():
claim = db.pending_claim_fee()
if claim is not None:
return 'fee_sent' if _send_fee(claim) else 'fee_failed'
now = datetime.now()
now = _utcnow()
window = next_window(now)
margin = timedelta(seconds=CLAIM_RETRY_SECONDS)
if now < window - margin: