Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

test(concurrency): multithreaded flow test for the scheduler #1830

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

barak-b-starkware
Copy link
Collaborator

@barak-b-starkware barak-b-starkware commented Apr 27, 2024

This change is Reviewable

@codecov-commenter
Copy link

codecov-commenter commented Apr 27, 2024

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 78.45%. Comparing base (f64dc0e) to head (7fcaa65).

Files Patch % Lines
crates/blockifier/src/abi/sierra_types.rs 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1830      +/-   ##
==========================================
- Coverage   78.47%   78.45%   -0.03%     
==========================================
  Files          62       62              
  Lines        8967     8970       +3     
  Branches     8967     8970       +3     
==========================================
  Hits         7037     7037              
- Misses       1483     1486       +3     
  Partials      447      447              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@barak-b-starkware barak-b-starkware force-pushed the barak/ml_test/decrease_validation_index branch 2 times, most recently from b60bfde to 03d3956 Compare May 6, 2024 14:03
@barak-b-starkware barak-b-starkware force-pushed the barak/ml_test/decrease_validation_index branch from 03d3956 to 9d187de Compare May 9, 2024 09:09
@barak-b-starkware barak-b-starkware changed the base branch from main to barak/delete_writes May 9, 2024 10:20
@barak-b-starkware barak-b-starkware force-pushed the barak/ml_test/decrease_validation_index branch 6 times, most recently from a428c02 to 689a2d4 Compare May 9, 2024 11:42
@barak-b-starkware barak-b-starkware force-pushed the barak/ml_test/decrease_validation_index branch from 689a2d4 to 00d12f6 Compare May 9, 2024 12:23
@barak-b-starkware barak-b-starkware force-pushed the barak/delete_writes branch 2 times, most recently from 318b27e to 5ff57c5 Compare May 9, 2024 13:11
@barak-b-starkware barak-b-starkware force-pushed the barak/ml_test/decrease_validation_index branch 2 times, most recently from 3e85214 to d69b884 Compare May 9, 2024 14:05
@barak-b-starkware barak-b-starkware force-pushed the barak/delete_writes branch 2 times, most recently from a3c035f to f7c2bd3 Compare May 12, 2024 08:10
@barak-b-starkware barak-b-starkware force-pushed the barak/ml_test/decrease_validation_index branch 2 times, most recently from b73d8cc to 1280c8b Compare May 12, 2024 08:15
@barak-b-starkware barak-b-starkware force-pushed the barak/delete_writes branch 7 times, most recently from d203adc to 2b138c8 Compare May 19, 2024 13:54
@barak-b-starkware barak-b-starkware force-pushed the barak/delete_writes branch 2 times, most recently from d9fccce to 88b32f4 Compare May 20, 2024 10:14
@barak-b-starkware barak-b-starkware force-pushed the barak/ml_test/decrease_validation_index branch from 39d59e8 to 4bbaba5 Compare May 22, 2024 17:10
Copy link
Collaborator Author

@barak-b-starkware barak-b-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, 8 unresolved discussions (waiting on @avi-starkware, @noaov1, and @Yoni-Starkware)


crates/blockifier/src/abi/sierra_types.rs line 39 at r3 (raw file):

    fn from_storage(
        state: &mut dyn StateReader,

Done.


crates/blockifier/src/concurrency/flow_test.rs line 90 at r2 (raw file):

Previously, avi-starkware wrote…

I just think that when discussing atomic variables, "atomic operations" evokes "operations on atomic variables", and not "operations in a scope where no other thread can access" so it is a bit confusing.
By the way, I think atomic operations actually mean operations that happen in a single CPU step and thus cannot be split.

Done.


crates/blockifier/src/concurrency/flow_test.rs line 30 at r3 (raw file):

    // they both read from and write to the same storage entry, this couples the tx_index with the
    // write set of the corresponding tx. However, to make the test more noisy, we determine the
    // write-set dynamically.

Done.


crates/blockifier/src/concurrency/flow_test.rs line 54 at r3 (raw file):

                        .unwrap();
                        // Simulate a write operation of a tx.
                        let writes = state_maps_with_single_storage_entry(

Done.


crates/blockifier/src/concurrency/flow_test.rs line 73 at r3 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

You can be more restrictive - the value must be there in validate phase.

When tx_index == 0 the .get(&(contract_address, storage_key)) returns None. In this case, we need to read this one somehow.
I can change the comment to explain this specific case, WDYT?


crates/blockifier/src/concurrency/flow_test.rs line 77 at r3 (raw file):

                        .unwrap();
                        // If tx number tx_index wrote tx_written_value then it must be read
                        // tx_written_value - 1.

Done.


crates/blockifier/src/concurrency/flow_test.rs line 130 at r3 (raw file):

fn state_maps_with_single_storage_entry(
    // tx_index: TxIndex,
    contract_address: ContractAddress,

Done.

Copy link
Collaborator

@avi-starkware avi-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 2 of 2 files at r4, all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @barak-b-starkware, @noaov1, and @Yoni-Starkware)

Copy link
Collaborator

@Yoni-Starkware Yoni-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 r4, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @barak-b-starkware and @noaov1)


crates/blockifier/src/concurrency/flow_test.rs line 73 at r3 (raw file):

Previously, barak-b-starkware wrote…

When tx_index == 0 the .get(&(contract_address, storage_key)) returns None. In this case, we need to read this one somehow.
I can change the comment to explain this specific case, WDYT?

Are you sure? It should return 1

Copy link
Collaborator

@Yoni-Starkware Yoni-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, 2 unresolved discussions (waiting on @barak-b-starkware and @noaov1)


crates/blockifier/src/concurrency/flow_test.rs line 73 at r3 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Are you sure? It should return 1

Unblocking because I'm OOO next week, but I'm pretty sure it should be fine

@barak-b-starkware barak-b-starkware force-pushed the barak/ml_test/decrease_validation_index branch 2 times, most recently from d87dba2 to c153712 Compare May 26, 2024 11:58
Copy link
Collaborator

@avi-starkware avi-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 4 of 5 files at r5, all commit messages.
Reviewable status: 5 of 6 files reviewed, 1 unresolved discussion (waiting on @barak-b-starkware and @noaov1)

avi-starkware
avi-starkware previously approved these changes May 27, 2024
Copy link
Collaborator

@avi-starkware avi-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 5 files at r5.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @barak-b-starkware and @noaov1)

