Skip to content

Move storage utils into storage pkg#15

Merged
elizabethengelman merged 3 commits intostagingfrom
rename-storage-utils
Dec 13, 2019
Merged

Move storage utils into storage pkg#15
elizabethengelman merged 3 commits intostagingfrom
rename-storage-utils

Conversation

@elizabethengelman
Copy link
Copy Markdown

This was cut from #8.

In lieu of renaming libraries/shared/storage/utils -> libraries/shared/storage/diff I just moved those files out into the main libraries/shared/storage dir. I didn't see a huge need for another package within the storage package, since all of the storage interactions in here are with storage diffs specifically. Happy to have change this if folks think that a diff directory would be helpful in breaking this package up some more.

Copy link
Copy Markdown

@gslaughl gslaughl left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Copy Markdown

@rmulhol rmulhol left a comment

Choose a reason for hiding this comment

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

LGTM 👍

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/makerdao/vulcanizedb/libraries/shared/factories/storage"
storage_factory "github.com/makerdao/vulcanizedb/libraries/shared/factories/storage"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Doesn't need to be addressed in this PR, but I'm not totally clear on how we distinguish what goes in /factories/storage vs /storage - and the fact that they're both useful for storage transformers probably makes this kind of aliasing necessary all over the place. Would be cool to reorganize stuff so that we only have one storage package likely to be imported in a given namespace

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Totally agree! I think this fits into the bigger restructuring of the project that we've mentioned - I'll add a story so we can set aside some time to do some deeper digging into how we want to structure things.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/statediff"
"github.com/makerdao/vulcanizedb/libraries/shared/storage/utils"
storage_pkg "github.com/makerdao/vulcanizedb/libraries/shared/storage"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why alias here?

Copy link
Copy Markdown
Author

@elizabethengelman elizabethengelman Dec 12, 2019

Choose a reason for hiding this comment

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

On line #63 we use storage as a reference to an account's storage, so we get a naming collision. I suppose instead of using a pkg alias, I could rename the storage variable to be accountStorage or something:

for _, accountStorage := range account.Storage {
    diff, formatErr := storage_pkg.FromGethStateDiff(account, stateDiff, accountStorage)
    ...
}

Do you have a preference? 🤔

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yeah I generally prefer renaming vars vs imports, but it's no big deal - just drawing from https://github.com/golang/go/wiki/CodeReviewComments#imports


type KeysLoader interface {
LoadMappings() (map[common.Hash]utils.StorageValueMetadata, error)
LoadMappings() (map[common.Hash]storage.StorageValueMetadata, error)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can probably rename this to just ValueMetadata if it lives in the storage pkg

metadata, ok = lookup.mappings[key]
if !ok {
return metadata, utils.ErrStorageKeyNotFound{Key: key.Hex()}
return metadata, storage.ErrStorageKeyNotFound{Key: key.Hex()}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similar thing here - thinking storage.ErrKeyNotFound would be sufficient

var (
fakeMetadata = utils.GetStorageValueMetadata("name", map[utils.Key]string{}, utils.Uint256)
lookup storage.KeysLookup
fakeMetadata = storage.GetStorageValueMetadata("name", map[storage.Key]string{}, storage.Uint256)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

GetValueMetadata

}

func (transformer Transformer) Execute(diff utils.PersistedStorageDiff) error {
func (transformer Transformer) Execute(diff storage.PersistedStorageDiff) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe this can just be PersistedDiff

ID: rand.Int63(),
HeaderID: fakeHeaderID,
RawStorageDiff: utils.RawStorageDiff{
RawStorageDiff: storage.RawStorageDiff{
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

RawDiff?

@rmulhol
Copy link
Copy Markdown

rmulhol commented Dec 11, 2019

Cool to re-target this PR at staging now that #8 is merged?

@elizabethengelman elizabethengelman merged commit 4558820 into staging Dec 13, 2019
@elizabethengelman elizabethengelman deleted the rename-storage-utils branch December 13, 2019 16:16
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.

3 participants