Skip to content

Commit a9da993

Browse files
committed
wallet: update FCMP++ timelock reporting to use lock height
1 parent dbe95f3 commit a9da993

3 files changed

Lines changed: 46 additions & 12 deletions

File tree

src/simplewallet/simplewallet.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8471,9 +8471,14 @@ bool simple_wallet::get_transfers(std::vector<std::string>& local_args, std::vec
84718471
if (bh >= last_block_height)
84728472
locked_msg = std::to_string(bh - last_block_height) + " blks";
84738473
}
8474+
else if (m_wallet->use_fork_rules(HF_VERSION_FCMP_PLUS_PLUS, 0))
8475+
{
8476+
const uint64_t last_locked = cryptonote::get_last_locked_block_index(pd.m_unlock_time, pd.m_block_height);
8477+
if (last_locked + 1 > last_block_height)
8478+
locked_msg = std::to_string(last_locked + 1 - last_block_height) + " blks";
8479+
}
84748480
else
84758481
{
8476-
// FIXME: update for FCMP++
84778482
const uint64_t adjusted_time = m_wallet->get_daemon_adjusted_time();
84788483
uint64_t threshold = adjusted_time + (m_wallet->use_fork_rules(2, 0) ? CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V2 : CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V1);
84798484
if (threshold < pd.m_unlock_time)
@@ -10217,9 +10222,16 @@ bool simple_wallet::show_transfer(const std::vector<std::string> &args)
1021710222
else
1021810223
success_msg_writer() << std::to_string(last_block_height - bh) << " confirmations";
1021910224
}
10225+
else if (m_wallet->use_fork_rules(HF_VERSION_FCMP_PLUS_PLUS, 0))
10226+
{
10227+
const uint64_t last_locked = cryptonote::get_last_locked_block_index(pd.m_unlock_time, pd.m_block_height);
10228+
if (last_locked + 1 > last_block_height)
10229+
success_msg_writer() << "Locked: " << (last_locked + 1 - last_block_height) << " blocks to unlock";
10230+
else
10231+
success_msg_writer() << (last_block_height - last_locked - 1) << " confirmations";
10232+
}
1022010233
else
1022110234
{
10222-
// FIXME: update for FCMP++
1022310235
const uint64_t adjusted_time = m_wallet->get_daemon_adjusted_time();
1022410236
uint64_t threshold = adjusted_time + (m_wallet->use_fork_rules(2, 0) ? CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V2 : CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V1);
1022510237
if (threshold >= pd.m_unlock_time)

src/wallet/wallet2.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7375,10 +7375,27 @@ std::map<uint32_t, std::pair<uint64_t, std::pair<uint64_t, uint64_t>>> wallet2::
73757375
uint64_t unlock_height = td.m_block_height + std::max<uint64_t>(CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE, CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS);
73767376
if (td.m_tx.unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER && td.m_tx.unlock_time > unlock_height)
73777377
unlock_height = td.m_tx.unlock_time;
7378-
// FIXME: update for FCMP++
7379-
uint64_t unlock_time = td.m_tx.unlock_time >= CRYPTONOTE_MAX_BLOCK_NUMBER ? td.m_tx.unlock_time : 0;
7380-
blocks_to_unlock = unlock_height > blockchain_height ? unlock_height - blockchain_height : 0;
7381-
time_to_unlock = unlock_time > now ? unlock_time - now : 0;
7378+
bool use_fcmp_pp_unlock_rules = false;
7379+
try
7380+
{
7381+
use_fcmp_pp_unlock_rules = td.m_tx.unlock_time >= CRYPTONOTE_MAX_BLOCK_NUMBER && use_fork_rules(HF_VERSION_FCMP_PLUS_PLUS, 0);
7382+
}
7383+
catch (...)
7384+
{
7385+
use_fcmp_pp_unlock_rules = td.m_tx.unlock_time >= CRYPTONOTE_MAX_BLOCK_NUMBER && use_fork_rules_offline(HF_VERSION_FCMP_PLUS_PLUS, 0);
7386+
}
7387+
if (use_fcmp_pp_unlock_rules)
7388+
{
7389+
unlock_height = std::max(unlock_height, cryptonote::get_last_locked_block_index(td.m_tx.unlock_time, td.m_block_height) + 1);
7390+
blocks_to_unlock = unlock_height > blockchain_height ? unlock_height - blockchain_height : 0;
7391+
time_to_unlock = 0;
7392+
}
7393+
else
7394+
{
7395+
const uint64_t unlock_time = td.m_tx.unlock_time >= CRYPTONOTE_MAX_BLOCK_NUMBER ? td.m_tx.unlock_time : 0;
7396+
blocks_to_unlock = unlock_height > blockchain_height ? unlock_height - blockchain_height : 0;
7397+
time_to_unlock = unlock_time > now ? unlock_time - now : 0;
7398+
}
73827399
amount = 0;
73837400
}
73847401
auto found = amount_per_subaddr.find(td.m_subaddr_index.minor);

