mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-03-12 09:29:51 +00:00
SideChain: reduce lock scope in get_outputs_blob
This commit is contained in:
parent
488ed8e562
commit
79a31ce57c
1 changed files with 29 additions and 28 deletions
|
@ -696,37 +696,38 @@ bool SideChain::get_outputs_blob(PoolBlock* block, uint64_t total_reward, std::v
|
||||||
{
|
{
|
||||||
blob.clear();
|
blob.clear();
|
||||||
|
|
||||||
ReadLock lock(m_sidechainLock);
|
|
||||||
|
|
||||||
auto it = m_blocksById.find(block->m_sidechainId);
|
|
||||||
if (it != m_blocksById.end()) {
|
|
||||||
PoolBlock* b = it->second;
|
|
||||||
const size_t n = b->m_outputs.size();
|
|
||||||
|
|
||||||
blob.reserve(n * 39 + 64);
|
|
||||||
writeVarint(n, blob);
|
|
||||||
|
|
||||||
const uint8_t tx_type = b->get_tx_type();
|
|
||||||
|
|
||||||
for (const PoolBlock::TxOutput& output : b->m_outputs) {
|
|
||||||
writeVarint(output.m_reward, blob);
|
|
||||||
blob.emplace_back(tx_type);
|
|
||||||
blob.insert(blob.end(), output.m_ephPublicKey.h, output.m_ephPublicKey.h + HASH_SIZE);
|
|
||||||
|
|
||||||
if (tx_type == TXOUT_TO_TAGGED_KEY) {
|
|
||||||
blob.emplace_back(static_cast<uint8_t>(output.m_viewTag));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
block->m_outputs = b->m_outputs;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<MinerShare> tmpShares;
|
std::vector<MinerShare> tmpShares;
|
||||||
std::vector<uint64_t> tmpRewards;
|
std::vector<uint64_t> tmpRewards;
|
||||||
|
{
|
||||||
|
ReadLock lock(m_sidechainLock);
|
||||||
|
|
||||||
if (!get_shares(block, tmpShares) || !split_reward(total_reward, tmpShares, tmpRewards) || (tmpRewards.size() != tmpShares.size())) {
|
auto it = m_blocksById.find(block->m_sidechainId);
|
||||||
return false;
|
if (it != m_blocksById.end()) {
|
||||||
|
PoolBlock* b = it->second;
|
||||||
|
const size_t n = b->m_outputs.size();
|
||||||
|
|
||||||
|
blob.reserve(n * 39 + 64);
|
||||||
|
writeVarint(n, blob);
|
||||||
|
|
||||||
|
const uint8_t tx_type = b->get_tx_type();
|
||||||
|
|
||||||
|
for (const PoolBlock::TxOutput& output : b->m_outputs) {
|
||||||
|
writeVarint(output.m_reward, blob);
|
||||||
|
blob.emplace_back(tx_type);
|
||||||
|
blob.insert(blob.end(), output.m_ephPublicKey.h, output.m_ephPublicKey.h + HASH_SIZE);
|
||||||
|
|
||||||
|
if (tx_type == TXOUT_TO_TAGGED_KEY) {
|
||||||
|
blob.emplace_back(static_cast<uint8_t>(output.m_viewTag));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
block->m_outputs = b->m_outputs;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!get_shares(block, tmpShares) || !split_reward(total_reward, tmpShares, tmpRewards) || (tmpRewards.size() != tmpShares.size())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t n = tmpShares.size();
|
const size_t n = tmpShares.size();
|
||||||
|
|
Loading…
Reference in a new issue