-
Notifications
You must be signed in to change notification settings - Fork 65
apollo_gateway: remove processing tx block #10592
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
apollo_gateway: remove processing tx block #10592
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
8790404 to
bfe5849
Compare
|
I know this is not the main topic, but I am distracted by this. Suggestion: let account_nonce = runtime
.block_on(self.gateway_fixed_block_state_reader.get_nonce(address))
.map_err(|e| {
// TODO(noamsp): Fix this. Need to map the errors better.
StarknetError::internal_with_signature_logging(
format!("Failed to get nonce for sender address {address}"),
&executable_tx.signature(),
e,
)
})?;
self.run_transaction_validations(executable_tx, account_nonce, mempool_client, runtime)?;
Ok(account_nonce)
}
}
impl<B: BlockifierStatefulValidatorTrait> StatefulTransactionValidator<B> {
fn run_transaction_validations(
&mut self,
executable_tx: &ExecutableTransaction,
account_nonce: Nonce,
mempool_client: SharedMempoolClient,
runtime: tokio::runtime::Handle,
) -> StatefulTransactionValidatorResult<()> {
self.validate_state_preconditions(executable_tx, account_nonce)?;
runtime.block_on(validate_by_mempool(
executable_tx,
account_nonce,
mempool_client.clone(),
))?;
self.run_validate_entry_point(executable_tx, account_nonce, mempool_client, runtime)?;
Ok(())
}
fn validate_state_preconditions( |
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 7 files reviewed, 1 unresolved discussion (waiting on @itamar-starkware and @TzahiTaub)
crates/apollo_gateway/src/stateful_transaction_validator.rs line 165 at r1 (raw file):
Previously, ArniStarkware (Arnon Hod) wrote…
I know this is not the main topic, but I am distracted by this.
This comment is still relevant.
|
Previously, ArniStarkware (Arnon Hod) wrote…
I'm missing the issue here. Please explain. |
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 7 files reviewed, 1 unresolved discussion (waiting on @itamar-starkware and @TzahiTaub)
crates/apollo_gateway/src/stateful_transaction_validator.rs line 165 at r1 (raw file):
Previously, itamar-starkware wrote…
I'm missing the issue here. Please explain.
- Don't change unnecessary things in this PR. Which leads to the second point.
- I like that the function called
extract_state_nonce_and_run_validationsdoes:
- extract the state nonce (one method).
- runs validations (second method). * This is the issue I refer to.
|
Join error? Blocking task? Code quote: message: format!("Blocking task join error: {e}"),
})??; |
|
What happened to the metric? IIUC, it should be handled as one of the two Code quote: metric_counters.record_add_tx_failure(&starknet_err); |
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 7 files reviewed, 4 unresolved discussions (waiting on @itamar-starkware and @TzahiTaub)
crates/apollo_gateway/src/stateful_transaction_validator_test.rs line 492 at r2 (raw file):
.map_err(|err| err.code); assert_eq!(result, expected_result_code); }
This was a unit test for the deleted method run_transaction_validations.
In this thread. I requested you bring it back.
This would make the changes to this test unnecessary.
Code quote:
async fn run_transaction_validation_test(
executable_tx: AccountTransaction,
account_nonce: Nonce,
max_allowed_nonce_gap: u32,
expected_result_code: Result<(), StarknetErrorCode>,
) {
let mut mock_blockifier_validator = MockBlockifierStatefulValidatorTrait::new();
mock_blockifier_validator.expect_validate().return_once(|_| Ok(()));
mock_blockifier_validator.expect_block_info().return_const(BlockInfo::default());
let mut stateful_validator = StatefulTransactionValidator {
config: StatefulTransactionValidatorConfig { max_allowed_nonce_gap, ..Default::default() },
blockifier_stateful_tx_validator: mock_blockifier_validator,
gateway_fixed_block_state_reader: {
let mut mock = MockGatewayFixedBlockStateReader::new();
mock.expect_get_nonce().return_once(move |_| Ok(account_nonce));
Box::new(mock)
},
};
let result = tokio::task::spawn_blocking(move || {
let mut mempool_client = MockMempoolClient::new();
mempool_client.expect_validate_tx().returning(|_| Ok(()));
stateful_validator.extract_state_nonce_and_run_validations(
&executable_tx,
Arc::new(mempool_client),
tokio::runtime::Handle::current(),
)
})
.await
.unwrap()
.map(|_| ())
.map_err(|err| err.code);
assert_eq!(result, expected_result_code);
}
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 7 files reviewed, 4 unresolved discussions (waiting on @itamar-starkware and @TzahiTaub)
crates/apollo_gateway/src/stateful_transaction_validator_test.rs line 492 at r2 (raw file):
Previously, ArniStarkware (Arnon Hod) wrote…
This was a unit test for the deleted method
run_transaction_validations.In this thread. I requested you bring it back.
This would make the changes to this test unnecessary.
Ditto other tests.
|
Go to Code quote: self.blockifier_stateful_tx_validator.get_nonce(address) |
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 7 files at r1.
Reviewable status: 1 of 7 files reviewed, 5 unresolved discussions (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.
@ArniStarkware reviewed 1 of 7 files at r1.
Reviewable status: 2 of 7 files reviewed, 5 unresolved discussions (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.
@ArniStarkware reviewed 1 of 4 files at r2.
Reviewable status: 3 of 7 files reviewed, 5 unresolved discussions (waiting on @itamar-starkware and @TzahiTaub)
|
What is the precedent? Code quote: Err(StateSyncClientError::StateSyncError(StateSyncError::ContractNotFound(_))) => {
Ok(Nonce::default())
} |
|
Previously, ArniStarkware (Arnon Hod) wrote…
Fixed. |
bfe5849 to
1445e7c
Compare
|
Previously, ArniStarkware (Arnon Hod) wrote…
spawn_blocking return a JoinHandle, but I don't think we should refer to it in our message. |
|
Previously, ArniStarkware (Arnon Hod) wrote…
On the get_nonce_at for the blockifier: sequencer/crates/apollo_gateway/src/sync_state_reader.rs Lines 153 to 165 in b38ede6
|
|
Previously, ArniStarkware (Arnon Hod) wrote…
Added a todo, this PR is already too long. |
|
Previously, ArniStarkware (Arnon Hod) wrote…
In the next PR we revert back to something close to that.
|
|
Previously, itamar-starkware wrote…
I would argue we can have three steps:
|
|
Previously, itamar-starkware wrote…
Sorry for saying "one of the two |
|
Done |
|
Previously, ArniStarkware (Arnon Hod) wrote…
Done. |
cf08661 to
fb3507f
Compare
|
Done. I should have seen it by myself. |
fb3507f to
6987806
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 2 files at r3.
Reviewable status: 4 of 8 files reviewed, all discussions resolved (waiting on @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.
@ArniStarkware reviewed 1 of 7 files at r1, 1 of 2 files at r4, 1 of 2 files at r5.
Reviewable status: 7 of 8 files reviewed, 1 unresolved discussion (waiting on @itamar-starkware and @TzahiTaub)
crates/apollo_gateway/src/stateful_transaction_validator_test.rs line 117 at r6 (raw file):
}; let expected_run_result = expected_result.as_ref().map(|_| account_nonce).map_err(|blockifier_error| StarknetError {
why do we need this?
Code quote:
.map(|_| account_nonce)087eff1 to
e77c3e5
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 2 files at r7, all commit messages.
Reviewable status: 7 of 8 files reviewed, all discussions resolved (waiting on @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.
@ArniStarkware reviewed 1 of 1 files at r9.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @TzahiTaub)
|
Please wait for @TzahiTaub's review. |
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 7 files at r1, 1 of 2 files at r3, 1 of 2 files at r4, 1 of 2 files at r5, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @itamar-starkware)
crates/apollo_gateway/src/gateway.rs line 168 at r8 (raw file):
mempool_client, tokio::runtime::Handle::current(), )
Suggestion:
let nonce = tokio::task::spawn_blocking(move || {
curr_span.in_scope(|| {
stateful_transaction_validator.extract_state_nonce_and_run_validations(
&executable_tx,
self.mempool_client.clone(),
tokio::runtime::Handle::current(),
)crates/apollo_gateway/src/gateway.rs line 173 at r8 (raw file):
.await .map_err(|e| { let err = StarknetError {
IIUC, this helps to understand why there are two consecutive error handlers.
Suggestion:
.map_err(|e| {
// Handle panics in the spawned thread (see tokio::task::JoinHandle).
let err = StarknetError {
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 2 files at r7, 1 of 1 files at r9.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @itamar-starkware)
|
Previously, TzahiTaub (Tzahi) wrote…
Done |
e77c3e5 to
52d9004
Compare
|
Can't be done. The compiler error here is: This is the cursor summary of the case: |
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.
Reviewable status: 7 of 8 files reviewed, 2 unresolved discussions (waiting on @ArniStarkware and @itamar-starkware)
crates/apollo_gateway/src/gateway.rs line 168 at r8 (raw file):
Previously, itamar-starkware wrote…
Can't be done.
We have lifetime issues here.
spawn_blocking create a closure which take ownership on all object get inside him, so working withself.mempool_clientwill require taking ownership on self.
The issue here, IIUC, is lifetime requiremnets. The spawn_blocking can live longer than theselfobject.The compiler error here is:
borrowed data escapes outside of method `self` escapes the method body hereThis is the cursor summary of the case:
The blocking validation runs in a thread via spawn_blocking, whose closure must be 'static (no non-'static borrows). Inlining self.mempool_client.clone() would capture &self, a non-'static borrow; instead, clone the Arc outside and move the owned clone into the closure. The local mempool_client variable isn’t 'static itself, but moving it into the closure makes the closure 'static because it owns its captures.
Right, then just remove the clone from &executable_tx
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 r10.
Reviewable status: all files reviewed (commit messages unreviewed), 2 unresolved discussions (waiting on @itamar-starkware)
52d9004 to
500b3b7
Compare
|
Previously, TzahiTaub (Tzahi) wrote…
Done |
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 r11, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (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 all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (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.
Reviewable status:
complete! all files reviewed, all discussions resolved (waiting on @itamar-starkware)

What changed?
ProcessTxBlockingTaskstruct and simplified the transaction validation flow inGateway::add_txStatefulTransactionValidatorto get the nonce directly from the state reader instead of the blockifierget_noncemethod to theGatewayFixedBlockStateReadertrait and its implementationsextract_state_nonce_and_run_validationstorun_transaction_validationsand simplified its implementationWhy make this change?
This refactoring simplifies the transaction validation flow by:
The changes maintain the same validation logic while making the code more maintainable and easier to understand.