Skip to content

Commit

Permalink
Merge branch 'main' into gprusak-endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
pompon0 authored Jul 26, 2024
2 parents b4b05ba + 1b61d07 commit aa9f7f4
Show file tree
Hide file tree
Showing 43 changed files with 957 additions and 569 deletions.
2 changes: 1 addition & 1 deletion .github/release-please/manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"core": "24.11.0",
"core": "24.12.0",
"prover": "16.1.0"
}
4 changes: 3 additions & 1 deletion .github/workflows/build-docker-from-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ jobs:
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}


build-gar-prover-fri-gpu:
name: Build GAR prover FRI GPU
needs: [setup, build-push-prover-images]
Expand All @@ -105,3 +104,6 @@ jobs:
setup_keys_id: ${{ needs.setup.outputs.prover_fri_gpu_key_id }}
image_tag_suffix: ${{ needs.setup.outputs.image_tag_suffix }}
protocol_version: ${{ needs.build-push-prover-images.outputs.protocol_version }}
secrets:
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
7 changes: 7 additions & 0 deletions .github/workflows/build-prover-fri-gpu-gar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ name: Build Prover FRI GPU with builtin setup data

on:
workflow_call:
secrets:
DOCKERHUB_USER:
description: "DOCKERHUB_USER"
required: true
DOCKERHUB_TOKEN:
description: "DOCKERHUB_TOKEN"
required: true
inputs:
image_tag_suffix:
description: "Commit sha or git tag for Docker tag"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ concurrency:

jobs:
changed_files:
runs-on: [matterlabs-default-infra-runners]
runs-on: ubuntu-latest
name: Get changed files
outputs:
core: ${{ steps.changed-files.outputs.core_any_changed }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-please-cargo-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
name: release-please-update-cargo-lock
jobs:
update_cargo_lock:
runs-on: [matterlabs-ci-runner]
runs-on: [matterlabs-default-infra-runners]

steps:
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/release-test-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ concurrency:

jobs:
changed_files:
runs-on: [matterlabs-default-infra-runners]
runs-on: ubuntu-latest
name: Test changed-files
outputs:
core: ${{ steps.changed-files-yaml.outputs.core_any_changed }}
Expand Down Expand Up @@ -116,3 +116,6 @@ jobs:
setup_keys_id: ${{ needs.setup.outputs.prover_fri_gpu_key_id }}
image_tag_suffix: ${{ needs.setup.outputs.image_tag_suffix }}
protocol_version: ${{ needs.build-push-prover-images.outputs.protocol_version }}
secrets:
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Cargo.lock
!/etc/env/configs/stage-proofs.toml
!/etc/env/configs/testnet.toml
!/etc/env/configs/mainnet.toml
!/etc/env/configs/prover-local.toml
/etc/env/l1-inits
!/etc/env/l1-inits/stage.env
!/etc/env/l1-inits/stage_proofs.env
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## [24.12.0](https://github.com/matter-labs/zksync-era/compare/core-v24.11.0...core-v24.12.0) (2024-07-25)


### Features

* add general config and secrets opts to snapshot creator ([#2471](https://github.com/matter-labs/zksync-era/issues/2471)) ([0f475c9](https://github.com/matter-labs/zksync-era/commit/0f475c949a28c4602539b4d75ee79e605f44e2de))
* Update to consensus 0.1.0-rc.4 (BFT-486) ([#2475](https://github.com/matter-labs/zksync-era/issues/2475)) ([ff6b10c](https://github.com/matter-labs/zksync-era/commit/ff6b10c4a994cf70297a034202bcb55152748cba))


### Bug Fixes

* consensus secrets generator ([#2484](https://github.com/matter-labs/zksync-era/issues/2484)) ([dea6969](https://github.com/matter-labs/zksync-era/commit/dea6969d1b67c54a0985278de68a8d50f1084dc1))


### Performance Improvements

* writing tx to bootloader memory is no longer quadratic ([#2479](https://github.com/matter-labs/zksync-era/issues/2479)) ([1c443e5](https://github.com/matter-labs/zksync-era/commit/1c443e5ecfd000279830262a4a35cbc83a9aacec))

## [24.11.0](https://github.com/matter-labs/zksync-era/compare/core-v24.10.0...core-v24.11.0) (2024-07-23)


Expand Down
2 changes: 1 addition & 1 deletion core/bin/external_node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "zksync_external_node"
description = "Non-validator ZKsync node"
version = "24.11.0" # x-release-please-version
version = "24.12.0" # x-release-please-version
edition.workspace = true
authors.workspace = true
homepage.workspace = true
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 50 additions & 7 deletions core/lib/dal/src/proof_generation_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ enum ProofGenerationJobStatus {
}

impl ProofGenerationDal<'_, '_> {
pub async fn get_next_block_to_be_proven(
/// Chooses the batch number so that it has all the necessary data to generate the proof
/// and is not already picked.
///
/// Marks the batch as picked by the prover, preventing it from being picked twice.
///
/// The batch can be unpicked either via a corresponding DAL method, or it is considered
/// not picked after `processing_timeout` passes.
pub async fn lock_batch_for_proving(
&mut self,
processing_timeout: Duration,
) -> DalResult<Option<L1BatchNumber>> {
Expand Down Expand Up @@ -72,14 +79,38 @@ impl ProofGenerationDal<'_, '_> {
"#,
&processing_timeout,
)
.fetch_optional(self.storage.conn())
.await
.unwrap()
.instrument("lock_batch_for_proving")
.with_arg("processing_timeout", &processing_timeout)
.fetch_optional(self.storage)
.await?
.map(|row| L1BatchNumber(row.l1_batch_number as u32));

Ok(result)
}

/// Marks a previously locked batch as 'unpicked', allowing it to be picked without having
/// to wait for the processing timeout.
pub async fn unlock_batch(&mut self, l1_batch_number: L1BatchNumber) -> DalResult<()> {
let batch_number = i64::from(l1_batch_number.0);
sqlx::query!(
r#"
UPDATE proof_generation_details
SET
status = 'unpicked',
updated_at = NOW()
WHERE
l1_batch_number = $1
"#,
batch_number,
)
.instrument("unlock_batch")
.with_arg("l1_batch_number", &l1_batch_number)
.execute(self.storage)
.await?;

Ok(())
}

pub async fn save_proof_artifacts_metadata(
&mut self,
batch_number: L1BatchNumber,
Expand Down Expand Up @@ -388,7 +419,7 @@ mod tests {

let picked_l1_batch = conn
.proof_generation_dal()
.get_next_block_to_be_proven(Duration::MAX)
.lock_batch_for_proving(Duration::MAX)
.await
.unwrap();
assert_eq!(picked_l1_batch, Some(L1BatchNumber(1)));
Expand All @@ -399,10 +430,22 @@ mod tests {
.unwrap();
assert_eq!(unpicked_l1_batch, None);

// Check that we can unlock the batch and then pick it again.
conn.proof_generation_dal()
.unlock_batch(L1BatchNumber(1))
.await
.unwrap();
let picked_l1_batch = conn
.proof_generation_dal()
.lock_batch_for_proving(Duration::MAX)
.await
.unwrap();
assert_eq!(picked_l1_batch, Some(L1BatchNumber(1)));

// Check that with small enough processing timeout, the L1 batch can be picked again
let picked_l1_batch = conn
.proof_generation_dal()
.get_next_block_to_be_proven(Duration::ZERO)
.lock_batch_for_proving(Duration::ZERO)
.await
.unwrap();
assert_eq!(picked_l1_batch, Some(L1BatchNumber(1)));
Expand All @@ -414,7 +457,7 @@ mod tests {

let picked_l1_batch = conn
.proof_generation_dal()
.get_next_block_to_be_proven(Duration::MAX)
.lock_batch_for_proving(Duration::MAX)
.await
.unwrap();
assert_eq!(picked_l1_batch, None);
Expand Down
104 changes: 67 additions & 37 deletions core/node/proof_data_handler/src/request_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,64 @@ impl RequestProcessor {
) -> Result<Json<ProofGenerationDataResponse>, RequestProcessorError> {
tracing::info!("Received request for proof generation data: {:?}", request);

let l1_batch_number_result = self
.pool
let l1_batch_number = match self.lock_batch_for_proving().await? {
Some(number) => number,
None => return Ok(Json(ProofGenerationDataResponse::Success(None))), // no batches pending to be proven
};

let proof_generation_data = self
.proof_generation_data_for_existing_batch(l1_batch_number)
.await;

// If we weren't able to fetch all the data, we should unlock the batch before returning.
match proof_generation_data {
Ok(data) => Ok(Json(ProofGenerationDataResponse::Success(Some(Box::new(
data,
))))),
Err(err) => {
self.unlock_batch(l1_batch_number).await?;
Err(err)
}
}
}

/// Will choose a batch that has all the required data and isn't picked up by any prover yet.
async fn lock_batch_for_proving(&self) -> Result<Option<L1BatchNumber>, RequestProcessorError> {
self.pool
.connection()
.await
.unwrap()
.map_err(RequestProcessorError::Dal)?
.proof_generation_dal()
.get_next_block_to_be_proven(self.config.proof_generation_timeout())
.lock_batch_for_proving(self.config.proof_generation_timeout())
.await
.map_err(RequestProcessorError::Dal)?;
.map_err(RequestProcessorError::Dal)
}

let l1_batch_number = match l1_batch_number_result {
Some(number) => number,
None => return Ok(Json(ProofGenerationDataResponse::Success(None))), // no batches pending to be proven
};
/// Marks the batch as 'unpicked', allowing it to be picked up by another prover.
async fn unlock_batch(
&self,
l1_batch_number: L1BatchNumber,
) -> Result<(), RequestProcessorError> {
self.pool
.connection()
.await
.map_err(RequestProcessorError::Dal)?
.proof_generation_dal()
.unlock_batch(l1_batch_number)
.await
.map_err(RequestProcessorError::Dal)
}

/// Will fetch all the required data for the batch and return it.
///
/// ## Panics
///
/// Expects all the data to be present in the database.
/// Will panic if any of the required data is missing.
async fn proof_generation_data_for_existing_batch(
&self,
l1_batch_number: L1BatchNumber,
) -> Result<ProofGenerationData, RequestProcessorError> {
let vm_run_data: VMRunWitnessInputData = self
.blob_store
.get(l1_batch_number)
Expand All @@ -77,52 +120,43 @@ impl RequestProcessor {
.await
.map_err(RequestProcessorError::ObjectStore)?;

let previous_batch_metadata = self
// Acquire connection after interacting with GCP, to avoid holding the connection for too long.
let mut conn = self
.pool
.connection()
.await
.unwrap()
.map_err(RequestProcessorError::Dal)?;

let previous_batch_metadata = conn
.blocks_dal()
.get_l1_batch_metadata(L1BatchNumber(l1_batch_number.checked_sub(1).unwrap()))
.await
.unwrap()
.map_err(RequestProcessorError::Dal)?
.expect("No metadata for previous batch");

let header = self
.pool
.connection()
.await
.unwrap()
let header = conn
.blocks_dal()
.get_l1_batch_header(l1_batch_number)
.await
.unwrap()
.map_err(RequestProcessorError::Dal)?
.unwrap_or_else(|| panic!("Missing header for {}", l1_batch_number));

let minor_version = header.protocol_version.unwrap();
let protocol_version = self
.pool
.connection()
.await
.unwrap()
let protocol_version = conn
.protocol_versions_dal()
.get_protocol_version_with_latest_patch(minor_version)
.await
.unwrap()
.map_err(RequestProcessorError::Dal)?
.unwrap_or_else(|| {
panic!("Missing l1 verifier info for protocol version {minor_version}")
});

let batch_header = self
.pool
.connection()
.await
.unwrap()
let batch_header = conn
.blocks_dal()
.get_l1_batch_header(l1_batch_number)
.await
.unwrap()
.unwrap();
.map_err(RequestProcessorError::Dal)?
.unwrap_or_else(|| panic!("Missing header for {}", l1_batch_number));

let eip_4844_blobs = match self.commitment_mode {
L1BatchCommitmentMode::Validium => Eip4844Blobs::empty(),
Expand All @@ -149,16 +183,12 @@ impl RequestProcessor {

METRICS.observe_blob_sizes(&blob);

let proof_gen_data = ProofGenerationData {
Ok(ProofGenerationData {
l1_batch_number,
witness_input_data: blob,
protocol_version: protocol_version.version,
l1_verifier_config: protocol_version.l1_verifier_config,
};

Ok(Json(ProofGenerationDataResponse::Success(Some(Box::new(
proof_gen_data,
)))))
})
}

pub(crate) async fn submit_proof(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit aa9f7f4

Please sign in to comment.