Skip to content
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

Persistent mode for saya using mock of SNOS #2253

Merged
merged 61 commits into from
Oct 9, 2024
Merged
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
f5f02d3
updated celestia and publishing proof
matzayonc Jun 4, 2024
86c7b89
merging all if end block specified
matzayonc Jul 1, 2024
f5c7398
running checker on calls
matzayonc Jul 5, 2024
85acffd
feat: Cairo 1 checker program update
tejks Jul 16, 2024
c6045c5
added contract checkr
matzayonc Jul 23, 2024
c2f29c2
choosing saya mode
matzayonc Jul 23, 2024
5679046
fragmented proof verification
matzayonc Jul 30, 2024
f0c5834
batcher input and output parsing
matzayonc Jul 30, 2024
74d98da
working piltover
matzayonc Jul 31, 2024
2ea4210
passing piltover from cli
matzayonc Jul 31, 2024
14b6075
saya flow script
matzayonc Jul 31, 2024
9bc20a9
fixes after rebase and new felts
matzayonc Aug 1, 2024
90169e1
clippy, formatter and warning
matzayonc Aug 1, 2024
bc978c3
Update bin/saya/README.md
matzayonc Aug 6, 2024
73b7408
fixes after rebase and new felts
matzayonc Aug 1, 2024
0537865
fixed failing build
matzayonc Aug 12, 2024
45e0adf
saya.sh small fix
chudkowsky Aug 12, 2024
11bda52
readme update
chudkowsky Aug 12, 2024
ff1b5d2
saya script using tags and sozo from source
matzayonc Aug 13, 2024
aada160
readme update for spawn and move example
chudkowsky Aug 13, 2024
ba2329f
minor test comments
matzayonc Aug 29, 2024
f372bfd
clippy and fixes after rebase
matzayonc Aug 29, 2024
38e4cf2
fixed test
matzayonc Aug 29, 2024
ed3f633
minor debugging
matzayonc Aug 30, 2024
c680b3b
updated saya contracts
matzayonc Sep 2, 2024
92e5590
just an unused import
matzayonc Sep 2, 2024
5d3620c
fixed consecutive proofs
matzayonc Sep 2, 2024
be66305
removed merger program
matzayonc Sep 3, 2024
931580f
limited wait time between transactions
matzayonc Sep 3, 2024
74f7edf
renamed shard file to settlement
matzayonc Sep 3, 2024
f005215
updates serialized args file
matzayonc Sep 3, 2024
de8095d
fix: refacto README + add new scripts + fix sozo issues with migratio…
glihm Sep 6, 2024
d1e83cc
fix: migrate to new prover sdk
glihm Sep 7, 2024
6b8a225
fix: add some comment and fix cairo 1 arguments
glihm Sep 8, 2024
65afea4
adapt saya to new prover, new batcher and checker
chudkowsky Sep 10, 2024
293d391
updated fact registry to herodotus
chudkowsky Sep 12, 2024
80f35f5
retries on onchain contracts
chudkowsky Sep 16, 2024
31519d2
piltover class hash update
chudkowsky Sep 16, 2024
518948e
refactor part1
chudkowsky Sep 24, 2024
0622280
errrors refactor, sharp prover
chudkowsky Oct 1, 2024
7eedc60
updated celestia and json upload
matzayonc Oct 2, 2024
4ed9d3a
publishing to celestia
matzayonc Oct 3, 2024
6b05fa4
Merge pull request #54 from neotheprogramist/celestia-proof
chudkowsky Oct 4, 2024
477afd5
Merge pull request #55 from neotheprogramist/refactor
chudkowsky Oct 4, 2024
d2f837e
Merge pull request #53 from neotheprogramist/saya/new-prover-interface
chudkowsky Oct 4, 2024
61a3bb3
errors, update script
chudkowsky Oct 4, 2024
b5492d3
added a header to celestia data
matzayonc Oct 4, 2024
fbd16d4
height and commitment calculated values
chudkowsky Oct 5, 2024
d23a246
piltover update
chudkowsky Oct 8, 2024
6a1e8d2
Readme
chudkowsky Oct 9, 2024
3941d38
fmt
chudkowsky Oct 9, 2024
51b6025
Merge remote-tracking branch 'origin/main' into saya/settle-katana
chudkowsky Oct 9, 2024
f2136f9
post merge fix
chudkowsky Oct 9, 2024
f5a9e80
fmt
chudkowsky Oct 9, 2024
46a770f
fmt and dependency
chudkowsky Oct 9, 2024
a67233e
fmt again
chudkowsky Oct 9, 2024
a65bb40
fmt
chudkowsky Oct 9, 2024
5356d15
removed unused variable
chudkowsky Oct 9, 2024
3d6be35
rebuild test artefacts
chudkowsky Oct 9, 2024
9ac3bdf
test fix
chudkowsky Oct 9, 2024
e47f0d1
db files update
chudkowsky Oct 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
merging all if end block specified
  • Loading branch information
