diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index a0aae121..06546edc 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1347,7 +1347,6 @@ void wallet2::unprocess_htlc_triggers_on_block_removed(uint64_t height) else { m_active_htlcs[pair_key] = it->second.transfer_index; - m_active_htlcs_txid[tr.tx_hash()] = it->second.transfer_index; } const crypto::hash tx_id = tr.tx_hash(); @@ -2263,6 +2262,27 @@ void wallet2::detach_blockchain(uint64_t including_height) for (size_t i = i_start; i != m_transfers.size(); i++) { + //check for htlc + if (m_transfers[i].m_ptx_wallet_info->m_tx.vout[m_transfers[i].m_internal_output_index].target.type() == typeid(txout_htlc)) + { + //need to find an entry in m_htlc and remove it + const txout_htlc& hltc = boost::get(m_transfers[i].m_ptx_wallet_info->m_tx.vout[m_transfers[i].m_internal_output_index].target); + uint64_t expiration_height = m_transfers[i].m_ptx_wallet_info->m_block_height + hltc.expiration; + auto pair_of_it = m_htlcs.equal_range(expiration_height); + bool found = false; + for (auto it = pair_of_it.first; it != pair_of_it.second; it++) + { + if (it->second.transfer_index == i) + { + found = true; + m_htlcs.erase(it); + break; + } + } + WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(found, "Internal error: not found record in m_htlcs during rollback"); + } + + if (!(m_transfers[i].m_key_image == null_ki && is_watch_only())) { auto it_ki = m_key_images.find(m_transfers[i].m_key_image); diff --git a/tests/core_tests/atomic_tests.cpp b/tests/core_tests/atomic_tests.cpp index fc8fdcc5..93174070 100644 --- a/tests/core_tests/atomic_tests.cpp +++ b/tests/core_tests/atomic_tests.cpp @@ -599,15 +599,27 @@ bool atomic_test_altchain_simple::c1(currency::core& c, size_t ev_index, const s alice_a_wlt_instance->refresh(); alice_b_wlt_instance->refresh(); + //here should be zero + htlcs_a.clear(); + alice_a_wlt_instance->get_list_of_active_htlc(htlcs_a, false); + CHECK_AND_FORCE_ASSERT_MES(htlcs_a.size() == 0, false, "Epected htlc not found"); + + //validate state of b + htlcs_b.clear(); + alice_b_wlt_instance->get_list_of_active_htlc(htlcs_b, true); + CHECK_AND_FORCE_ASSERT_MES(htlcs_b.size() == 0, false, "Epected htlc not found"); + //memorize block id at split height before split to make sure split happened crypto::hash id_first_splited_block_2 = c.get_blockchain_storage().get_block_id_by_height(split_height_2 + 1); txs.clear(); txs.push_back(result_redeem_tx); - r = mine_next_pow_blocks_in_playtime_with_given_txs(m_mining_accunt.get_public_address(), txs, c, 10, split_id_2); + r = mine_next_pow_blocks_in_playtime_with_given_txs(m_mining_accunt.get_public_address(), txs, c, 4, split_id_2); CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed"); + c.get_blockchain_storage().truncate_blockchain(c.get_top_block_height() - 2); + //make sure reorganize happened crypto::hash id_new_chain_2 = c.get_blockchain_storage().get_block_id_by_height(split_height_2 + 1); CHECK_AND_ASSERT_MES(id_new_chain_2 != id_first_splited_block_2, false, "Reorganize didn't happen");