-
Notifications
You must be signed in to change notification settings - Fork 25
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
fix(blockifier): merge state diff with squash #2310
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2310 +/- ##
===========================================
+ Coverage 40.10% 71.16% +31.05%
===========================================
Files 26 102 +76
Lines 1895 13739 +11844
Branches 1895 13739 +11844
===========================================
+ Hits 760 9777 +9017
- Misses 1100 3547 +2447
- Partials 35 415 +380 ☔ View full report in Codecov by Sentry. |
29a614f
to
8640df0
Compare
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.
Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @yoavGrs and @Yoni-Starkware)
a discussion (no related file):
nice! much cleaner, and nice squashing algorithm :)
crates/blockifier/src/state/cached_state.rs
line 62 at r1 (raw file):
pub fn to_state_cache(&mut self) -> StateResult<StateCache> { self.update_initial_values_of_write_only_access()?;
what is this?
Code quote:
self.update_initial_values_of_write_only_access()?;
crates/blockifier/src/state/cached_state.rs
line 395 at r1 (raw file):
// Invariant: keys cannot be deleted from fields (only used internally by the cached state). #[derive(Clone, Debug, Default, PartialEq, Eq)]
I'd rather not ad this Clone if possible - the struct size is not O(1).
can you return a reference in to_state_cache?
or, change the signature to accept mut self
instead of &mut self
; to_X
functions are consuming by convension
Code quote:
(Clone,
crates/blockifier/src/state/cached_state.rs
line 417 at r1 (raw file):
/// is important. pub fn merge(state_caches: Vec<Self>) -> Self { let mut merged_state_cache = StateCache::default();
i think this is the terminology
Suggestion:
/// Squashes the given state caches into a single one. Note that the order of the state caches
/// is important.
pub fn squash(state_caches: Vec<Self>) -> Self {
let mut squashed_state_cache = StateCache::default();
crates/blockifier/src/state/cached_state_test.rs
line 418 at r1 (raw file):
#[case(true, vec![felt!("0x7"), felt!("0x0")], false)] #[case(false, vec![felt!("0x7"), felt!("0x1")], false)] #[case(false, vec![felt!("0x0"), felt!("0x8")], false)]
nice
Code quote:
#[case(false, vec![felt!("0x0"), felt!("0x8")], false)]
f50f2fa
to
e3c7be2
Compare
8640df0
to
dd019b3
Compare
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 3 files reviewed, 4 unresolved discussions (waiting on @dorimedini-starkware and @Yoni-Starkware)
a discussion (no related file):
Previously, dorimedini-starkware wrote…
nice! much cleaner, and nice squashing algorithm :)
:)
crates/blockifier/src/state/cached_state.rs
line 62 at r1 (raw file):
Previously, dorimedini-starkware wrote…
what is this?
It fills missing initial_reads, as done in to_state_diff
.
crates/blockifier/src/state/cached_state.rs
line 395 at r1 (raw file):
Previously, dorimedini-starkware wrote…
I'd rather not ad this Clone if possible - the struct size is not O(1).
can you return a reference in to_state_cache?
or, change the signature to acceptmut self
instead of&mut self
;to_X
functions are consuming by convension
I don't see an immediate solution to this.
In account_transaction.rs
, we should save a "snapshot" of the validation state cache and update the state for the execution stage.
(Conceptually, only the fn commit
needs a mutable base state, so it is possible to own a reference to the state cache up to this point.)
crates/blockifier/src/state/cached_state.rs
line 417 at r1 (raw file):
Previously, dorimedini-starkware wrote…
i think this is the terminology
Done.
dd019b3
to
1a882c4
Compare
fe48ec5
to
b77df1c
Compare
1dde6f9
to
267afb2
Compare
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.
Reviewed 8 of 8 files at r4, all commit messages.
Reviewable status: 8 of 17 files reviewed, 3 unresolved discussions (waiting on @Yoni-Starkware)
crates/blockifier/src/fee/receipt.rs
line 107 at r5 (raw file):
.starknet_resources .state .da_gas_vector(tx_context.block_context.block_info.use_kzg_da);
this change - and others here - are from 2301, please rebase
Code quote:
.da_gas_vector(tx_context.block_context.block_info.use_kzg_da);
crates/blockifier/resources/versioned_constants_0_13_0.json
line 11 at r5 (raw file):
"disable_cairo0_redeclaration": false, "enable_stateful_compression": false, "comprehensive_state_diff": false,
@Yoni-Starkware any opinion on the name?
Code quote:
"comprehensive_state_diff"
2de8cb3
to
203c076
Compare
267afb2
to
e5f8ab9
Compare
203c076
to
920ed48
Compare
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.
Reviewed 1 of 1 files at r8, 1 of 1 files at r9, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Yoni-Starkware)
bd621f5
to
923bc81
Compare
6115e79
to
24343e4
Compare
923bc81
to
c9454fc
Compare
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: all files reviewed, 3 unresolved discussions (waiting on @dorimedini-starkware and @yoavGrs)
crates/blockifier/src/state/cached_state.rs
line 395 at r1 (raw file):
Previously, dorimedini-starkware wrote…
ok, I think it won't hit performance too much.
@Yoni-Starkware thoughts?
tl;dr extraclone
of the state cache of a tx is now required
If you define let mut execution_state = CachedState::new(MutRefState::new(validate_state));
, you could access the cache of validate after execution. But it might be too ugly, so I'm okay with this clone.
crates/blockifier/src/state/cached_state.rs
line 414 at r9 (raw file):
/// If 'comprehensive_state_diff' is false, opposite updates may not be canceled out. Used for /// backward compatibility. pub fn squashed_state_diff(
I think it's better to have a separate function that only returns a squashed StateCache (in your smart ordering)
crates/blockifier/src/state/cached_state.rs
line 415 at r9 (raw file):
/// backward compatibility. pub fn squashed_state_diff( state_caches: Vec<Self>,
Can you at least save the clone of execute
? it is much heavier
Suggestion:
state_caches: Vec<&Self>,
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: all files reviewed, 4 unresolved discussions (waiting on @dorimedini-starkware and @yoavGrs)
crates/blockifier/src/transaction/account_transaction.rs
line 601 at r9 (raw file):
), execution_steps_consumed, );
@dorimedini-starkware any fancy way to save this iteration over the cache if not needed? (I.e., if the tx is not reverted)
Suggestion:
// Save the state changes resulting from running `validate_tx`, to be used later for
// resource and fee calculation.
let validate_state_cache = state.to_state_cache()?;
// Create copies of state and validate_resources for the execution.
// Both will be rolled back if the execution is reverted or committed upon success.
let mut execution_state = TransactionalState::create_transactional(state);
let execution_result =
self.run_execute(&mut execution_state, &mut execution_context, remaining_gas);
// Pre-compute cost in case of revert.
// TODO(tzahi): add reverted_l2_gas to the receipt.
let execution_steps_consumed =
n_allotted_execution_steps - execution_context.n_remaining_steps();
let revert_receipt = TransactionReceipt::from_account_tx(
self,
&tx_context,
&validate_state_cache.to_state_diff(),
CallInfo::summarize_many(
validate_call_info.iter(),
&tx_context.block_context.versioned_constants,
),
execution_steps_consumed,
);
c9454fc
to
3a7681a
Compare
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: 14 of 17 files reviewed, 4 unresolved discussions (waiting on @dorimedini-starkware and @Yoni-Starkware)
crates/blockifier/src/state/cached_state.rs
line 414 at r9 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
I think it's better to have a separate function that only returns a squashed StateCache (in your smart ordering)
Done.
(If I understood correctly what you asked me)
crates/blockifier/src/state/cached_state.rs
line 415 at r9 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Can you at least save the clone of
execute
? it is much heavier
Yes. Done.
crates/blockifier/src/transaction/account_transaction.rs
line 601 at r9 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
@dorimedini-starkware any fancy way to save this iteration over the cache if not needed? (I.e., if the tx is not reverted)
If we don't return one big match
, it's possible.
crates/blockifier/resources/versioned_constants_0_13_0.json
line 11 at r5 (raw file):
Previously, dorimedini-starkware wrote…
@Yoni-Starkware any opinion on the name?
Approved in the previous PR
3a7681a
to
fb29524
Compare
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: 14 of 17 files reviewed, 5 unresolved discussions (waiting on @dorimedini-starkware and @yoavGrs)
crates/blockifier/src/state/cached_state.rs
line 69 at r10 (raw file):
/// It is not guaranteed that every write has a corresponding initial read.
Why are we okay with this?
Code quote:
pub fn to_state_cache(&mut self) -> StateResult<StateCache> {
self.update_initial_values_of_write_only_access()?;
Ok(self.cache.borrow().clone())
}
/// It is not guaranteed that every write has a corresponding initial read.
pub fn raw_state_cache(&self) -> Ref<'_, StateCache> {
self.cache.borrow()
}
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: 14 of 17 files reviewed, 4 unresolved discussions (waiting on @dorimedini-starkware and @yoavGrs)
crates/blockifier/src/state/cached_state.rs
line 414 at r9 (raw file):
Previously, yoavGrs wrote…
Done.
(If I understood correctly what you asked me)
Almost - just move the .to_state_diff
outside (and rename squashed_state_diff()
-> squash_state_caches
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: 14 of 17 files reviewed, 5 unresolved discussions (waiting on @dorimedini-starkware and @yoavGrs)
crates/blockifier/src/state/cached_state.rs
line 69 at r10 (raw file):
pub fn raw_state_cache(&self) -> Ref<'_, StateCache> { self.cache.borrow() }
Oh, I see that you moved it outside. If there is not particular reason, I think it's better to have a single function like this. You can clone the result outside for validate.
Suggestion:
pub fn borrow_updated_state_cache(&mut self) -> StateResult<Ref<'_, StateCache>> {
self.update_initial_values_of_write_only_access()?;
Ok(self.cache.borrow())
}
fb29524
to
dc573fe
Compare
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: 14 of 17 files reviewed, 5 unresolved discussions (waiting on @dorimedini-starkware and @Yoni-Starkware)
crates/blockifier/src/state/cached_state.rs
line 414 at r9 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Almost - just move the
.to_state_diff
outside (and renamesquashed_state_diff()
->squash_state_caches
Done.
crates/blockifier/src/state/cached_state.rs
line 69 at r10 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
/// It is not guaranteed that every write has a corresponding initial read.
Why are we okay with this?
Removed.
crates/blockifier/src/state/cached_state.rs
line 69 at r10 (raw file):
Previously, Yoni-Starkware (Yoni) wrote…
Oh, I see that you moved it outside. If there is not particular reason, I think it's better to have a single function like this. You can clone the result outside for validate.
Nice. Done.
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: 14 of 17 files reviewed, 5 unresolved discussions (waiting on @dorimedini-starkware and @Yoni-Starkware)
crates/blockifier/src/transaction/account_transaction.rs
line 601 at r9 (raw file):
Previously, yoavGrs wrote…
If we don't return one big
match
, it's possible.
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.
Reviewed 3 of 3 files at r12, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @Yoni-Starkware)
crates/blockifier/src/state/cached_state_test.rs
line 447 at r12 (raw file):
} let merged_changes = StateCache::squash_state_diff_backward_compatible(
I don't think it's necessary to append _backward_compatible
to the name; you have the (documented) boolean parameter
non-blocking
Code quote:
squash_state_diff_backward_compatible
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: all files reviewed, 4 unresolved discussions (waiting on @Yoni-Starkware)
crates/blockifier/src/state/cached_state_test.rs
line 447 at r12 (raw file):
Previously, dorimedini-starkware wrote…
I don't think it's necessary to append
_backward_compatible
to the name; you have the (documented) boolean parameter
non-blocking
Done.
dc573fe
to
5861d2a
Compare
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.
Reviewed 3 of 3 files at r13, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @Yoni-Starkware)
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.
Reviewed all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @yoavGrs)
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 @yoavGrs)
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 @yoavGrs)
* chore(starknet_batcher): delete obsolete todo (starkware-libs#2389) * chore(blockifier): add global max_sierra_gas to versioned constants (starkware-libs#2330) * feat(starknet_api): checked mul for gas vector (starkware-libs#2300) * feat(consensus): proposer rotates across validators (starkware-libs#2405) * feat(sequencing): validate streamed proposals (starkware-libs#2305) * feat(ci): deny rust warnings in all workflows (starkware-libs#2388) Signed-off-by: Dori Medini <[email protected]> * feat(blockifier): compute allocation cost (starkware-libs#2301) * chore(starknet_sequencer_infra): add dynamic logging util fn commit-id:9ffe9fbe * chore(starknet_sequencer_infra): add tracing test commit-id:76d16e9a * chore(starknet_sequencer_infra): add run_until utility fn commit-id:194a4b6c * chore(infra_utils): change run_until to support async functions commit-id:92e1f8a3 * chore(starknet_integration_tests): use run_until to await for block creation commit-id:667e001c * chore(infra_utils): rename logger struct commit-id:6520ae54 * chore(blockifier): explicit creation of AccountTransaction (starkware-libs#2331) * test(starknet_integration_tests): test commit blocks by running multiple heights * chore(starknet_batcher): set temp gas prices in propose block input (starkware-libs#2341) * chore(starknet_batcher): set use_kzg_da flag in build block input (starkware-libs#2345) * feat(ci): inherit the rust toolchain toml in moonrepo action (starkware-libs#2423) Signed-off-by: Dori Medini <[email protected]> * chore(blockifier): enforce_fee() impl by api::executable_transaction::AccountTransaction (starkware-libs#2377) * chore(starknet_integration_tests): inherit sequencer node's stdout (starkware-libs#2427) * chore(blockifier): invoke() declare() deploy_account() change ret val to api_tx (starkware-libs#2412) * chore(starknet_consensus_manager): set proposer address in propose block input (starkware-libs#2346) * feat(consensus): add observer mode * feat(consensus): sequencer context broadcasts votes (starkware-libs#2422) * chore(deployment): support unified deployment config (starkware-libs#2378) * feat(starknet_api): add sierra version to class info (starkware-libs#2313) * refactor(starknet_api): change default sierra contract class to valid one (starkware-libs#2439) * feat(starknet_l1_provider): add uninitiailized state and make it the default (starkware-libs#2434) This is to comply with upcoming integration with infra, which separates instantiation with initialization. In particular, `Pending` state should be already post-syncing with L1, whereas `Uninitialized` is unsynced and unusable. Co-Authored-By: Gilad Chase <[email protected]> * feat(papyrus_storage)!: bump storage version for version 13.4 (starkware-libs#2333) * feat(native_blockifier): allow deserialization of python l1_data_gas (starkware-libs#2447) * refactor(blockifier): split FC to groups base on their tags (starkware-libs#2236) * test(consensus): remove warning on into mock propsal part (starkware-libs#2448) * chore(blockifier): use test_utils::invoke_tx() instead of trans::test_utils::account_invoke_tx() (starkware-libs#2428) * chore(blockifier): save sierra to Feature contracts (starkware-libs#2370) * feat(blockifier): don't count Sierra gas in CairoSteps mode (starkware-libs#2440) * chore(blockifier): convert Sierra gas to L1 gas if in L1 gas mode (starkware-libs#2451) * feat(blockifier): add comprehensive state diff versioned constant (starkware-libs#2407) * chore(starknet_consensus_manager): add chain_id to config * refactor(papyrus_p2p_sync): add random_header utility function (starkware-libs#2381) * chore(starknet_batcher): pass block info from consensus to batcher (starkware-libs#2238) * test(starknet_mempool): tx added to mempool are forwarded to propagator client (starkware-libs#2288) * fix: fix CR comments * test(starknet_mempool): tx added to mempool are forwarded to propagator client * feat(sequencing): cache proposals from bigger heights(starkware-libs#2325) * fix: change to latest ubuntu version in feature combo CI (starkware-libs#2414) * chore(blockifier): replace entry_point_gas_cost with initial_budget (starkware-libs#2247) * test(starknet_gateway): handle todo in test_get_block_info (starkware-libs#2267) * chore(starknet_api): revert use get_packaget_dir instead of env var This reverts commit c45f5cc. commit-id:a48736e7 * chore(starknet_api): rely on env::current_dir() instead of CARGO_MANIFEST_DIR commit-id:301ed4eb * chore(blockifier): move env var from run time to compile time commit-id:80a7265d * chore(starknet_sierra_compile): move env var from run time to compile time commit-id:6e7f2a75 * chore: remove the use of zero as a validator id (starkware-libs#2411) * refactor(papyrus_p2p_sync): add_test receives query size instead of constant (starkware-libs#2379) * fix(blockifier): merge state diff with squash (starkware-libs#2310) * feat(blockifier): get revert receipt only in case of revert (starkware-libs#2471) * chore(starknet_integration_tests): create chain info once (starkware-libs#2482) * chore(starknet_sierra_compile): split build utils commit-id:0f504fd7 * chore(starknet_sierra_compile): set runtime-accessible out_dir env var commit-id:539f16db * chore(starknet_sierra_compile): avoid using OUT_DIR in run time commit-id:cd6fba29 * refactor(starknet_api): use const in sierra version (starkware-libs#2477) * chore: cleanups of OUT_DIR env var (starkware-libs#2484) commit-id:18d61b1d * chore(starknet_api): shorten executable_transaction usage path * fix(sequencing): remove old proposal pipes from consensus (starkware-libs#2452) * test(starknet_integration_tests): match sequencer address with default validator id (starkware-libs#2486) * fix(ci): move specific versioned deps to root toml (starkware-libs#2487) * fix(ci): move specific versioned deps to root toml Signed-off-by: Dori Medini <[email protected]> * fix(starknet_sierra_compile): fix build.rs Signed-off-by: Dori Medini <[email protected]> * chore(starknet_batcher): in block builder use the consensus suplied sequncer address (starkware-libs#2409) * chore: cleanups of CARGO_MANIFEST_DIR env var commit-id:c96f2d88 * fix(starknet_sierra_compile): missing import in feature (starkware-libs#2495) commit-id:abd0a286 * chore(blockifier): add keccak_builtin_gas_cost (starkware-libs#2327) * chore(blockifier): add struct ExecutionFlags to AccTx & use instead of transaction::ExecutionFlags (starkware-libs#2429) * chore(blockifier): add new constructor to AccountTransaction (starkware-libs#2431) * chore(blockifier): remove only_qury from IvokeTxArgs (starkware-libs#2437) * chore(blockifier): remove struct ExecutionFlags and replace w concurrency_mode bool (starkware-libs#2470) * chore(blockifier): remove declare.rs deploy_account.rs invoke.rs from blockifier (starkware-libs#2478) --------- Signed-off-by: Dori Medini <[email protected]> Co-authored-by: YaelD <[email protected]> Co-authored-by: aner-starkware <[email protected]> Co-authored-by: yoavGrs <[email protected]> Co-authored-by: matan-starkware <[email protected]> Co-authored-by: guy-starkware <[email protected]> Co-authored-by: dorimedini-starkware <[email protected]> Co-authored-by: Itay Tsabary <[email protected]> Co-authored-by: avivg-starkware <[email protected]> Co-authored-by: Yair Bakalchuk <[email protected]> Co-authored-by: Arnon Hod <[email protected]> Co-authored-by: Alon Haramati <[email protected]> Co-authored-by: Asmaa Magdoub <[email protected]> Co-authored-by: alon-dotan-starkware <[email protected]> Co-authored-by: AvivYossef-starkware <[email protected]> Co-authored-by: giladchase <[email protected]> Co-authored-by: Gilad Chase <[email protected]> Co-authored-by: DvirYo-starkware <[email protected]> Co-authored-by: nimrod-starkware <[email protected]> Co-authored-by: Meshi Peled <[email protected]> Co-authored-by: Yoni <[email protected]> Co-authored-by: Yael Doweck <[email protected]> Co-authored-by: ShahakShama <[email protected]> Co-authored-by: Alon-Lukatch-Starkware <[email protected]> Co-authored-by: Yonatan-Starkware <[email protected]> Co-authored-by: Yair <[email protected]> Co-authored-by: Itay-Tsabary-Starkware <[email protected]>
No description provided.