pub(crate) fn insert(
        &mut self,
        txn: MempoolTransaction,
        current_sequence_number: u64,
    ) -> MempoolStatus {
        if self.handle_gas_price_update(&txn).is_err() {
            return MempoolStatus::new(MempoolStatusCode::InvalidUpdate).with_message(format!(
                "Failed to update gas price to {}",
                txn.get_gas_price()
            ));
        }

        if self.check_if_full() {
            return MempoolStatus::new(MempoolStatusCode::MempoolIsFull).with_message(format!(
                "mempool size: {}, capacity: {}",
                self.system_ttl_index.size(),
                self.capacity,
            ));
        }

        let address = txn.get_sender();
        let sequence_number = txn.get_sequence_number();

        self.transactions
            .entry(address)
            .or_insert_with(AccountTransactions::new);

        self.clean_committed_transactions(&address, current_sequence_number);

        if let Some(txns) = self.transactions.get_mut(&address) {
            // capacity check
            if txns.len() >= self.capacity_per_user {
                return MempoolStatus::new(MempoolStatusCode::TooManyTransactions).with_message(
                    format!(
                        "txns length: {} capacity per user: {}",
                        txns.len(),
                        self.capacity_per_user,
                    ),
                );
            }

            // insert into storage and other indexes
            self.system_ttl_index.insert(&txn);
            self.expiration_time_index.insert(&txn);
            txns.insert(sequence_number, txn);
            self.track_indices();
        }
        self.process_ready_transactions(&address, current_sequence_number);
        MempoolStatus::new(MempoolStatusCode::Accepted)
    }
/// insert transaction into TransactionStore
/// performs validation checks and updates indexes
insert transaction into TransactionStore
performs validation checks and updates indexes
insert transaction into TransactionStore performs validation checks and updates indexes
pub(crate) fn insert(
        &mut self,
        txn: MempoolTransaction,
        current_sequence_number: u64,
    ) -> MempoolStatus {
        if self.handle_gas_price_update(&txn).is_err() {
            return MempoolStatus::new(MempoolStatusCode::InvalidUpdate).with_message(format!(
                "Failed to update gas price to {}",
                txn.get_gas_price()
            ));
        }
        if self.check_if_full() {
            return MempoolStatus::new(MempoolStatusCode::MempoolIsFull).with_message(format!(
                "mempool size: {}, capacity: {}",
                self.system_ttl_index.size(),
                self.capacity,
            ));
        }
        let address = txn.get_sender();
        let sequence_number = txn.get_sequence_number();
        self.transactions
            .entry(address)
            .or_insert_with(AccountTransactions::new);
        self.clean_committed_transactions(&address, current_sequence_number);
        if let Some(txns) = self.transactions.get_mut(&address) {
            // capacity check
            if txns.len() >= self.capacity_per_user {
                return MempoolStatus::new(MempoolStatusCode::TooManyTransactions).with_message(
                    format!(
                        "txns length: {} capacity per user: {}",
                        txns.len(),
                        self.capacity_per_user,
                    ),
                );
            }
            // insert into storage and other indexes
            self.system_ttl_index.insert(&txn);
            self.expiration_time_index.insert(&txn);
            txns.insert(sequence_number, txn);
            self.track_indices();
        }
        self.process_ready_transactions(&address, current_sequence_number);
        MempoolStatus::new(MempoolStatusCode::Accepted)
    }
pub ( crate ) fn insert ( & mut self , txn : MempoolTransaction , current_sequence_number : u64 , ) -> MempoolStatus { if self . handle_gas_price_update ( & txn ) . is_err ( ) { return MempoolStatus :: new ( MempoolStatusCode :: InvalidUpdate ) . with_message ( format ! ( " " txn get_gas_price ( ) ) ) ; } if self . check_if_full ( ) { return MempoolStatus :: new ( MempoolStatusCode :: MempoolIsFull ) . with_message ( format ! ( " " self system_ttl_index size ( ) self capacity ) ) ; } let address = txn . get_sender ( ) ; let sequence_number = txn . get_sequence_number ( ) ; self . transactions . entry ( address ) . or_insert_with ( AccountTransactions :: new ) ; self . clean_committed_transactions ( & address , current_sequence_number ) ; if let Some ( txns ) = self . transactions . get_mut ( & address ) { // capacity check if txns . len ( ) >= self . capacity_per_user { return MempoolStatus :: new ( MempoolStatusCode :: TooManyTransactions ) . with_message ( format ! ( " " txns len ( ) self capacity_per_user ) , ) ; } // insert into storage and other indexes self . system_ttl_index . insert ( & txn ) ; self . expiration_time_index . insert ( & txn ) ; txns . insert ( sequence_number , txn ) ; self . track_indices ( ) ; } self . process_ready_transactions ( & address , current_sequence_number ) ; MempoolStatus :: new ( MempoolStatusCode :: Accepted ) }
insert transaction into TransactionStore
performs validation checks and updates indexes
insert transaction into TransactionStore performs validation checks and updates indexes
&mut self
txn
MempoolTransaction
current_sequence_number
u64
&mut self
txn
MempoolTransaction
current_sequence_number
u64