matzayonc committed Sep 2, 2024

Verified

This commit was signed with the committer’s verified signature.
Kikobeats Kiko Beats
commit 86c7b89e5035e484144a910d2e7c0b73e8646185
9 changes: 7 additions & 2 deletions bin/saya/src/args/mod.rs
Original file line number Diff line number Diff line change
@@ -52,9 +52,12 @@ pub struct SayaArgs {
/// Specify a block to start fetching data from.
#[arg(short, long, default_value = "0")]
pub start_block: u64,
#[arg(short, long)]
pub end_block: Option<u64>,
Comment on lines +49 to +50
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ohayo, sensei! Let's add a quick check for end_block!

The addition of the end_block field is a great improvement for flexibility. However, to prevent potential issues, we should ensure that end_block is greater than or equal to start_block when it's provided.

Consider adding this validation in the try_from implementation:

if let Some(end_block) = args.end_block {
    if end_block < args.start_block {
        return Err(SayaConfigError::InvalidInput(
            "`end_block` must be greater than or equal to `start_block`".to_string()
        ));
    }
}

This check will help prevent invalid block ranges and potential runtime errors.

Also applies to: 184-184


#[arg(short, long, default_value = "1")]
#[arg(help = "The number of blocks to be merged into a single proof.")]
#[arg(conflicts_with = "end_block")]
pub batch_size: usize,

#[command(flatten)]
@@ -147,7 +150,7 @@ impl TryFrom<SayaArgs> for SayaConfig {
prover_url: args.proof.prover_url,
prover_key,
store_proofs: args.store_proofs,
start_block: args.start_block,
block_range: (args.start_block, args.end_block),
batch_size: args.batch_size,
data_availability: da_config,
world_address: args.proof.world_address,
@@ -180,6 +183,7 @@ mod tests {
store_proofs: true,
json_log: false,
start_block: 0,
end_block: None,
batch_size: 4,
data_availability: DataAvailabilityOptions {
da_chain: None,
@@ -215,7 +219,8 @@ mod tests {
);
assert!(!config.store_proofs);
assert!(config.skip_publishing_proof);
assert_eq!(config.start_block, 0);
assert_eq!(config.block_range.0, 0);
assert_eq!(config.block_range.1, None);
if let Some(DataAvailabilityConfig::Celestia(celestia_config)) = config.data_availability {
assert_eq!(celestia_config.node_url.as_str(), "http://localhost:26657/");
assert_eq!(celestia_config.node_auth_token, Some("your_auth_token".to_string()));
3 changes: 1 addition & 2 deletions bin/saya/src/main.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@
use clap::Parser;
use console::Style;
use saya_core::{Saya, SayaConfig};
use tokio::signal::ctrl_c;

mod args;

@@ -23,7 +22,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
saya.start().await?;

// Wait until Ctrl + C is pressed, then shutdown
ctrl_c().await?;
// ctrl_c().await?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required anymore to be able to kill the program? Or it's handled by the .start() function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not required, as the ephemeral shard will shut itself down after reaching the shutdown event.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but we may want to kill saya. :) In this case it would be better keeping it to ensure graceful shutdown in case of manual interruption.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the opposite, this line simply prevents saya from closing until ctrl+c is pressed. Now we do the same thing by simply not returning from the start function until all the blocks are prover (for ephemeral shard).
A graceful shutdown would have to be implemented there.

// handle.stop()?;

Ok(())
90 changes: 58 additions & 32 deletions crates/saya/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

#![cfg_attr(not(test), warn(unused_crate_dependencies))]

use std::convert::identity;
use std::ops::RangeInclusive;
use std::sync::Arc;

@@ -10,12 +11,13 @@ use cairo_proof_parser::output::{extract_output, ExtractOutputResult};
use cairo_proof_parser::parse;
use cairo_proof_parser::program::{extract_program, ExtractProgramResult};
use futures::future;
use itertools::Itertools;
use katana_primitives::block::{BlockNumber, FinalityStatus, SealedBlock, SealedBlockWithStatus};
use katana_primitives::state::StateUpdatesWithDeclaredClasses;
use katana_primitives::transaction::Tx;
use katana_primitives::FieldElement;
use katana_rpc_types::trace::TxExecutionInfo;
use prover::{HttpProverParams, ProverIdentifier};
use prover::{HttpProverParams, ProofAndDiff, ProverIdentifier};
pub use prover_sdk::ProverAccessKey;
use saya_provider::rpc::JsonRpcProvider;
use saya_provider::Provider as SayaProvider;
@@ -52,7 +54,7 @@ pub struct SayaConfig {
pub prover_url: Url,
pub prover_key: ProverAccessKey,
pub store_proofs: bool,
pub start_block: u64,
pub block_range: (u64, Option<u64>),
pub batch_size: usize,
pub data_availability: Option<DataAvailabilityConfig>,
pub world_address: FieldElement,
@@ -138,7 +140,8 @@ impl Saya {
/// Should be refacto in crates as necessary.
pub async fn start(&mut self) -> SayaResult<()> {
let poll_interval_secs = 1;
let mut block = self.config.start_block.max(1); // Genesis block is not proven. We advance to block 1

let mut block = self.config.block_range.0.max(1); // Genesis block is not proven. We advance to block 1

let block_before_the_first = self.provider.fetch_block(block - 1).await;
let mut previous_block_state_root = block_before_the_first?.header.header.state_root;
@@ -149,13 +152,9 @@ impl Saya {
}));

// The structure responsible for proving.
let mut prove_scheduler = Scheduler::new(
self.config.batch_size,
self.config.world_address,
prover_identifier.clone(),
);
let mut prove_scheduler = None;

loop {
let unproven_blocks = loop {
let latest_block = match self.provider.block_number().await {
Ok(block_number) => block_number,
Err(e) => {
@@ -165,8 +164,10 @@ impl Saya {
}
};

if block > latest_block {
trace!(target: LOG_TARGET, block_number = block, "Waiting for block.");
// Wait for the end of the range if it is specified
let minimum_expected = self.config.block_range.1.unwrap_or(block);
if minimum_expected > latest_block {
trace!(target: LOG_TARGET, block_number = latest_block + 1, "Waiting for block.");
tokio::time::sleep(tokio::time::Duration::from_secs(poll_interval_secs)).await;
continue;
}
@@ -178,22 +179,51 @@ impl Saya {
// Updating the local state sequentially, as there is only one instance of
// `self.blockchain` This part does no actual proving, so should not be a
// problem
for p in params {
self.process_block(&mut prove_scheduler, block, p)?;

if prove_scheduler.is_full() {
self.process_proven(prove_scheduler).await?;

prove_scheduler = Scheduler::new(
self.config.batch_size,
self.config.world_address,
prover_identifier.clone(),
);
if self.config.block_range.1.is_none() {
for p in params {
let mut scheduler = if let Some(scheduler) = prove_scheduler {
prove_scheduler = None;
scheduler
} else {
Scheduler::new(
self.config.batch_size,
self.config.world_address,
prover_identifier.clone(),
)
};

if let Some(prover_input) = self.process_block(block, p)? {
scheduler.push_diff(prover_input)?;
if scheduler.is_full() {
self.process_proven(scheduler.proved().await?).await?;
} else {
prove_scheduler = Some(scheduler);
}
}
}

block += 1;
} else {
break params
.into_iter()
.map(|p| self.process_block(block, p))
.collect::<Result<Vec<_>, _>>()?
.into_iter()
.filter_map(identity)
.collect_vec();
}
}
};

let (proof, diff) =
Scheduler::merge(unproven_blocks, self.config.world_address, prover_identifier).await?;

let block_range = (self.config.block_range.0, self.config.block_range.1.unwrap());
self.process_proven((proof, diff, block_range)).await?;

println!("Successfully processed all {} blocks.", block_range.1 - block_range.0 + 1);

Ok(())
}

async fn prefetch_blocks(
@@ -277,10 +307,9 @@ impl Saya {
/// the genesis block.
fn process_block(
&mut self,
prove_scheduler: &mut Scheduler,
block_number: BlockNumber,
block_info: FetchedBlockInfo,
) -> SayaResult<()> {
) -> SayaResult<Option<ProgramInput>> {
trace!(target: LOG_TARGET, block_number = %block_number, "Processing block.");

let FetchedBlockInfo { block, prev_state_root, state_updates, exec_infos, block_number } =
@@ -293,12 +322,12 @@ impl Saya {
self.blockchain.update_state_with_block(block.clone(), state_updates)?;

if block_number == 0 {
return Ok(());
return Ok(None);
}

if exec_infos.is_empty() {
trace!(target: LOG_TARGET, block_number, "Skipping empty block.");
return Ok(());
return Ok(None);
}

let transactions = block
@@ -327,11 +356,9 @@ impl Saya {
};
state_diff_prover_input.fill_da(self.config.world_address);

prove_scheduler.push_diff(state_diff_prover_input)?;

info!(target: LOG_TARGET, block_number, "Block processed.");

Ok(())
Ok(Some(state_diff_prover_input))
}

/// Registers the facts + the send the proof to verifier. Not all provers require this step
@@ -341,10 +368,9 @@ impl Saya {
///
/// * `prove_scheduler` - A full parallel prove scheduler.
/// * `last_block` - The last block number in the `prove_scheduler`.
async fn process_proven(&self, prove_scheduler: Scheduler) -> SayaResult<()> {
async fn process_proven(&self, proven: ProofAndDiff) -> SayaResult<()> {
// Prove each of the leaf nodes of the recursion tree and merge them into one
let (proof, state_diff, (_, last_block)) =
prove_scheduler.proved().await.context("Failed to prove.")?;
let (proof, state_diff, (_, last_block)) = proven;

trace!(target: LOG_TARGET, last_block, "Processing proven blocks.");

4 changes: 3 additions & 1 deletion crates/saya/core/src/prover/scheduler.rs
Original file line number Diff line number Diff line change
@@ -20,7 +20,9 @@ pub enum ProvingState {
Proved,
NotPushed,
}

type ProvingStateWithBlock = (u64, ProvingState);
pub type ProofAndDiff = (Proof, ProgramInput, (u64, u64));

#[allow(missing_debug_implementations)]
pub struct Scheduler {
@@ -70,7 +72,7 @@ impl Scheduler {
Ok(())
}

pub async fn proved(self) -> anyhow::Result<(Proof, ProgramInput, (u64, u64))> {
pub async fn proved(self) -> anyhow::Result<ProofAndDiff> {
let (proof, input) = self.root_task.await?;
Ok((proof, input, self.block_range))
}