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

Gas should be charged for Next, rather than Key() and Value() #2017

Closed
jaekwon opened this issue Aug 14, 2018 · 5 comments · Fixed by #2357
Closed

Gas should be charged for Next, rather than Key() and Value() #2017

jaekwon opened this issue Aug 14, 2018 · 5 comments · Fixed by #2357
Assignees

Comments

@jaekwon
Copy link
Contributor

jaekwon commented Aug 14, 2018

g.gasMeter.ConsumeGas(g.gasConfig.KeyCostFlat, "KeyFlat")

We should prob not be charging for each call of Key()/Value(), since they'd be cached once fetched anyways. I also don't think we need two separate key/value charges either.

I'd change our store gas system to charge a FlatRead upon iterator initialization, and a new FlatIterNext for calling Next, and no charge for Key or Value.

Maybe also a "UnsafeGetParent()" function that returns the parent so we can debug applications, and a TODO to add a conditional on Unsafe to only allow it when e.g. a "mode=develop" flag is set somewhere. I had to expose gasIterator to debug the 7003 crash... (see #1938)

@jaekwon
Copy link
Contributor Author

jaekwon commented Aug 14, 2018

(assigning to Chris to reassign)

@jaekwon
Copy link
Contributor Author

jaekwon commented Aug 14, 2018

Also TODO: consider creating a new issue for CosmosSDK "develop mode" to enable this and auto-enabling tracing etc.

@cwgoes
Copy link
Contributor

cwgoes commented Aug 14, 2018

The reason that the gas KV store charges gas costs this way is that calling .Key() or .Value() copies a new slice each time, at least in GoLevelDB:

Does the IAVL tree (which is what we're iterating over) do that or something else?

We can definitely charge for .Next() instead, not hard to change, but I want to understand the underlying disk I/O cost model.

@alexanderbez
Copy link
Contributor

Would like to look into this more myself...subscribing

@cwgoes
Copy link
Contributor

cwgoes commented Aug 14, 2018

Per discussion with @jaekwon:

  • Call .Key() and .Value() when .Next() is called to charge for size

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants