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(fee): tx_args holds valid resource bounds #508

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

nimrod-starkware
Copy link
Contributor

@nimrod-starkware nimrod-starkware commented Aug 19, 2024

This change is Reviewable

Copy link
Contributor Author

@nimrod-starkware nimrod-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 10 files reviewed, 5 unresolved discussions (waiting on @dorimedini-starkware and @TzahiTaub)


crates/blockifier/src/test_utils/declare.rs line 111 at r1 (raw file):

                    signature: declare_tx_args.signature,
                    sender_address: declare_tx_args.sender_address,
                    resource_bounds: declare_tx_args.resource_bounds.0.try_into().expect("todo"),

will be handled in an upper branch

Code quote:

0.try_into().expect("todo")

crates/blockifier/src/test_utils/deploy_account.rs line 99 at r1 (raw file):

        starknet_api::transaction::DeployAccountTransaction::V3(DeployAccountTransactionV3 {
            signature: deploy_tx_args.signature,
            resource_bounds: deploy_tx_args.resource_bounds.0.try_into().expect("todo"),

ditto

Code quote:

.0.try_into().expect("todo"),

crates/blockifier/src/test_utils/invoke.rs line 99 at r1 (raw file):

    } else if invoke_args.version == TransactionVersion::THREE {
        starknet_api::transaction::InvokeTransaction::V3(InvokeTransactionV3 {
            resource_bounds: invoke_args.resource_bounds.0.try_into().expect("todo"),

ditto

Code quote:

s.0.try_into().expect("todo")

crates/papyrus_common/src/transaction_hash.rs line 226 at r1 (raw file):

) -> Result<Felt, StarknetApiError> {
    let (l1_resource_bounds, l2_resource_bounds) = match resource_bounds {
        ValidResourceBounds::L1Gas(l1_gas_bounds) => (l1_gas_bounds, &ResourceBounds::default()),

WDYT?
Assuming l2_gas previously was always zero.

Code quote:

&ResourceBounds::default())

crates/starknet_api/src/transaction_hash.rs line 181 at r1 (raw file):

) -> Result<Felt, StarknetApiError> {
    let (l1_resource_bounds, l2_resource_bounds) = match resource_bounds {
        ValidResourceBounds::L1Gas(l1_gas_bounds) => (l1_gas_bounds, &ResourceBounds::default()),

ditto

Code quote:

ResourceBounds::default()

@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/block_context_creator branch from d772755 to 5c10c7b Compare August 19, 2024 11:43
@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/tx_args branch from 181dc7a to a859ccb Compare August 19, 2024 11:43
@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/block_context_creator branch from 5c10c7b to cbb4e6a Compare August 19, 2024 11:55
@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/tx_args branch from a859ccb to 8d05eef Compare August 19, 2024 11:55
@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/block_context_creator branch from cbb4e6a to c9aa976 Compare August 19, 2024 12:39
@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/tx_args branch from 8d05eef to 985744e Compare August 19, 2024 12:39
@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/block_context_creator branch from c9aa976 to ad9d50c Compare August 19, 2024 13:16
@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/tx_args branch 2 times, most recently from 0b8e76a to 22cb18b Compare August 20, 2024 08:26
@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/block_context_creator branch from ad9d50c to 72bc281 Compare August 20, 2024 08:39
@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/tx_args branch from 22cb18b to fcf41bf Compare August 20, 2024 08:39
@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/block_context_creator branch from 72bc281 to cdb9892 Compare August 20, 2024 08:52
@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/tx_args branch from fcf41bf to 3d745d1 Compare August 20, 2024 08:52
@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/block_context_creator branch from cdb9892 to 0397362 Compare August 20, 2024 10:11
Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @dorimedini-starkware, @nimrod-starkware, and @TzahiTaub)


crates/papyrus_protobuf/src/converters/transaction.rs line 577 at r23 (raw file):

Previously, nimrod-starkware wrote…

I spoke with Shahak about it, and he said that's what he and Ariel agreed on.

Yes. @dorimedini-starkware the reason it's ok here is that this is a transaction inside a block, and the gateway would've rejected it if l2_gas=0 but l1_data_gas is present


crates/papyrus_protobuf/src/converters/transaction.rs line 582 at r25 (raw file):

}

impl TryFrom<protobuf::ResourceLimits> for ResourceBounds {

Unrelated to your PR: ResourceBounds is very confusing. Can we rename it?


crates/papyrus_protobuf/src/proto/p2p/proto/transaction.proto line 13 at r24 (raw file):

Previously, dorimedini-starkware wrote…

what's this...? @ShahakShama any BC issues may arise from this addition?

No, because it's appended to the list of fields. If we would've added it before l2_gas then BC issues would've happened


crates/papyrus_rpc/src/v0_6/transaction.rs line 172 at r3 (raw file):

Previously, nimrod-starkware wrote…

WDYM?
Should I panic in the case of ValidResourceBounds::AllResources(_)?

No, you should just convert the l1_gas and l2_gas to the output struct and not use the l1_data_gas
This code is called when the user asks: "Give me all the txs of block 1,000,000". If in block 1,000,000 we have a "new style" transaction then we don't want to panic, we'll just give the data that we know how to give and drop the data we don't know how to. That was what the l2_gas A/C preparation was for, right?

In summary, just remove the TODO


crates/papyrus_rpc/src/v0_7/transaction.rs line 190 at r25 (raw file):

                Self { l1_gas, l2_gas: ResourceBounds::default() }
            }
            // TODO(Nimrod): Don't allow this conversion.

Same as before, remove this TODO


crates/starknet_api/src/transaction.rs line 990 at r3 (raw file):

Previously, dorimedini-starkware wrote…

backwards compatibility

I think you can derive Serialize with serde(untagged) and the result will be the same. Only in deserialization you are doing something unique


crates/starknet_api/src/transaction.rs line 1001 at r22 (raw file):

Previously, nimrod-starkware wrote…

Your suggestion won't work..
It will always deserialize to the AllResources variant...
We need to check somewhere that l2 gas is zero in the first variant

That's why I suggested adding serde(deny_unknown_fields). This way it will distinguish between the two by looking if the l1_data_gas field is present. Is that good enough or do you prefer distinguishing through l2_gas being zero specifically?


crates/starknet_client/src/reader/objects/transaction.rs line at r3 (raw file):

Previously, dorimedini-starkware wrote…

yes

Approved

Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @nimrod-starkware and @TzahiTaub)

Copy link
Contributor Author

@nimrod-starkware nimrod-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @dorimedini-starkware, @ShahakShama, and @TzahiTaub)


crates/papyrus_protobuf/src/converters/transaction.rs line 582 at r25 (raw file):

Previously, ShahakShama wrote…

Unrelated to your PR: ResourceBounds is very confusing. Can we rename it?

Added a TODO to consider renaming it


crates/papyrus_rpc/src/v0_6/transaction.rs line 172 at r3 (raw file):

Previously, ShahakShama wrote…

No, you should just convert the l1_gas and l2_gas to the output struct and not use the l1_data_gas
This code is called when the user asks: "Give me all the txs of block 1,000,000". If in block 1,000,000 we have a "new style" transaction then we don't want to panic, we'll just give the data that we know how to give and drop the data we don't know how to. That was what the l2_gas A/C preparation was for, right?

In summary, just remove the TODO

Done.


crates/papyrus_rpc/src/v0_7/transaction.rs line 190 at r25 (raw file):

Previously, ShahakShama wrote…

Same as before, remove this TODO

Done.


crates/starknet_api/src/transaction.rs line 990 at r3 (raw file):

Previously, ShahakShama wrote…

I think you can derive Serialize with serde(untagged) and the result will be the same. Only in deserialization you are doing something unique

let's do it in a separate PR, i added a TODO


crates/starknet_api/src/transaction.rs line 1001 at r22 (raw file):

Previously, ShahakShama wrote…

That's why I suggested adding serde(deny_unknown_fields). This way it will distinguish between the two by looking if the l1_data_gas field is present. Is that good enough or do you prefer distinguishing through l2_gas being zero specifically?

Will do it in a separate PR (added a TODO)

@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/tx_args branch from 78c8a82 to f6d0bb9 Compare September 3, 2024 15:17
Copy link
Collaborator

@dorimedini-starkware dorimedini-starkware left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r26, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @nimrod-starkware, @ShahakShama, and @TzahiTaub)

Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @dorimedini-starkware, @nimrod-starkware, and @TzahiTaub)

Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @dorimedini-starkware, @nimrod-starkware, and @TzahiTaub)


