Repository: bitcoin/bitcoin
File: src/validation.cpp (C++)

Code before:
        if (mempoolRejectFee > 0 && package_fee < mempoolRejectFee) {
            return state.Invalid(TxValidationResult::TX_RECONSIDERABLE, "mempool min fee not met", strprintf("%d < %d", package_fee, mempoolRejectFee));
        }

        if (package_fee < m_pool.m_min_relay_feerate.GetFee(package_size)) {
            return state.Invalid(TxValidationResult::TX_RECONSIDERABLE, "min relay fee not met",
                                 strprintf("%d < %d", package_fee, m_pool.m_min_relay_feerate.GetFee(package_size)));
        }
        return true;
    }

private:
    CTxMemPool& m_pool;
    CCoinsViewCache m_view;
    CCoinsViewMemPool m_viewmempool;
    CCoinsView m_dummy;

    Chainstate& m_active_chainstate;

    // Fields below are per *sub*package state and must be reset prior to subsequent
    // AcceptSingleTransaction and AcceptMultipleTransactions invocations

    /** Aggregated modified fees of all transactions, used to calculate package feerate. */
    CAmount m_total_modified_fees;
    /** Aggregated virtual size of all transactions, used to calculate package feerate. */
    int64_t m_total_vsize;

    // RBF-related members
    /** Whether the transaction(s) would replace any mempool transactions and/or evict any siblings.
     * If so, RBF rules apply. */
    bool m_rbf{false};
    /** All directly conflicting mempool transactions and their descendants. */
    CTxMemPool::setEntries m_all_conflicts;
    /** Mempool transactions that were replaced. */
    std::list<CTransactionRef> m_replaced_transactions;

    /** Total modified fees of mempool transactions being replaced. */
    CAmount m_conflicting_fees{0};
    /** Total size (in virtual bytes) of mempool transactions being replaced. */
    size_t m_conflicting_size{0};

    /** Re-set sub-package state to not leak between evaluations */
    void ClearSubPackageState() EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs)
    {
        m_total_modified_fees = 0;
        m_total_vsize = 0;
        m_rbf = false;
        m_all_conflicts.clear();
        m_replaced_transactions.clear();
        m_conflicting_fees = 0;
        m_conflicting_size = 0;

Review comment (suggestion):
```suggestion
    CAmount m_total_modified_fees{0};
    /** Aggregated virtual size of all transactions, used to calculate package feerate. */
    int64_t m_total_vsize{0};
```

Code after:
    // limiting is performed, false otherwise.
    bool Finalize(const ATMPArgs& args, Workspace& ws) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);

    // Submit all transactions to the mempool and call ConsensusScriptChecks to add to the script
    // cache - should only be called after successful validation of all transactions in the package.
    // Does not call LimitMempoolSize(), so mempool max_size_bytes may be temporarily exceeded.
    bool SubmitPackage(const ATMPArgs& args, std::vector<Workspace>& workspaces, PackageValidationState& package_state,
                       std::map<uint256, MempoolAcceptResult>& results)
         EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_pool.cs);

    // Compare a package's feerate against minimum allowed.
    bool CheckFeeRate(size_t package_size, CAmount package_fee, TxValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_pool.cs)
    {
        AssertLockHeld(::cs_main);
        AssertLockHeld(m_pool.cs);
        CAmount mempoolRejectFee = m_pool.GetMinFee().GetFee(package_size);
        if (mempoolRejectFee > 0 && package_fee < mempoolRejectFee) {
            return state.Invalid(TxValidationResult::TX_RECONSIDERABLE, "mempool min fee not met", strprintf("%d < %d", package_fee, mempoolRejectFee));
        }

        if (package_fee < m_pool.m_opts.min_relay_feerate.GetFee(package_size)) {
            return state.Invalid(TxValidationResult::TX_RECONSIDERABLE, "min relay fee not met",
                                 strprintf("%d < %d", package_fee, m_pool.m_opts.min_relay_feerate.GetFee(package_size)));
        }
        return true;
    }

private:
    CTxMemPool& m_pool;
    CCoinsViewCache m_view;
    CCoinsViewMemPool m_viewmempool;
    CCoinsView m_dummy;

    Chainstate& m_active_chainstate;

    // Fields below are per *sub*package state and must be reset prior to subsequent
    // AcceptSingleTransaction and AcceptMultipleTransactions invocations
    struct SubPackageState {
        /** Aggregated modified fees of all transactions, used to calculate package feerate. */
        CAmount m_total_modified_fees{0};
        /** Aggregated virtual size of all transactions, used to calculate package feerate. */
        int64_t m_total_vsize{0};

        // RBF-related members
        /** Whether the transaction(s) would replace any mempool transactions and/or evict any siblings.
         * If so, RBF rules apply. */
        bool m_rbf{false};
        /** All directly conflicting mempool transactions and their descendants. */
        CTxMemPool::setEntries m_all_conflicts;
        /** Mempool transactions that were replaced. */
        std::list<CTransactionRef> m_replaced_transactions;