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

refactor: 1:1 mapping for ActionCosts to fees #8044

Merged
merged 8 commits into from
Nov 15, 2022

Conversation

jakmeier
Copy link
Contributor

So far, several actions fees were conflated right when they are added to
the profile. Here is a first step to make profiles universal by tracking
in more fine-grained manner at the profile interface. Inside, it's
still conflated but it's easier to refactor in steps. (see #8033)

So far several actions fees were conflated right when they are added to
the profile. This is a first step to make profiles universal by tracking
 in more fine-grained manner at the profile interface. Inside, it's
 still conflated but it's easier to refactor in steps. (see near#8033)
@jakmeier jakmeier requested a review from a team as a code owner November 14, 2022 19:14
@jakmeier jakmeier requested a review from mzhangmzz November 14, 2022 19:14
@jakmeier jakmeier requested review from matklad and removed request for mzhangmzz November 14, 2022 19:20
@jakmeier
Copy link
Contributor Author

Context for next steps as outline in #8033 is quite important here. Notably, the DataProfile is about to be frozen and only used to read old profiles from DB. So the fixed length hack is only temporary.

The reason for this intermediate step is some circular requirements. I can't easily change the profile's inside before changing runtime config to use parameters everywhere. But I cannot use parameters for actions as long as there is no 1:1 mapping.
Further, using parameters requires to change how the protocol config is serialized on the RPC.

core/primitives-core/src/profile.rs Show resolved Hide resolved
core/primitives-core/src/profile.rs Outdated Show resolved Hide resolved
core/primitives/src/views.rs Show resolved Hide resolved
Comment on lines +188 to +189
Cost::ActionCost { action_cost_kind: ActionCosts::function_call_base } => 3,
Cost::ActionCost { action_cost_kind: ActionCosts::function_call_byte } => 3,
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think it's fine to map them to a single entry for the time being. Long term, we should just make the array bigger. The serialization/deserialization code doesn't really care about length, is just zeros unknown cost.

It's better not to change the meaning of indicies, to simplify historical analysis, but even that, strinctly speaking, is not required. If we want, wee can reassign the meaning without protocol change.

Comment on lines +659 to +662
deploy_contract_base,
deploy_contract_byte,
function_call_base,
function_call_byte,
Copy link
Contributor

Choose a reason for hiding this comment

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

😍

@near-bulldozer near-bulldozer bot merged commit aeccaaa into near:master Nov 15, 2022
@jakmeier jakmeier deleted the refator-gas-profiles-part0 branch November 15, 2022 14:13
jakmeier added a commit to jakmeier/nearcore that referenced this pull request Nov 16, 2022
This cost never made sense to me. It's cost is defined by
`new_data_receipt_byte` but for some reason it was tracked
as `value_return`.

In  near#8044 I introduced `new_data_receipt_byte` as an action cost
but it is actually never used. This change replaces the old
`value_return` cost with `new_data_receipt_byte`.

This is an observable change on the RPC, as the profile now returns
a different key for this cost. But is is not a breaking change because
the profile keys are untyped.
near-bulldozer bot pushed a commit that referenced this pull request Nov 18, 2022
This cost never made sense to me. It's cost is defined by
`new_data_receipt_byte` but for some reason it was tracked
as `value_return`.

In  #8044 I introduced `new_data_receipt_byte` as an action cost
but it is actually never used. This change replaces the old
`value_return` cost with `new_data_receipt_byte`.

This is an observable change on the RPC, as the profile now returns
a different key for this cost. But is is not a breaking change because
the profile keys are untyped.
nikurt pushed a commit that referenced this pull request Nov 22, 2022
This cost never made sense to me. It's cost is defined by
`new_data_receipt_byte` but for some reason it was tracked
as `value_return`.

In  #8044 I introduced `new_data_receipt_byte` as an action cost
but it is actually never used. This change replaces the old
`value_return` cost with `new_data_receipt_byte`.

This is an observable change on the RPC, as the profile now returns
a different key for this cost. But is is not a breaking change because
the profile keys are untyped.
jakmeier added a commit to jakmeier/nearcore that referenced this pull request Nov 24, 2022
We have to charge the gas in one block to preserve the old behavior in
case of an "out of gas" failure in between.

I will maybe submit the change that makes it "right" with a protocol
feature flag, for now just revert it.
near-bulldozer bot pushed a commit that referenced this pull request Nov 26, 2022
We have to charge the gas in one block to preserve the old behavior in
case of an "out of gas" failure in between.

I will maybe submit the change that makes it "right" with a protocol
feature flag, for now just revert it.
nikurt pushed a commit that referenced this pull request Nov 26, 2022
We have to charge the gas in one block to preserve the old behavior in
case of an "out of gas" failure in between.

I will maybe submit the change that makes it "right" with a protocol
feature flag, for now just revert it.
jakmeier added a commit to jakmeier/nearcore that referenced this pull request Nov 29, 2022
Any action can fail due to gas limit exceeded or gas attached exceeded.
We must preserve the exact result, including how much gas is burnt.

In near#8044, we missed such a case and accidentally changed the burnt
gas value if it fails in the wrong place and only exceeds the attached
gas, not the gas burnt limit.

Tests added here cover this case for all existing action gas costs and
would catch this specific error in the future.

Not covered yet are ext costs and the case where we add new action
costs. We can bandage aid by adding similar tests for ext costs but we
also have to come up with a more general prevention.
near-bulldozer bot pushed a commit that referenced this pull request Jan 20, 2023
Any action can fail due to gas limit exceeded or gas attached exceeded.
We must preserve the exact result, including how much gas is burnt.

In #8044, we missed such a case and accidentally changed the burnt
gas value if it fails in the wrong place and only exceeds the attached
gas, not the gas burnt limit.

Tests added here cover this case for all existing action gas costs and
would catch this specific error in the future.

Not covered yet are ext costs and the case where we add new action
costs. We can bandage aid by adding similar tests for ext costs but we
also have to come up with a more general prevention.
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.

2 participants