pub async fn sync_mempool(
        &mut self,
        stashed_accounts: &[Address],
        purged_accounts: &[Address],
        gas_per_pubdata: u32,
        fee_per_gas: u64,
        allow_l1_txs: bool,
        limit: usize,
    ) -> DalResult<Vec<(Transaction, TransactionTimeRangeConstraint)>> {
        let stashed_addresses: Vec<_> = stashed_accounts.iter().map(Address::as_bytes).collect();
        let result = sqlx::query!(
            r#"
            UPDATE transactions
            SET
                in_mempool = FALSE
            FROM
                UNNEST($1::bytea []) AS s (address)
            WHERE
                transactions.in_mempool = TRUE
                AND transactions.initiator_address = s.address
            "#,
            &stashed_addresses as &[&[u8]],
        )
        .instrument("sync_mempool#update_stashed")
        .with_arg("stashed_addresses.len", &stashed_addresses.len())
        .execute(self.storage)
        .await?;

        tracing::debug!(
            "Updated {} transactions for stashed accounts, stashed accounts amount: {}, stashed_accounts: {:?}",
            result.rows_affected(),
            stashed_addresses.len(),
            stashed_accounts.iter().map(|a|format!("{:x}", a)).collect::<Vec<_>>()
        );

        let purged_addresses: Vec<_> = purged_accounts.iter().map(Address::as_bytes).collect();
        let result = sqlx::query!(
            r#"
            DELETE FROM transactions
            WHERE
                in_mempool = TRUE
                AND initiator_address = ANY($1)
            "#,
            &purged_addresses as &[&[u8]]
        )
        .instrument("sync_mempool#delete_purged")
        .with_arg("purged_addresses.len", &purged_addresses.len())
        .execute(self.storage)
        .await?;

        tracing::debug!(
            "Updated {} transactions for purged accounts, purged accounts amount: {}",
            result.rows_affected(),
            purged_addresses.len()
        );

        // Note, that transactions are updated in order of their hashes to avoid deadlocks with other UPDATE queries.
        let transactions = sqlx::query_as!(
            StorageTransaction,
            r#"
            UPDATE transactions
            SET
                in_mempool = TRUE
            FROM
                (
                    SELECT
                        hash
                    FROM
                        (
                            SELECT
                                hash
                            FROM
                                transactions
                            WHERE
                                miniblock_number IS NULL
                                AND in_mempool = FALSE
                                AND error IS NULL
                                AND (
                                    (
                                        is_priority = TRUE
                                        AND $5 = TRUE
                                    )
                                    OR (
                                        is_priority = FALSE
                                        AND max_fee_per_gas >= $2
                                        AND gas_per_pubdata_limit >= $3
                                    )
                                )
                                AND tx_format != $4
                            ORDER BY
                                is_priority DESC,
                                priority_op_id,
                                received_at
                            LIMIT
                                $1
                        ) AS subquery1
                    ORDER BY
                        hash
                ) AS subquery2
            WHERE
                transactions.hash = subquery2.hash
            RETURNING
            transactions.*
            "#,
            limit as i32,
            BigDecimal::from(fee_per_gas),
            BigDecimal::from(gas_per_pubdata),
            i32::from(PROTOCOL_UPGRADE_TX_TYPE),
            allow_l1_txs
        )
        .instrument("sync_mempool")
        .with_arg("fee_per_gas", &fee_per_gas)
        .with_arg("gas_per_pubdata", &gas_per_pubdata)
        .with_arg("limit", &limit)
        .with_arg("allow_l1_txs", &allow_l1_txs)
        .fetch_all(self.storage)
        .await?;

        let transactions_with_constraints = transactions
            .into_iter()
            .map(|tx| {
                let constraint = TransactionTimeRangeConstraint::from(&tx);
                (tx.into(), constraint)
            })
            .collect();
        Ok(transactions_with_constraints)
    }
Fetches new updates for mempool. Returns new transactions and current nonces for related accounts;
the latter are only used to bootstrap mempool for given account.
core/lib/dal/src/transactions_dal.rs