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

Storage Fees - Storage Updates #76

Merged

Conversation

janezpodhostnik
Copy link
Contributor

ref: onflow/flow#99

  • Update storage_used when updating register values.
  • Create storage_used register when creating a new account

@janezpodhostnik janezpodhostnik self-assigned this Oct 16, 2020
@janezpodhostnik janezpodhostnik changed the title Janez/storage fees storage updates Storage Fees - Storage Updates Oct 16, 2020
@janezpodhostnik

This comment has been minimized.

@ramtinms ramtinms requested a review from m4ksio October 19, 2020 18:03
@janezpodhostnik janezpodhostnik marked this pull request as ready for review October 20, 2020 19:29
@janezpodhostnik janezpodhostnik marked this pull request as draft October 27, 2020 21:58
@janezpodhostnik
Copy link
Contributor Author

Converting to draft, because I want to move the logic to accounts.go

@janezpodhostnik janezpodhostnik marked this pull request as ready for review November 2, 2020 16:04
Copy link
Contributor

@psiemens psiemens left a comment

Choose a reason for hiding this comment

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

Nice!

engine/execution/state/delta/view.go Show resolved Hide resolved
fvm/state/accounts.go Outdated Show resolved Hide resolved
fvm/state/accounts.go Outdated Show resolved Hide resolved
fvm/state/accounts.go Outdated Show resolved Hide resolved
fvm/state/accounts_test.go Show resolved Hide resolved
fvm/state/accounts.go Outdated Show resolved Hide resolved
Comment on lines -54 to -62
// Delete records a deletion in this delta.
func (d Delta) Delete(owner, controller, key string) {
k := toString(owner, controller, key)
d.Data[k] = flow.RegisterEntry{
Key: toRegisterID(owner, controller, key),
Value: nil,
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Are we sure about removing this? I thought we kept this as part of the API for the future supporting of deletion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The delete on the delta was not used anywhere except in the delete of the view. I figured these were two code paths that are doing the same thing, so any changes in one would also need to be made on the other. That is why I thought removing the explicit delete would simplify the code.

I didn't know about any future plan for supporting deletion. I can re-add this.

Copy link
Member

Choose a reason for hiding this comment

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

if we are not using it all good on my side

Comment on lines +324 to +328
if isController {
a.ledger.Set(string(address.Bytes()), string(address.Bytes()), key, value)
} else {
a.ledger.Set(string(address.Bytes()), "", key, value)
}
Copy link
Member

Choose a reason for hiding this comment

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

is the controller still a thing we need to cover from the past @m4ksio ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think so, we should be able to get rid of it (we can start just by setting it to "" in this PR)

fvm/state/accounts.go Outdated Show resolved Hide resolved
Comment on lines +97 to 100
v, _ := e.accounts.GetValue(
flow.BytesToAddress(owner),
string(key),
)
Copy link
Member

Choose a reason for hiding this comment

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

This assumes every register is owned by an account, are we okey with this assumption?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not all registers are owned by addresses, but all owners that go currently through this function are addresses. I think that the owner here was always intended to be an address. The comments even state so

// GetValue gets a value for the given key in the storage, owned by the given account.
GetValue(owner, key []byte) (value []byte, err error)
// SetValue sets a value for the given key in the storage, owned by the given account.
SetValue(owner, key, value []byte) (err error)

I wanted to change the interface in cadence to accept an address instead of a byte array in a separate PR (before merging the storage feature branch into master).

@turbolent do you think there is a problem with owner having the type of Address in these two functions?

Copy link
Member

Choose a reason for hiding this comment

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

When we started working on the interface we didn’t quite know yet if we would ever have another kind of key, so we used the lowest level type possible, a byte array.

I think it's OK to change this now, though it'll be a breaking change – given that the interface is only implemented/used by Flow code, and no users are using it yet, that should be fine though.

fvm/state/accounts.go Outdated Show resolved Hide resolved
fvm/state/accounts.go Outdated Show resolved Hide resolved
return err
}

sizeChange := int64(len(value) - len(oldValue))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not using the key part as part of storage used yet. I want to add that in a different PR as it needs a few more changes.

@janezpodhostnik janezpodhostnik merged commit ba6c009 into feature/storage-fees Nov 17, 2020
@janezpodhostnik janezpodhostnik deleted the janez/storage-fees-storage-updates branch November 17, 2020 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants