Skip to content

fix: invalidate principal ETag on matured miner rewards and their re-orgs - #2704

Merged
rafa-stacks merged 1 commit into
mainfrom
miner-etag
Oct 6, 2026
Merged

rafa-stacks merged 1 commit into
mainfrom
miner-etag

Conversation

@rafa-stacks

@rafa-stacks rafa-stacks commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Principal ETags ignored miner rewards, so cached STX balances went stale whenever a reward matured or a re-org orphaned one.

  • getPrincipalLastActivityTxIds now also returns the latest canonical matured reward for the recipient as mature_block_height:index_block_hash.
  • The principal ETag hash includes that value, and reward-only principals now get an ETag instead of ETAG_EMPTY.
  • New migration adds a partial index miner_rewards (recipient, mature_block_height DESC) WHERE canonical = true.

@codecov

codecov Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.55072% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...00000027_miner-rewards-recipient-maturity-index.ts 96.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation correctly invalidates principal ETags for miner reward changes and includes focused regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Adds miner rewards to principal ETag calculation, preventing stale cached STX balances after reward maturation or reorganization.

Changes:

  • Includes the latest canonical matured miner reward in principal ETags.
  • Adds a partial index supporting efficient reward lookup.
  • Adds coverage for reward maturation, rollback, and reward-only principals.
File Description
src/​datastore/​pg-store.ts Retrieves the latest canonical reward for ETag generation.
src/​api/​controllers/​cache-controller.ts Incorporates reward state into principal ETags.
migrations/​1779800000027_miner-rewards-recipient-maturity-index.ts Adds the supporting partial index.
tests/​api/​cache/​cache-control.test.ts Tests reward-driven cache invalidation and reward-only principals.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@rafa-stacks
rafa-stacks marked this pull request as ready for review October 6, 2026 14:32
@rafa-stacks
rafa-stacks merged commit 21e2c31 into main Oct 6, 2026
27 checks passed
@rafa-stacks
rafa-stacks deleted the miner-etag branch October 6, 2026 14:54

This branch was successfully deployed

1 active deployment
Production — 4975a3a7 Deployed Oct 6, 2026 by rafa-stacks via build-publish #3808
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants