consensus: integrate script, transaction Verifiers

This commit is contained in:
Jane Lusby 2020-10-16 15:14:19 -07:00 committed by Deirdre Connolly
parent 248c318906
commit 4a36c4485a
2 changed files with 16 additions and 9 deletions

View File

@ -23,6 +23,7 @@ use crate::BoxError;
/// ///
/// After verification, the script future completes. State changes are handled by /// After verification, the script future completes. State changes are handled by
/// `BlockVerifier` or `MempoolTransactionVerifier`. /// `BlockVerifier` or `MempoolTransactionVerifier`.
#[derive(Debug, Clone)]
pub struct Verifier<ZS> { pub struct Verifier<ZS> {
state: ZS, state: ZS,
branch: ConsensusBranchId, branch: ConsensusBranchId,
@ -35,9 +36,9 @@ impl<ZS> Verifier<ZS> {
} }
#[derive(Debug)] #[derive(Debug)]
struct Request { pub struct Request {
transaction: Arc<Transaction>, pub transaction: Arc<Transaction>,
input_index: usize, pub input_index: usize,
} }
impl<ZS> tower::Service<Request> for Verifier<ZS> impl<ZS> tower::Service<Request> for Verifier<ZS>

View File

@ -41,11 +41,8 @@ use crate::{script, BoxError};
/// ///
/// After verification, the transaction future completes. State changes are /// After verification, the transaction future completes. State changes are
/// handled by `BlockVerifier` or `MempoolTransactionVerifier`. /// handled by `BlockVerifier` or `MempoolTransactionVerifier`.
pub struct Verifier<ZS> #[derive(Debug, Clone)]
where pub struct Verifier<ZS> {
ZS: Service<zs::Request, Response = zs::Response, Error = BoxError> + Send + Clone + 'static,
ZS::Future: Send + 'static,
{
script_verifier: script::Verifier<ZS>, script_verifier: script::Verifier<ZS>,
// spend_verifier: groth16::Verifier, // spend_verifier: groth16::Verifier,
// output_verifier: groth16::Verifier, // output_verifier: groth16::Verifier,
@ -134,13 +131,14 @@ where
}; };
let mut redjubjub_verifier = crate::primitives::redjubjub::VERIFIER.clone(); let mut redjubjub_verifier = crate::primitives::redjubjub::VERIFIER.clone();
let mut script_verifier = self.script_verifier.clone();
async move { async move {
match &*tx { match &*tx {
Transaction::V1 { .. } | Transaction::V2 { .. } | Transaction::V3 { .. } => { Transaction::V1 { .. } | Transaction::V2 { .. } | Transaction::V3 { .. } => {
Err(VerifyTransactionError::WrongVersion) Err(VerifyTransactionError::WrongVersion)
} }
Transaction::V4 { Transaction::V4 {
// inputs, inputs,
// outputs, // outputs,
// lock_time, // lock_time,
// expiry_height, // expiry_height,
@ -162,6 +160,14 @@ where
} else { } else {
// otherwise, check no coinbase inputs // otherwise, check no coinbase inputs
// feed all of the inputs to the script verifier // feed all of the inputs to the script verifier
for input_index in 0..inputs.len() {
let rsp = script_verifier.ready_and().await?.call(script::Request {
transaction: tx.clone(),
input_index,
});
async_checks.push(rsp);
}
} }
let sighash = tx.sighash( let sighash = tx.sighash(