async fn process_incoming_transactions<V>(
    smp: &SharedMempool<V>,
    transactions: Vec<SignedTransaction>,
    timeline_state: TimelineState,
) -> Vec<SubmissionStatus>
where
    V: TransactionValidation,
{
    let mut statuses = vec![];

    let seq_numbers = transactions
        .iter()
        .map(|t| get_account_sequence_number(smp.db.as_ref(), t.sender()))
        .collect::<Vec<_>>();

    let transactions: Vec<_> = transactions
        .into_iter()
        .enumerate()
        .filter_map(|(idx, t)| {
            if let Ok(sequence_number) = seq_numbers[idx] {
                if t.sequence_number() >= sequence_number {
                    return Some((t, sequence_number));
                } else {
                    statuses.push((
                        MempoolStatus::new(MempoolStatusCode::VmError),
                        Some(VMStatus::Error(SEQUENCE_NUMBER_TOO_OLD)),
                    ));
                }
            } else {
                // failed to get transaction
                statuses.push((
                    MempoolStatus::new(MempoolStatusCode::VmError),
                    Some(VMStatus::Error(RESOURCE_DOES_NOT_EXIST)),
                ));
            }
            None
        })
        .collect();

    let validation_results = transactions
        .iter()
        .map(|t| {
            smp.validator
                .read()
                .unwrap()
                .validate_transaction(t.0.clone())
        })
        .collect::<Vec<_>>();

    {
        let mut mempool = smp
            .mempool
            .lock()
            .expect("[shared mempool] failed to acquire mempool lock");
        for (idx, (transaction, sequence_number)) in transactions.into_iter().enumerate() {
            if let Ok(validation_result) = &validation_results[idx] {
                match validation_result.status() {
                    None => {
                        let gas_amount = transaction.max_gas_amount();
                        let rankin_score = validation_result.score();
                        let is_governance_txn = validation_result.is_governance_txn();
                        let mempool_status = mempool.add_txn(
                            transaction,
                            gas_amount,
                            rankin_score,
                            sequence_number,
                            timeline_state,
                            is_governance_txn,
                        );
                        statuses.push((mempool_status, None));
                    }
                    Some(validation_status) => {
                        statuses.push((
                            MempoolStatus::new(MempoolStatusCode::VmError),
                            Some(validation_status.clone()),
                        ));
                    }
                }
            }
        }
    }
    notify_subscribers(SharedMempoolNotification::NewTransactions, &smp.subscribers);
    statuses
}
/// submits a list of SignedTransaction to the local mempool
/// and returns a vector containing AdmissionControlStatus
submits a list of SignedTransaction to the local mempool
and returns a vector containing AdmissionControlStatus
submits a list of SignedTransaction to the local mempool and returns a vector containing AdmissionControlStatus
async fn process_incoming_transactions<V>(
    smp: &SharedMempool<V>,
    transactions: Vec<SignedTransaction>,
    timeline_state: TimelineState,
) -> Vec<SubmissionStatus>
where
    V: TransactionValidation,
{
    let mut statuses = vec![];
    let seq_numbers = transactions
        .iter()
        .map(|t| get_account_sequence_number(smp.db.as_ref(), t.sender()))
        .collect::<Vec<_>>();
    let transactions: Vec<_> = transactions
        .into_iter()
        .enumerate()
        .filter_map(|(idx, t)| {
            if let Ok(sequence_number) = seq_numbers[idx] {
                if t.sequence_number() >= sequence_number {
                    return Some((t, sequence_number));
                } else {
                    statuses.push((
                        MempoolStatus::new(MempoolStatusCode::VmError),
                        Some(VMStatus::Error(SEQUENCE_NUMBER_TOO_OLD)),
                    ));
                }
            } else {
                // failed to get transaction
                statuses.push((
                    MempoolStatus::new(MempoolStatusCode::VmError),
                    Some(VMStatus::Error(RESOURCE_DOES_NOT_EXIST)),
                ));
            }
            None
        })
        .collect();
    let validation_results = transactions
        .iter()
        .map(|t| {
            smp.validator
                .read()
                .unwrap()
                .validate_transaction(t.0.clone())
        })
        .collect::<Vec<_>>();
    {
        let mut mempool = smp
            .mempool
            .lock()
            .expect("[shared mempool] failed to acquire mempool lock");
        for (idx, (transaction, sequence_number)) in transactions.into_iter().enumerate() {
            if let Ok(validation_result) = &validation_results[idx] {
                match validation_result.status() {
                    None => {
                        let gas_amount = transaction.max_gas_amount();
                        let rankin_score = validation_result.score();
                        let is_governance_txn = validation_result.is_governance_txn();
                        let mempool_status = mempool.add_txn(
                            transaction,
                            gas_amount,
                            rankin_score,
                            sequence_number,
                            timeline_state,
                            is_governance_txn,
                        );
                        statuses.push((mempool_status, None));
                    }
                    Some(validation_status) => {
                        statuses.push((
                            MempoolStatus::new(MempoolStatusCode::VmError),
                            Some(validation_status.clone()),
                        ));
                    }
                }
            }
        }
    }
    notify_subscribers(SharedMempoolNotification::NewTransactions, &smp.subscribers);
    statuses
}
async fn process_incoming_transactions < V > ( smp : & SharedMempool < V > , transactions : Vec < SignedTransaction > , timeline_state : TimelineState , ) -> Vec < SubmissionStatus > where V : TransactionValidation , { let mut statuses = vec ! [ ] ; let seq_numbers = transactions . iter ( ) . map ( | t | get_account_sequence_number ( smp . db . as_ref ( ) , t . sender ( ) ) ) . collect :: < Vec < _ > > ( ) ; let transactions : Vec < _ > = transactions . into_iter ( ) . enumerate ( ) . filter_map ( | ( idx , t ) | { if let Ok ( sequence_number ) = seq_numbers [ idx ] { if t . sequence_number ( ) >= sequence_number { return Some ( ( t , sequence_number ) ) ; } else { statuses . push ( ( MempoolStatus :: new ( MempoolStatusCode :: VmError ) , Some ( VMStatus :: Error ( SEQUENCE_NUMBER_TOO_OLD ) ) , ) ) ; } } else { // failed to get transaction statuses . push ( ( MempoolStatus :: new ( MempoolStatusCode :: VmError ) , Some ( VMStatus :: Error ( RESOURCE_DOES_NOT_EXIST ) ) , ) ) ; } None } ) . collect ( ) ; let validation_results = transactions . iter ( ) . map ( | t | { smp . validator . read ( ) . unwrap ( ) . validate_transaction ( t . 0 . clone ( ) ) } ) . collect :: < Vec < _ > > ( ) ; { let mut mempool = smp . mempool . lock ( ) . expect ( " " ) ; for ( idx , ( transaction , sequence_number ) ) in transactions . into_iter ( ) . enumerate ( ) { if let Ok ( validation_result ) = & validation_results [ idx ] { match validation_result . status ( ) { None => { let gas_amount = transaction . max_gas_amount ( ) ; let rankin_score = validation_result . score ( ) ; let is_governance_txn = validation_result . is_governance_txn ( ) ; let mempool_status = mempool . add_txn ( transaction , gas_amount , rankin_score , sequence_number , timeline_state , is_governance_txn , ) ; statuses . push ( ( mempool_status , None ) ) ; } Some ( validation_status ) => { statuses . push ( ( MempoolStatus :: new ( MempoolStatusCode :: VmError ) , Some ( validation_status . clone ( ) ) , ) ) ; } } } } } notify_subscribers ( SharedMempoolNotification :: NewTransactions , & smp . subscribers ) ; statuses }
submits a list of SignedTransaction to the local mempool
and returns a vector containing AdmissionControlStatus
submits a list of SignedTransaction to the local mempool and returns a vector containing AdmissionControlStatus
smp
&SharedMempool<V>
transactions
Vec<SignedTransaction>
timeline_state
TimelineState
smp
&SharedMempool<V>
transactions
Vec<SignedTransaction>
timeline_state
TimelineState