src/wallet/wallet_rpc_server.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ namespace
161161
return pwd_container;
162162
}
163163
//------------------------------------------------------------------------------------------------------------------------------
164-
void set_confirmations(tools::wallet_rpc::transfer_entry &entry, uint64_t blockchain_height, uint64_t block_reward, uint64_t unlock_time)
164+
void set_confirmations(tools::wallet_rpc::transfer_entry &entry, tools::wallet2 &wallet, uint64_t blockchain_height, uint64_t block_reward, uint64_t unlock_time)
165165
{
166166
if (entry.height >= blockchain_height || (entry.height == 0 && (!strcmp(entry.type.c_str(), "pending") || !strcmp(entry.type.c_str(), "pool"))))
167167
entry.confirmations = 0;
@@ -178,9 +178,14 @@ namespace
178178
if (unlock_time > blockchain_height)
179179
entry.suggested_confirmations_threshold = std::max(entry.suggested_confirmations_threshold, unlock_time - blockchain_height);
180180
}
181+
else if (wallet.use_fork_rules(HF_VERSION_FCMP_PLUS_PLUS, 0))
182+
{
183+
const uint64_t last_locked = cryptonote::get_last_locked_block_index(unlock_time, entry.height);
184+
if (last_locked + 1 > blockchain_height)
185+
entry.suggested_confirmations_threshold = std::max(entry.suggested_confirmations_threshold, last_locked + 1 - blockchain_height);
186+
}
181187
else
182188
{
183-
// FIXME: update for FCMP++
184189
const uint64_t now = time(NULL);
185190
if (unlock_time > now)
186191
entry.suggested_confirmations_threshold = std::max(entry.suggested_confirmations_threshold, (unlock_time - now + DIFFICULTY_TARGET_V2 - 1) / DIFFICULTY_TARGET_V2);
@@ -506,7 +511,7 @@ namespace tools
506511
entry.subaddr_index = pd.m_subaddr_index;
507512
entry.subaddr_indices.push_back(pd.m_subaddr_index);
508513
entry.address = m_wallet->get_subaddress_as_str(pd.m_subaddr_index);
509-
set_confirmations(entry, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward(), pd.m_unlock_time);
514+
set_confirmations(entry, *m_wallet, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward(), pd.m_unlock_time);
510515
}
511516
//------------------------------------------------------------------------------------------------------------------------------
512517
void wallet_rpc_server::fill_transfer_entry(tools::wallet_rpc::transfer_entry &entry, const crypto::hash &txid, const tools::wallet2::confirmed_transfer_details &pd) const
@@ -536,7 +541,7 @@ namespace tools
536541
for (uint32_t i: pd.m_subaddr_indices)
537542
entry.subaddr_indices.push_back({pd.m_subaddr_account, i});
538543
entry.address = m_wallet->get_subaddress_as_str({pd.m_subaddr_account, 0});
539-
set_confirmations(entry, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward(), pd.m_unlock_time);
544+
set_confirmations(entry, *m_wallet, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward(), pd.m_unlock_time);
540545
}
541546
//------------------------------------------------------------------------------------------------------------------------------
542547
void wallet_rpc_server::fill_transfer_entry(tools::wallet_rpc::transfer_entry &entry, const crypto::hash &txid, const tools::wallet2::unconfirmed_transfer_details &pd) const
@@ -566,7 +571,7 @@ namespace tools
566571
for (uint32_t i: pd.m_subaddr_indices)
567572
entry.subaddr_indices.push_back({pd.m_subaddr_account, i});
568573
entry.address = m_wallet->get_subaddress_as_str({pd.m_subaddr_account, 0});
569-
set_confirmations(entry, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward(), pd.m_tx.unlock_time);
574+
set_confirmations(entry, *m_wallet, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward(), pd.m_tx.unlock_time);
570575
}
571576
//------------------------------------------------------------------------------------------------------------------------------
572577
void wallet_rpc_server::fill_transfer_entry(tools::wallet_rpc::transfer_entry &entry, const crypto::hash &payment_id, const tools::wallet2::pool_payment_details &ppd) const
@@ -589,7 +594,7 @@ namespace tools
589594
entry.subaddr_index = pd.m_subaddr_index;
590595
entry.subaddr_indices.push_back(pd.m_subaddr_index);
591596
entry.address = m_wallet->get_subaddress_as_str(pd.m_subaddr_index);
592-
set_confirmations(entry, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward(), pd.m_unlock_time);
597+
set_confirmations(entry, *m_wallet, m_wallet->get_blockchain_current_height(), m_wallet->get_last_block_reward(), pd.m_unlock_time);
593598
}
594599
//------------------------------------------------------------------------------------------------------------------------------
595600
bool wallet_rpc_server::on_getbalance(const wallet_rpc::COMMAND_RPC_GET_BALANCE::request& req, wallet_rpc::COMMAND_RPC_GET_BALANCE::response& res, epee::json_rpc::error& er, const connection_context *ctx)

0 commit comments

Comments
 (0)