Per review, drop the separate truncate mode and use its logic for
has_prefix instead. Order amounts are stored without trailing zeros
(1.50 as "1.5"), so the plain string prefix check let the 1.5 order
claim a 1.51 payment meant for a concurrent order on the same address.
Truncate the received amount to the larger of the atom precision and
the order's own decimals, then compare exactly: overpayment below the
atom precision still matches, underpayment and overpayment of a full
atom no longer do.
Truncate the received amount to the atom precision before an exact comparison, so overpayment below the atom precision still matches while concurrent orders on one address (1.50, 1.51, ...) never claim each other's payments.
lookbackOrdersPending ignored the query error, so a failed read counted
as "no order needs a lookback" and dropped the progress of a range that
was still needed. Return the error and keep the progress until the next
tick can check again.
syncSlotForward stops fetching the head slot as soon as any slot waits
for a retry. One slot that keeps failing with a timeout, 429 or -32004
therefore holds back every later payment until it succeeds or is given
up after about 7 minutes, although the following slots can be fetched
normally.
Pause forward scanning only when solanaForwardPauseRetries (10) slots
wait for a retry. That still stops new slots from piling into the retry
set during a node outage, while a single failing slot no longer delays
new payments.
getBlock returns -32001 (BlockCleanedUp) for a slot older than the
node's first available block. Retrying cannot succeed, yet the slot was
retried 10 times over about 7 minutes, and forward scanning stays paused
while any retry is pending.
In production a lookback range from a week earlier hit this for 627
slots at once: forward scanning stopped for about 10 minutes and the
node started to answer 429, which delayed a real payment by four
minutes.
Treat -32001 as final: log an ERROR with the slot number, clear any
retry left from an earlier failure of the same slot, and do not schedule
another one. Other errors keep the bounded retry. The existing retry
test now uses -32004 (block not available), a transient error.
lookbackSlots keeps its progress (lookbackNext/lookbackEnd) across ticks,
but returns early through syncBreak once no order needs scanning. When an
order is paid, canceled or expires before its range is fully queued, the
remainder stays in memory. The next Solana order, possibly days later,
resumes that old range first.
In production the remainder was 627 slots from a week earlier. The RPC
node had already pruned them (-32001), every slot was retried, forward
scanning paused while retries were pending, and the node started to
answer 429. A payment made 90 seconds after the order was created was
seen four minutes late.
Before resuming, check that at least one order of the range still needs
a lookback (same condition as hasLookbackOrders); otherwise drop the
remaining range. The check runs before syncBreak so the state is also
cleared while scanning is idle.
Block scanning gives every slot one chance. A skipped or abandoned slot,
a restart, or an incomplete lookback range loses a payment for good, and
nothing finds it again.
Once a Solana order has been expired for a minute (up to two hours), look
it up once in the receiving token accounts' own history:
- token accounts: the wallet's associated token account, derived locally,
plus any other account from getTokenAccountsByOwner when the node
supports it (publicnode's free tier rejects that method);
- getSignaturesForAddress back to the order's creation time, keeping
successful signatures inside the order window that no order has used;
- getTransaction, parsed with parseTransaction and checked with the
existing orderTransferMatch. A match is marked confirming and then
follows the normal confirm and callback flow.
RPC errors leave the order for the next round. Cost: a few RPC calls per
expired Solana order plus one getTransaction per candidate payment.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Move the per-transaction body of slotParse into parseTransaction so the
same parser can be used on getTransaction results. No behavior change:
`git diff -w` shows only the loop/return edits.
Add mainnet fixtures for legacy transfer (USDT), legacy transferChecked,
a transfer to a token account created in the same transaction, and a v1
transaction; expected transfers come from an independent decoder.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pendingLookbackUnix ended the lookback range at the expiry of the last
expired order in created_at order. When a batch mixes expired and still
waiting orders (common after a restart), or an earlier order has a
longer timeout, part of the other orders' windows was outside the range
but they were still marked as looked back.
End the range at the latest min(expired_at, now) over the batch. Used by
every chain's lookback.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With block_offset_confirm enabled, tradeConfirmHandle compared the
order's slot with lastSlotNum, the forward scan cursor. The cursor stops
moving once no unexpired order is pending and is 0 after a restart, so a
payment matched shortly before expiry stayed "confirming" forever.
Use result.context.slot from the same getSignatureStatuses response
instead. This also removes the unsynchronized read of lastSlotNum from
the confirm goroutines.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The jump to the latest slot when the scanner falls more than
block_height_max_diff behind is meant for resuming after an idle period
(no pending orders) or on startup. It also fired while orders were
active, e.g. after a retry pause, dropping every slot in between without
a log; payments in those slots were never matched.
Now the scanner jumps only on startup or after idling, and otherwise
logs a warning and keeps catching up within blockQueueLimit per round.
A full queue does not count as idle.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Give up a slot after 10 failed scans (about 7 minutes with the
existing backoff) and log an ERROR with the slot number. Before, a slot
that can never be fetched (e.g. "Block cleaned up", -32001) was retried
forever, and forward sync stayed paused the whole time.
- A retry is queued as soon as its timer fires instead of being
postponed while the queue is full, so a busy queue is never counted as
a failed attempt.
- Add shared task test helpers (temporary log dir and SQLite).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- slotParse ignores transactions whose meta.err is not null. Failed
transactions are still included in blocks with their instructions and
token balances, but every transfer in them was rolled back.
- tradeConfirmHandle only confirms a signature that is finalized and has
err == null; getSignatureStatuses reports failed transactions as
finalized too.
- Add mainnet fixtures (failed v1 top-level transfer, failed v0 inner
transfer, succeeded v0 inner transfer) and tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Validate getBlock JSON, JSON-RPC error, result and result.transactions;
record scan success only after a complete block is parsed.
- Treat skipped slots (result: null, -32007, -32009) as empty slots.
- Retry failed slots with bounded 2s/5s/15s/30s/60s backoff, one timer
per slot; pause forward sync while retries are pending.
- Fill the slot queue only up to blockQueueLimit per round, keeping the
existing BlockHeightMaxDiff jump-ahead.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>