Skip to content

Commit

Permalink
fix(en): chunk factory deps (#2077)
Browse files Browse the repository at this point in the history
Signed-off-by: tomg10 <[email protected]>
  • Loading branch information
tomg10 authored May 29, 2024
1 parent 2189571 commit 4b9e6fa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions checks-config/era.dic
Original file line number Diff line number Diff line change
Expand Up @@ -969,3 +969,4 @@ preloaded
e2e
upcasting
foundryup
UNNEST
28 changes: 16 additions & 12 deletions core/lib/snapshots_applier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,18 +588,22 @@ impl<'a> SnapshotsApplier<'a> {
factory_deps.factory_deps.len()
);

let all_deps_hashmap: HashMap<H256, Vec<u8>> = factory_deps
.factory_deps
.into_iter()
.map(|dep| (hash_bytecode(&dep.bytecode.0), dep.bytecode.0))
.collect();
storage
.factory_deps_dal()
.insert_factory_deps(
self.applied_snapshot_status.l2_block_number,
&all_deps_hashmap,
)
.await?;
// we cannot insert all factory deps because of field size limit triggered by UNNEST
// in underlying query, see `https://www.postgresql.org/docs/current/limits.html`
// there were around 100 thousand contracts on mainnet, where this issue first manifested
for chunk in factory_deps.factory_deps.chunks(1000) {
let chunk_deps_hashmap: HashMap<H256, Vec<u8>> = chunk
.iter()
.map(|dep| (hash_bytecode(&dep.bytecode.0), dep.bytecode.0.clone()))
.collect();
storage
.factory_deps_dal()
.insert_factory_deps(
self.applied_snapshot_status.l2_block_number,
&chunk_deps_hashmap,
)
.await?;
}

let latency = latency.observe();
tracing::info!("Applied factory dependencies in {latency:?}");
Expand Down

0 comments on commit 4b9e6fa

Please sign in to comment.