diff --git a/src/ripple/app/ledger/impl/LedgerMaster.cpp b/src/ripple/app/ledger/impl/LedgerMaster.cpp index 2963243d9..ecd00e4ba 100644 --- a/src/ripple/app/ledger/impl/LedgerMaster.cpp +++ b/src/ripple/app/ledger/impl/LedgerMaster.cpp @@ -273,7 +273,7 @@ LedgerMaster::getValidatedLedgerAge() #ifdef RIPPLED_REPORTING if (app_.config().reporting()) - return dynamic_cast( + return static_cast( &app_.getRelationalDBInterface()) ->getValidatedLedgerAge(); #endif @@ -299,20 +299,9 @@ LedgerMaster::isCaughtUp(std::string& reason) #ifdef RIPPLED_REPORTING if (app_.config().reporting()) - { - auto age = PgQuery(app_.getPgPool())("SELECT age()"); - if (!age || age.isNull()) - { - reason = "No ledgers in database"; - return false; - } - if (std::chrono::seconds{age.asInt()} > 3min) - { - reason = "No recently-published ledger"; - return false; - } - return true; - } + return static_cast( + &app_.getRelationalDBInterface()) + ->isCaughtUp(reason); #endif if (getPublishedLedgerAge() > 3min) @@ -1665,7 +1654,7 @@ LedgerMaster::getCompleteLedgers() { #ifdef RIPPLED_REPORTING if (app_.config().reporting()) - return dynamic_cast( + return static_cast( &app_.getRelationalDBInterface()) ->getCompleteLedgers(); #endif diff --git a/src/ripple/app/rdb/backend/RelationalDBInterfacePostgres.cpp b/src/ripple/app/rdb/backend/RelationalDBInterfacePostgres.cpp index 91e85d043..8b9a96210 100644 --- a/src/ripple/app/rdb/backend/RelationalDBInterfacePostgres.cpp +++ b/src/ripple/app/rdb/backend/RelationalDBInterfacePostgres.cpp @@ -128,6 +128,9 @@ public: bool transactionDbHasSpace(Config const& config) override; + bool + isCaughtUp(std::string& reason) override; + private: Application& app_; beast::Journal j_; @@ -272,5 +275,24 @@ getRelationalDBInterfacePostgres( return std::make_unique( app, config, jobQueue); } +bool +RelationalDBInterfacePostgresImp::isCaughtUp(std::string& reason) +{ +#ifdef RIPPLED_REPORTING + using namespace std::chrono_literals; + auto age = PgQuery(pgPool_)("SELECT age()"); + if (!age || age.isNull()) + { + reason = "No ledgers in database"; + return false; + } + if (std::chrono::seconds{age.asInt()} > 3min) + { + reason = "No recently-published ledger"; + return false; + } +#endif + return true; +} } // namespace ripple diff --git a/src/ripple/app/rdb/backend/RelationalDBInterfacePostgres.h b/src/ripple/app/rdb/backend/RelationalDBInterfacePostgres.h index 77193d245..7149f475f 100644 --- a/src/ripple/app/rdb/backend/RelationalDBInterfacePostgres.h +++ b/src/ripple/app/rdb/backend/RelationalDBInterfacePostgres.h @@ -104,6 +104,18 @@ public: */ virtual Transaction::Locator locateTransaction(uint256 const& id) = 0; + + /** + * @brief isCaughtUp returns whether the database is caught up with the + * network + * @param[out] reason if the database is not caught up, reason contains a + * helpful message describing why + * @return false if the most recently written + * ledger has a close time over 3 minutes ago, or if there are + * no ledgers in the database. true otherwise + */ + virtual bool + isCaughtUp(std::string& reason) = 0; }; } // namespace ripple