aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db/lmdb
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-04-04 00:15:57 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-04-05 09:35:19 +0000
commit089c7637a64652c8bcf6c437065237c23266d4a9 (patch)
tree1edb32e38080ab18184c0809ce0607c060682d05 /src/blockchain_db/lmdb
parentMerge pull request #5390 (diff)
downloadmonero-089c7637a64652c8bcf6c437065237c23266d4a9.tar.xz
cryptonote: rework block blob size sanity check
Use the actual block weight limit, assuming that weight is always greater or equal to size
Diffstat (limited to 'src/blockchain_db/lmdb')
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp52
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.h3
2 files changed, 55 insertions, 0 deletions
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 9f71fd068..a07e9ac55 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -2513,6 +2513,58 @@ std::vector<uint64_t> BlockchainLMDB::get_block_info_64bit_fields(uint64_t start
return ret;
}
+uint64_t BlockchainLMDB::get_max_block_size()
+{
+ LOG_PRINT_L3("BlockchainLMDB::" << __func__);
+ check_open();
+
+ TXN_PREFIX_RDONLY();
+ RCURSOR(properties)
+ MDB_val_str(k, "max_block_size");
+ MDB_val v;
+ int result = mdb_cursor_get(m_cur_properties, &k, &v, MDB_SET);
+ if (result == MDB_NOTFOUND)
+ return std::numeric_limits<uint64_t>::max();
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to retrieve max block size: ", result).c_str()));
+ if (v.mv_size != sizeof(uint64_t))
+ throw0(DB_ERROR("Failed to retrieve or create max block size: unexpected value size"));
+ uint64_t max_block_size;
+ memcpy(&max_block_size, v.mv_data, sizeof(max_block_size));
+ TXN_POSTFIX_RDONLY();
+ return max_block_size;
+}
+
+void BlockchainLMDB::add_max_block_size(uint64_t sz)
+{
+ LOG_PRINT_L3("BlockchainLMDB::" << __func__);
+ check_open();
+ mdb_txn_cursors *m_cursors = &m_wcursors;
+
+ CURSOR(properties)
+
+ MDB_val_str(k, "max_block_size");
+ MDB_val v;
+ int result = mdb_cursor_get(m_cur_properties, &k, &v, MDB_SET);
+ if (result && result != MDB_NOTFOUND)
+ throw0(DB_ERROR(lmdb_error("Failed to retrieve max block size: ", result).c_str()));
+ uint64_t max_block_size = 0;
+ if (result == 0)
+ {
+ if (v.mv_size != sizeof(uint64_t))
+ throw0(DB_ERROR("Failed to retrieve or create max block size: unexpected value size"));
+ memcpy(&max_block_size, v.mv_data, sizeof(max_block_size));
+ }
+ if (sz > max_block_size)
+ max_block_size = sz;
+ v.mv_data = (void*)&max_block_size;
+ v.mv_size = sizeof(max_block_size);
+ result = mdb_cursor_put(m_cur_properties, &k, &v, 0);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to set max_block_size: ", result).c_str()));
+}
+
+
std::vector<uint64_t> BlockchainLMDB::get_block_weights(uint64_t start_height, size_t count) const
{
return get_block_info_64bit_fields(start_height, count, offsetof(mdb_block_info, bi_weight));
diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h
index 2f89b77ac..f6b00817d 100644
--- a/src/blockchain_db/lmdb/db_lmdb.h
+++ b/src/blockchain_db/lmdb/db_lmdb.h
@@ -400,6 +400,9 @@ private:
std::vector<uint64_t> get_block_info_64bit_fields(uint64_t start_height, size_t count, off_t offset) const;
+ uint64_t get_max_block_size();
+ void add_max_block_size(uint64_t sz);
+
// fix up anything that may be wrong due to past bugs
virtual void fixup();