mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
core, triedb: polish
This commit is contained in:
parent
90d9e313f4
commit
a86e67dfa8
3 changed files with 14 additions and 7 deletions
|
|
@ -1138,7 +1138,6 @@ func (t *freezerTable) RetrieveBytes(item, offset, length uint64) ([]byte, error
|
|||
|
||||
// Perform the partial read if no-compression was enabled upon
|
||||
if t.config.noSnappy {
|
||||
// Range check before reading
|
||||
if offset > uint64(itemSize) || offset+length > uint64(itemSize) {
|
||||
return nil, fmt.Errorf("requested range out of bounds: item size %d, offset %d, length %d", itemSize, offset, length)
|
||||
}
|
||||
|
|
@ -1151,12 +1150,14 @@ func (t *freezerTable) RetrieveBytes(item, offset, length uint64) ([]byte, error
|
|||
}
|
||||
return buf, nil
|
||||
} else {
|
||||
// If compressed, read the full item, decompress, then slice.
|
||||
// Unfortunately, in this case, there is no performance gain
|
||||
// by performing the partial read at all.
|
||||
buf := make([]byte, itemSize)
|
||||
_, err = dataFile.ReadAt(buf, int64(itemStart))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// If compressed, read the full item, decompress, then slice
|
||||
data, err := snappy.Decode(nil, buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -1606,6 +1606,12 @@ func TestFreezerAncientBytes(t *testing.T) {
|
|||
if !bytes.Equal(got, full) {
|
||||
t.Fatalf("full read mismatch for entry %d", i)
|
||||
}
|
||||
// Empty read
|
||||
got, err = f.RetrieveBytes(uint64(i), 0, 0)
|
||||
require.NoError(t, err)
|
||||
if !bytes.Equal(got, full[:0]) {
|
||||
t.Fatalf("empty read mismatch for entry %d", i)
|
||||
}
|
||||
// Middle slice
|
||||
got, err = f.RetrieveBytes(uint64(i), 10, 50)
|
||||
require.NoError(t, err)
|
||||
|
|
|
|||
|
|
@ -145,10 +145,10 @@ func (r *historyReader) readAccountMetadata(address common.Address, historyID ui
|
|||
// state history.
|
||||
func (r *historyReader) readStorageMetadata(storageKey common.Hash, storageHash common.Hash, historyID uint64, slotOffset, slotNumber int) ([]byte, error) {
|
||||
data, err := rawdb.ReadStateStorageIndex(r.freezer, historyID, slotIndexSize*slotOffset, slotIndexSize*slotNumber)
|
||||
if err != nil || len(data) != slotIndexSize*slotNumber {
|
||||
return nil, fmt.Errorf("storage indices is truncated, historyID: %d, size: %d, offset: %d, length: %d", historyID, len(data), slotOffset, slotNumber)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("id: %d, slot-offset: %d, slot-length: %d", historyID, slotOffset, slotNumber)
|
||||
return nil, fmt.Errorf("storage indices corrupted, %s, %w", msg, err)
|
||||
}
|
||||
|
||||
// TODO(rj493456442) get rid of the metadata resolution
|
||||
var (
|
||||
m meta
|
||||
|
|
@ -187,7 +187,7 @@ func (r *historyReader) readAccount(address common.Address, historyID uint64) ([
|
|||
offset := int(binary.BigEndian.Uint32(metadata[common.AddressLength+1 : common.AddressLength+5])) // four bytes for the account data offset
|
||||
|
||||
data, err := rawdb.ReadStateAccountHistory(r.freezer, historyID, offset, length)
|
||||
if err != nil || len(data) != length {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("account data is truncated, address: %#x, historyID: %d, size: %d, offset: %d, len: %d", address, historyID, len(data), offset, length)
|
||||
}
|
||||
return data, nil
|
||||
|
|
@ -214,7 +214,7 @@ func (r *historyReader) readStorage(address common.Address, storageKey common.Ha
|
|||
offset := int(binary.BigEndian.Uint32(slotMetadata[common.HashLength+1 : common.HashLength+5])) // four bytes for slot data offset
|
||||
|
||||
data, err := rawdb.ReadStateStorageHistory(r.freezer, historyID, offset, length)
|
||||
if err != nil || len(data) != length {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("storage data is truncated, address: %#x, key: %#x, historyID: %d, size: %d, offset: %d, len: %d", address, storageKey, historyID, len(data), offset, length)
|
||||
}
|
||||
return data, nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue