Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add `BlockRawByHash` to DB interface and `lazyBlock` type for zero-copy
per-tx block access without full deserialization
([#1051](https://github.com/hemilabs/heminetwork/pull/1051)).
- Add generic `lru` package with cost-based LRU cache (`lru.Cache[K,V]`)
([#1034](https://github.com/hemilabs/heminetwork/pull/1034)).
- Add utxo read LRU cache (`TBC_UTXO_READ_CACHE_SIZE`) to reduce LevelDB
Expand Down
1 change: 1 addition & 0 deletions database/tbcd/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ type Database interface {
BlockInsert(ctx context.Context, b *btcutil.Block) (int64, error)
// BlocksInsert(ctx context.Context, bs []*btcutil.Block) (int64, error)
BlockByHash(ctx context.Context, hash chainhash.Hash) (*btcutil.Block, error)
BlockRawByHash(ctx context.Context, hash chainhash.Hash) ([]byte, error)
BlockExistsByHash(ctx context.Context, hash chainhash.Hash) (bool, error)
BlockCacheStats() CacheStats

Expand Down
17 changes: 17 additions & 0 deletions database/tbcd/level/level.go
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,23 @@ func (l *ldb) BlockByHash(ctx context.Context, hash chainhash.Hash) (*btcutil.Bl
return b, nil
}

// BlockRawByHash returns the raw block bytes. Not cached, unlike BlockByHash.
func (l *ldb) BlockRawByHash(ctx context.Context, hash chainhash.Hash) ([]byte, error) {
log.Tracef("BlockRawByHash")
defer log.Tracef("BlockRawByHash exit")

bDB := l.rawPool[level.BlocksDB]
eb, err := bDB.Get(hash[:])
if err != nil {
if errors.Is(err, leveldb.ErrNotFound) {
return nil, database.BlockNotFoundError{Hash: hash}
}
return nil, fmt.Errorf("block raw get: %w", err)
}

return eb, nil
}

func (l *ldb) BlockExistsByHash(ctx context.Context, hash chainhash.Hash) (bool, error) {
log.Tracef("BlockExistsByHash")
defer log.Tracef("BlockExistsByHash exit")
Expand Down
4 changes: 4 additions & 0 deletions service/tbc/cpfp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func (stubDB) BlockByHash(context.Context, chainhash.Hash) (*btcutil.Block, erro
panic("stub")
}

func (stubDB) BlockRawByHash(context.Context, chainhash.Hash) ([]byte, error) {
panic("stub")
}

func (stubDB) BlockExistsByHash(context.Context, chainhash.Hash) (bool, error) {
panic("stub")
}
Expand Down
Loading