Fix rescan to invalid blockchain height bug (#48)

This commit is contained in:
Lee *!* Clagett 2023-02-10 07:18:50 -05:00 committed by Lee *!* Clagett
parent aff7603519
commit 64f5d4a9ab
3 changed files with 21 additions and 0 deletions

View file

@ -1352,6 +1352,24 @@ namespace db
MONERO_PRECOND(db != nullptr);
return db->try_write([this, height, addresses] (MDB_txn& txn) -> expect<std::vector<account_address>>
{
{
cursor::blocks blocks_cur;
MONERO_CHECK(check_cursor(txn, this->db->tables.blocks, blocks_cur));
MDB_val key = lmdb::to_val(blocks_version);
MDB_val value{};
MONERO_LMDB_CHECK(mdb_cursor_get(blocks_cur.get(), &key, &value, MDB_SET));
MONERO_LMDB_CHECK(mdb_cursor_get(blocks_cur.get(), &key, &value, MDB_LAST_DUP));
const expect<block_id> current_height =
blocks.get_value<MONERO_FIELD(block_info, id)>(value);
if (!current_height)
return current_height.error();
if (*current_height < height)
return {error::bad_height};
}
std::vector<account_address> updated{};
updated.reserve(addresses.size());

View file

@ -57,6 +57,8 @@ namespace lws
return "Received invalid transaction from REST client";
case error::bad_daemon_response:
return "Response from monerod daemon was bad/unexpected";
case error::bad_height:
return "Invalid blockchain height";
case error::blockchain_reorg:
return "A blockchain reorg has been detected";
case error::configuration:

View file

@ -42,6 +42,7 @@ namespace lws
bad_blockchain, //!< Blockchain is invalid or wrong network type
bad_client_tx, //!< REST client submitted invalid transaction
bad_daemon_response, //!< RPC Response from daemon was invalid
bad_height, //!< Invalid blockchain height
blockchain_reorg, //!< Blockchain reorg after fetching/scanning block(s)
configuration, //!< Process configuration invalid
crypto_failure, //!< Cryptographic function failed