-
Notifications
You must be signed in to change notification settings - Fork 810
feat: add in memory implementation of HeightIndex Database #4212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 introduces an in-memory implementation of the BlockDatabase interface for testing purposes, allowing tests to avoid using on-disk storage when not necessary.
- Adds a new
MemoryDatabase
struct that implements theBlockDatabase
interface - Provides thread-safe operations using read-write mutexes
- Includes proper error handling for closed database states and empty blocks
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
6501406
to
01d9423
Compare
3e996ff
to
88f2394
Compare
database/database.go
Outdated
// Has checks if an entry exists at the given height. | ||
// Has checks if a value exists at the given height. | ||
// | ||
// Return true even if the stored value is nil, or empty. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also confused here, I thought Get
returned nil
if you inserted empty - why does Has
return nil or empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is to clarify Has
returns true
if the value at the key is nil or empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment nits then lgtm
Why this should be merged
Adds an in memory implementation of
database.HeightIndex
. The main use of this will be in tests where we don't need a on-disk height-indexed database.How this works
The package is in
database/heightindexdb/memdb
. It uses a map to store data by height.How this was tested
Unit tests
Need to be documented in RELEASES.md?
No