-
Notifications
You must be signed in to change notification settings - Fork 94
feat: enable DAP-backed transaction script debugging #1959
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
Changes from all commits
d359523
4e19609
053e1d1
0297697
cfd63a6
230760f
938dbb5
d4506a5
4facba6
b2add88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,13 @@ | ||
| use std::collections::BTreeMap; | ||
| use std::fs; | ||
| #[cfg(feature = "dap")] | ||
| use std::net::SocketAddr; | ||
| use std::path::PathBuf; | ||
|
|
||
| use clap::Parser; | ||
| use miden_client::account::AccountId; | ||
| use miden_client::keystore::Keystore; | ||
| use miden_client::transaction::{ForeignAccount, TransactionScript}; | ||
| use miden_client::vm::AdviceInputs; | ||
| use miden_client::{Client, Felt, Word}; | ||
| use serde::{Deserialize, Deserializer, Serialize, de}; | ||
|
|
@@ -47,6 +52,12 @@ pub struct ExecCmd { | |
| /// Print the output stack grouped into words | ||
| #[arg(long, default_value_t = false)] | ||
| hex_words: bool, | ||
|
|
||
| /// Start a DAP debug adapter server on the given address (e.g. "127.0.0.1:4711") | ||
| /// and wait for a DAP client to connect before executing. | ||
| #[cfg(feature = "dap")] | ||
| #[arg(long = "start-debug-adapter")] | ||
| start_debug_adapter: Option<SocketAddr>, | ||
| } | ||
|
|
||
| impl ExecCmd { | ||
|
|
@@ -62,7 +73,7 @@ impl ExecCmd { | |
| )); | ||
| } | ||
|
|
||
| let program = std::fs::read_to_string(script_path)?; | ||
| let program = fs::read_to_string(script_path)?; | ||
|
|
||
| let account_id = | ||
| get_input_acc_id_by_prefix_or_default(&client, self.account_id.clone()).await?; | ||
|
|
@@ -77,7 +88,7 @@ impl ExecCmd { | |
| )); | ||
| } | ||
|
|
||
| let input_data = std::fs::read_to_string(input_file)?; | ||
| let input_data = fs::read_to_string(input_file)?; | ||
| deserialize_tx_inputs(&input_data)? | ||
| }, | ||
| None => vec![], | ||
|
|
@@ -87,19 +98,13 @@ impl ExecCmd { | |
|
|
||
| let tx_script = client.code_builder().compile_tx_script(&program)?; | ||
|
|
||
| let result = client | ||
| .execute_program(account_id, tx_script, advice_inputs, BTreeMap::new()) | ||
| .await; | ||
| let output_stack = | ||
| self.execute_program(&mut client, account_id, tx_script, advice_inputs).await?; | ||
|
|
||
| match result { | ||
| Ok(output_stack) => { | ||
| println!("Program executed successfully"); | ||
| println!("Output stack:"); | ||
| self.print_stack(output_stack); | ||
| Ok(()) | ||
| }, | ||
| Err(err) => Err(CliError::Exec(err.into(), "error executing the program".to_string())), | ||
| } | ||
| println!("Program executed successfully"); | ||
| println!("Output stack:"); | ||
| self.print_stack(output_stack); | ||
| Ok(()) | ||
| } | ||
|
Comment on lines
+101
to
108
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this change proposed by
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. This was not needed for lint. |
||
|
|
||
| /// Print the output stack in a human-readable format | ||
|
|
@@ -130,6 +135,53 @@ impl ExecCmd { | |
| } | ||
| } | ||
| } | ||
|
|
||
| async fn execute_program<AUTH: Keystore + Sync + 'static>( | ||
| &self, | ||
| client: &mut Client<AUTH>, | ||
| account_id: AccountId, | ||
| tx_script: TransactionScript, | ||
| advice_inputs: AdviceInputs, | ||
| ) -> Result<[Felt; 16], CliError> { | ||
|
Comment on lines
+139
to
+145
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this compile well without the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. :) |
||
| let foreign_accounts = BTreeMap::<AccountId, ForeignAccount>::new(); | ||
|
|
||
| #[cfg(feature = "dap")] | ||
| if let Some(addr) = self.start_debug_adapter.as_ref() { | ||
| let config = miden_debug::DapConfig::new(addr.to_string()); | ||
| let config_handle = config.clone(); | ||
| miden_debug::DapConfig::set_global(config); | ||
|
|
||
| let script_path = PathBuf::from(&self.script_path); | ||
| loop { | ||
| let program = fs::read_to_string(&script_path)?; | ||
| let tx_script = client.code_builder().compile_tx_script(&program)?; | ||
|
|
||
| let result = client | ||
| .execute_program_with_dap( | ||
| account_id, | ||
| tx_script, | ||
| advice_inputs.clone(), | ||
| foreign_accounts.clone(), | ||
| ) | ||
| .await; | ||
|
|
||
| if config_handle.restart_requested() { | ||
| config_handle.reset_restart(); | ||
| println!("Recompiling from source and restarting debug session..."); | ||
| continue; | ||
| } | ||
|
|
||
| return result.map_err(|err| { | ||
| CliError::Exec(err.into(), "error executing the program".to_string()) | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| client | ||
| .execute_program(account_id, tx_script, advice_inputs, foreign_accounts) | ||
| .await | ||
| .map_err(|err| CliError::Exec(err.into(), "error executing the program".to_string())) | ||
| } | ||
| } | ||
|
|
||
| // INPUT FILE PROCESSING | ||
|
|
||
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.
This file has many
stdimports that could be top-leveled.