-
Notifications
You must be signed in to change notification settings - Fork 16
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
Change edr_napi::provider::Response::solidity_trace
to return a stack trace
#734
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: b8f0703 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@agostbiro I pushed the changes to run the stack traces tests using the new
This will stop at the first failure. The test that is failing runs this bytecode:
with calldata |
* wip: make tracing config a provider argument * Patch Hardhat to pass tracing config to provider --------- Co-authored-by: Franco Victorio <[email protected]>
let build_info_config: edr_solidity::contract_decoder::BuildInfoConfig = | ||
serde_json::from_value(tracing_config)?; | ||
let contract_decoder = ContractDecoder::new(&build_info_config) | ||
.map_err(|error| napi::Error::from_reason(error.to_string()))?; | ||
let contract_decoder = Arc::new(contract_decoder); |
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 work should be done on a thread from the blocking thread pool to avoid blocking the JS event loop, but that's difficult to achieve, because this is not an async function (precluded by the Env
argument not being Send
) and the contract decoder needs to be passed in to the logger which also needs the Env
.
Since constructing the contract decoder (previously called VmTraceDecoder
) was blocking previously as well, and this PR is getting very large, I don't think we have to fix it here.
The goal of this PR is to port Solidity stack trace generation to pure Rust and without NAPI dependencies. Doing this also necessitated porting
hardhat_addCompilationResult
to EDR from Hardhat.Most of the additions
edr_solidity
come from movingedr_napi
code there and stripping the NAPI dependencies. As the stack trace error inference involves complex heuristics, this code was originally ported verbatim from JS which lead to non-idiomatic Rust code. I originally wanted to clean it up as part of moving inference code fromedr_napi
toedr_solidity
, but I only managed to it partially due to running out of time, so much of it remains unidiomatic Rust code. I'd ask to exclude this aspect from review.I think these are the important changes in
edr_solidity
that need review:Bytecode
is renamed toContractMetadata
,VmTrace
is renamed toNestedTrace
(to differentiate from flat traces fromedr_evm
) andVmTraceDecoder
is renamed toContractDecoder
.NestedTracer
that has interior mutability, but it's converted to a nested trace type without interior mutability when returned fromNestedTracer
. This way the risk of panics from interior mutability is confined to thenested_tracer
module.Arc<RwLock>
in build model types instead ofRc<RefCell>
. This was necessary, because the EDR provider holds on to those types now to supporthardhat_addCompilationResult
, so they need to beSend
. We don't really need to write to the types held byArc<RwLock>
outside theedr_solidity
crate, but it took too long to remove that so I gave up on it as part of this PR.Besides
edr_solidity
, on the Rust side changes to the provider inedr_provider
andedr_napi
would be important to review I think.