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

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Changes from 1 commit
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
}
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)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good point, we can perform the bucket copy, after we know there's no error.

// 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