-
Notifications
You must be signed in to change notification settings - Fork 381
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
feat: cpu and store gas updates #3054
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just make the txtars all just use a -gas-wanted
of 10M
?
just because they'll have to be updated again. I'd want for us to keep track of "golden" gas values just in one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that we need to update for gas changes. This provides an opportunity to verify the changes and understand where the gas impact comes from, especially if there is a significant increase in gas usage in our implementation. We can add a 50% buffer to the gas usage as a safeguard. I am also open to other solutions.
@@ -1154,127 +1154,130 @@ func (m *Machine) incrCPU(cycles int64) { | |||
} | |||
|
|||
const ( | |||
// CPU cycles |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a reference to the benchmarks and methodology?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please 🙏
I'm a bit worried about the new gas values, and a comparison would help us make a fair assessment of the gas bumps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned that this approach renders ugnot
nearly valueless, as it results in excessively long and difficult-to-read numbers.
We should either adopt a strategy that sacrifices some precision, such as dividing by N (which could be a parameter), or consider introducing another level of gnot
conversion, like ngnot
for gas, to maintain the relevance of ugnot
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@moul @zivkovicmilos I totally agree; the high gas fees create a poor user experience. Let me think about how we can address this later. I think we could maintain precision in the program and round it up at the UI layer.
gno.land/pkg/sdk/vm/keeper.go
Outdated
@@ -205,6 +205,7 @@ var gnoStoreContextKey gnoStoreContextKeyType | |||
func (vm *VMKeeper) newGnoTransactionStore(ctx sdk.Context) gno.TransactionStore { | |||
base := ctx.Store(vm.baseKey) | |||
iavl := ctx.Store(vm.iavlKey) | |||
vm.gnoStore.SetGasMeter(ctx.GasMeter()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unsafe, because vm.gnoStore is shared, and this would set the gas meter globally; ie. not scoped to the transaction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds reasonable to switch to start with per transaction and later move to per machine if we also have machine concurrency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thehowl good catch! I will pass the gasMeter to gnoStore.BeginTransaction() instead
gnovm/pkg/gnolang/store.go
Outdated
func (ds *defaultStore) SetGasMeter(gm store.GasMeter) { | ||
ds.gasMeter = gm | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this ought to go in BeginTransaction
, and the store shouldn't use a gas store otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense to count gas for the store independently since future features will dissociate CPU gas from storage gas, allowing costs to cover cpuCost + storageCost + futureStorageRent
. Additionally, realms could have different storage cost ratios—some sponsored by the chain, others transitioned to 'archives,' or even storage classes with varying configurations based on price tiers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this ought to go in
BeginTransaction
, and the store shouldn't use a gas store otherwise.
@thehowl Agreed, I will assign the gasMeter in BeginTransaction and remove this method.
func DefaultGasConfig() GasConfig { | ||
return GasConfig{ | ||
GasGetObject: 16, // per byte cost | ||
GasSetObject: 16, // per byte cost | ||
GasGetType: 52, // per byte cost | ||
GasSetType: 52, // per byte cost | ||
GasGetPackageRealm: 524, // per byte cost | ||
GasSetPackageRealm: 524, // per byte cost | ||
GasAddMemPackage: 8, // per byte cost | ||
GasGetMemPackage: 8, // per byte cost | ||
GasDeleteObject: 3715, // flat cost | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are constants for the VM. Can these also not be constants?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to keep the gas constant until we implement other ways to update the value, such as through genesis or GovDAO with the parameter module. For now, whenever we change the value, we should modify this section of the code and go through code reviews again.
func (c Context) Store(key store.StoreKey) store.Store { | ||
return c.MultiStore().GetStore(key) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can understand the rename to GasStore, but I don't think we should expose a gas-less Store
method, especially when getting the underlying store is still trivial and exported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (c Context) Store(key store.StoreKey) store.Store { | |
return c.MultiStore().GetStore(key) | |
} | |
func (c Context) GaslessStore(key store.StoreKey) store.Store { | |
return c.MultiStore().GetStore(key) | |
} |
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can understand the rename to GasStore, but I don't think we should expose a gas-less
Store
method, especially when getting the underlying store is still trivial and exported.
The purpose here is not to rename the store but to separate gas store access from non-gas store access in the context. This separation is necessary because we need to wrap the gas meter at different levels for Auth Keeper gas consumption and VM gas consumption.
Please refer to the diagram above. In Auth Keeper, the GasStore wraps the gas meter at the underlying base store level. In VM Keeper, the gas meter is wrapped above the underlying store in the gnoStore, allowing us to capture activity to persist realm objects. The ctx.Store is used by the VM Keeper to access the underlying store without the gas meter, so it can wrap it at a higher layer.
The context.Store abstracts away the underlying MultiStore concept. This approach is consistent with how context, app, and keeper store access are managed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the PR looks fine, apart from the comments left by @thehowl, which should be addressed about the global gas meter setting in the VM keeper 🙏
I'm temporarily just putting a pause on the PR, to allow for us to discuss whether these new gas values make sense, since they are a huge change. I also want to see some more reasoning and gas comparisons, apart from #2241
If we're fine with the bumps, I am also cool with the PR moving forward as is ✅
@@ -1154,127 +1154,130 @@ func (m *Machine) incrCPU(cycles int64) { | |||
} | |||
|
|||
const ( | |||
// CPU cycles |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please 🙏
I'm a bit worried about the new gas values, and a comparison would help us make a fair assessment of the gas bumps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, it looks good. In this PR or a future one, I suggest we:
- Add a global multiplier/divider parameter to avoid using
ngnot
while keeping the numbers relatively readable. - Create a benchmarking tool that runs all the gnocode in the repository and generates a CSV or TXT file with the gas details we commit periodically (there's no need for this on every commit, in my opinion). This way, whenever we want to fine-tune a parameter, we can run the same script again and compare the results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unblocking after @moul is fine with the bumps
I'm a bot that assists the Gno Core team in maintaining this repository. My role is to ensure that contributors understand and follow our guidelines, helping to streamline the development process. The following requirements must be fulfilled before a pull request can be merged. These requirements are defined in this configuration file. Automated Checks🟢 Maintainers must be able to edit this pull request (more info) Manual ChecksNo manual checks match this pull request. Debug
|
Codecov ReportAttention: Patch coverage is 📢 Thoughts on this report? Let us know! |
Summary:
This PR updates the CPU and Store gas based on results from the benchmarking tool:#2241
For CPU gas, the measurement is in nanoseconds per opcode execution.
For storage gas, the measurement is in nanoseconds per byte for each type of Gno store access.
Changes:
We moved the gas meter from the underlying store to the upper Gno store to capture accurate resource consumption for VM transactions. At the same time, we retain the original gas store and gas meter for the Auth Keeper to handle regular blockchain transactions that do not necessarily involve the VM.
We also updated the gas-wanted in the integration test to reflect actual gas usage. This can serve as a flag to alert us to future changes that might increase gas assumptions.
Additional reasons for these changes include:
Here are the diagrams to explain the store access gas before and after changes
Before:
After:
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description