Skip to content

Commit

Permalink
refactor validator.rs -> tx_validator.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
huitseeker committed Nov 17, 2022
1 parent 3d6f90c commit ba0ecbb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions narwhal/worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ mod handlers;
pub mod metrics;
mod primary_connector;
mod quorum_waiter;
mod validator;
mod tx_validator;
mod worker;

pub use crate::validator::{TrivialTxValidator, TxValidator};
pub use crate::tx_validator::{TrivialTxValidator, TxValidator};
pub use crate::worker::Worker;
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::{Debug, Display};

// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
use types::Batch;
Expand All @@ -6,21 +8,24 @@ use types::Batch;
/// of a batch of transactions (from another validator). Invalid transactions will not receive
/// further processing.
pub trait TxValidator: Clone + Send + Sync + 'static {
type Error: Send + Sync + 'static;

type Error: Display + Debug + Send + Sync + 'static;
/// Determines if a transaction valid for the worker to consider putting in a batch
fn validate(&self, _t: &[u8]) -> Result<(), Self::Error> {
Ok(())
}
fn validate(&self, t: &[u8]) -> Result<(), Self::Error>;
/// Determines if this batch can be voted on
fn validate_batch(&self, _b: &Batch) -> Result<(), Self::Error> {
Ok(())
}
fn validate_batch(&self, b: &Batch) -> Result<(), Self::Error>;
}

/// Simple validator that accepts all transactions and batches.
#[derive(Debug, Clone, Default)]
pub struct TrivialTxValidator;
impl TxValidator for TrivialTxValidator {
type Error = eyre::Report;

fn validate(&self, _t: &[u8]) -> Result<(), Self::Error> {
Ok(())
}

fn validate_batch(&self, _b: &Batch) -> Result<(), Self::Error> {
Ok(())
}
}

0 comments on commit ba0ecbb

Please sign in to comment.