Skip to content

Commit

Permalink
Merge pull request #397 from onflow/gregor/decode-fix
Browse files Browse the repository at this point in the history
Return storage copy of data
  • Loading branch information
sideninja authored Jul 29, 2024
2 parents d61e717 + fef1458 commit d1e1ffd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 0 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,6 @@ func (b *BlockChainAPI) prepareBlockResponse(
fullTx bool,
) (*Block, error) {
h, err := block.Hash()
fmt.Println("### HASH", h)
if err != nil {
b.logger.Error().Err(err).Msg("failed to calculate hash for block by number")
return nil, errs.ErrInternal
Expand Down
6 changes: 5 additions & 1 deletion storage/pebble/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func (s *Storage) get(keyCode byte, key ...[]byte) ([]byte, error) {
prefixedKey := makePrefix(keyCode, key...)

data, closer, err := s.db.Get(prefixedKey)
// temp workaround to a weird bug where the data changes after returned
cp := make([]byte, len(data))
copy(cp, data)

if err != nil {
if errors.Is(err, pebble.ErrNotFound) {
return nil, errs.ErrNotFound
Expand All @@ -102,7 +106,7 @@ func (s *Storage) get(keyCode byte, key ...[]byte) ([]byte, error) {
}
}(closer)

return data, nil
return cp, nil
}

// batchGet loads the value from an indexed batch if data is found, else it loads the value from the storage.
Expand Down

0 comments on commit d1e1ffd

Please sign in to comment.