From 9077818238d18c62219299ec6e68eacae60d0df5 Mon Sep 17 00:00:00 2001 From: Draco Date: Mon, 28 Jul 2025 13:24:09 -0400 Subject: [PATCH 1/4] feat: add BlockDatabase interface to database --- database/database.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/database/database.go b/database/database.go index 182699949b3d..9ec9b3118c1e 100644 --- a/database/database.go +++ b/database/database.go @@ -94,3 +94,24 @@ type Database interface { io.Closer health.Checker } + +// BlockDatabase defines the interface for storing and retrieving blockchain blocks. +type BlockDatabase interface { + // WriteBlock inserts a block into the store at the given height with the specified header size. + WriteBlock(height uint64, block []byte, headerSize uint32) error + + // ReadBlock retrieves a block by its height. + ReadBlock(height uint64) ([]byte, error) + + // ReadHeader retrieves only the header portion of a block by its height. + ReadHeader(height uint64) ([]byte, error) + + // ReadBody retrieves only the body portion (excluding header) of a block by its height. + ReadBody(height uint64) ([]byte, error) + + // HasBlock checks if a block exists at the given height. + HasBlock(height uint64) (bool, error) + + // Close closes the block database. + Close() error +} From dfc987367e4b699d6dd6abf174cdaf5c26126eb5 Mon Sep 17 00:00:00 2001 From: Draco Date: Sun, 17 Aug 2025 16:47:28 -0400 Subject: [PATCH 2/4] refactor: Remove ReadHeader and ReadBody methods, and add Inspect method for reporting --- database/database.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/database/database.go b/database/database.go index 9ec9b3118c1e..c48519573f06 100644 --- a/database/database.go +++ b/database/database.go @@ -103,15 +103,12 @@ type BlockDatabase interface { // ReadBlock retrieves a block by its height. ReadBlock(height uint64) ([]byte, error) - // ReadHeader retrieves only the header portion of a block by its height. - ReadHeader(height uint64) ([]byte, error) - - // ReadBody retrieves only the body portion (excluding header) of a block by its height. - ReadBody(height uint64) ([]byte, error) - // HasBlock checks if a block exists at the given height. HasBlock(height uint64) (bool, error) + // Inspect returns a detailed report of the block database. + Inspect() (string, error) + // Close closes the block database. Close() error } From 69bc6698d3cb5f6bd2fcc0287af6af2773380e8f Mon Sep 17 00:00:00 2001 From: Draco Date: Fri, 22 Aug 2025 13:43:29 -0400 Subject: [PATCH 3/4] remove header size --- database/database.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/database.go b/database/database.go index c48519573f06..c96b66ba890a 100644 --- a/database/database.go +++ b/database/database.go @@ -97,8 +97,8 @@ type Database interface { // BlockDatabase defines the interface for storing and retrieving blockchain blocks. type BlockDatabase interface { - // WriteBlock inserts a block into the store at the given height with the specified header size. - WriteBlock(height uint64, block []byte, headerSize uint32) error + // WriteBlock inserts a block into the store at the given height. + WriteBlock(height uint64, block []byte) error // ReadBlock retrieves a block by its height. ReadBlock(height uint64) ([]byte, error) From 8fe9f45f2f6a0e53e61c4cce09e10ef08a31f65d Mon Sep 17 00:00:00 2001 From: Draco Date: Fri, 22 Aug 2025 14:19:45 -0400 Subject: [PATCH 4/4] Update database/database.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Draco --- database/database.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/database.go b/database/database.go index c96b66ba890a..9d0c9128a839 100644 --- a/database/database.go +++ b/database/database.go @@ -110,5 +110,5 @@ type BlockDatabase interface { Inspect() (string, error) // Close closes the block database. - Close() error + io.Closer }