-
Notifications
You must be signed in to change notification settings - Fork 65
apollo_gateway: make StatefulTransactionValidatorTrait async #10621
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
base: 12-07-apollo_gateway_remove_processing_tx_block
Are you sure you want to change the base?
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
ArniStarkware
left a comment
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.
Reviewable status: 0 of 4 files reviewed, 1 unresolved discussion (waiting on @itamar-starkware and @TzahiTaub)
crates/apollo_gateway/src/gateway.rs line 161 at r1 (raw file):
let nonce = stateful_transaction_validator .extract_state_nonce_and_run_validations(&executable_tx, self.mempool_client.clone()) .await?;
I didn't start looking at the PR yet.
I do like this interface, and it is clean and good (to say the least).
If it makes things simpler, we can:
Suggestion:
let nonce = stateful_tx_validator_factory
.instantiate_validator_extract_state_nonce_and_run_validations(self.state_reader_factory.clone(), &executable_tx, self.mempool_client.clone())
.await?;
ArniStarkware
left a comment
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.
Reviewable status: 0 of 4 files reviewed, 1 unresolved discussion (waiting on @itamar-starkware and @TzahiTaub)
crates/apollo_gateway/src/gateway.rs line 161 at r1 (raw file):
Previously, ArniStarkware (Arnon Hod) wrote…
I didn't start looking at the PR yet.
I do like this interface, and it is clean and good (to say the least).If it makes things simpler, we can:
For the record.
ArniStarkware
left a comment
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.
@ArniStarkware reviewed 2 of 4 files at r1.
Reviewable status: 2 of 4 files reviewed, 1 unresolved discussion (waiting on @itamar-starkware and @TzahiTaub)
ArniStarkware
left a comment
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.
Reviewable status: 2 of 4 files reviewed, 3 unresolved discussions (waiting on @itamar-starkware and @TzahiTaub)
crates/apollo_gateway/src/stateful_transaction_validator.rs line 111 at r1 (raw file):
// Consumed when running the CPU-heavy blockifier validation. state_reader_and_contract_manager: Option<StateReaderAndContractManager<Box<dyn GatewayStateReaderWithCompiledClasses>>>,
Connects to this comment
Suggestion:
// TODO(Itamar): Fix this. The whole `StatefulTransactionValidator` is never used after `state_reader_and_contract_manager` is taken.
// Make it non-optional and discard the instance after use.
// Consumed when running the CPU-heavy blockifier validation.
state_reader_and_contract_manager:
Option<StateReaderAndContractManager<Box<dyn GatewayStateReaderWithCompiledClasses>>>,crates/apollo_gateway/src/stateful_transaction_validator.rs line 113 at r1 (raw file):
Option<StateReaderAndContractManager<Box<dyn GatewayStateReaderWithCompiledClasses>>>, gateway_fixed_block_state_reader: Box<dyn GatewayFixedBlockStateReader>, }
Make the interface clear and safe.
(Not as important as the fields are not public.
Suggestion:
pub struct StatefulTransactionValidator {
config: StatefulTransactionValidatorConfig,
chain_info: ChainInfo,
// Consumed when running the CPU-heavy blockifier validation.
state_reader_and_contract_manager:
Option<StateReaderAndContractManager<Box<dyn GatewayStateReaderWithCompiledClasses>>>,
gateway_fixed_block_state_reader: Box<dyn GatewayFixedBlockStateReader>,
}
impl StatefulTransactionValidator {
// Itamar - note `state_reader_and_contract_manager` is not optional.
fn new(..., state_reader_and_contract_manager:
StateReaderAndContractManager<Box<dyn GatewayStateReaderWithCompiledClasses>>, ...) -> Self {..}
}
fn take_state_reader_and_contract_manager(&mut self) -> StateReaderAndContractManager<Box<dyn GatewayStateReaderWithCompiledClasses>> {
self.state_reader_and_contract_manager.take().expect("Validator was already consumed");
}
}6f207af to
14dc6b0
Compare
bfe5849 to
1445e7c
Compare
ArniStarkware
left a comment
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.
Reviewable status: 1 of 4 files reviewed, 3 unresolved discussions (waiting on @itamar-starkware and @TzahiTaub)
crates/apollo_gateway/src/stateful_transaction_validator.rs line 113 at r1 (raw file):
Previously, ArniStarkware (Arnon Hod) wrote…
Make the interface clear and safe.
(Not as important as the fields are not public.
Note, both these functions are not public.
|
Document this function and/or rename it. Suggestion: async fn extract_state_nonce_and_run_pre_validation_checks( |
|
Cool hack. We can now create a It does make me think that there should be a Code quote: let stateful_validator = StatefulTransactionValidator {
config: StatefulTransactionValidatorConfig::default(),
chain_info: ChainInfo::create_for_testing(),
state_reader_and_contract_manager: None,
gateway_fixed_block_state_reader: Box::new(mock_gateway_fixed_block),
}; |
|
offline discussion with Arni about this suggestion: Suggestion: expected_result_code: Result<Nonce, StarknetErrorCode>, |
|
Previously, ArniStarkware (Arnon Hod) wrote…
We decided to split into two functions here. |
14dc6b0 to
84b5660
Compare
1445e7c to
16492e8
Compare
84b5660 to
820c1d6
Compare
16492e8 to
d50b76a
Compare
820c1d6 to
7fc9b01
Compare
|
Previously, ArniStarkware (Arnon Hod) wrote…
Done |

Refactored the
StatefulTransactionValidatorto use async/await instead of spawning blocking tasks for each validation step.What changed?
extract_state_nonce_and_run_validationsspawn_blockingfor the CPU-intensive blockifier validationrun_pre_validation_checksandrun_validate_entry_pointblock_info()method, using the gateway's block info provider insteadWhy make this change?
This refactoring improves code clarity and performance by:
The change preserves all existing validation logic while making the code structure more straightforward and efficient.