forked from madara-alliance/madara-orchestrator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Data Submission Worker Integration. (madara-alliance#51)
* update: DA job draft #1 * docs: changelog updated * update: is_worker_enabled impl & usage in da_submission, removal of String from VerificationFailed * update: renamed to * update: run worker only if it's enabled using is_worker_enabled check * build: linter fixes * Update CHANGELOG.md Co-authored-by: Apoorv Sadana <95699312+apoorvsadana@users.noreply.github.com> * update: limit_to_one on get_jobs_by_status * update: removed get_last_successful_job_by_type, added get_latest_job_by_type_and_status * update: added error to job metadata * update: pr resolution, simplifying get_jobs_by_status, rejected status in verify_jobs * update: linting fixes * Update crates/orchestrator/src/jobs/mod.rs Co-authored-by: Apoorv Sadana <95699312+apoorvsadana@users.noreply.github.com> * update: removing .expect from mongodb mod file * update: fixed testcase for snos worker * chore: correct variable name * update: added support to check againt multiple status - is_worker_enabled, get_jobs_by_statuses * docs: rewrote 1 job per block assumption * docs: DataSubmissionWorker -> DataAvailabilitySynchronizer * chore: liniting fix * update: changed name : DataAvailabilitySynchronizer -> DataSubmissionWorker --------- Co-authored-by: Apoorv Sadana <95699312+apoorvsadana@users.noreply.github.com>
- Loading branch information
1 parent
03d79b7
commit 09ee4fb
Showing
13 changed files
with
152 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use crate::config::config; | ||
use crate::jobs::create_job; | ||
use crate::jobs::types::{JobStatus, JobType}; | ||
use crate::workers::Worker; | ||
use async_trait::async_trait; | ||
use std::collections::HashMap; | ||
use std::error::Error; | ||
|
||
pub struct DataSubmissionWorker; | ||
|
||
#[async_trait] | ||
impl Worker for DataSubmissionWorker { | ||
// 0. All ids are assumed to be block numbers. | ||
// 1. Fetch the latest completed Proving job. | ||
// 2. Fetch the latest DA job creation. | ||
// 3. Create jobs from after the lastest DA job already created till latest completed proving job. | ||
async fn run_worker(&self) -> Result<(), Box<dyn Error>> { | ||
let config = config().await; | ||
|
||
// provides latest completed proof creation job id | ||
let latest_proven_job_id = config | ||
.database() | ||
.get_latest_job_by_type_and_status(JobType::ProofCreation, JobStatus::Completed) | ||
.await | ||
.unwrap() | ||
.map(|item| item.internal_id) | ||
.unwrap_or("0".to_string()); | ||
|
||
// provides latest triggered data submission job id | ||
let latest_data_submission_job_id = config | ||
.database() | ||
.get_latest_job_by_type(JobType::DataSubmission) | ||
.await | ||
.unwrap() | ||
.map(|item| item.internal_id) | ||
.unwrap_or("0".to_string()); | ||
|
||
let latest_data_submission_id: u64 = latest_data_submission_job_id.parse()?; | ||
let latest_proven_id: u64 = latest_proven_job_id.parse()?; | ||
|
||
// creating data submission jobs for latest blocks that don't have existing data submission jobs yet. | ||
for new_job_id in latest_data_submission_id + 1..latest_proven_id + 1 { | ||
create_job(JobType::DataSubmission, new_job_id.to_string(), HashMap::new()).await?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,46 @@ | ||
use std::error::Error; | ||
|
||
use crate::{config::config, jobs::types::JobStatus}; | ||
use async_trait::async_trait; | ||
use std::error::Error; | ||
|
||
pub mod data_submission_worker; | ||
pub mod proof_registration; | ||
pub mod proving; | ||
pub mod snos; | ||
pub mod update_state; | ||
|
||
#[async_trait] | ||
pub trait Worker: Send + Sync { | ||
async fn run_worker_if_enabled(&self) -> Result<(), Box<dyn Error>> { | ||
if !self.is_worker_enabled().await? { | ||
return Ok(()); | ||
} | ||
self.run_worker().await | ||
} | ||
|
||
async fn run_worker(&self) -> Result<(), Box<dyn Error>>; | ||
|
||
// Assumption | ||
// If say a job for block X fails, we don't want the worker to respawn another job for the same block | ||
// we will resolve the existing failed job first. | ||
|
||
// We assume the system to keep working till a job hasn't failed, | ||
// as soon as it fails we currently halt any more execution and wait for manual intervention. | ||
|
||
// Checks if any of the jobs have failed | ||
// Failure : JobStatus::VerificationFailed, JobStatus::VerificationTimeout, JobStatus::Failed | ||
// Halts any new job creation till all the count of failed jobs is not Zero. | ||
async fn is_worker_enabled(&self) -> Result<bool, Box<dyn Error>> { | ||
let config = config().await; | ||
|
||
let failed_jobs = config | ||
.database() | ||
.get_jobs_by_statuses(vec![JobStatus::VerificationFailed, JobStatus::VerificationTimeout], Some(1)) | ||
.await?; | ||
|
||
if !failed_jobs.is_empty() { | ||
return Ok(false); | ||
} | ||
|
||
Ok(true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters