Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
add verify tx execution in the workflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
musitdev committed Feb 20, 2024
1 parent d44e527 commit ff72aed
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.DS_Store
.idea
*.pki
**/.sqlx
crates/tests/e2e-tests/files
crates/tests/e2e-tests/prover
crates/tests/e2e-tests/verifier

This file was deleted.

3 changes: 3 additions & 0 deletions crates/node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ impl workflow::TransactionStore for storage::Database {
async fn find_transaction(&self, tx_hash: &Hash) -> Result<Option<Transaction<Validated>>> {
self.find_transaction(tx_hash).await
}
async fn mark_tx_executed(&self, tx_hash: &Hash) -> Result<()> {
self.mark_tx_executed(tx_hash).await
}
}

async fn run(config: Arc<Config>) -> Result<()> {
Expand Down
1 change: 1 addition & 0 deletions crates/node/src/storage/database/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ impl Database {
verification,
files,
} => {
tracing::trace!("Postgres add_transaction tx:{}", tx.hash.to_string());
sqlx::query(
"INSERT INTO verification ( tx, parent, verifier, verification ) VALUES ( $1, $2, $3, $4 ) ON CONFLICT (tx) DO NOTHING",
)
Expand Down
13 changes: 13 additions & 0 deletions crates/node/src/workflow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub enum WorkflowError {
#[async_trait]
pub trait TransactionStore: Sync + Send {
async fn find_transaction(&self, tx_hash: &Hash) -> Result<Option<Transaction<Validated>>>;
async fn mark_tx_executed(&self, tx_hash: &Hash) -> Result<()>;
}

pub struct WorkflowEngine {
Expand Down Expand Up @@ -149,6 +150,14 @@ impl WorkflowEngine {
Err(WorkflowError::IncompatibleTransaction(proof_tx.hash.to_string()).into())
}
}
Payload::Verification { .. } => {
// Execute the verify tx by setting to executed.
// Ideally it's not the right place to execute a Tx
// but as the execution is nothing, it's more convenient.
tracing::debug!("Mark as executed Payload::Verification tx {}", &cur_tx.hash);
self.tx_store.mark_tx_executed(&cur_tx.hash).await?;
Ok(None)
}
_ => Err(WorkflowError::IncompatibleTransaction(
"unsupported payload type".to_string(),
)
Expand Down Expand Up @@ -328,6 +337,10 @@ mod tests {
async fn find_transaction(&self, tx_hash: &Hash) -> Result<Option<Transaction<Validated>>> {
Ok(self.txs.get(tx_hash).cloned())
}
async fn mark_tx_executed(&self, tx_hash: &Hash) -> Result<()> {
// Do nothing because the txs map can't be modified behind a &self.
Ok(())
}
}

#[tokio::test]
Expand Down

0 comments on commit ff72aed

Please sign in to comment.