From b0b44d32bd1460b23a9291a747a731f6883aa8e2 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Tue, 5 Jul 2022 16:56:54 -0400 Subject: [PATCH] Fix amendment voting persistence: An incorrect SQL query could cause the server to improperly configure its voting state after a restart; typically, this would manifest as an apparent failure to store a vote which the administrator of the server had configured. This commit fixes the broken SQL and ensures that amendment votes are properly reloaded post-restart and closes #4220. --- src/ripple/app/rdb/impl/Wallet.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ripple/app/rdb/impl/Wallet.cpp b/src/ripple/app/rdb/impl/Wallet.cpp index c6040964bd..24715404ce 100644 --- a/src/ripple/app/rdb/impl/Wallet.cpp +++ b/src/ripple/app/rdb/impl/Wallet.cpp @@ -254,7 +254,10 @@ readAmendments( soci::transaction tr(session); std::string sql = - "SELECT AmendmentHash, AmendmentName, Veto FROM FeatureVotes"; + "SELECT AmendmentHash, AmendmentName, Veto FROM " + "( SELECT AmendmentHash, AmendmentName, Veto, RANK() OVER " + "( PARTITION BY AmendmentHash ORDER BY ROWID DESC ) " + "as rnk FROM FeatureVotes ) WHERE rnk = 1"; // SOCI requires boost::optional (not std::optional) as parameters. boost::optional amendment_hash; boost::optional amendment_name;