void unspent_outputs::add(const transaction& tx, size_t height, uint32_t median_time_past, bool confirmed) { if (disabled() || tx.outputs().empty()) return; if (tx.is_coinbase()) { LOG_DEBUG(LOG_DATABASE) << "Output cache hit rate: " << hit_rate() << ", size: " << size(); } // Critical Section /////////////////////////////////////////////////////////////////////////// unique_lock lock(mutex_); // It's been a long time since the last restart (~16 years). if (sequence_ == max_uint32) unspent_.clear(); // Remove the oldest entry if the buffer is at capacity. if (unspent_.size() >= capacity_) unspent_.right.erase(unspent_.right.begin()); // TODO: promote the unconfirmed tx cache instead of replacing it. // A confirmed tx may replace the same unconfirmed tx here. unspent_.insert( { unspent_transaction{ tx, height, median_time_past, confirmed }, ++sequence_ }); /////////////////////////////////////////////////////////////////////////// }
void unspent_outputs::add(const transaction& transaction, size_t height) { if (capacity_ == 0 || transaction.outputs().empty()) return; // Critical Section /////////////////////////////////////////////////////////////////////////// unique_lock lock(mutex_); // It's been a long time since the last restart (~16 years). if (sequence_ == max_uint32) unspent_.clear(); // Remove the oldest entry if the buffer is at capacity. if (unspent_.size() >= capacity_) unspent_.right.erase(unspent_.right.begin()); unspent_.insert( { unspent_transaction{ transaction, height }, ++sequence_ }); /////////////////////////////////////////////////////////////////////////// }