Skip to content

feat: evict headers alongside blocks#340

Open
cgeorgii wants to merge 1 commit intomainfrom
feat/header-eviction
Open

feat: evict headers alongside blocks#340
cgeorgii wants to merge 1 commit intomainfrom
feat/header-eviction

Conversation

@cgeorgii
Copy link
Member

Extends the eviction component to also evict headers periodically.

  • HeaderRepo.evictHeaders deletes headers with no associated tags and returns the count; header_receipts are removed via ON DELETE CASCADE
  • Headers are kept if they have a header_tag or if their hash appears in block_tags (i.e. the corresponding block is tagged)
  • BlockEviction component now calls both evictBlocks and evictHeaders, reporting counts as evicted.blocks / evicted.headers span attributes
  • Integration tests cover: empty table, untagged eviction, header-tagged retention, block-tagged retention, receipt cascade, mixed tagged/untagged

@cgeorgii cgeorgii requested a review from Gipphe March 18, 2026 14:36
  Extends the periodic eviction component (renamed from `BlockEviction` to
  `Eviction`) to also evict headers and their receipts.

  **Eviction rules (symmetric for blocks and headers):**
  - A hash tagged in `block_tags` protects both the block and the header
  - A hash tagged in `header_tags` protects both the header and the block
  - `header_receipts` are removed automatically via `ON DELETE CASCADE`
@cgeorgii cgeorgii force-pushed the feat/header-eviction branch from 6d688c2 to d41f77b Compare March 19, 2026 12:47
getEvictableHeaderHashesQuery =
Rel8.run . Rel8.select $ do
header <- Rel8.each HeadersSchema.schema
hasHeaderTag <- headerHasTag header.hash
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: Use Hoard.DB.Schemas.HeaderTags.hashHasTag.

Suggested change
hasHeaderTag <- headerHasTag header.hash
hasHeaderTag <- HeaderTagsSchema.hashHasTag header.hash

Comment on lines +156 to +160
headerHasTag :: Rel8.Expr BlockHash -> Rel8.Query (Rel8.Expr Bool)
headerHasTag hash = Rel8.exists $ do
tagRow <- Rel8.each HeaderTagsSchema.schema
where_ $ tagRow.hash ==. hash
pure tagRow
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: Use Hoard.DB.Schemas.HeaderTags.hashHasTag.

Suggested change
headerHasTag :: Rel8.Expr BlockHash -> Rel8.Query (Rel8.Expr Bool)
headerHasTag hash = Rel8.exists $ do
tagRow <- Rel8.each HeaderTagsSchema.schema
where_ $ tagRow.hash ==. hash
pure tagRow

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops, I extracted it but forgot to use it :/

Copy link
Collaborator

@Gipphe Gipphe Mar 19, 2026

Choose a reason for hiding this comment

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

question: Should this file be migrated into test/Integration/Hoard/DB/EvictionSpec.hs?

As in: is it a relic of a HeaderEviction component that existed in the past, or is it just that it makes sense to keep as a separate spec suite?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it is. I decided to join the two modules and forgot the specs.

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.

2 participants