crates/papyrus_protobuf/src/converters/transaction.rs line 567 at r26 (raw file):

        };
        let Some(l1_data_gas) = value.l1_data_gas else {
            return Err(ProtobufConversionError::MissingField {

Don't return an error here. Use unwrap_or_default and add a TODO to assert this is not None once we remove support for 0.13.2

Copy link
Contributor Author

@nimrod-starkware nimrod-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @dorimedini-starkware, @ShahakShama, and @TzahiTaub)


crates/papyrus_protobuf/src/converters/transaction.rs line 567 at r26 (raw file):

Previously, ShahakShama wrote…

Don't return an error here. Use unwrap_or_default and add a TODO to assert this is not None once we remove support for 0.13.2

Done.

@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/tx_args branch from f6d0bb9 to daec58f Compare September 4, 2024 06:39
Copy link
Contributor Author

@nimrod-starkware nimrod-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 42 of 44 files reviewed, 3 unresolved discussions (waiting on @dorimedini-starkware, @ShahakShama, and @TzahiTaub)


crates/papyrus_protobuf/src/converters/transaction.rs line 567 at r26 (raw file):

Previously, nimrod-starkware wrote…

Done.

Added your name to the TODO if that's ok :)

@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/tx_args branch from daec58f to 2307ff1 Compare September 4, 2024 07:04
Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r27.
Reviewable status: 42 of 44 files reviewed, 2 unresolved discussions (waiting on @dorimedini-starkware, @nimrod-starkware, and @TzahiTaub)

Copy link
Contributor

@ShahakShama ShahakShama left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: 42 of 44 files reviewed, 2 unresolved discussions (waiting on @dorimedini-starkware, @nimrod-starkware, and @TzahiTaub)

Copy link
Contributor Author

@nimrod-starkware nimrod-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 42 of 44 files reviewed, 1 unresolved discussion (waiting on @dorimedini-starkware and @TzahiTaub)


crates/papyrus_protobuf/src/converters/transaction.rs line 652 at r11 (raw file):

Previously, ShahakShama wrote…

Yes, but you need to add the new fields at the end of the message so that it can work with nodes that didn't do this upgrade (Juno/Pathfinder)

Done.

@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/tx_args branch from 2307ff1 to 6be435e Compare September 4, 2024 11:06
@nimrod-starkware nimrod-starkware force-pushed the nimrod/resources_enum/tx_args branch from 6be435e to 5477cc6 Compare September 4, 2024 11:09
@nimrod-starkware nimrod-starkware changed the title build(fee): tx_args holds valid resource bounds refactor(fee): tx_args holds valid resource bounds Sep 4, 2024
Copy link
Contributor Author

@nimrod-starkware nimrod-starkware left a comment

Choose a reason for hiding this comment

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

Dismissed @dorimedini-starkware from a discussion.
Reviewable status: 42 of 44 files reviewed, all discussions resolved (waiting on @dorimedini-starkware and @TzahiTaub)

Copy link
Contributor Author

@nimrod-starkware nimrod-starkware left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r28, all commit messages.
Reviewable status: 43 of 44 files reviewed, all discussions resolved (waiting on @dorimedini-starkware)

Copy link
Contributor Author

@nimrod-starkware nimrod-starkware left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r27.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @nimrod-starkware)

Copy link
Contributor Author

nimrod-starkware commented Sep 4, 2024

Merge activity

@nimrod-starkware nimrod-starkware merged commit 9260e52 into main Sep 4, 2024
32 of 54 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants