Skip to content

Commit

Permalink
Esad/proof sampling (#623)
Browse files Browse the repository at this point in the history
* implement proof sampling

* fix
  • Loading branch information
eyusufatik authored May 27, 2024
1 parent a077ba2 commit f99f791
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions bin/citrea/tests/e2e/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,8 +1108,8 @@ async fn test_prover_sync_with_commitments() -> Result<(), anyhow::Error> {
GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
Some(ProverConfig {
proving_mode: sov_stf_runner::ProverGuestRunConfig::Execute,
skip_proving_until_l1_height: None,
db_config: Some(SharedBackupDbConfig::default()),
proof_sampling_number: 0,
}),
NodeMode::Prover(seq_port),
None,
Expand Down Expand Up @@ -2114,7 +2114,7 @@ async fn test_db_get_proof() {
GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
Some(ProverConfig {
proving_mode: sov_stf_runner::ProverGuestRunConfig::Execute,
skip_proving_until_l1_height: None,
proof_sampling_number: 0,
db_config: Some(SharedBackupDbConfig::default()),
}),
NodeMode::Prover(seq_port),
Expand Down Expand Up @@ -2229,7 +2229,7 @@ async fn full_node_verify_proof_and_store() {
GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
Some(ProverConfig {
proving_mode: sov_stf_runner::ProverGuestRunConfig::Execute,
skip_proving_until_l1_height: None,
proof_sampling_number: 0,
db_config: None,
}),
NodeMode::Prover(seq_port),
Expand Down Expand Up @@ -2403,7 +2403,7 @@ async fn test_all_flow() {
GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
Some(ProverConfig {
proving_mode: sov_stf_runner::ProverGuestRunConfig::Execute,
skip_proving_until_l1_height: None,
proof_sampling_number: 0,
db_config: Some(SharedBackupDbConfig::default()),
}),
NodeMode::Prover(seq_port),
Expand Down
2 changes: 1 addition & 1 deletion bin/citrea/tests/sequencer_commitments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ async fn test_ledger_get_commitments_on_slot_prover() {
GenesisPaths::from_dir("../test-data/genesis/integration-tests"),
Some(ProverConfig {
proving_mode: sov_stf_runner::ProverGuestRunConfig::Execute,
skip_proving_until_l1_height: None,
proof_sampling_number: 0,
db_config: None,
}),
NodeMode::Prover(seq_port),
Expand Down
2 changes: 2 additions & 0 deletions crates/sovereign-sdk/full-node/sov-stf-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ serde_json = { workspace = true }
serde = { workspace = true }
toml = { workspace = true, optional = true }
rs_merkle = { workspace = true }
rand = { workspace = true, optional = true }
jsonrpsee = { workspace = true, features = [
"http-client",
"server",
Expand Down Expand Up @@ -78,4 +79,5 @@ native = [
"thiserror",
"shared-backup-db",
"backoff",
"rand",
]
10 changes: 5 additions & 5 deletions crates/sovereign-sdk/full-node/sov-stf-runner/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ pub struct RollupConfig<DaServiceConfig> {
pub struct ProverConfig {
/// Prover run mode
pub proving_mode: ProverGuestRunConfig,
/// If set, the prover will skip proving until the L1 height is reached.
pub skip_proving_until_l1_height: Option<u64>,
/// Average number of commitments to prove
pub proof_sampling_number: usize,
/// Offchain db config
pub db_config: Option<SharedBackupDbConfig>,
}
Expand All @@ -89,7 +89,7 @@ impl Default for ProverConfig {
fn default() -> Self {
Self {
proving_mode: ProverGuestRunConfig::Execute,
skip_proving_until_l1_height: None,
proof_sampling_number: 0,
db_config: None,
}
}
Expand Down Expand Up @@ -183,7 +183,7 @@ mod tests {
fn test_correct_prover_config() {
let config = r#"
proving_mode = "skip"
skip_proving_until_l1_height = 100
proof_sampling_number = 500
[db_config]
db_host = "localhost"
Expand All @@ -198,7 +198,7 @@ mod tests {
let config: ProverConfig = from_toml_path(config_file.path()).unwrap();
let expected = ProverConfig {
proving_mode: ProverGuestRunConfig::Skip,
skip_proving_until_l1_height: Some(100),
proof_sampling_number: 500,
db_config: Some(SharedBackupDbConfig::default()),
};
assert_eq!(config, expected);
Expand Down
20 changes: 18 additions & 2 deletions crates/sovereign-sdk/full-node/sov-stf-runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use borsh::de::BorshDeserialize;
use borsh::BorshSerialize as _;
use jsonrpsee::core::Error;
use jsonrpsee::RpcModule;
use rand::Rng;
use rs_merkle::algorithms::Sha256;
use rs_merkle::MerkleTree;
use sequencer_client::SequencerClient;
Expand Down Expand Up @@ -252,7 +253,9 @@ where

let mut l2_height = self.start_height;

let pg_client = match self.prover_config.clone().unwrap().db_config {
let prover_config = self.prover_config.clone().unwrap();

let pg_client = match prover_config.db_config {
Some(db_config) => {
tracing::info!("Connecting to postgres");
Some(PostgresConnector::new(db_config.clone()).await)
Expand Down Expand Up @@ -587,10 +590,21 @@ where
sequencer_da_public_key: self.sequencer_da_pub_key.clone(),
};

let should_prove: bool = {
let mut rng = rand::thread_rng();
// if proof_sampling_number is 0, then we always prove and submit
// otherwise we submit and prove with a probability of 1/proof_sampling_number
if prover_config.proof_sampling_number == 0 {
true
} else {
rng.gen_range(0..prover_config.proof_sampling_number) == 0
}
};

// Skip submission until l1 height
// hotfix for devnet deployment
// TODO: make a better way to skip submission, and fixing deployed bugs
if l1_height >= skip_submission_until_l1 {
if l1_height >= skip_submission_until_l1 && should_prove {
let prover_service = self
.prover_service
.as_ref()
Expand Down Expand Up @@ -675,6 +689,8 @@ where
proof,
stored_state_transition,
)?;
} else {
tracing::info!("Skipping proving for l1 height {}", l1_height);
}

for (sequencer_commitment, l1_heights) in
Expand Down

0 comments on commit f99f791

Please sign in to comment.