Skip to content

Commit

Permalink
enha: make finish_pending_block hold write logs for less time
Browse files Browse the repository at this point in the history
  • Loading branch information
carneiro-cw committed Dec 11, 2024
1 parent 062fedd commit a0d4e96
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/eth/storage/temporary/inmemory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,27 @@ impl TemporaryStorage for InMemoryTemporaryStorage {

fn finish_pending_block(&self) -> anyhow::Result<PendingBlock> {
let mut pending_block = self.pending_block.write();
let mut latest = self.latest_block.write();

let next_number = (*pending_block).block.header.number.next_block_number();
*latest = Some(std::mem::replace(&mut *pending_block, InMemoryTemporaryStorageState::new(next_number)));

drop(latest);
let latest = self.latest_block.read();
drop(pending_block);

#[cfg(feature = "dev")]
let mut finished_block = pending_block.block.clone();
let mut finished_block = (*latest)
.as_ref()
.expect("latest should be Some after finishing the pending block")
.block
.clone();
#[cfg(not(feature = "dev"))]
let finished_block = pending_block.block.clone();
let finished_block = (*latest)
.as_ref()
.expect("latest should be Some after finishing the pending block")
.block
.clone();

#[cfg(feature = "dev")]
{
Expand All @@ -195,12 +211,6 @@ impl TemporaryStorage for InMemoryTemporaryStorage {
}
}

let mut latest = self.latest_block.write();
*latest = Some(std::mem::replace(
&mut *pending_block,
InMemoryTemporaryStorageState::new(finished_block.header.number.next_block_number()),
));

Ok(finished_block)
}

Expand Down

0 comments on commit a0d4e96

Please sign in to comment.