Skip to content

fix: payout rounding drift, Kaspa shared-template nonce race, and lost aux submissions - #14

Merged
colneech-dev merged 1 commit into
mainfrom
fix/payout-rounding-kaspa-race-aux-submit
Nov 24, 2026
Merged

colneech-dev merged 1 commit into
mainfrom
fix/payout-rounding-kaspa-race-aux-submit

Conversation

@colneech-dev

Copy link
Copy Markdown
Owner

Summary

  • BitcoinPayoutHandler: the sendmany branch rounded the amount sent on-chain but debited/recorded the un-rounded balance, silently destroying the sub-unit remainder every payout. Now debits and records exactly what was sent.
  • KaspaJob: ProcessShareInternal mutated the shared BlockTemplate.Header.Nonce in place then read it back - a real race under concurrent share submission (normal traffic) that could validate a share against the wrong nonce. Now works on a per-call clone of the header.
  • AuxPowManager / BitcoinJobManager: a transport failure/timeout submitting an aux block was treated the same as a definite rejection, so the pool silently lost track of aux blocks that may have actually been accepted server-side. Now surfaces an admin notification and keeps the dedup entry instead of guessing and silently dropping it.

Test plan

  • dotnet build (Release, SkipNativeLibBuild=true) — 0 errors, only pre-existing warnings
  • Not yet exercised against live concurrent Kaspa submissions or a real aux-daemon timeout

🤖 Generated with Claude Code

…t aux submissions

BitcoinPayoutHandler (sendmany branch): the amount actually sent on-chain was
rounded to payoutDecimalPlaces, but the balance debited afterwards and the
Payment row recorded were the un-rounded amount. The sub-unit remainder was
silently destroyed on every payout instead of staying in the miner's balance
for a future cycle. Now debits and records exactly the rounded amount that
was sent (via a new payoutBalances array built from the same rounded
`amounts` dictionary used for the RPC call); the per-sendtoaddress fallback
branch already did this correctly and is unchanged.

KaspaJob.ProcessShareInternal: mutated the shared BlockTemplate.Header.Nonce
in place, then read it back to serialize/hash. BlockTemplate is shared
across every connection working this job, so two shares submitted
concurrently (normal under real traffic) could interleave: one thread sets
the nonce, another thread's SerializeHeader runs against that nonce before
the first thread reads it back, so a share gets validated against the wrong
nonce entirely. Now clones the header per call and works on the clone, never
touching the shared BlockTemplate.

AuxPowManager.SubmitAuxBlockAsync / BitcoinJobManager: a submitblock/
getauxblock transport failure or timeout was treated identically to a
definite daemon rejection - the caller removed the dedup entry and recorded
nothing, even though the daemon may have already accepted the block
server-side before the connection dropped. That silently lost the aux block
(and its reward) with no trace. Now distinguishes "outcome unknown" (via the
existing PayoutErrorClassifier.IsOutcomeUnknown) from a definite rejection:
on an unknown outcome, logs an error, sends an AdminNotification, keeps the
dedup entry (never resubmits it) and skips the DB write - the admin is
expected to verify the aux chain manually rather than the pool silently
guessing either way.

Build-verified: dotnet build (Release, SkipNativeLibBuild=true), 0 errors.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@colneech-dev
colneech-dev merged commit 3812e1e into main Nov 24, 2026
1 check passed
@colneech-dev
colneech-dev deleted the fix/payout-rounding-kaspa-race-aux-submit branch November 24, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant