Skip to content

Commit

Permalink
API: filter out unnecessary updates
Browse files Browse the repository at this point in the history
  • Loading branch information
SChernykh committed Aug 11, 2024
1 parent c49f12b commit 2b47218
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
8 changes: 5 additions & 3 deletions src/p2pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/p2pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class p2pool : public MinerCallbackHandler, public nocopy_nomove

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);

Expand Down
27 changes: 17 additions & 10 deletions src/p2pool_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/p2pool_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class p2pool_api
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;

Expand Down

0 comments on commit 2b47218

Please sign in to comment.