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

escrow bucket.Create does not save #170

Closed
husio opened this issue Oct 29, 2018 · 8 comments · Fixed by #201
Closed

escrow bucket.Create does not save #170

husio opened this issue Oct 29, 2018 · 8 comments · Fixed by #201
Assignees
Labels
bug A functionality that was delivered is no longer working as expected.

Comments

@husio
Copy link
Contributor

husio commented Oct 29, 2018

In package x/escrow, Bucket.Create is described to be saving the created instance (see comment), but it only creates an ID and returns entity without storing it.

Method is used in creation handler and it seems to expect the instance to be stored in the database when Create is called.

@husio husio added the invalid label Oct 29, 2018
@ruseinov
Copy link
Contributor

@husio It happens in Deposit, so all good. Just looks a bit confusing.

@husio
Copy link
Contributor Author

husio commented Oct 29, 2018

Good point.

I think the comment of the Create method should be changed then, because right now it is

// Saves the object and returns it (to inspect the ID)

@ruseinov
Copy link
Contributor

@husio sure, I'm pretty sure this was copy-pasted from other implementations as this is a pretty standard workflow.

@ruseinov
Copy link
Contributor

There's more where this is coming from, might be helpful to go through the code and see where else we are missing/have invalid comments. Makes extension development easier for newcomers and just in general.

@ethanfrey
Copy link
Contributor

Yeah, this is a bit confusing. Just update to write to the db in Create as well.

And a cleanup of comments is always welcome. Most of this code was writen quite quickly when I was the only one reading/writing the project, so happy for any fixups.

I think we are not too worried about optimizing writes yet, and they go to a memory db now. You can update this to Save in create as well (and maybe save a second time). There is an old issue to optimize the CacheWrap, so for any given key we only write at most once per block to the underlying leveldb on Commit. Right now we will replay all writes for all successful transactions, but could safely be squashed to the last write for a given key, when we need to squeeze some more performance.

@ethanfrey ethanfrey added bug A functionality that was delivered is no longer working as expected. and removed invalid labels Oct 29, 2018
@alpe
Copy link
Contributor

alpe commented Oct 29, 2018

As @husio brought this up, now. Some definition for create in this project would make sense for me. I saw this with save and without. Especially in context of nft we create first and save in a second step as some data is set/modified on the object. This can be changed by passing all data though.

@ethanfrey
Copy link
Contributor

I'm fine with any usage, but clarity and consistency is better.

It seems like we would assume a save in create, but we could also document otherwise. I think I originally conceived it as not saving, but I probably mixed it. I will defer to your decisions, but consistency is good, which this issue properly points out.

@husio
Copy link
Contributor Author

husio commented Oct 29, 2018

I think it is less surprising if Create is saving an entity. It is common for ORMs to work this way. If it is not intended to save it, maybe the method could be renamed to Build or New?

@husio husio self-assigned this Nov 27, 2018
husio added a commit that referenced this issue Nov 27, 2018
Escrow `Bucket.Create` method documentation is updated to be acurate.

fix #170
husio added a commit that referenced this issue Nov 27, 2018
Escrow `Bucket.Create` method and documentation is updated to be acurate.

fix #170
ruseinov pushed a commit that referenced this issue Nov 28, 2018
* fix bucket.Create method

Escrow `Bucket.Create` method and documentation is updated to be acurate.

fix #170

* replace escrow.Bucket.Create with Build method

Rename `Create` to `Build` and update documentation.

Create method should persist returned object in the store. Because of
how escrow extension is implemented, a zero value escrow instance cannot
be persisted due to validation.
Escrow controller is expecting a zero amount escrow instance, that it
will deposit initial amount to. Rename `Create` to `Build` so that the
logic can remain as is, but the confusing naming is fixed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A functionality that was delivered is no longer working as expected.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants