API: filter out unnecessary updates

This commit is contained in:
SChernykh 2024-08-12 00:47:27 +02:00
parent c49f12b41d
commit 2b47218406
4 changed files with 24 additions and 15 deletions

View file

@ -521,7 +521,7 @@ void p2pool::handle_chain_main(ChainMain& data, const char* extra)
LOGINFO(0, log::LightCyan() << "Your wallet " << log::LightYellow() << w << log::LightCyan() << " didn't get a payout in block " << log::LightYellow() << data.height << log::LightCyan() << " because you had no shares in PPLNS window");
}
api_update_block_found(&data, block);
api_update_block_found(&data, block, false);
}
else {
side_chain().watch_mainchain_block(data, merkle_root);
@ -1680,7 +1680,7 @@ void p2pool::cleanup_mainchain_data(uint64_t height)
}
}
void p2pool::api_update_block_found(const ChainMain* data, const PoolBlock* block)
void p2pool::api_update_block_found(const ChainMain* data, const PoolBlock* block, bool update_stats_mod)
{
if (!m_api || m_stopped) {
return;
@ -1727,7 +1727,9 @@ void p2pool::api_update_block_found(const ChainMain* data, const PoolBlock* bloc
s << ']';
});
api_update_stats_mod();
if (update_stats_mod) {
api_update_stats_mod();
}
}
bool p2pool::get_difficulty_at_height(uint64_t height, difficulty_type& diff)

View file

@ -110,7 +110,7 @@ public:
bool chainmain_get_by_hash(const hash& id, ChainMain& data) const;
void api_update_block_found(const ChainMain* data, const PoolBlock* block);
void api_update_block_found(const ChainMain* data, const PoolBlock* block, bool update_stats_mod = true);
bool get_difficulty_at_height(uint64_t height, difficulty_type& diff);

View file

@ -130,29 +130,36 @@ void p2pool_api::dump_to_file_async_internal(Category category, const char* file
}
MutexLock lock(m_dumpDataLock);
m_dumpData[path] = std::move(buf);
if (!uv_is_closing(reinterpret_cast<uv_handle_t*>(&m_dumpToFileAsync))) {
uv_async_send(&m_dumpToFileAsync);
std::pair<std::vector<char>, bool>& data = m_dumpData[path];
if (data.first != buf) {
data.first = buf;
data.second = true;
if (!uv_is_closing(reinterpret_cast<uv_handle_t*>(&m_dumpToFileAsync))) {
uv_async_send(&m_dumpToFileAsync);
}
}
}
void p2pool_api::dump_to_file()
{
unordered_map<std::string, std::vector<char>> data;
{
MutexLock lock(m_dumpDataLock);
data = std::move(m_dumpData);
}
MutexLock lock(m_dumpDataLock);
char buf[log::Stream::BUF_SIZE + 1];
buf[0] = '\0';
for (auto& it : data) {
for (auto& it : m_dumpData) {
if (!it.second.second) {
continue;
}
it.second.second = false;
log::Stream s(buf);
s << it.first << m_counter << '\0';
DumpFileWork* work = new DumpFileWork{ {}, 0, it.first, buf, std::move(it.second) };
DumpFileWork* work = new DumpFileWork{ {}, 0, it.first, buf, it.second.first };
work->req.data = work;
++m_counter;

View file

@ -68,7 +68,7 @@ private:
std::string m_localPath;
uv_mutex_t m_dumpDataLock;
unordered_map<std::string, std::vector<char>> m_dumpData;
unordered_map<std::string, std::pair<std::vector<char>, bool>> m_dumpData;
uv_async_t m_dumpToFileAsync;