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
fix(static-file): pass producer as Arc<Mutex<_>>
to ensure only one is active
#7143
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.
it's not super pretty, but this should do it
@@ -21,7 +21,7 @@ pub type StaticFileProducerResult = RethResult<StaticFileTargets>; | |||
pub type StaticFileProducerWithResult<DB> = (StaticFileProducer<DB>, StaticFileProducerResult); | |||
|
|||
/// Static File producer routine. See [StaticFileProducer::run] for more detailed description. | |||
#[derive(Debug, Clone)] | |||
#[derive(Debug)] |
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.
good!
can do it prettier via a type alias that's public and a private internal type |
no aliases please :) |
newtype |
6e8c0e7
to
e7f0930
Compare
c79d9ec
to
f7f3f30
Compare
Arc<Mutex<_>>
Arc<Mutex<_>>
to ensure only one active at a time
Arc<Mutex<_>>
to ensure only one active at a timeArc<Mutex<_>>
to ensure only one active
Arc<Mutex<_>>
to ensure only one activeArc<Mutex<_>>
to ensure only one is active
@@ -131,7 +131,7 @@ where | |||
) -> Option<CallOutcome> { | |||
call_inspectors!([&mut self.custom_print_tracer], |inspector| { | |||
if let Some(outcome) = inspector.call(context, inputs) { | |||
return Some(outcome); |
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.
how do these keep making their way back into the codebase
… is active (paradigmxyz#7143) Co-authored-by: joshieDo <ranriver@protonmail.com>
… is active (paradigmxyz#7143) Co-authored-by: joshieDo <ranriver@protonmail.com>
This PR fixes a critical bug with multiple
StaticFileProducer
instances writing to static files at the same time, potentially causing duplicate and inconsistent data.We need to have at most one
StaticFileProducer
active at a time. Otherwise, such a situation is possible:StaticFileHook
is started in the engine loop via polling the next hookreth/crates/consensus/beacon/src/engine/mod.rs
Lines 1860 to 1870 in 3d86c4a
reth/crates/consensus/beacon/src/engine/mod.rs
Lines 1839 to 1840 in 3d86c4a
StaticFileProducer
before actually starting the execution of all stagesreth/crates/stages/src/pipeline/mod.rs
Lines 185 to 186 in 3d86c4a
StaticFileHook
andPipeline::produce_static_files
run theStaticFileProducer
, and it writes to static files from both places.Having only one
StaticFileProducer
can be ensured via sharing one copy between everyone usingArc<Mutex<StaticFileProducer>>
, so that the user will need to lock the static file producer first for the duration of its usage. This PR introduces a newtype wrapperStaticFileProducer(Arc<Mutex<StaticFileProducerInner>>)
that makes it easier to initialize and pass it around.An additional measure that can be done to prevent the static files corruption is implemented #7137.