Add sncast get tx-trace - #4546
Conversation
f44eb8d to
e41c61f
Compare
| @@ -163,6 +165,20 @@ impl OutputBuilder { | |||
| field_value, | |||
| ) | |||
| .unwrap(); | |||
|
|
|||
| for line in value_lines { | |||
| if line.is_empty() { | |||
| content.push('\n'); | |||
| } else { | |||
| writeln!( | |||
| content, | |||
| "{}{}", | |||
| " ".repeat(field_width + 1), | |||
| style(line).yellow() | |||
| ) | |||
| .unwrap(); | |||
| } | |||
| } | |||
There was a problem hiding this comment.
note: This change is needed to align continuation lines with the field value, keeping multiline values (such as revert reason) readable.
| starknet-rust = "0.19.0" | ||
| # TODO: Restore version once starknet-rust releases new version | ||
| starknet-rust = { git = "https://github.com/software-mansion/starknet-rust", rev = "56efca00feffac6beb39f464eca71afa42c1813b" } |
There was a problem hiding this comment.
note: Temporary, due to change in the content type in NoTraceAvailable error.
3fdf536 to
bf9b114
Compare
bb2b7d8 to
a3154a4
Compare
|
|
||
| fn decode_invocation_json( | ||
| invocation: &FunctionInvocation, | ||
| json: &mut Value, |
There was a problem hiding this comment.
Why decode_execute_invocation_json takes Option and decode_invocation_json not?
| json.get_mut("validate_invocation"), | ||
| decoder, | ||
| ); | ||
| if let Some(json) = json.get_mut("constructor_invocation") { |
There was a problem hiding this comment.
Shouldn't we rather throw an error if required field is missing? 🤔
| where | ||
| S: Serializer, | ||
| { | ||
| let mut json = serde_json::to_value(&self.trace).map_err(S::Error::custom)?; |
There was a problem hiding this comment.
What is the rationale that it is first parsed to json instead of direct serialization of the struct like for other commands e.g. get tx-receipt?
There was a problem hiding this comment.
Direct serialization would return raw felts. We convert to JSON first to preserve the original trace schema while replacing selectors, calldata etc. with decoded values. Mentioned tx-receipt (and others) do not require such transformations.
| let builder = append_calls(builder, &invocation.calls, decoder, indent); | ||
| let builder = builder | ||
| .with_indent(indent) | ||
| .felt_field("Class Hash", &invocation.class_hash) |
There was a problem hiding this comment.
Let's use padded_felt_field for class hashes and contract addresses
| } | ||
|
|
||
| #[must_use] | ||
| pub fn contract_addresses_by_class_hash( |
There was a problem hiding this comment.
It seems that this and related code should be placed in starknet_commands/get/tx_trace.rs not in reponse dir
| fn provider_error_message(error: &ProviderError) -> String { | ||
| match error { | ||
| ProviderError::StarknetError(error) => error.message().to_string(), | ||
| error => error.to_string(), | ||
| } | ||
| } |
There was a problem hiding this comment.
Does it make sense to fix it on the starknet-rust side?
There was a problem hiding this comment.
Yeah it does, changed in software-mansion/starknet-rust#160
| builder | ||
| } | ||
|
|
||
| fn append_full_invocation( |
There was a problem hiding this comment.
The current display seems to be in this order:
- root Call Type, Calldata, Caller Address
- root Calls
- nested call details
- root Class Hash, Contract Address, Entry Point Selector etc.
which is very hard to read, please fix it so all root data go first
|
|
||
| ## `--full` | ||
| Optional. | ||
| Conflicts with: [`--json`](../common.md#--json--j) |
There was a problem hiding this comment.
If --json is passed directly after sncast there is no conflict and --full is ignored
There was a problem hiding this comment.
Yeah, right. In #4567 I made --json flag global, so the conflict could be defined at clap level. However, clap does not detect it when --json appears before the subcommand. I think the cleanest solution is to validate the --json / --full conflict at runtime remove the now-unnecessary change from mentioned PR.
Runtime validation -> 7758ae0
There was a problem hiding this comment.
Could you remind me why actually we can't use both these flags together? 🙏
00e1a51 to
ff96770
Compare
c6d690a to
7bbf106
Compare
62ead40 to
295bedc
Compare
| Type: INVOKE | ||
| Validate Invocation | ||
| Entry Point Selector: __validate__ | ||
| Contract Address: 0x[..] |
There was a problem hiding this comment.
Why not to show the exact values here?
| fetch_contract_classes(&provider, class_hashes(&trace)).await; | ||
|
|
||
| if !failures.is_empty() { | ||
| ui.print_warning(WarningMessage::new(format_class_fetch_warning(&failures))); |
There was a problem hiding this comment.
Would it be possible to make it part of decoding_warnings so all decoding errors are gathered in one place? It should work better for json output then
|
|
||
| fn selector(&self, invocation: &FunctionInvocation) -> String { | ||
| if let Some(abi) = self.sierra_abis.get(&invocation.class_hash.into_()) | ||
| && let Some(function) = |
There was a problem hiding this comment.
invocation.class_hash.into_() is evaluated a few times in this function, let's just add
let class_hash: ClassHash = invocation.class_hash.into_();also in the functions below
| format!("Some trace data is shown as raw felts:\n{details}") | ||
| } | ||
|
|
||
| #[must_use] |
There was a problem hiding this comment.
| #[must_use] |
| let builder = if decoder.decoding_warnings().is_empty() { | ||
| OutputBuilder::new() | ||
| } else { | ||
| let warning_message = format_decoding_warning(&decoder.decoding_warnings()); |
There was a problem hiding this comment.
nit: decoder.decoding_warnings() is called twice
| sierra_abis: HashMap<ClassHash, Vec<AbiEntry>>, | ||
| legacy_class_hashes: HashSet<ClassHash>, | ||
| legacy_selectors: HashMap<(ClassHash, Felt), String>, | ||
| decoding_warnings: RefCell<BTreeSet<TraceDecodingWarning>>, |
There was a problem hiding this comment.
Can we omit using interior mutability here?
|
|
||
| ## `--full` | ||
| Optional. | ||
| Conflicts with: [`--json`](../common.md#--json--j) |
There was a problem hiding this comment.
Could you remind me why actually we can't use both these flags together? 🙏
| let results = stream::iter(class_hashes) | ||
| .map(|class_hash| async move { | ||
| match provider | ||
| .get_class(BlockId::Tag(BlockTag::PreConfirmed), *class_hash) |
There was a problem hiding this comment.
Why pre confirmed and not latest?
| .field("Calldata", &decoder.calldata(invocation)) | ||
| .padded_felt_field("Caller Address", &invocation.caller_address) | ||
| .padded_felt_field("Class Hash", &invocation.class_hash) | ||
| .padded_felt_field("Contract Address", &invocation.contract_address) |
There was a problem hiding this comment.
| .padded_felt_field("Contract Address", &invocation.contract_address) | |
| .contract_address(&invocation.contract_address) |
|
|
||
| ## Overview | ||
|
|
||
| Starknet Foundry `sncast` supports the inspection of transaction statuses on a given network with the `sncast get tx-status` command. |
Towards #3557
Introduced changes
Add
sncast get tx-tracecommandChecklist
CHANGELOG.md