Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy slice when setting block hash list #6734

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions fvm/evm/handler/blockHashList.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func (bhl *BlockHashList) Push(height uint64, bh gethCommon.Hash) error {
if !bhl.IsEmpty() && height != bhl.height+1 {
return fmt.Errorf("out of the order block hash, expected: %d, got: %d", bhl.height+1, height)
}

// updates the block hash stored at index
err := bhl.updateBlockHashAt(bhl.tail, bh)
if err != nil {
Expand Down Expand Up @@ -147,19 +148,22 @@ func (bhl *BlockHashList) updateBlockHashAt(idx int, bh gethCommon.Hash) error {
// fetch the bucket
bucketNumber := idx / hashCountPerBucket
bucket, err := bhl.fetchBucket(bucketNumber)
cpy := make([]byte, len(bucket))
copy(cpy, bucket)

if err != nil {
return err
}
Comment on lines +151 to 156
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cpy := make([]byte, len(bucket))
copy(cpy, bucket)
if err != nil {
return err
}
if err != nil {
return err
}
cpy := make([]byte, len(bucket))
copy(cpy, bucket)

// update the block hash
start := (idx % hashCountPerBucket) * hashEncodingSize
end := start + hashEncodingSize
copy(bucket[start:end], bh.Bytes())
copy(cpy[start:end], bh.Bytes())

// store bucket
return bhl.backend.SetValue(
bhl.rootAddress[:],
[]byte(fmt.Sprintf(blockHashListBucketKeyFormat, bucketNumber)),
bucket,
cpy,
)
}

Expand Down
Loading