-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(vm): Support tracers for old vm (#926)
## What ❔ Support existing tracers for old vms ## Why ❔ First step for making tracing on flight instead of saving it in db ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zk fmt` and `zk lint`. - [ ] Spellcheck has been run via `zk spellcheck`. --------- Signed-off-by: Danil <deniallugo@gmail.com>
- Loading branch information
1 parent
1c1f131
commit 9fc2d95
Showing
11 changed files
with
196 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use std::sync::Arc; | ||
|
||
use once_cell::sync::OnceCell; | ||
use zksync_types::vm_trace::Call; | ||
|
||
/// For backward compatibility with vm before vm with virtual blocks. | ||
/// These tracers are tightly coupled with the VM implementation and we have to pass only params for them and not tracers by itself. | ||
#[derive(Debug, Clone)] | ||
pub enum OldTracers { | ||
CallTracer(Arc<OnceCell<Vec<Call>>>), | ||
StorageInvocations(usize), | ||
/// Special cases for not supported tracers. | ||
None, | ||
} | ||
|
||
impl OldTracers { | ||
pub fn call_tracer(&self) -> Option<Arc<OnceCell<Vec<Call>>>> { | ||
match self { | ||
OldTracers::CallTracer(a) => Some(a.clone()), | ||
_ => None, | ||
} | ||
} | ||
pub fn storage_invocations(&self) -> Option<usize> { | ||
match self { | ||
OldTracers::StorageInvocations(a) => Some(*a), | ||
_ => None, | ||
} | ||
} | ||
} | ||
|
||
/// Tracer dispatcher is a tracer that can convert list of tracers to params for old VM. | ||
#[derive(Debug, Default, Clone)] | ||
pub struct TracerDispatcher { | ||
pub(crate) call_tracer: Option<Arc<OnceCell<Vec<Call>>>>, | ||
pub(crate) storage_invocations: Option<usize>, | ||
} | ||
|
||
impl TracerDispatcher { | ||
pub fn new(tracers: Vec<OldTracers>) -> Self { | ||
let call_tracer = tracers.iter().find_map(|x| x.call_tracer()); | ||
let storage_invocations = tracers.iter().find_map(|x| x.storage_invocations()); | ||
|
||
Self { | ||
call_tracer, | ||
storage_invocations, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.