-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(cheatcodes): ensure file sync on vm.writeFile #11590
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
base: master
Are you sure you want to change the base?
Conversation
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.
i think this makes sense
Makes sense to me, small nit |
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.
is it important that we flush all data (incl metadata) to disk for this to work? or can we just do File::sync_data
?
good point, yeah, I guess we can omit metadata |
this makes sense however i wonder if we should lock the file instead of syncing during cheatcode execution? this is on stable now so you can just call file.lock() for write, .lock_shared() for read, and .unlock() and should avoid fs |
warning: current MSRV (Minimum Supported Rust Version) is `1.88.0` but this item is stable since `1.89.0`
--> crates/cheatcodes/src/fs.rs:154:14
|
154 | file.lock_shared()?; should I bump? |
yes |
983337d
to
68dfb90
Compare
done, please recheck. |
} | ||
} | ||
|
||
impl Cheatcode for readFileBinaryCall { | ||
fn apply(&self, state: &mut Cheatcodes) -> Result { | ||
let Self { path } = self; | ||
let path = state.config.ensure_path_allowed(path, FsAccessKind::Read)?; | ||
Ok(fs::read(path)?.abi_encode()) | ||
let file = std::fs::OpenOptions::new().read(true).open(path)?; | ||
file.lock_shared()?; |
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.
should we move to common::fs
module?
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.
yep, will do, also noticed that writeJson
is doing let data_string = fs::read_to_string(&data_path)?;
for read which should be locked
Motivation
writeFile
cheatcode and then reading withreadFile
cheatcode and assert contentreadFile
issued after several writes in the same file failed witheven if traces were showing write just above the read

forge test
of the specific test in a loop<JSON file>
in traces above masked atfoundry/crates/evm/traces/src/decoder/mod.rs
Line 565 in f60a1d8
Solution
write_sync
towrite_all
andsync_all
on cheatcode writesPR Checklist