Skip to content

Commit

Permalink
Do not mutate function argument of GetSnapshotAt
Browse files Browse the repository at this point in the history
Co-authored-by: Leo Zhang <[email protected]>
  • Loading branch information
m-Peter and zhangchiqing authored Feb 21, 2025
1 parent ea6e833 commit b92120d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions storage/pebble/register_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,17 @@ func newLookupKey(height uint64, key []byte) *lookupKey {
func (r *RegisterStorage) GetSnapshotAt(
evmBlockHeightOfStartStateToQuery uint64,
) (types.BackendStorageSnapshot, error) {
// Avoid a possible underflow
var snapshotHeightOfEndState uint64
if evmBlockHeightOfStartStateToQuery > 0 {
// `evmBlockHeightOfStartStateToQuery-1` to get the end state of the previous block.
evmBlockHeightOfStartStateToQuery -= 1
snapshotHeightOfEndState = evmBlockHeightOfStartStateToQuery - 1
} else {
// Avoid a possible underflow
snapshotHeightOfEndState = uint64(0)
}
return NewStorageSnapshot(r.Get, evmBlockHeightOfStartStateToQuery), nil

// NewStorageSnapshot return the end state of a given height.
return NewStorageSnapshot(r.Get, snapshotHeightOfEndState), nil
}

func registerOwnerMismatch(expected flow.Address, owner flow.Address) error {
Expand Down

0 comments on commit b92120d

Please sign in to comment.