-
Notifications
You must be signed in to change notification settings - Fork 65
apollo_gateway: move instantiate_validator to be async #10122
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: graphite-base/10122
Are you sure you want to change the base?
apollo_gateway: move instantiate_validator to be async #10122
Conversation
a3dddb1 to
98fcb6b
Compare
abdeac9 to
2460176
Compare
2460176 to
dde47f9
Compare
98fcb6b to
86763ed
Compare
|
Do we still need this? Code quote: #[tokio::test(flavor = "multi_thread")] |
|
Previously, ArniStarkware (Arnon Hod) wrote…
No, fixed |
86763ed to
d56e2f7
Compare
dde47f9 to
90355f7
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.
@ArniStarkware reviewed 1 of 4 files at r1.
Reviewable status: 0 of 4 files reviewed, all discussions resolved (waiting on @TzahiTaub)
d56e2f7 to
cf45842
Compare
3bcd98e to
e6c5529
Compare
TzahiTaub
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.
@TzahiTaub reviewed 1 of 1 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: 2 of 4 files reviewed, 1 unresolved discussion (waiting on @ArniStarkware and @itamar-starkware)
crates/apollo_gateway/src/stateful_transaction_validator_test.rs line 178 at r4 (raw file):
let validator = stateful_validator_factory.instantiate_validator(Arc::new(mock_state_reader_factory)).await;
This can be removed, became irrelevant a long time ago apperantly
Suggestion:
let validator =
stateful_validator_factory.instantiate_validator(Arc::new(state_reader_factory)).await;
itamar-starkware
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, 1 unresolved discussion (waiting on @ArniStarkware, @itamar-starkware, and @TzahiTaub)
crates/apollo_gateway/src/stateful_transaction_validator_test.rs line 178 at r4 (raw file):
Previously, TzahiTaub (Tzahi) wrote…
This can be removed, became irrelevant a long time ago apperantly
Done.
e6c5529 to
6f8b1a1
Compare
TzahiTaub
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.
@TzahiTaub reviewed 1 of 4 files at r1, 1 of 2 files at r2, 2 of 2 files at r5, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @itamar-starkware)
crates/apollo_gateway/src/gateway_test.rs line 573 at r4 (raw file):
)) }) });
Revert (see comment in stateful_transaction_validator)
Code quote:
mock_stateful_transaction_validator_factory.expect_instantiate_validator().return_once(|_| {
Box::pin(async {
Ok::<Box<dyn StatefulTransactionValidatorTrait>, _>(Box::new(
mock_stateful_transaction_validator,
))
})
});crates/apollo_gateway/src/gateway_test.rs line 616 at r4 (raw file):
mock_stateful_transaction_validator_factory .expect_instantiate_validator() .return_once(|_| Box::pin(async { Err::<_, _>(expected_error) }));
Revert (see comment in stateful_transaction_validator)
Code quote:
.return_once(|_| Box::pin(async { Err::<_, _>(expected_error) }));crates/apollo_gateway/src/rpc_state_reader.rs line 116 at r5 (raw file):
let block_header: BlockHeader = serde_json::from_value(get_block_with_tx_hashes_result) .map_err(serde_err_to_state_err)?;
Why was this changed? The former seems better.
Code quote:
let block_header: BlockHeader = serde_json::from_value(get_block_with_tx_hashes_result)
.map_err(serde_err_to_state_err)?;crates/apollo_gateway/src/stateful_transaction_validator.rs line 53 at r4 (raw file):
#[async_trait] #[cfg_attr(test, mockall::automock)]
See the first bullet here:
- The
#[automock]attribute must appear before the crate’s attribute.
This caused the Box::Pin requirement.
Please search for similar wrongly ordered async+automock annotations in the repo and replace them as well (in a separate PR).
Suggestion:
#[cfg_attr(test, mockall::automock)]
#[async_trait]6f8b1a1 to
9825d27
Compare
cf45842 to
d0a3118
Compare
|
Previously, TzahiTaub (Tzahi) wrote…
Fixed. |
|
Previously, TzahiTaub (Tzahi) wrote…
Done. |
|
Previously, TzahiTaub (Tzahi) wrote…
Done. |
|
Previously, TzahiTaub (Tzahi) wrote…
Done. |
9825d27 to
e1ada60
Compare
TzahiTaub
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.
@TzahiTaub reviewed 3 of 3 files at r6, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @itamar-starkware)
crates/apollo_gateway/src/stateful_transaction_validator.rs line 53 at r4 (raw file):
Previously, itamar-starkware wrote…
Done.
This is the only place in sequencer repo with this combination.
We have two more (pub trait PreconfirmedBlockWriterTrait and pub trait SignatureManagerClient)
|
Previously, TzahiTaub (Tzahi) wrote…
Sorry for that. I should have verified it better. |
|
The original change is unnecessary. Suggestion: #[async_trait]
#[cfg_attr(test, mockall::automock)] |
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 1 of 3 files at r6.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @itamar-starkware)
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 1 of 1 files at r4, 1 of 2 files at r5.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @itamar-starkware)
crates/apollo_gateway/src/stateful_transaction_validator.rs line 71 at r6 (raw file):
async fn instantiate_validator( &self, state_reader_factory: Arc<dyn StateReaderFactory>,
Why the arc? Is it explained in the upstream?
Code quote:
state_reader_factory: Arc<dyn StateReaderFactory>,|
Previously, ArniStarkware (Arnon Hod) wrote…
We shared pointer across tasks. The exact error I get: The reason is: since automock is done before async_trait (first annotation done first) |
|
Previously, ArniStarkware (Arnon Hod) wrote…
This documentation says otherwise: |

TL;DR
Make
instantiate_validatorasync to avoid blocking the runtime.What changed?
instantiate_validatorinStatefulTransactionValidatorFactoryTraitto be an async functionawaitinstead ofblock_onfor asynchronous operationsprocess_txinProcessTxBlockingTaskto useruntime.block_onto call the now-asyncinstantiate_validatorHow to test?
Run the existing test suite to ensure that the functionality works as expected with the new async interface.
Why make this change?
This change improves the code by avoiding blocking operations within async contexts. By making
instantiate_validatorasync, we eliminate the need to callblock_onwithin the method, which can lead to runtime issues when called from an async context. This creates a more consistent async/await pattern throughout the codebase and prevents potential deadlocks that can occur when blocking the runtime.