diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index bc14bae90b..fa5759280b 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -3308,10 +3308,6 @@ hf Blockchain::get_network_version(std::optional height) const { return cryptonote::get_network_version(m_nettype, *height); } -cryptonote::BlockchainSQLite& Blockchain::sqlite_db() { - return *m_sqlite_db; -} - //------------------------------------------------------------------ void Blockchain::flush_invalid_blocks() { log::trace(logcat, "Blockchain::{}", __func__); diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h index e9ca92b1b8..757654687f 100644 --- a/src/cryptonote_core/blockchain.h +++ b/src/cryptonote_core/blockchain.h @@ -1146,7 +1146,10 @@ class Blockchain { const ons::name_system_db& name_system_db() const { return m_ons_db; } - cryptonote::BlockchainSQLite& sqlite_db(); + cryptonote::BlockchainSQLite& sqlite_db() { return *m_sqlite_db; } + + /// SQLite DB can be nullptr in some unit tests + cryptonote::BlockchainSQLite* maybe_sqlite_db() { return m_sqlite_db.get(); } /// NOTE: unchecked access; should only be called in service node more where this is guaranteed /// to be set. diff --git a/src/cryptonote_core/service_node_list.cpp b/src/cryptonote_core/service_node_list.cpp index 38b93c707f..2f88bd2108 100644 --- a/src/cryptonote_core/service_node_list.cpp +++ b/src/cryptonote_core/service_node_list.cpp @@ -2727,7 +2727,8 @@ void service_node_list::block_add( } // NOTE: Add block to SQL in lock-step with SNL - blockchain.sqlite_db().add_block(block, m_state); + if (auto* sql_db = blockchain.maybe_sqlite_db()) + sql_db->add_block(block, m_state); } static std::mt19937_64 quorum_rng(hf hf_version, crypto::hash const& hash, quorum_type type) {