mirror of
https://github.com/XRPLF/rippled.git
synced 2026-04-29 15:37:57 +00:00
Compare commits
6 Commits
bthomee/ap
...
pratik/Add
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2ee835952 | ||
|
|
f1723d8647 | ||
|
|
320f9c8866 | ||
|
|
229df04edd | ||
|
|
640428a1d4 | ||
|
|
0363c12b23 |
@@ -136,6 +136,7 @@ words:
|
|||||||
- legleux
|
- legleux
|
||||||
- levelization
|
- levelization
|
||||||
- levelized
|
- levelized
|
||||||
|
- lgrdb
|
||||||
- libpb
|
- libpb
|
||||||
- libxrpl
|
- libxrpl
|
||||||
- llection
|
- llection
|
||||||
|
|||||||
@@ -92,7 +92,11 @@ public:
|
|||||||
private:
|
private:
|
||||||
beast::Journal mutable journal_;
|
beast::Journal mutable journal_;
|
||||||
std::mutex mutable mutex_;
|
std::mutex mutable mutex_;
|
||||||
DatabaseCon* connection_;
|
// Initialized to nullptr for safety. Set by load() during the second
|
||||||
|
// phase of ApplicationImp initialization. Methods that dereference
|
||||||
|
// this pointer must validate it first, since two-phase init means
|
||||||
|
// load() may not have been called yet.
|
||||||
|
DatabaseCon* connection_ = nullptr;
|
||||||
std::unordered_set<PeerReservation, beast::uhash<>, KeyEqual> table_;
|
std::unordered_set<PeerReservation, beast::uhash<>, KeyEqual> table_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -386,15 +386,6 @@ public:
|
|||||||
SQLiteDatabase&
|
SQLiteDatabase&
|
||||||
operator=(SQLiteDatabase&&) = delete;
|
operator=(SQLiteDatabase&&) = delete;
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief ledgerDbHasSpace Checks if the ledger database has available
|
|
||||||
* space.
|
|
||||||
* @param config Config object.
|
|
||||||
* @return True if space is available.
|
|
||||||
*/
|
|
||||||
bool
|
|
||||||
ledgerDbHasSpace(Config const& config);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief transactionDbHasSpace Checks if the transaction database has
|
* @brief transactionDbHasSpace Checks if the transaction database has
|
||||||
* available space.
|
* available space.
|
||||||
@@ -446,13 +437,27 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief checkoutTransaction Checks out and returns node store ledger
|
* @brief checkoutLedger Checks out and returns node store ledger
|
||||||
* database.
|
* database.
|
||||||
* @return Session to the node store ledger database.
|
* @return Session to the node store ledger database.
|
||||||
|
* @throws std::runtime_error if ledger database is not available.
|
||||||
|
*
|
||||||
|
* @note Callers typically guard with existsLedger() before calling
|
||||||
|
* this method. The explicit null check here provides
|
||||||
|
* defense-in-depth so that safety does not depend solely on
|
||||||
|
* an implicit caller contract. See PR #6029 for context on
|
||||||
|
* the pattern of relying on config settings instead of
|
||||||
|
* validating actual objects.
|
||||||
*/
|
*/
|
||||||
auto
|
auto
|
||||||
checkoutLedger()
|
checkoutLedger()
|
||||||
{
|
{
|
||||||
|
if (!ledgerDb_)
|
||||||
|
{
|
||||||
|
constexpr auto msg = "Ledger database is not available";
|
||||||
|
JLOG(j_.fatal()) << msg;
|
||||||
|
Throw<std::runtime_error>(msg);
|
||||||
|
}
|
||||||
return ledgerDb_->checkoutDb();
|
return ledgerDb_->checkoutDb();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,10 +465,23 @@ private:
|
|||||||
* @brief checkoutTransaction Checks out and returns the node store
|
* @brief checkoutTransaction Checks out and returns the node store
|
||||||
* transaction database.
|
* transaction database.
|
||||||
* @return Session to the node store transaction database.
|
* @return Session to the node store transaction database.
|
||||||
|
* @throws std::runtime_error if transaction database is not available.
|
||||||
|
*
|
||||||
|
* @note Callers typically guard with existsTransaction() and/or
|
||||||
|
* useTxTables_ before calling this method. The explicit null
|
||||||
|
* check here provides defense-in-depth so that safety does
|
||||||
|
* not depend solely on an implicit caller contract or config
|
||||||
|
* settings. See PR #6029 for context.
|
||||||
*/
|
*/
|
||||||
auto
|
auto
|
||||||
checkoutTransaction()
|
checkoutTransaction()
|
||||||
{
|
{
|
||||||
|
if (!txdb_)
|
||||||
|
{
|
||||||
|
constexpr auto msg = "Transaction database is not available";
|
||||||
|
JLOG(j_.fatal()) << msg;
|
||||||
|
Throw<std::runtime_error>(msg);
|
||||||
|
}
|
||||||
return txdb_->checkoutDb();
|
return txdb_->checkoutDb();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -524,18 +524,6 @@ SQLiteDatabase::SQLiteDatabase(SQLiteDatabase&& rhs) noexcept
|
|||||||
std::exchange(txdb_, std::move(rhs.txdb_));
|
std::exchange(txdb_, std::move(rhs.txdb_));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
|
||||||
SQLiteDatabase::ledgerDbHasSpace(Config const& config)
|
|
||||||
{
|
|
||||||
if (existsLedger())
|
|
||||||
{
|
|
||||||
auto db = checkoutLedger();
|
|
||||||
return detail::dbHasSpace(*db, config, j_);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SQLiteDatabase::transactionDbHasSpace(Config const& config)
|
SQLiteDatabase::transactionDbHasSpace(Config const& config)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <xrpl/basics/contract.h>
|
||||||
#include <xrpl/core/PeerReservationTable.h>
|
#include <xrpl/core/PeerReservationTable.h>
|
||||||
#include <xrpl/json/json_value.h>
|
#include <xrpl/json/json_value.h>
|
||||||
#include <xrpl/protocol/PublicKey.h>
|
#include <xrpl/protocol/PublicKey.h>
|
||||||
@@ -85,6 +86,15 @@ PeerReservationTable::insert_or_assign(PeerReservation const& reservation)
|
|||||||
}
|
}
|
||||||
table_.insert(hint, reservation);
|
table_.insert(hint, reservation);
|
||||||
|
|
||||||
|
// connection_ is set by load() during two-phase init. Validate
|
||||||
|
// before dereferencing to guard against use-before-load or a reset
|
||||||
|
// connection. See PR #6029 for the general pattern discussion.
|
||||||
|
if (!connection_)
|
||||||
|
{
|
||||||
|
Throw<std::runtime_error>(
|
||||||
|
"PeerReservationTable::insert_or_assign: database connection is "
|
||||||
|
"not available");
|
||||||
|
}
|
||||||
auto db = connection_->checkoutDb();
|
auto db = connection_->checkoutDb();
|
||||||
insertPeerReservation(*db, reservation.nodeId, reservation.description);
|
insertPeerReservation(*db, reservation.nodeId, reservation.description);
|
||||||
|
|
||||||
@@ -103,6 +113,14 @@ PeerReservationTable::erase(PublicKey const& nodeId)
|
|||||||
{
|
{
|
||||||
previous = *it;
|
previous = *it;
|
||||||
table_.erase(it);
|
table_.erase(it);
|
||||||
|
// Validate connection_ before dereferencing — see comment in
|
||||||
|
// insert_or_assign above.
|
||||||
|
if (!connection_)
|
||||||
|
{
|
||||||
|
Throw<std::runtime_error>(
|
||||||
|
"PeerReservationTable::erase: database connection is not "
|
||||||
|
"available");
|
||||||
|
}
|
||||||
auto db = connection_->checkoutDb();
|
auto db = connection_->checkoutDb();
|
||||||
deletePeerReservation(*db, nodeId);
|
deletePeerReservation(*db, nodeId);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user