Documentation
¶
Index ¶
- Constants
- Variables
- type BlockData
- type BlockHeight
- type Database
- type DatabaseConfig
- func (c DatabaseConfig) Validate() error
- func (c DatabaseConfig) WithCheckpointInterval(interval uint64) DatabaseConfig
- func (c DatabaseConfig) WithDataDir(dataDir string) DatabaseConfig
- func (c DatabaseConfig) WithDir(directory string) DatabaseConfig
- func (c DatabaseConfig) WithIndexDir(indexDir string) DatabaseConfig
- func (c DatabaseConfig) WithMaxDataFileSize(maxSize uint64) DatabaseConfig
- func (c DatabaseConfig) WithMaxDataFiles(maxFiles int) DatabaseConfig
- func (c DatabaseConfig) WithMinimumHeight(minHeight uint64) DatabaseConfig
- func (c DatabaseConfig) WithSyncToDisk(syncToDisk bool) DatabaseConfig
Constants ¶
const ( // IndexFileVersion is the version of the index file format. IndexFileVersion uint64 = 1 // BlockEntryVersion is the version of the block entry. BlockEntryVersion uint16 = 1 )
const DefaultMaxDataFileSize = 500 * 1024 * 1024 * 1024
DefaultMaxDataFileSize is the default maximum size of the data block file in bytes (500GB).
const DefaultMaxDataFiles = 10
DefaultMaxDataFiles is the default maximum number of data files descriptors cached.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database stores blockchain blocks on disk and provides methods to read and write blocks.
func New ¶
func New(config DatabaseConfig, log logging.Logger) (*Database, error)
New creates a block database. Parameters:
- config: Configuration parameters
- log: Logger instance for structured logging
func (*Database) Get ¶
func (s *Database) Get(height BlockHeight) (BlockData, error)
Get retrieves a block by its height. Returns database.ErrNotFound if the block is not found.
type DatabaseConfig ¶
type DatabaseConfig struct {
// IndexDir is the directory where the index file is stored.
IndexDir string
// DataDir is the directory where the data files are stored.
DataDir string
// MinimumHeight is the lowest block height tracked by the database.
MinimumHeight uint64
// MaxDataFileSize sets the maximum size of the data block file in bytes.
MaxDataFileSize uint64
// MaxDataFiles is the maximum number of data files descriptors cached.
MaxDataFiles int
// CheckpointInterval defines how frequently (in blocks) the index file header is updated (default: 1024).
CheckpointInterval uint64
// SyncToDisk determines if fsync is called after each write for durability.
SyncToDisk bool
}
DatabaseConfig contains configuration parameters for BlockDB.
func DefaultConfig ¶
func DefaultConfig() DatabaseConfig
DefaultConfig returns the default options for BlockDB.
func (DatabaseConfig) Validate ¶
func (c DatabaseConfig) Validate() error
Validate checks if the store options are valid.
func (DatabaseConfig) WithCheckpointInterval ¶
func (c DatabaseConfig) WithCheckpointInterval(interval uint64) DatabaseConfig
WithCheckpointInterval returns a copy of the config with CheckpointInterval set to the given value.
func (DatabaseConfig) WithDataDir ¶
func (c DatabaseConfig) WithDataDir(dataDir string) DatabaseConfig
WithDataDir returns a copy of the config with DataDir set to the given value.
func (DatabaseConfig) WithDir ¶
func (c DatabaseConfig) WithDir(directory string) DatabaseConfig
WithDir sets both IndexDir and DataDir to the given value.
func (DatabaseConfig) WithIndexDir ¶
func (c DatabaseConfig) WithIndexDir(indexDir string) DatabaseConfig
WithIndexDir returns a copy of the config with IndexDir set to the given value.
func (DatabaseConfig) WithMaxDataFileSize ¶
func (c DatabaseConfig) WithMaxDataFileSize(maxSize uint64) DatabaseConfig
WithMaxDataFileSize returns a copy of the config with MaxDataFileSize set to the given value.
func (DatabaseConfig) WithMaxDataFiles ¶
func (c DatabaseConfig) WithMaxDataFiles(maxFiles int) DatabaseConfig
WithMaxDataFiles returns a copy of the config with MaxDataFiles set to the given value.
func (DatabaseConfig) WithMinimumHeight ¶
func (c DatabaseConfig) WithMinimumHeight(minHeight uint64) DatabaseConfig
WithMinimumHeight returns a copy of the config with MinimumHeight set to the given value.
func (DatabaseConfig) WithSyncToDisk ¶
func (c DatabaseConfig) WithSyncToDisk(syncToDisk bool) DatabaseConfig
WithSyncToDisk returns a copy of the config with SyncToDisk set to the given value.