Fix locked_funds computation (#200)

This commit is contained in:
Lee *!* Clagett
2025-11-14 12:44:18 -05:00
committed by Lee *!* Clagett
parent 26a882965f
commit 0caec18f84
2 changed files with 9 additions and 4 deletions

View File

@@ -75,6 +75,9 @@ namespace db
};
WIRE_AS_INTEGER(block_id);
inline constexpr std::uint64_t to_uint(const block_id src) noexcept
{ return std::uint64_t(src); }
//! References a global output number, as determined by the public chain
struct output_id
{

View File

@@ -196,11 +196,13 @@ namespace lws
};
using async_complete = void(expect<copyable_slice>);
bool is_locked(std::uint64_t unlock_time, db::block_id last) noexcept
bool is_locked(std::uint64_t unlock_time, db::block_id last, db::block_id tx_height) noexcept
{
if (unlock_time > CRYPTONOTE_MAX_BLOCK_NUMBER)
return std::chrono::seconds{unlock_time} > std::chrono::system_clock::now().time_since_epoch();
return db::block_id(unlock_time) > last;
return std::chrono::seconds{unlock_time} > std::chrono::system_clock::now().time_since_epoch() + std::chrono::seconds{CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V2};
if (unlock_time > to_uint(last) - 1 + CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_BLOCKS)
return true;
return to_uint(tx_height) + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE > to_uint(last);
}
std::vector<db::output::spend_meta_>::const_iterator
@@ -534,7 +536,7 @@ namespace lws
metas.insert(find_metadata(metas, meta.id), meta);
resp.total_received = rpc::safe_uint64(std::uint64_t(resp.total_received) + meta.amount);
if (is_locked(output.get_value<MONERO_FIELD(db::output, unlock_time)>(), last->id))
if (is_locked(output.get_value<MONERO_FIELD(db::output, unlock_time)>(), last->id, output.get_value<MONERO_FIELD(db::output, link)>().height))
resp.locked_funds = rpc::safe_uint64(std::uint64_t(resp.locked_funds) + meta.amount);
}