mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-12-23 02:18:52 +00:00
Merge pull request #2739
99f398a2
wallet2: avoid growing the short history when refreshing in a loop (moneromooo-monero)
This commit is contained in:
commit
815e158bdf
@ -444,6 +444,19 @@ static void emplace_or_replace(std::unordered_multimap<crypto::hash, tools::wall
|
|||||||
container.emplace(key, pd);
|
container.emplace(key, pd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drop_from_short_history(std::list<crypto::hash> &short_chain_history, size_t N)
|
||||||
|
{
|
||||||
|
std::list<crypto::hash>::iterator right;
|
||||||
|
// drop early N off, skipping the genesis block
|
||||||
|
if (short_chain_history.size() > N) {
|
||||||
|
right = short_chain_history.end();
|
||||||
|
std::advance(right,-1);
|
||||||
|
std::list<crypto::hash>::iterator left = right;
|
||||||
|
std::advance(left, -N);
|
||||||
|
short_chain_history.erase(left, right);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} //namespace
|
} //namespace
|
||||||
|
|
||||||
namespace tools
|
namespace tools
|
||||||
@ -1485,6 +1498,8 @@ void wallet2::pull_next_blocks(uint64_t start_height, uint64_t &blocks_start_hei
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
drop_from_short_history(short_chain_history, 3);
|
||||||
|
|
||||||
// prepend the last 3 blocks, should be enough to guard against a block or two's reorg
|
// prepend the last 3 blocks, should be enough to guard against a block or two's reorg
|
||||||
cryptonote::block bl;
|
cryptonote::block bl;
|
||||||
std::list<cryptonote::block_complete_entry>::const_reverse_iterator i = prev_blocks.rbegin();
|
std::list<cryptonote::block_complete_entry>::const_reverse_iterator i = prev_blocks.rbegin();
|
||||||
@ -1774,16 +1789,8 @@ void wallet2::fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height,
|
|||||||
if (hashes.size() <= 3)
|
if (hashes.size() <= 3)
|
||||||
return;
|
return;
|
||||||
if (hashes.size() + current_index < stop_height) {
|
if (hashes.size() + current_index < stop_height) {
|
||||||
std::list<crypto::hash>::iterator right;
|
drop_from_short_history(short_chain_history, 3);
|
||||||
// drop early 3 off, skipping the genesis block
|
std::list<crypto::hash>::iterator right = hashes.end();
|
||||||
if (short_chain_history.size() > 3) {
|
|
||||||
right = short_chain_history.end();
|
|
||||||
std::advance(right,-1);
|
|
||||||
std::list<crypto::hash>::iterator left = right;
|
|
||||||
std::advance(left, -3);
|
|
||||||
short_chain_history.erase(left, right);
|
|
||||||
}
|
|
||||||
right = hashes.end();
|
|
||||||
// prepend 3 more
|
// prepend 3 more
|
||||||
for (int i = 0; i<3; i++) {
|
for (int i = 0; i<3; i++) {
|
||||||
right--;
|
right--;
|
||||||
|
Loading…
Reference in New Issue
Block a user