core/rawdb: fill in the missing method

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2025-07-02 01:33:01 +08:00 committed by Gary Rong
parent 32884e0b43
commit 6bfd8dff52
4 changed files with 38 additions and 0 deletions

View file

@ -403,6 +403,10 @@ func (f *chainFreezer) AncientRange(kind string, start, count, maxBytes uint64)
return f.ancients.AncientRange(kind, start, count, maxBytes) return f.ancients.AncientRange(kind, start, count, maxBytes)
} }
func (f *chainFreezer) AncientBytes(kind string, item, offset, length uint64) ([]byte, error) {
return f.ancients.AncientBytes(kind, item, offset, length)
}
func (f *chainFreezer) ModifyAncients(fn func(ethdb.AncientWriteOp) error) (int64, error) { func (f *chainFreezer) ModifyAncients(fn func(ethdb.AncientWriteOp) error) (int64, error) {
return f.ancients.ModifyAncients(fn) return f.ancients.ModifyAncients(fn)
} }

View file

@ -100,6 +100,11 @@ func (db *nofreezedb) AncientRange(kind string, start, max, maxByteSize uint64)
return nil, errNotSupported return nil, errNotSupported
} }
// AncientBytes retrieves a byte range [offset:offset+length] from the specified ancient item.
func (db *nofreezedb) AncientBytes(kind string, item, offset, length uint64) ([]byte, error) {
return nil, errNotSupported
}
// Ancients returns an error as we don't have a backing chain freezer. // Ancients returns an error as we don't have a backing chain freezer.
func (db *nofreezedb) Ancients() (uint64, error) { func (db *nofreezedb) Ancients() (uint64, error) {
return 0, errNotSupported return 0, errNotSupported

View file

@ -412,3 +412,26 @@ func (f *MemoryFreezer) Reset() error {
func (f *MemoryFreezer) AncientDatadir() (string, error) { func (f *MemoryFreezer) AncientDatadir() (string, error) {
return "", nil return "", nil
} }
// AncientBytes retrieves a byte range [offset:offset+length] from the specified ancient item in memory.
func (f *MemoryFreezer) AncientBytes(kind string, item, offset, length uint64) ([]byte, error) {
f.lock.RLock()
defer f.lock.RUnlock()
table := f.tables[kind]
if table == nil {
return nil, errUnknownTable
}
entries, err := table.retrieve(item, 1, 0)
if err != nil {
return nil, err
}
if len(entries) == 0 {
return nil, errOutOfBounds
}
data := entries[0]
if offset > uint64(len(data)) || offset+length > uint64(len(data)) {
return nil, fmt.Errorf("requested range out of bounds: item size %d, offset %d, length %d", len(data), offset, length)
}
return data[offset : offset+length], nil
}

View file

@ -62,6 +62,12 @@ func (t *table) AncientRange(kind string, start, count, maxBytes uint64) ([][]by
return t.db.AncientRange(kind, start, count, maxBytes) return t.db.AncientRange(kind, start, count, maxBytes)
} }
// AncientBytes is a noop passthrough that just forwards the request to the underlying
// database.
func (t *table) AncientBytes(kind string, item, offset, length uint64) ([]byte, error) {
return t.db.AncientBytes(kind, item, offset, length)
}
// Ancients is a noop passthrough that just forwards the request to the underlying // Ancients is a noop passthrough that just forwards the request to the underlying
// database. // database.
func (t *table) Ancients() (uint64, error) { func (t *table) Ancients() (uint64, error) {