Copy link
Collaborator

@Yoni-Starkware Yoni-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 2 of 5 files at r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @barak-b-starkware and @noaov1)

Copy link
Collaborator Author

@barak-b-starkware barak-b-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: 1 of 6 files reviewed, all discussions resolved (waiting on @avi-starkware, @noaov1, and @Yoni-Starkware)


crates/blockifier/src/concurrency/flow_test.rs line 94 at r3 (raw file):

Previously, avi-starkware wrote…

We changed the method finish_validation to finish_abort (to be used only if aborted == true)

Done.

@barak-b-starkware barak-b-starkware changed the title test(concurrency): multithreaded test for decrease_validation_index test(concurrency): multithreaded flow test for the scheduler Jun 17, 2024
Copy link
Collaborator

@Yoni-Starkware Yoni-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: 1 of 6 files reviewed, 2 unresolved discussions (waiting on @avi-starkware, @barak-b-starkware, and @noaov1)


crates/blockifier/src/concurrency/flow_test.rs line 64 at r6 (raw file):

                        }
                    }
                }

This is kind of duplicated and not relevant for this test, since nothing special is happening in the commit phase, but I can't think of an elegant halt condition

Code quote:

                if let Some(mut transaction_committer) = scheduler.try_enter_commit_phase() {
                    while let Some(tx_index) = transaction_committer.try_commit() {
                        let mut state_proxy = versioned_state.pin_version(tx_index);
                        let (reads, writes) =
                            get_reads_writes_for(Task::ValidationTask(tx_index), &versioned_state);
                        let reads_valid = state_proxy.validate_reads(&reads);
                        if !reads_valid {
                            state_proxy.delete_writes(&writes, &ContractClassMapping::default());
                            let (_, new_writes) = get_reads_writes_for(
                                Task::ExecutionTask(tx_index),
                                &versioned_state,
                            );
                            state_proxy.apply_writes(
                                &new_writes,
                                &ContractClassMapping::default(),
                                &HashMap::default(),
                            );
                            scheduler.finish_execution_during_commit(tx_index);
                        }
                    }
                }

crates/blockifier/src/concurrency/flow_test.rs line 180 at r6 (raw file):

    contract_address: ContractAddress,
    storage_key: StorageKey,
    value: u128,

Make the contract_address and the storage_key constant

Suggestion:

fn state_maps_with_single_value(value: u128)

@barak-b-starkware barak-b-starkware force-pushed the barak/ml_test/decrease_validation_index branch from beee66a to 90e7e69 Compare June 19, 2024 10:45
Copy link
Collaborator Author

@barak-b-starkware barak-b-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: 1 of 6 files reviewed, 1 unresolved discussion (waiting on @avi-starkware, @noaov1, and @Yoni-Starkware)


crates/blockifier/src/concurrency/flow_test.rs line 64 at r6 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

This is kind of duplicated and not relevant for this test, since nothing special is happening in the commit phase, but I can't think of an elegant halt condition

Why is it "kind of duplicated"?
I think it's relevant for this test because it aims to check all pub functions of the scheduler (and the transaction committer) together in one flow. And in this block, you have:

  1. scheduler.try_enter_commit_phase
  2. transaction_committer.try_commit
  3. scheduler.finish_execution_during_commit

BTW, when running the test, you do get "re-executions" from the if !reads_valid block in the above quote.


crates/blockifier/src/concurrency/flow_test.rs line 180 at r6 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Make the contract_address and the storage_key constant

Done.
Notice that we can't use the fixture of contrat_address that way (I think it's a good suggestion to use the constant).
Maybe we can share the string from test_utils, instead of:

