@@ -444,6 +444,7 @@ void BlockChain::removeLastBlock() {
444444 --lastSequence_;
445445 total_transactions_count_ -= pool.transactions ().size ();
446446 removeWalletsInPoolFromCache (pool);
447+ removeLastBlockFromTrxIndex (pool);
447448
448449 emit removeBlockEvent (pool.sequence ());
449450
@@ -461,7 +462,31 @@ csdb::Address BlockChain::getAddressFromKey(const std::string& key) {
461462 return res;
462463 }
463464}
464-
465+
466+ void BlockChain::removeLastBlockFromTrxIndex (const csdb::Pool& pool) {
467+ std::set<csdb::Address> uniqueAddresses;
468+
469+ auto lbd = [&uniqueAddresses, this ](const csdb::Address& addr, cs::Sequence sq) {
470+ auto key = getAddressByType (addr, AddressType::PublicKey);
471+ if (uniqueAddresses.insert (key).second ) {
472+ std::lock_guard<decltype (dbLock_)> l (dbLock_);
473+ storage_.remove_last_from_trx_index (key, sq);
474+ }
475+ };
476+
477+ for (const auto & t : pool.transactions ()) {
478+ lbd (t.source (), lastIndexedPool);
479+ lbd (t.target (), lastIndexedPool);
480+ }
481+ --lastIndexedPool;
482+ updateLastIndFile ();
483+
484+ if (lastNonEmptyBlock_.poolSeq == pool.sequence ()) {
485+ lastNonEmptyBlock_ = previousNonEmpty_[lastNonEmptyBlock_.poolSeq ];
486+ previousNonEmpty_.erase (pool.sequence ());
487+ }
488+ }
489+
465490void BlockChain::removeWalletsInPoolFromCache (const csdb::Pool& pool) {
466491 try {
467492 std::lock_guard lock (cacheMutex_);
0 commit comments