Skip to content

Conversation

DracoLi
Copy link
Contributor

@DracoLi DracoLi commented Sep 23, 2025

Why this should be merged

Follow up to #4133, update x/blockdb Database to align with the database.HeightIndex interface and use the errors from database/errors.go for database closed and not found.

How this works

  • Renamed public methods WriteBlock, ReadBlock, and HasBlock to Put, Get, and Has
  • Replaced ErrDatabaseClosed and ErrBlockNotFound with the common errors in database/errors.go
  • Add HeightIndex dbtests to tests and aligned behaviour

How this was tested

Unit tests

Need to be documented in RELEASES.md?

No

@Copilot Copilot AI review requested due to automatic review settings September 23, 2025 14:37
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR aligns the blockdb Database with the database.HeightIndex interface by renaming public methods and updating file naming conventions to be more generic rather than block-specific.

  • Renamed public methods WriteBlock, ReadBlock, and HasBlock to Put, Get, and Has respectively
  • Updated file naming from block-specific to generic (e.g., blockdb.idx to db.idx)
  • Renamed BlockEntryVersion constant to DataEntryVersion to reflect generic data storage

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
x/blockdb/database.go Core database implementation with method renames and constant updates
x/blockdb/writeblock_test.go Test file updated to use new Put method instead of WriteBlock
x/blockdb/readblock_test.go Test file updated to use new Get method instead of ReadBlock
x/blockdb/recovery_test.go Recovery tests updated with new method names and DataEntryVersion constant
x/blockdb/datasplit_test.go Data splitting tests updated to use new Put and Get methods
x/blockdb/database_test.go Database tests updated with new method names
Comments suppressed due to low confidence (2)

x/blockdb/readblock_test.go:1

  • The error message still references the old method name 'ReadBlock' but should be updated to 'Get' to match the renamed method.
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.

x/blockdb/recovery_test.go:1

  • [nitpick] The error message refers to ErrBlockNotFound but this constant should likely be renamed to ErrDataNotFound or similar to align with the generic nature of the database as mentioned in the PR description.
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@DracoLi DracoLi changed the title chore: align blockdb with the database.HeightIndex interface chore: align blockdb with HeightIndex interface and errors in database pkg Sep 23, 2025
@DracoLi DracoLi changed the title chore: align blockdb with HeightIndex interface and errors in database pkg chore: update blockdb to use HeightIndex interface and errors in database pkg Sep 23, 2025
@DracoLi DracoLi force-pushed the dl/blockdb-interface-adjust branch from e98ed7a to 6326739 Compare September 23, 2025 15:17
@DracoLi DracoLi requested review from a team and rrazvan1 and removed request for a team September 23, 2025 15:50
@DracoLi
Copy link
Contributor Author

DracoLi commented Sep 23, 2025

Once #4212 is merged in. I'll also add the common interface tests to blockdb tests to ensure consistent behaviour.

@DracoLi DracoLi changed the base branch from master to dl/blockdb-memory-mock September 25, 2025 19:40
@DracoLi DracoLi force-pushed the dl/blockdb-interface-adjust branch from af3d8b1 to e3652bd Compare September 25, 2025 19:41
@DracoLi DracoLi removed the request for review from StephenButtolph September 25, 2025 19:43
@DracoLi DracoLi changed the base branch from dl/blockdb-memory-mock to master September 25, 2025 19:44
@DracoLi DracoLi changed the base branch from master to dl/blockdb-memory-mock September 25, 2025 19:44
@DracoLi DracoLi marked this pull request as draft September 30, 2025 15:27
Base automatically changed from dl/blockdb-memory-mock to master September 30, 2025 17:44
@DracoLi DracoLi force-pushed the dl/blockdb-interface-adjust branch 2 times, most recently from ebef129 to 3663e7f Compare September 30, 2025 20:07
@DracoLi DracoLi marked this pull request as ready for review September 30, 2025 21:46
@DracoLi DracoLi requested a review from joshua-kim September 30, 2025 22:13
@DracoLi DracoLi requested a review from joshua-kim October 1, 2025 16:27
@DracoLi DracoLi force-pushed the dl/blockdb-interface-adjust branch from 2ef8932 to 11cf2a0 Compare October 3, 2025 15:58
@DracoLi DracoLi force-pushed the dl/blockdb-interface-adjust branch from 11cf2a0 to 4461ccf Compare October 3, 2025 16:32
Comment on lines 181 to 186
// Verify all written blocks are readable and data is correct
for h, expectedBlock := range blocksWritten {
readBlock, err := store.ReadBlock(h)
require.NoError(t, err, "ReadBlock failed at height %d", h)
readBlock, err := store.Get(h)
require.NoError(t, err, "Get failed at height %d", h)
require.Equal(t, expectedBlock, readBlock)
}
Copy link
Contributor

@joshua-kim joshua-kim Oct 3, 2025

Choose a reason for hiding this comment

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

We test this behavior in TestWriteBlock_Basic that a block inserted via Put is returned through Get. It feels like we're duplicating coverage here, since it seems that this test is intended to verify heights.

Some ideas might be to either:

  1. Refactor the tests to share the same test table, since it seems that testing the correctness of Put requires us to verify behavior on Get and the height apis
  2. Remove this assertion entirely from this test, so we'd have a single test for Put/Get and one for Put/heights?

Copy link
Contributor Author

@DracoLi DracoLi Oct 3, 2025

Choose a reason for hiding this comment

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

I think 2 makes sense here. The basic Put/Get tests should be covered and we can focus this tests on just the height verification. I'll remove this dup assertion to keep this tests more focused

Copy link
Contributor

Choose a reason for hiding this comment

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

Sweet. We might also want to rename the tests here to reflect that the former is testing the contract between Put/Get and this one is testing the contract between Put/Height.

@joshua-kim joshua-kim enabled auto-merge October 3, 2025 18:13
@joshua-kim joshua-kim added this pull request to the merge queue Oct 3, 2025
Merged via the queue into master with commit 584c333 Oct 3, 2025
35 checks passed
@joshua-kim joshua-kim deleted the dl/blockdb-interface-adjust branch October 3, 2025 18:47
@github-project-automation github-project-automation bot moved this to Done 🎉 in avalanchego Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done 🎉
Development

Successfully merging this pull request may close these issues.

3 participants