#[fixture]
pub fn contract_address() -> ContractAddress {
    contract_address!("0x18031991")
}

We could use the following:

const CONTRACT_ADDRESS: &str = "0x18031991";

#[fixture]
pub fn contract_address() -> ContractAddress {
    contract_address!(CONTRACT_ADDRESS)
}

LMK if you prefer this option

Copy link
Collaborator

@Yoni-Starkware Yoni-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: 1 of 6 files reviewed, all discussions resolved (waiting on @avi-starkware and @noaov1)


crates/blockifier/src/concurrency/flow_test.rs line 64 at r6 (raw file):

Previously, barak-b-starkware wrote…

Why is it "kind of duplicated"?
I think it's relevant for this test because it aims to check all pub functions of the scheduler (and the transaction committer) together in one flow. And in this block, you have:

  1. scheduler.try_enter_commit_phase
  2. transaction_committer.try_commit
  3. scheduler.finish_execution_during_commit

BTW, when running the test, you do get "re-executions" from the if !reads_valid block in the above quote.

In the sense that nothing new is happening in the commit phase (e.g., bouncer).
the following halt condition makes the commit logic unnecessary:
"all tasks were executed and validated"

The worker's commit also has annoying code duplication - it repeats validate and re-execute with small changes.

But I don't have a better solution, and as you said, you add coverage to the commit methods.

Copy link
Collaborator Author

@barak-b-starkware barak-b-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: 1 of 6 files reviewed, all discussions resolved (waiting on @avi-starkware, @noaov1, and @Yoni-Starkware)


crates/blockifier/src/concurrency/flow_test.rs line 64 at r6 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

In the sense that nothing new is happening in the commit phase (e.g., bouncer).
the following halt condition makes the commit logic unnecessary:
"all tasks were executed and validated"

The worker's commit also has annoying code duplication - it repeats validate and re-execute with small changes.

But I don't have a better solution, and as you said, you add coverage to the commit methods.

Got it, so you want to merge it as is?

@barak-b-starkware
Copy link
Collaborator Author

crates/blockifier/src/concurrency/flow_test.rs line 64 at r6 (raw file):

Previously, barak-b-starkware wrote…

Got it, so you want to merge it as is?

Alternatives:

  1. Try to add the bouncer logic to this test (I think we shouldn't do that because even without the bouncer, you do check the re-execution flow of the commit mechanism)
  2. I can think about how to eliminate the code duplication in the worker, and maybe the solution there can also be implemented in the test.

Copy link
Collaborator

@Yoni-Starkware Yoni-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: 1 of 6 files reviewed, all discussions resolved (waiting on @avi-starkware and @noaov1)


crates/blockifier/src/concurrency/flow_test.rs line 64 at r6 (raw file):

Previously, barak-b-starkware wrote…

Alternatives:

  1. Try to add the bouncer logic to this test (I think we shouldn't do that because even without the bouncer, you do check the re-execution flow of the commit mechanism)
  2. I can think about how to eliminate the code duplication in the worker, and maybe the solution there can also be implemented in the test.

We can merge it as is for now. I didn't approve since I didn't look at the entire code yet (if someone else approves, you can merge)

Copy link
Collaborator

@Yoni-Starkware Yoni-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 5 files at r6, 2 of 2 files at r7, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @barak-b-starkware and @noaov1)


crates/blockifier/src/concurrency/versioned_state.rs line 248 at r7 (raw file):

    pub fn state(&self) -> LockedVersionedState<'_, S> {
        self.0.lock().expect("Failed to acquire state lock.")
    }

Use use it only once.
Remove and use into_inner_state instead (or .lock().unwrap() if something goes wrong)

Code quote:

    #[cfg(test)]
    pub fn state(&self) -> LockedVersionedState<'_, S> {
        self.0.lock().expect("Failed to acquire state lock.")
    }

Copy link
Collaborator

@Yoni-Starkware Yoni-Starkware left a comment

Choose a reason for hiding this comment

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

One last comment

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @barak-b-starkware and @noaov1)

@barak-b-starkware barak-b-starkware force-pushed the barak/ml_test/decrease_validation_index branch from 90e7e69 to 7fcaa65 Compare June 24, 2024 07:21
Copy link
Collaborator Author

@barak-b-starkware barak-b-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, 1 unresolved discussion (waiting on @noaov1 and @Yoni-Starkware)


crates/blockifier/src/concurrency/versioned_state.rs line 248 at r7 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

Use use it only once.
Remove and use into_inner_state instead (or .lock().unwrap() if something goes wrong)

Done.

Copy link
Collaborator

@Yoni-Starkware Yoni-Starkware 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 2 of 2 files at r8, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @noaov1)

@barak-b-starkware barak-b-starkware merged commit c3267c0 into main Jun 24, 2024
9 checks passed
@barak-b-starkware barak-b-starkware deleted the barak/ml_test/decrease_validation_index branch June 24, 2024 13:27
gswirski pushed a commit to reilabs/blockifier that referenced this pull request Jun 26, 2024
derive Default for GenesisJson
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