SideChain: tweaked precalculation during sync

pull/271/head
SChernykh 2023-04-22 18:00:31 +02:00
parent fd67ec1f86
commit 75c156578c
1 changed files with 16 additions and 7 deletions

View File

@ -197,6 +197,7 @@ SideChain::SideChain(p2pool* pool, NetworkType type, const char* pool_name)
} }
m_uniquePrecalcInputs = new unordered_set<size_t>(); m_uniquePrecalcInputs = new unordered_set<size_t>();
m_uniquePrecalcInputs->reserve(1 << 18);
} }
SideChain::~SideChain() SideChain::~SideChain()
@ -2156,7 +2157,7 @@ void SideChain::launch_precalc(const PoolBlock* block)
return; return;
} }
for (int h = UNCLE_BLOCK_DEPTH - 1; h >= 0; --h) { for (int h = UNCLE_BLOCK_DEPTH; h >= 0; --h) {
auto it = m_blocksByHeight.find(block->m_sidechainHeight + m_chainWindowSize + h - 1); auto it = m_blocksByHeight.find(block->m_sidechainHeight + m_chainWindowSize + h - 1);
if (it == m_blocksByHeight.end()) { if (it == m_blocksByHeight.end()) {
continue; continue;
@ -2183,6 +2184,7 @@ void SideChain::precalc_worker()
{ {
do { do {
PrecalcJob* job; PrecalcJob* job;
size_t num_inputs;
{ {
MutexLock lock(m_precalcJobsMutex); MutexLock lock(m_precalcJobsMutex);
@ -2205,22 +2207,29 @@ void SideChain::precalc_worker()
uint8_t t[HASH_SIZE * 2 + sizeof(size_t)]; uint8_t t[HASH_SIZE * 2 + sizeof(size_t)];
memcpy(t, job->b->m_txkeySec.h, HASH_SIZE); memcpy(t, job->b->m_txkeySec.h, HASH_SIZE);
for (size_t i = 0, n = job->shares.size(); i < n; ++i) { const size_t n = job->shares.size();
num_inputs = n;
for (size_t i = 0; i < n; ++i) {
memcpy(t + HASH_SIZE, job->shares[i].m_wallet->view_public_key().h, HASH_SIZE); memcpy(t + HASH_SIZE, job->shares[i].m_wallet->view_public_key().h, HASH_SIZE);
memcpy(t + HASH_SIZE * 2, &i, sizeof(i)); memcpy(t + HASH_SIZE * 2, &i, sizeof(i));
if (!m_uniquePrecalcInputs->insert(robin_hood::hash_bytes(t, array_size(t))).second) { if (!m_uniquePrecalcInputs->insert(robin_hood::hash_bytes(t, array_size(t))).second) {
job->shares[i].m_wallet = nullptr; job->shares[i].m_wallet = nullptr;
--num_inputs;
} }
} }
} }
for (size_t i = 0, n = job->shares.size(); i < n; ++i) { if (num_inputs) {
if (job->shares[i].m_wallet) { for (size_t i = 0, n = job->shares.size(); i < n; ++i) {
hash eph_public_key; if (job->shares[i].m_wallet) {
uint8_t view_tag; hash eph_public_key;
job->shares[i].m_wallet->get_eph_public_key(job->b->m_txkeySec, i, eph_public_key, view_tag); uint8_t view_tag;
job->shares[i].m_wallet->get_eph_public_key(job->b->m_txkeySec, i, eph_public_key, view_tag);
}
} }
} }
delete job; delete job;
} while (true); } while (true);
} }