diff --git a/CMakeLists.txt b/CMakeLists.txt
index 75a3a2fdb..a44ecc6ec 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15)
set(_CLIENT_VERSION_MAJOR 0)
set(_CLIENT_VERSION_MINOR 20)
-set(_CLIENT_VERSION_REVISION 22)
+set(_CLIENT_VERSION_REVISION 23)
set(_CLIENT_VERSION_BUILD 0)
set(_CLIENT_VERSION_IS_RELEASE false)
set(_COPYRIGHT_YEAR 2022)
diff --git a/build_msvc/libpocketcoin_server/libpocketcoin_server.vcxproj b/build_msvc/libpocketcoin_server/libpocketcoin_server.vcxproj
index f2a27db1a..5453ed9df 100644
--- a/build_msvc/libpocketcoin_server/libpocketcoin_server.vcxproj
+++ b/build_msvc/libpocketcoin_server/libpocketcoin_server.vcxproj
@@ -244,7 +244,7 @@
-
+
diff --git a/build_msvc/pocketcoin_config.h b/build_msvc/pocketcoin_config.h
index 597ed381a..1b0823177 100644
--- a/build_msvc/pocketcoin_config.h
+++ b/build_msvc/pocketcoin_config.h
@@ -14,7 +14,7 @@
#define CLIENT_VERSION_MINOR 20
/* Build revision */
-#define CLIENT_VERSION_REVISION 22
+#define CLIENT_VERSION_REVISION 23
/* Version Build */
#define CLIENT_VERSION_BUILD 0
@@ -346,7 +346,7 @@
#define PACKAGE_NAME "Pocketnet Core"
/* Define to the full name and version of this package. */
-#define PACKAGE_STRING "Pocketnet Core 0.20.22"
+#define PACKAGE_STRING "Pocketnet Core 0.20.23"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "pocketcoin"
@@ -355,7 +355,7 @@
#define PACKAGE_URL "https://github.com/pocketnetteam"
/* Define to the version of this package. */
-#define PACKAGE_VERSION "0.20.22"
+#define PACKAGE_VERSION "0.20.23"
/* Define to necessary symbol if this constant uses a non-standard name on
your system. */
diff --git a/configure.ac b/configure.ac
index b886a326d..0998a2516 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 0)
define(_CLIENT_VERSION_MINOR, 20)
-define(_CLIENT_VERSION_REVISION, 22)
+define(_CLIENT_VERSION_REVISION, 23)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2022)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 37194e52b..13af94c58 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -362,7 +362,7 @@ add_library(${POCKETDB}
pocketdb/models/base/TransactionOutput.h
pocketdb/models/base/SocialTransaction.h
pocketdb/models/base/Rating.h
- pocketdb/models/base/ReturnDtoModels.h
+ pocketdb/models/base/DtoModels.h
pocketdb/models/dto/Default.h
pocketdb/models/dto/Coinbase.h
pocketdb/models/dto/Coinstake.h
@@ -785,6 +785,8 @@ add_library(${POCKETCOIN_SERVER}
pocketdb/repositories/CheckpointRepository.cpp
pocketdb/repositories/SystemRepository.h
pocketdb/repositories/SystemRepository.cpp
+ pocketdb/repositories/MigrationRepository.h
+ pocketdb/repositories/MigrationRepository.cpp
pocketdb/repositories/web/NotifierRepository.h
pocketdb/repositories/web/NotifierRepository.cpp
pocketdb/repositories/web/WebRepository.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 027d3ad6d..c81918992 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -127,6 +127,7 @@ POCKETDB_H = \
pocketdb/repositories/RatingsRepository.h \
pocketdb/repositories/CheckpointRepository.h \
pocketdb/repositories/SystemRepository.h \
+ pocketdb/repositories/MigrationRepository.h \
pocketdb/repositories/web/WebRepository.h \
pocketdb/repositories/web/WebRpcRepository.h \
pocketdb/repositories/web/NotifierRepository.h \
@@ -175,7 +176,7 @@ POCKETDB_H = \
pocketdb/models/base/SocialTransaction.h \
pocketdb/models/base/Rating.h \
pocketdb/models/base/Payload.h \
- pocketdb/models/base/ReturnDtoModels.h \
+ pocketdb/models/base/DtoModels.h \
\
pocketdb/models/dto/Default.h \
pocketdb/models/dto/Coinbase.h \
@@ -228,6 +229,7 @@ POCKETDB_CPP = \
pocketdb/repositories/RatingsRepository.cpp \
pocketdb/repositories/CheckpointRepository.cpp \
pocketdb/repositories/SystemRepository.cpp \
+ pocketdb/repositories/MigrationRepository.cpp \
pocketdb/repositories/web/WebRepository.cpp \
pocketdb/repositories/web/WebRpcRepository.cpp \
pocketdb/repositories/web/NotifierRepository.cpp \
diff --git a/src/init.cpp b/src/init.cpp
index 1b7ce929c..fde8d8ceb 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -173,6 +173,7 @@ void ShutdownPocketServices()
PocketDb::RatingsRepoInst.Destroy();
PocketDb::ConsensusRepoInst.Destroy();
PocketDb::NotifierRepoInst.Destroy();
+ PocketDb::MigrationRepoInst.Destroy();
PocketDb::SQLiteDbInst.DetachDatabase("web");
PocketDb::SQLiteDbInst.Close();
@@ -849,7 +850,10 @@ static void ThreadImport(std::vector vImportFiles)
int i = (int)gArgs.GetArg("-reindex-start", 0);
LogPrintf("Start indexing pocketnet part at height %d\n", i);
- PocketServices::ChainPostProcessing::Rollback(i);
+ if (i == 0)
+ PocketDb::ChainRepoInst.ClearDatabase();
+ else
+ PocketServices::ChainPostProcessing::Rollback(i);
while (i <= chainActive.Height() && !ShutdownRequested())
{
@@ -1714,6 +1718,12 @@ bool AppInitMain()
if (!gArgs.GetBoolArg("-withoutweb", false))
PocketServices::WebPostProcessorInst.Start(threadGroup);
+ if (ShutdownRequested())
+ {
+ LogPrintf("Shutdown requested. Exiting.\n");
+ return false;
+ }
+
// ********************************************************* Step 4b: Additional settings
if (gArgs.GetArg("-reindex", 0) == 4)
diff --git a/src/pocketdb/SQLiteConnection.cpp b/src/pocketdb/SQLiteConnection.cpp
index b451adda6..d7a0fcbee 100644
--- a/src/pocketdb/SQLiteConnection.cpp
+++ b/src/pocketdb/SQLiteConnection.cpp
@@ -18,6 +18,7 @@ namespace PocketDb
ExplorerRepoInst = make_shared(*SQLiteDbInst);
SearchRepoInst = make_shared(*SQLiteDbInst);
TransactionRepoInst = make_shared(*SQLiteDbInst);
+ ConsensusRepoInst = make_shared(*SQLiteDbInst);
}
SQLiteConnection::~SQLiteConnection()
@@ -28,6 +29,7 @@ namespace PocketDb
ExplorerRepoInst->Destroy();
SearchRepoInst->Destroy();
TransactionRepoInst->Destroy();
+ ConsensusRepoInst->Destroy();
SQLiteDbInst->DetachDatabase("web");
SQLiteDbInst->Close();
diff --git a/src/pocketdb/SQLiteConnection.h b/src/pocketdb/SQLiteConnection.h
index 70739c1e6..3b717a6f4 100644
--- a/src/pocketdb/SQLiteConnection.h
+++ b/src/pocketdb/SQLiteConnection.h
@@ -10,6 +10,7 @@
#include "pocketdb/repositories/web/WebRpcRepository.h"
#include "pocketdb/repositories/web/ExplorerRepository.h"
#include "pocketdb/repositories/web/SearchRepository.h"
+#include "pocketdb/repositories/ConsensusRepository.h"
#include "pocketdb/repositories/TransactionRepository.h"
#include "pocketdb/web/PocketFrontend.h"
@@ -34,6 +35,7 @@ namespace PocketDb
ExplorerRepositoryRef ExplorerRepoInst;
SearchRepositoryRef SearchRepoInst;
TransactionRepositoryRef TransactionRepoInst;
+ ConsensusRepositoryRef ConsensusRepoInst;
};
diff --git a/src/pocketdb/SQLiteDatabase.cpp b/src/pocketdb/SQLiteDatabase.cpp
index 1afa9c56c..9d48b051d 100644
--- a/src/pocketdb/SQLiteDatabase.cpp
+++ b/src/pocketdb/SQLiteDatabase.cpp
@@ -59,6 +59,25 @@ namespace PocketDb
ConsensusRepoInst.Init();
NotifierRepoInst.Init();
SystemRepoInst.Init();
+ MigrationRepoInst.Init();
+
+ // Execute migration scripts
+ if (gArgs.GetArg("-reindex", 0) == 0)
+ {
+ if (!MigrationRepoInst.SplitLikers())
+ {
+ LogPrintf("SQLDB Migration: SplitLikers completed.\n");
+ StartShutdown();
+ return;
+ }
+
+ if (!MigrationRepoInst.AccumulateLikers())
+ {
+ LogPrintf("SQLDB Migration: AccumulateLikers completed.\n");
+ StartShutdown();
+ return;
+ }
+ }
// Open, create structure and close `web` db
PocketDbMigrationRef webDbMigration = std::make_shared();
diff --git a/src/pocketdb/consensus/Base.h b/src/pocketdb/consensus/Base.h
index 271b3862c..aa4e522d5 100644
--- a/src/pocketdb/consensus/Base.h
+++ b/src/pocketdb/consensus/Base.h
@@ -166,6 +166,8 @@ namespace PocketConsensus
enum ConsensusLimit
{
+ ConsensusLimit_depth,
+
ConsensusLimit_threshold_reputation,
ConsensusLimit_threshold_reputation_score,
ConsensusLimit_threshold_balance,
@@ -173,7 +175,20 @@ namespace PocketConsensus
ConsensusLimit_threshold_likers_count,
ConsensusLimit_threshold_low_likers_count,
ConsensusLimit_threshold_low_likers_depth,
- ConsensusLimit_depth,
+
+ // Thresholds for obtaining badges - SHARK
+ threshold_shark_reg_depth,
+ threshold_shark_likers_all,
+ threshold_shark_likers_content,
+ threshold_shark_likers_comment,
+ threshold_shark_likers_comment_answer,
+
+ // Thresholds for obtaining badges - WHALE
+ threshold_whale_reg_depth,
+ threshold_whale_likers_all,
+ threshold_whale_likers_content,
+ threshold_whale_likers_comment,
+ threshold_whale_likers_comment_answer,
ConsensusLimit_trial_post,
ConsensusLimit_trial_video,
@@ -235,104 +250,26 @@ namespace PocketConsensus
typedef map>> ConsensusLimits;
static inline ConsensusLimits m_consensus_limits = {
- // ConsensusLimit_bad_reputation
- {
- ConsensusLimit_bad_reputation,
- {
- {
- NetworkMain,
- {
- {0, -500}
- }
- },
- {
- NetworkTest,
- {
- {0, -50}
- }
- }
- }
- },
- // ConsensusLimit_threshold_reputation
- {
- ConsensusLimit_threshold_reputation,
- {
- {
- NetworkMain,
- {
- {0, 500},
- {292800, 1000}
- }
- },
- {
- NetworkTest,
- {
- {0, 100},
- {761000, 10}
- }
- }
- }
- },
- // ConsensusLimit_threshold_reputation_score
- {
- ConsensusLimit_threshold_reputation_score,
- {
- {
- NetworkMain,
- {
- {0, -10000},
- {108300, 500},
- {292800, 1000}
- }
- },
- {
- NetworkTest,
- {
- {0, 0},
- {100000, 100}
- }
- }
- }
- },
- // ConsensusLimit_threshold_balance
- {
- ConsensusLimit_threshold_balance,
- {
- {
- NetworkMain,
- {
- {0, 50 * COIN}
- }
- },
- {
- NetworkTest,
- {
- {0, 5 * COIN}
- }
- }
- }
- },
- // ConsensusLimit_threshold_balance_pro
- {
- ConsensusLimit_threshold_balance_pro,
- {
- {
- NetworkMain,
- {
- {0, INT64_MAX},
- {65000, 250 * COIN}
- }
- },
- {
- NetworkTest,
- {
- {0, INT64_MAX},
- {65000, 25 * COIN}
- }
- }
- }
- },
- // ConsensusLimit_threshold_likers_count
+ { ConsensusLimit_bad_reputation, {
+ { NetworkMain, { {0, -500} } },
+ { NetworkTest, { {0, -50} } }
+ } },
+ { ConsensusLimit_threshold_reputation, {
+ { NetworkMain, { {0, 500}, {292800, 1000} } },
+ { NetworkTest, { {0, 100}, {761000, 10} } }
+ } },
+ { ConsensusLimit_threshold_reputation_score, {
+ { NetworkMain, { {0, -10000}, {108300, 500}, {292800, 1000} } },
+ { NetworkTest, { {0, 0}, {100000, 100} } }
+ } },
+ { ConsensusLimit_threshold_balance, {
+ { NetworkMain, { {0, 50 * COIN} } },
+ { NetworkTest, { {0, 5 * COIN} } }
+ } },
+ { ConsensusLimit_threshold_balance_pro, {
+ { NetworkMain, { {0, INT64_MAX}, {65000, 250 * COIN} } },
+ { NetworkTest, { {0, INT64_MAX}, {65000, 25 * COIN} } }
+ } },
{ ConsensusLimit_threshold_likers_count, {
{ NetworkMain, { {0, 0}, {1124000, 100} }},
{ NetworkTest, { {0, 0}, {100000, 10} }},
@@ -342,737 +279,224 @@ namespace PocketConsensus
{ NetworkMain, { {0, 30} }},
{ NetworkTest, { {0, 30}, {761000, 0} }}
}},
- // ConsensusLimit_threshold_low_likers_depth
- {
- ConsensusLimit_threshold_low_likers_depth,
- {
- {
- NetworkMain,
- {
- {1180000, 250'000},
- }
- },
- {
- NetworkTest,
- {
- {0, 250'000},
- }
- }
- }
- },
- // ConsensusLimit_depth
- {
- ConsensusLimit_depth,
- {
- {
- NetworkMain,
- {
- {0, 86400},
- {1180000, 1440}
- }
- },
- {
- NetworkTest,
- {
- {0, 1440}
- }
- }
- }
- },
-
- // ConsensusLimit_trial_post
- {
- ConsensusLimit_trial_post,
- {
- {
- NetworkMain,
- {
- {0, 15},
- {1324655, 5}
- }
- },
- {
- NetworkTest,
- {
- {0, 15}
- }
- }
- }
- },
- // ConsensusLimit_trial_video
- {
- ConsensusLimit_trial_video,
- {
- {
- NetworkMain,
- {
- {0, 15},
- {1324655, 5}
- }
- },
- {
- NetworkTest,
- {
- {0, 15}
- }
- }
- }
- },
- // ConsensusLimit_trial_article
- {
- ConsensusLimit_trial_article,
- {
- {
- NetworkMain,
- {
- {0, 1}
- }
- },
- {
- NetworkTest,
- {
- {0, 10}
- }
- }
- }
- },
- // ConsensusLimit_trial_score
- {
- ConsensusLimit_trial_score,
- {
- {
- NetworkMain,
- {
- {0, 45},
- {175600, 100},
- {1324655, 15}
- }
- },
- {
- NetworkTest,
- {
- {0, 100}
- }
- }
- }
- },
- // ConsensusLimit_trial_complain
- {
- ConsensusLimit_trial_complain,
- {
- {
- NetworkMain,
- {
- {0, 6}
- }
- },
- {
- NetworkTest,
- {
- {0, 6}
- }
- }
- }
- },
- // ConsensusLimit_full_post
- {
- ConsensusLimit_full_post,
- {
- {
- NetworkMain,
- {
- {0, 30}
- }
- },
- {
- NetworkTest,
- {
- {0, 30}
- }
- }
- }
- },
- // ConsensusLimit_full_video
- {
- ConsensusLimit_full_video,
- {
- {
- NetworkMain,
- {
- {0, 30}
- }
- },
- {
- NetworkTest,
- {
- {0, 30}
- }
- }
- }
- },
- // ConsensusLimit_full_article
- {
- ConsensusLimit_full_article,
- {
- {
- NetworkMain,
- {
- {0, 3}
- }
- },
- {
- NetworkTest,
- {
- {0, 30}
- }
- }
- }
- },
- // ConsensusLimit_full_score
- {
- ConsensusLimit_full_score,
- {
- {
- NetworkMain,
- {
- {0, 90},
- {175600, 200}
- }
- },
- {
- NetworkTest,
- {
- {0, 200}
- }
- }
- }
- },
- // ConsensusLimit_full_complain
- {
- ConsensusLimit_full_complain,
- {
- {
- NetworkMain,
- {
- {0, 12}
- }
- },
- {
- NetworkTest,
- {
- {0, 12}
- }
- }
- }
- },
- // ConsensusLimit_pro_video
- {
- ConsensusLimit_pro_video,
- {
- {
- NetworkMain,
- {
- {0, 0},
- {1324655, 100}
- }
- },
- {
- NetworkTest,
- {
- {0, 100}
- }
- }
- }
- },
-
- // ConsensusLimit_post_edit_count
- {
- ConsensusLimit_post_edit_count,
- {
- {
- NetworkMain,
- {
- {0, 5}
- }
- },
- {
- NetworkTest,
- {
- {0, 5}
- }
- }
- }
- },
- // ConsensusLimit_video_edit_count
- {
- ConsensusLimit_video_edit_count,
- {
- {
- NetworkMain,
- {
- {0, 5}
- }
- },
- {
- NetworkTest,
- {
- {0, 5}
- }
- }
- }
- },
- // ConsensusLimit_article_edit_count
- {
- ConsensusLimit_article_edit_count,
- {
- {
- NetworkMain,
- {
- {0, 10}
- }
- },
- {
- NetworkTest,
- {
- {0, 10}
- }
- }
- }
- },
- // ConsensusLimit_comment_edit_count
- {
- ConsensusLimit_comment_edit_count,
- {
- {
- NetworkMain,
- {
- {0, 4}
- }
- },
- {
- NetworkTest,
- {
- {0, 4}
- }
- }
- }
- },
-
- // ConsensusLimit_edit_user_depth
- {
- ConsensusLimit_edit_user_depth,
- {
- {
- NetworkMain,
- {
- {0, 3600},
- {1180000, 60}
- }
- },
- {
- NetworkTest,
- {
- {0, 30}
- }
- }
- }
- },
- // ConsensusLimit_edit_user_daily_count
- {
- ConsensusLimit_edit_user_daily_count,
- {
- {
- NetworkMain,
- {
- {0, 10}
- }
- },
- {
- NetworkTest,
- {
- {0, 10}
- }
- }
- }
- },
- // ConsensusLimit_edit_post_depth
- {
- ConsensusLimit_edit_post_depth,
- {
- {
- NetworkMain,
- {
- {0, 86400},
- {1180000, 1440}
- }
- },
- {
- NetworkTest,
- {
- {0, 1440}
- }
- }
- }
- },
- // ConsensusLimit_edit_video_depth
- {
- ConsensusLimit_edit_video_depth,
- {
- {
- NetworkMain,
- {
- {0, 1440}
- }
- },
- {
- NetworkTest,
- {
- {0, 1440}
- }
- }
- }
- },
- // ConsensusLimit_edit_article_depth
- {
- ConsensusLimit_edit_article_depth,
- {
- {
- NetworkMain,
- {
- {0, 4320}
- }
- },
- {
- NetworkTest,
- {
- {0, 4320}
- }
- }
- }
- },
- // ConsensusLimit_edit_comment_depth
- {
- ConsensusLimit_edit_comment_depth,
- {
- {
- NetworkMain,
- {
- {0, 86400},
- {1180000, 1440}
- }
- },
- {
- NetworkTest,
- {
- {0, 1440}
- }
- }
- }
- },
-
- // ConsensusLimit_max_user_size
- {
- ConsensusLimit_max_user_size,
- {
- {
- NetworkMain,
- {
- {0, 2000}
- }
- },
- {
- NetworkTest,
- {
- {0, 2000}
- }
- }
- }
- },
- // ConsensusLimit_max_post_size
- {
- ConsensusLimit_max_post_size,
- {
- {
- NetworkMain,
- {
- {0, 60000}
- }
- },
- {
- NetworkTest,
- {
- {0, 60000}
- }
- }
- }
- },
- // ConsensusLimit_max_video_size
- {
- ConsensusLimit_max_video_size,
- {
- {
- NetworkMain,
- {
- {0, 60000}
- }
- },
- {
- NetworkTest,
- {
- {0, 60000}
- }
- }
- }
- },
- // ConsensusLimit_max_article_size
- {
- ConsensusLimit_max_article_size,
- {
- {
- NetworkMain,
- {
- {0, 120000}
- }
- },
- {
- NetworkTest,
- {
- {0, 60000}
- }
- }
- }
- },
- // ConsensusLimit_scores_one_to_one
- {
- ConsensusLimit_scores_one_to_one,
- {
- {
- NetworkMain,
- {
- {0, 99999},
- {225000, 2}
- }
- },
- {
- NetworkTest,
- {
- {0, 2}
- }
- }
- }
- },
- // ConsensusLimit_scores_one_to_one_over_comment
- {
- ConsensusLimit_scores_one_to_one_over_comment,
- {
- {
- NetworkMain,
- {
- {0, 20}
- }
- },
- {
- NetworkTest,
- {
- {0, 20}
- }
- }
- }
- },
- // ConsensusLimit_scores_one_to_one_depth
- {
- ConsensusLimit_scores_one_to_one_depth,
- {
- {
- NetworkMain,
- {
- {0, 336 * 24 * 3600},
- {225000, 1 * 24 * 3600},
- {292800, 7 * 24 * 3600},
- {322700, 2 * 24 * 3600}
- }
- },
- {
- NetworkTest,
- {
- {0, 2 * 24 * 3600}
- }
- }
- }
- },
- // ConsensusLimit_trial_comment
- {
- ConsensusLimit_trial_comment,
- {
- {
- NetworkMain,
- {
- {0, 150}
- }
- },
- {
- NetworkTest,
- {
- {0, 150}
- }
- }
- }
- },
- // ConsensusLimit_trial_comment_score
- {
- ConsensusLimit_trial_comment_score,
- {
- {
- NetworkMain,
- {
- {0, 300}
- }
- },
- {
- NetworkTest,
- {
- {0, 300}
- }
- }
- }
- },
- // ConsensusLimit_full_comment
- {
- ConsensusLimit_full_comment,
- {
- {
- NetworkMain,
- {
- {0, 300}
- }
- },
- {
- NetworkTest,
- {
- {0, 300}
- }
- }
- }
- },
- // ConsensusLimit_full_comment_score
- {
- ConsensusLimit_full_comment_score,
- {
- {
- NetworkMain,
- {
- {0, 600}
- }
- },
- {
- NetworkTest,
- {
- {0, 600}
- }
- }
- }
- },
- // ConsensusLimit_max_comment_size
- {
- ConsensusLimit_max_comment_size,
- {
- {
- NetworkMain,
- {
- {0, 2000}
- }
- },
- {
- NetworkTest,
- {
- {0, 2000}
- }
- }
- }
- },
- // ConsensusLimit_scores_depth_modify_reputation
- {
- ConsensusLimit_scores_depth_modify_reputation,
- {
- {
- NetworkMain,
- {
- {0, 336 * 24 * 3600},
- {322700, 30 * 24 * 3600}
- }
- },
- {
- NetworkTest,
- {
- {0, 30 * 24 * 3600}
- }
- }
- }
- },
+ { ConsensusLimit_threshold_low_likers_depth, {
+ { NetworkMain, { {1180000, 250'000}, } },
+ { NetworkTest, { {0, 250'000},
+ }
+ }
+ } },
+ { ConsensusLimit_depth, {
+ { NetworkMain, { {0, 86400}, {1180000, 1440} } },
+ { NetworkTest, { {0, 1440} } }
+ } },
+
+ // Thresholds for obtaining badges - SHARK
+ { threshold_shark_reg_depth, {
+ { NetworkMain, { {0, 129600} } },
+ { NetworkTest, { {0, 1} } }
+ } },
+ { threshold_shark_likers_all, {
+ { NetworkMain, { {0, 100} } },
+ { NetworkTest, { {0, 1} } }
+ } },
+ { threshold_shark_likers_content, {
+ { NetworkMain, { {0, 0} } },
+ { NetworkTest, { {0, 0} } }
+ } },
+ { threshold_shark_likers_comment, {
+ { NetworkMain, { {0, 15} } },
+ { NetworkTest, { {0, 1} } }
+ } },
+ { threshold_shark_likers_comment_answer, {
+ { NetworkMain, { {0, 0} } },
+ { NetworkTest, { {0, 0} } }
+ } },
+
+ // Thresholds for obtaining badges - WHALE
+ { threshold_shark_reg_depth, {
+ { NetworkMain, { {0, 207360} } },
+ { NetworkTest, { {0, 1} } }
+ } },
+ { threshold_whale_likers_all, {
+ { NetworkMain, { {0, 1000} } },
+ { NetworkTest, { {0, 10} } }
+ } },
+ { threshold_whale_likers_content, {
+ { NetworkMain, { {0, 100} } },
+ { NetworkTest, { {0, 10} } }
+ } },
+ { threshold_whale_likers_comment, {
+ { NetworkMain, { {0, 100} } },
+ { NetworkTest, { {0, 10} } }
+ } },
+ { threshold_whale_likers_comment_answer, {
+ { NetworkMain, { {0, 100} } },
+ { NetworkTest, { {0, 10} } }
+ } },
+
+ // Other
+ { ConsensusLimit_edit_user_depth, {
+ { NetworkMain, { {0, 3600}, {1180000, 60} } },
+ { NetworkTest, { {0, 30} } }
+ } },
+ { ConsensusLimit_edit_user_daily_count, {
+ { NetworkMain, { {0, 10} } },
+ { NetworkTest, { {0, 10} } }
+ } },
+ { ConsensusLimit_edit_post_depth, {
+ { NetworkMain, { {0, 86400}, {1180000, 1440} } },
+ { NetworkTest, { {0, 1440} } }
+ } },
+ { ConsensusLimit_edit_video_depth, {
+ { NetworkMain, { {0, 1440} } },
+ { NetworkTest, { {0, 1440} } }
+ } },
+ { ConsensusLimit_edit_article_depth, {
+ { NetworkMain, { {0, 4320} } },
+ { NetworkTest, { {0, 4320} } }
+ } },
+ { ConsensusLimit_edit_comment_depth, {
+ { NetworkMain, { {0, 86400}, {1180000, 1440} } },
+ { NetworkTest, { {0, 1440} } }
+ } },
+ { ConsensusLimit_scores_one_to_one, {
+ { NetworkMain, { {0, 99999}, {225000, 2} } },
+ { NetworkTest, { {0, 2} } }
+ } },
+ { ConsensusLimit_scores_one_to_one_over_comment, {
+ { NetworkMain, { {0, 20} } },
+ { NetworkTest, { {0, 20} } }
+ } },
+ { ConsensusLimit_scores_one_to_one_depth, {
+ { NetworkMain, { {0, 336 * 24 * 3600}, {225000, 1 * 24 * 3600}, {292800, 7 * 24 * 3600}, {322700, 2 * 24 * 3600} } },
+ { NetworkTest, { {0, 2 * 24 * 3600} } }
+ } },
+ { ConsensusLimit_scores_depth_modify_reputation, {
+ { NetworkMain, { {0, 336 * 24 * 3600}, {322700, 30 * 24 * 3600} } },
+ { NetworkTest, { {0, 30 * 24 * 3600} } }
+ } },
// TODO (brangr) (v0.21.0): change GetLotteryReferralDepth Time to Height
- // ConsensusLimit_lottery_referral_depth
- {
- ConsensusLimit_lottery_referral_depth,
- {
- {
- NetworkMain,
- {
- {0, 30 * 24 * 3600}
- }
- },
- {
- NetworkTest,
- {
- {0, 30 * 24 * 3600}
- }
- }
- }
- },
- // ConsensusLimit_max_account_setting_size
- {
- ConsensusLimit_max_account_setting_size,
- {
- {
- NetworkMain,
- {
- {0, 2048}
- }
- },
- {
- NetworkTest,
- {
- {0, 2048}
- }
- }
- }
- },
- // ConsensusLimit_account_settings_daily_count
- {
- ConsensusLimit_account_settings_daily_count,
- {
- {
- NetworkMain,
- {
- {0, 5}
- }
- },
- {
- NetworkTest,
- {
- {0, 5}
- }
- }
- }
- },
-
- //
- // MODERATION
- //
-
+ { ConsensusLimit_lottery_referral_depth, {
+ { NetworkMain, { {0, 30 * 24 * 3600} } },
+ { NetworkTest, { {0, 30 * 24 * 3600} } }
+ } },
+
+ // Limits
+ { ConsensusLimit_trial_post, {
+ { NetworkMain, { {0, 15}, {1324655, 5} } },
+ { NetworkTest, { {0, 15} } }
+ } },
+ { ConsensusLimit_trial_video, {
+ { NetworkMain, { {0, 15}, {1324655, 5} } },
+ { NetworkTest, { {0, 15} } }
+ } },
+ { ConsensusLimit_trial_article, {
+ { NetworkMain, { {0, 1} } },
+ { NetworkTest, { {0, 10} } }
+ } },
+ { ConsensusLimit_trial_score, {
+ { NetworkMain, { {0, 45}, {175600, 100}, {1324655, 15} } },
+ { NetworkTest, { {0, 100} } }
+ } },
+ { ConsensusLimit_trial_complain, {
+ { NetworkMain, { {0, 6} } },
+ { NetworkTest, { {0, 6} } }
+ } },
+ { ConsensusLimit_trial_comment, {
+ { NetworkMain, { {0, 150}, {1757000, 50} } },
+ { NetworkTest, { {0, 150} } }
+ } },
+ { ConsensusLimit_trial_comment_score, {
+ { NetworkMain, { {0, 300}, {1757000, 100} } },
+ { NetworkTest, { {0, 300} } }
+ } },
+
+ { ConsensusLimit_full_post, {
+ { NetworkMain, { {0, 30}, {1757000, 10} } },
+ { NetworkTest, { {0, 30} } }
+ } },
+ { ConsensusLimit_full_video, {
+ { NetworkMain, { {0, 30}, {1757000, 10} } },
+ { NetworkTest, { {0, 30} } }
+ } },
+ { ConsensusLimit_full_article, {
+ { NetworkMain, { {0, 3} } },
+ { NetworkTest, { {0, 30} } }
+ } },
+ { ConsensusLimit_full_score, {
+ { NetworkMain, { {0, 90}, {175600, 200}, {1757000, 60} } },
+ { NetworkTest, { {0, 200} } }
+ } },
+ { ConsensusLimit_full_complain, {
+ { NetworkMain, { {0, 12} } },
+ { NetworkTest, { {0, 12} } }
+ } },
+ { ConsensusLimit_full_comment, {
+ { NetworkMain, { {0, 300}, {1757000, 100} } },
+ { NetworkTest, { {0, 300} } }
+ } },
+ { ConsensusLimit_full_comment_score, {
+ { NetworkMain, { {0, 600}, {1757000, 200} } },
+ { NetworkTest, { {0, 600} } }
+ } },
+
+ { ConsensusLimit_pro_video, {
+ { NetworkMain, { {0, 0}, {1324655, 100} } },
+ { NetworkTest, { {0, 100} } }
+ } },
+
{ ConsensusLimit_moderation_flag_count, {
{ NetworkMain, { {0, 30} }},
{ NetworkTest, { {0, 100} }}
}},
+
+ { ConsensusLimit_post_edit_count, {
+ { NetworkMain, { {0, 5} } },
+ { NetworkTest, { {0, 5} } }
+ } },
+ { ConsensusLimit_video_edit_count, {
+ { NetworkMain, { {0, 5} } },
+ { NetworkTest, { {0, 5} } }
+ } },
+ { ConsensusLimit_article_edit_count, {
+ { NetworkMain, { {0, 10} } },
+ { NetworkTest, { {0, 10} } }
+ } },
+ { ConsensusLimit_comment_edit_count, {
+ { NetworkMain, { {0, 4} } },
+ { NetworkTest, { {0, 4} } }
+ } },
+
+ { ConsensusLimit_account_settings_daily_count, {
+ { NetworkMain, { {0, 5} } },
+ { NetworkTest, { {0, 5} } }
+ } },
+
+ // Size
+ { ConsensusLimit_max_user_size, {
+ { NetworkMain, { {0, 2000} } },
+ { NetworkTest, { {0, 2000} } }
+ } },
+ { ConsensusLimit_max_post_size, {
+ { NetworkMain, { {0, 60000} } },
+ { NetworkTest, { {0, 60000} } }
+ } },
+ { ConsensusLimit_max_video_size, {
+ { NetworkMain, { {0, 60000} } },
+ { NetworkTest, { {0, 60000} } }
+ } },
+ { ConsensusLimit_max_article_size, {
+ { NetworkMain, { {0, 120000} } },
+ { NetworkTest, { {0, 60000} } }
+ } },
+ { ConsensusLimit_max_comment_size, {
+ { NetworkMain, { {0, 2000} } },
+ { NetworkTest, { {0, 2000} } }
+ } },
+ { ConsensusLimit_max_account_setting_size, {
+ { NetworkMain, { {0, 2048} } },
+ { NetworkTest, { {0, 2048} } }
+ } },
};
diff --git a/src/pocketdb/consensus/Reputation.h b/src/pocketdb/consensus/Reputation.h
index 9683d1313..c22d825de 100644
--- a/src/pocketdb/consensus/Reputation.h
+++ b/src/pocketdb/consensus/Reputation.h
@@ -20,7 +20,7 @@ namespace PocketConsensus
return GetConsensusLimit(ConsensusLimit_threshold_likers_count);
}
- virtual string SelectAddressScoreContent(shared_ptr& scoreData, bool lottery)
+ virtual string SelectAddressScoreContent(ScoreDataDtoRef& scoreData, bool lottery)
{
if (lottery)
return scoreData->ScoreAddressHash;
@@ -28,10 +28,10 @@ namespace PocketConsensus
return scoreData->ContentAddressHash;
}
- virtual bool AllowModifyReputationOverPost(shared_ptr& scoreData, bool lottery)
+ virtual bool AllowModifyReputationOverPost(ScoreDataDtoRef& scoreData, bool lottery)
{
// Check user reputation
- if (!IsShark(SelectAddressScoreContent(scoreData, lottery), ConsensusLimit_threshold_reputation_score))
+ if (!GetBadges(SelectAddressScoreContent(scoreData, lottery), ConsensusLimit_threshold_reputation_score).Shark)
return false;
// Disable reputation increment if from one address to one address > 2 scores over day
@@ -63,10 +63,10 @@ namespace PocketConsensus
return true;
}
- virtual bool AllowModifyReputationOverComment(shared_ptr& scoreData, bool lottery)
+ virtual bool AllowModifyReputationOverComment(ScoreDataDtoRef& scoreData, bool lottery)
{
// Check user reputation
- if (!IsShark(scoreData->ScoreAddressHash, ConsensusLimit_threshold_reputation_score))
+ if (!GetBadges(scoreData->ScoreAddressHash, ConsensusLimit_threshold_reputation_score).Shark)
return false;
// Disable reputation increment if from one address to one address > Limit::scores_one_to_one scores over Limit::scores_one_to_one_depth
@@ -94,21 +94,60 @@ namespace PocketConsensus
return true;
}
+ virtual void ExtendLikersList(vector& lkrs, int likerId)
+ {
+ lkrs.clear();
+ lkrs.emplace_back(likerId);
+ }
+
+ virtual void ExtendLikersList(map>>& likersValues, map>& ratingValues, const ScoreDataDtoRef& scoreData)
+ {
+ for (const auto& type : likersValues)
+ if (type.first != RatingType::ACCOUNT_LIKERS)
+ likersValues[type.first][scoreData->ContentAddressId].clear();
+
+ likersValues[scoreData->LikerType(false)][scoreData->ContentAddressId].emplace_back(scoreData->ScoreAddressId);
+
+ ratingValues[RatingType::ACCOUNT_LIKERS_POST_LAST][scoreData->ContentAddressId] = 0;
+ ratingValues[RatingType::ACCOUNT_LIKERS_COMMENT_ROOT_LAST][scoreData->ContentAddressId] = 0;
+ ratingValues[RatingType::ACCOUNT_LIKERS_COMMENT_ANSWER_LAST][scoreData->ContentAddressId] = 0;
+ }
+
+ virtual bool ValidateScoreValue(const ScoreDataDtoRef& scoreData)
+ {
+ // For scores to posts allowed only 4 and 5 values
+ if (scoreData->ScoreType == ACTION_SCORE_CONTENT)
+ if (scoreData->ScoreValue == 4 || scoreData->ScoreValue == 5)
+ return true;
+
+ // For scores to comments allowed only 1 value
+ if (scoreData->ScoreType == ACTION_SCORE_COMMENT)
+ if (scoreData->ScoreValue == 1)
+ return true;
+
+ // Another types not allowed
+ return false;
+ }
+
public:
explicit ReputationConsensus(int height) : BaseConsensus(height) {}
- virtual bool IsShark(const AccountData& accountData, ConsensusLimit limit = ConsensusLimit_threshold_reputation)
+ virtual BadgeSet GetBadges(const AccountData& data, ConsensusLimit limit = ConsensusLimit_threshold_reputation)
{
- auto minReputation = GetConsensusLimit(limit);
- auto minLikersCount = GetMinLikers(accountData.RegistrationHeight);
+ BadgeSet badgeSet;
- return accountData.Reputation >= minReputation && accountData.LikersCount >= minLikersCount;
+ badgeSet.Developer = IsDeveloper(data.AddressHash);
+ badgeSet.Shark = data.Reputation >= GetConsensusLimit(limit) && data.LikersAll() >= GetMinLikers(data.RegistrationHeight);
+ badgeSet.Whale = false;
+ badgeSet.Moderator = false;
+
+ return badgeSet;
}
- virtual bool IsShark(const string& address, ConsensusLimit limit = ConsensusLimit_threshold_reputation)
+ virtual BadgeSet GetBadges(const string& address, ConsensusLimit limit = ConsensusLimit_threshold_reputation)
{
auto accountData = ConsensusRepoInst.GetAccountData(address);
- return IsShark(accountData, limit);
+ return GetBadges(accountData, limit);
}
virtual AccountMode GetAccountMode(int reputation, int64_t balance)
@@ -128,7 +167,7 @@ namespace PocketConsensus
return {GetAccountMode(reputation, balance), reputation, balance};
}
- virtual bool AllowModifyReputation(shared_ptr& scoreData, bool lottery)
+ virtual bool AllowModifyReputation(ScoreDataDtoRef& scoreData, bool lottery)
{
if (scoreData->ScoreType == TxType::ACTION_SCORE_CONTENT)
return AllowModifyReputationOverPost(scoreData, lottery);
@@ -151,21 +190,6 @@ namespace PocketConsensus
return true;
}
}
-
- virtual void PrepareAccountLikers(map>& accountLikersSrc, map>& accountLikers)
- {
- for (const auto& account : accountLikersSrc)
- {
- for (const auto& likerId : account.second)
- {
- if (!PocketDb::RatingsRepoInst.ExistsLiker(account.first, likerId, Height))
- {
- accountLikers[account.first].clear();
- accountLikers[account.first].emplace_back(likerId);
- }
- }
- }
- }
virtual int GetScoreContentAuthorValue(int scoreValue)
{
@@ -176,6 +200,74 @@ namespace PocketConsensus
{
return scoreValue;
}
+
+ virtual void DistinctScores(const ScoreDataDtoRef& scoreData, vector& distinctScores)
+ {
+ if (!ValidateScoreValue(scoreData))
+ return;
+
+ auto it = find_if(
+ distinctScores.begin(),
+ distinctScores.end(),
+ [&scoreData](const ScoreDataDtoRef& _scoreData)
+ {
+ return _scoreData->ContentAddressId == scoreData->ContentAddressId &&
+ _scoreData->ScoreAddressId == scoreData->ScoreAddressId;
+ });
+
+ if (it == distinctScores.end())
+ distinctScores.push_back(scoreData);
+ }
+
+ virtual void ValidateAccountLiker(const ScoreDataDtoRef& scoreData, map>>& likersValues, map>& ratingValues)
+ {
+ // Check already added to list and exists in DB
+ auto& lkrs = likersValues[ACCOUNT_LIKERS][scoreData->ContentAddressId];
+ if (find(lkrs.begin(), lkrs.end(), scoreData->ScoreAddressId) == lkrs.end())
+ {
+ if (!PocketDb::RatingsRepoInst.ExistsLiker(
+ scoreData->ContentAddressId,
+ scoreData->ScoreAddressId,
+ { ACCOUNT_LIKERS }
+ ))
+ {
+ ExtendLikersList(
+ lkrs,
+ scoreData->ScoreAddressId
+ );
+ }
+ }
+
+ //
+ // Split likers types
+ //
+ auto& lkrs_post = likersValues[ACCOUNT_LIKERS_POST][scoreData->ContentAddressId];
+ if ((find(lkrs_post.begin(), lkrs_post.end(), scoreData->ScoreAddressId) != lkrs_post.end()))
+ return;
+
+ auto& lkrs_cmnt_root = likersValues[ACCOUNT_LIKERS_COMMENT_ROOT][scoreData->ContentAddressId];
+ if ((find(lkrs_cmnt_root.begin(), lkrs_cmnt_root.end(), scoreData->ScoreAddressId) != lkrs_cmnt_root.end()))
+ return;
+
+ auto& lkrs_cmnt_answer = likersValues[ACCOUNT_LIKERS_COMMENT_ANSWER][scoreData->ContentAddressId];
+ if ((find(lkrs_cmnt_answer.begin(), lkrs_cmnt_answer.end(), scoreData->ScoreAddressId) != lkrs_cmnt_answer.end()))
+ return;
+
+ if (!PocketDb::RatingsRepoInst.ExistsLiker(
+ scoreData->ContentAddressId,
+ scoreData->ScoreAddressId,
+ { ACCOUNT_LIKERS_POST, ACCOUNT_LIKERS_COMMENT_ROOT, ACCOUNT_LIKERS_COMMENT_ANSWER }
+ ))
+ {
+ ExtendLikersList(
+ likersValues,
+ ratingValues,
+ scoreData
+ );
+
+ ratingValues[scoreData->LikerType(true)][scoreData->ContentAddressId] += 1;
+ }
+ }
};
// Consensus checkpoint at 151600 block
@@ -184,7 +276,7 @@ namespace PocketConsensus
public:
explicit ReputationConsensus_checkpoint_151600(int height) : ReputationConsensus(height) {}
protected:
- string SelectAddressScoreContent(shared_ptr& scoreData, bool lottery) override
+ string SelectAddressScoreContent(ScoreDataDtoRef& scoreData, bool lottery) override
{
return scoreData->ScoreAddressHash;
}
@@ -205,9 +297,17 @@ namespace PocketConsensus
}
};
- // Consensus checkpoint at 1324655 block
class ReputationConsensus_checkpoint_1324655 : public ReputationConsensus_checkpoint_1180000
{
+ protected:
+ void ExtendLikersList(vector& lkrs, int likerId) override
+ {
+ lkrs.emplace_back(likerId);
+ }
+ void ExtendLikersList(map>>& lkrs, map>& ratingValues, const ScoreDataDtoRef& scoreData) override
+ {
+ lkrs[scoreData->LikerType(false)][scoreData->ContentAddressId].emplace_back(scoreData->ScoreAddressId);
+ }
public:
explicit ReputationConsensus_checkpoint_1324655(int height) : ReputationConsensus_checkpoint_1180000(height) {}
AccountMode GetAccountMode(int reputation, int64_t balance) override
@@ -227,25 +327,11 @@ namespace PocketConsensus
}
};
- // Consensus checkpoint at 1324655_2 block
- class ReputationConsensus_checkpoint_1324655_2 : public ReputationConsensus_checkpoint_1324655
- {
- public:
- explicit ReputationConsensus_checkpoint_1324655_2(int height) : ReputationConsensus_checkpoint_1324655(height) {}
- void PrepareAccountLikers(map>& accountLikersSrc, map>& accountLikers) override
- {
- for (const auto& account : accountLikersSrc)
- for (const auto& likerId : account.second)
- if (!PocketDb::RatingsRepoInst.ExistsLiker(account.first, likerId, Height))
- accountLikers[account.first].emplace_back(likerId);
- }
- };
-
// Consensus checkpoint: reducing the impact on the reputation of scores 1,2 for content
- class ReputationConsensus_checkpoint_scores_content_author_reducing_impact : public ReputationConsensus_checkpoint_1324655_2
+ class ReputationConsensus_checkpoint_scores_content_author_reducing_impact : public ReputationConsensus_checkpoint_1324655
{
public:
- explicit ReputationConsensus_checkpoint_scores_content_author_reducing_impact(int height) : ReputationConsensus_checkpoint_1324655_2(height) {}
+ explicit ReputationConsensus_checkpoint_scores_content_author_reducing_impact(int height) : ReputationConsensus_checkpoint_1324655(height) {}
int GetScoreContentAuthorValue(int scoreValue) override
{
int multiplier = 10;
@@ -254,13 +340,6 @@ namespace PocketConsensus
return (scoreValue - 3) * multiplier;
}
- };
-
- // Consensus checkpoint: disable the impact on the reputation of scores -1 for comment
- class ReputationConsensus_checkpoint_scores_comment_author_disable_impact : public ReputationConsensus_checkpoint_scores_content_author_reducing_impact
- {
- public:
- explicit ReputationConsensus_checkpoint_scores_comment_author_disable_impact(int height) : ReputationConsensus_checkpoint_scores_content_author_reducing_impact(height) {}
int GetScoreCommentAuthorValue(int scoreValue) override
{
if (scoreValue == -1)
@@ -270,6 +349,35 @@ namespace PocketConsensus
}
};
+ // Consensus checkpoint: reducing the impact on the reputation of scores 1,2 for content
+ class ReputationConsensus_checkpoint_badges : public ReputationConsensus_checkpoint_scores_content_author_reducing_impact
+ {
+ public:
+ explicit ReputationConsensus_checkpoint_badges(int height) : ReputationConsensus_checkpoint_scores_content_author_reducing_impact(height) {}
+ BadgeSet GetBadges(const AccountData& data, ConsensusLimit limit = ConsensusLimit_threshold_reputation) override
+ {
+ BadgeSet badgeSet;
+
+ badgeSet.Developer = IsDeveloper(data.AddressHash);
+
+ badgeSet.Shark = data.LikersAll() >= GetConsensusLimit(threshold_shark_likers_all)
+ && data.LikersContent >= GetConsensusLimit(threshold_shark_likers_content)
+ && data.LikersComment >= GetConsensusLimit(threshold_shark_likers_comment)
+ && data.LikersCommentAnswer >= GetConsensusLimit(threshold_shark_likers_comment_answer)
+ && Height - data.RegistrationHeight >= GetConsensusLimit(threshold_shark_reg_depth);
+
+ badgeSet.Whale = data.LikersAll() >= GetConsensusLimit(threshold_whale_likers_all)
+ && data.LikersContent >= GetConsensusLimit(threshold_whale_likers_content)
+ && data.LikersComment >= GetConsensusLimit(threshold_whale_likers_comment)
+ && data.LikersCommentAnswer >= GetConsensusLimit(threshold_whale_likers_comment_answer)
+ && Height - data.RegistrationHeight >= GetConsensusLimit(threshold_whale_reg_depth);
+
+ // badgeSet.Moderator = TODO (brangr): implement for future
+
+ return badgeSet;
+ }
+ };
+
// Factory for select actual rules version
class ReputationConsensusFactory
@@ -280,9 +388,8 @@ namespace PocketConsensus
{ 151600, -1, [](int height) { return make_shared(height); }},
{ 1180000, 0, [](int height) { return make_shared(height); }},
{ 1324655, 65000, [](int height) { return make_shared(height); }},
- { 1324655, 75000, [](int height) { return make_shared(height); }},
{ 1700000, 761000, [](int height) { return make_shared(height); }},
- { 1700000, 772000, [](int height) { return make_shared(height); }},
+ { 1757000, 947500, [](int height) { return make_shared(height); }},
};
public:
shared_ptr Instance(int height)
diff --git a/src/pocketdb/consensus/moderation/Flag.hpp b/src/pocketdb/consensus/moderation/Flag.hpp
index a36a1f5c0..04cf1c117 100644
--- a/src/pocketdb/consensus/moderation/Flag.hpp
+++ b/src/pocketdb/consensus/moderation/Flag.hpp
@@ -32,7 +32,7 @@ namespace PocketConsensus
// Only `Shark` account can flag content
auto reputationConsensus = ReputationConsensusFactoryInst.Instance(Height);
- if (!reputationConsensus->IsShark(*ptx->GetAddress()))
+ if (!reputationConsensus->GetBadges(*ptx->GetAddress()).Shark)
return {false, SocialConsensusResult_LowReputation};
// Target transaction must be a exists and is a content and author should be equals ptx->GetContentAddressHash()
diff --git a/src/pocketdb/consensus/social/BoostContent.hpp b/src/pocketdb/consensus/social/BoostContent.hpp
index 59ef17d21..ab490ec75 100644
--- a/src/pocketdb/consensus/social/BoostContent.hpp
+++ b/src/pocketdb/consensus/social/BoostContent.hpp
@@ -35,6 +35,10 @@ namespace PocketConsensus
if (*contentTx->GetType() == CONTENT_DELETE)
return {false, SocialConsensusResult_CommentDeletedContent};
+ // Check Blocking
+ if (auto[ok, result] = ValidateBlocking(*contentTx->GetString1(), ptx); !ok)
+ return {false, result};
+
return Success;
}
ConsensusValidateResult Check(const CTransactionRef& tx, const BoostContentRef& ptx) override
@@ -66,6 +70,10 @@ namespace PocketConsensus
{
return {*ptx->GetAddress()};
}
+ virtual ConsensusValidateResult ValidateBlocking(const string& contentAddress, const BoostContentRef& ptx)
+ {
+ return Success;
+ }
};
/*******************************************************************************************************************
@@ -82,12 +90,29 @@ namespace PocketConsensus
}
};
+ // Disable scores for blocked accounts
+ class BoostContentConsensus_checkpoint_disable_for_blocked : public BoostContentConsensus_checkpoint_accept
+ {
+ public:
+ BoostContentConsensus_checkpoint_disable_for_blocked(int height) : BoostContentConsensus_checkpoint_accept(height) {}
+ protected:
+ ConsensusValidateResult ValidateBlocking(const string& contentAddress, const BoostContentRef& ptx) override
+ {
+ if (auto[existsBlocking, blockingType] = PocketDb::ConsensusRepoInst.GetLastBlockingType(
+ contentAddress, *ptx->GetAddress()); existsBlocking && blockingType == ACTION_BLOCKING)
+ return {false, SocialConsensusResult_Blocking};
+
+ return Success;
+ }
+ };
+
class BoostContentConsensusFactory
{
private:
const vector> m_rules = {
{ 0, 0, [](int height) { return make_shared(height); }},
{ 1586000, 528100, [](int height) { return make_shared(height); }},
+ { 1757000, 953000, [](int height) { return make_shared(height); }},
};
public:
shared_ptr Instance(int height)
diff --git a/src/pocketdb/consensus/social/Post.hpp b/src/pocketdb/consensus/social/Post.hpp
index 37f3fa28e..12ec0e0fe 100644
--- a/src/pocketdb/consensus/social/Post.hpp
+++ b/src/pocketdb/consensus/social/Post.hpp
@@ -41,8 +41,16 @@ namespace PocketConsensus
if (!relayOk && !CheckpointRepoInst.IsSocialCheckpoint(*ptx->GetHash(), *ptx->GetType(), SocialConsensusResult_RelayContentNotFound))
return {false, SocialConsensusResult_RelayContentNotFound};
- if (relayOk && *relayTx->GetType() == CONTENT_DELETE)
- return {false, SocialConsensusResult_RepostDeletedContent};
+ if (relayOk)
+ {
+ // Repost deleted content not allowed
+ if (*relayTx->GetType() == CONTENT_DELETE)
+ return {false, SocialConsensusResult_RepostDeletedContent};
+
+ // Check Blocking
+ if (auto[ok, result] = ValidateBlocking(*relayTx->GetString1(), ptx); !ok)
+ return {false, result};
+ }
}
// Check payload size
@@ -257,6 +265,10 @@ namespace PocketConsensus
return Success;
}
+ virtual ConsensusValidateResult ValidateBlocking(const string& contentAddress, const PostRef& ptx)
+ {
+ return Success;
+ }
};
/*******************************************************************************************************************
@@ -298,6 +310,26 @@ namespace PocketConsensus
}
};
+ // Disable scores for blocked accounts
+ class PostConsensus_checkpoint_disable_for_blocked : public PostConsensus_checkpoint_1180000
+ {
+ public:
+ PostConsensus_checkpoint_disable_for_blocked(int height) : PostConsensus_checkpoint_1180000(height) {}
+ protected:
+ ConsensusValidateResult ValidateBlocking(const string& contentAddress, const PostRef& ptx) override
+ {
+ auto[existsBlocking, blockingType] = PocketDb::ConsensusRepoInst.GetLastBlockingType(
+ contentAddress,
+ *ptx->GetAddress()
+ );
+
+ if (existsBlocking && blockingType == ACTION_BLOCKING)
+ return {false, SocialConsensusResult_Blocking};
+
+ return Success;
+ }
+ };
+
/*******************************************************************************************************************
* Factory for select actual rules version
*******************************************************************************************************************/
@@ -305,9 +337,10 @@ namespace PocketConsensus
{
protected:
const vector> m_rules = {
- { 0, -1, [](int height) { return make_shared(height); }},
- { 1124000, -1, [](int height) { return make_shared(height); }},
- { 1180000, -1, [](int height) { return make_shared(height); }},
+ { 0, -1, [](int height) { return make_shared(height); }},
+ { 1124000, -1, [](int height) { return make_shared(height); }},
+ { 1180000, -1, [](int height) { return make_shared(height); }},
+ { 1757000, 953000, [](int height) { return make_shared(height); }},
};
public:
shared_ptr Instance(int height)
diff --git a/src/pocketdb/consensus/social/ScoreComment.hpp b/src/pocketdb/consensus/social/ScoreComment.hpp
index 2c37f5776..891cc4301 100644
--- a/src/pocketdb/consensus/social/ScoreComment.hpp
+++ b/src/pocketdb/consensus/social/ScoreComment.hpp
@@ -238,9 +238,6 @@ namespace PocketConsensus
}
};
- /*******************************************************************************************************************
- * Start checkpoint at 1180000 block
- *******************************************************************************************************************/
class ScoreCommentConsensus_checkpoint_1180000 : public ScoreCommentConsensus_checkpoint_1124000
{
public:
@@ -256,6 +253,26 @@ namespace PocketConsensus
}
};
+ class ScoreCommentConsensus_checkpoint_disable_for_blocked : public ScoreCommentConsensus_checkpoint_1180000
+ {
+ public:
+ explicit ScoreCommentConsensus_checkpoint_disable_for_blocked(int height) : ScoreCommentConsensus_checkpoint_1180000(height) {}
+ protected:
+ ConsensusValidateResult ValidateBlocking(const string& commentAddress, const ScoreCommentRef& ptx) override
+ {
+
+ auto[existsBlocking, blockingType] = PocketDb::ConsensusRepoInst.GetLastBlockingType(
+ commentAddress,
+ *ptx->GetAddress()
+ );
+
+ if (existsBlocking && blockingType == ACTION_BLOCKING)
+ return {false, SocialConsensusResult_Blocking};
+
+ return Success;
+ }
+ };
+
/*******************************************************************************************************************
* Factory for select actual rules version
*******************************************************************************************************************/
@@ -268,6 +285,7 @@ namespace PocketConsensus
{ 514184, -1, [](int height) { return make_shared(height); }},
{ 1124000, -1, [](int height) { return make_shared(height); }},
{ 1180000, 0, [](int height) { return make_shared(height); }},
+ { 1757000, 953000, [](int height) { return make_shared(height); }},
};
public:
shared_ptr Instance(int height)
diff --git a/src/pocketdb/consensus/social/ScoreContent.hpp b/src/pocketdb/consensus/social/ScoreContent.hpp
index 5b51516fc..f1e6cdab0 100644
--- a/src/pocketdb/consensus/social/ScoreContent.hpp
+++ b/src/pocketdb/consensus/social/ScoreContent.hpp
@@ -270,6 +270,26 @@ namespace PocketConsensus
}
};
+ // Disable scores for blocked accounts
+ class ScoreContentConsensus_checkpoint_disable_for_blocked : public ScoreContentConsensus_checkpoint_1324655
+ {
+ public:
+ ScoreContentConsensus_checkpoint_disable_for_blocked(int height) : ScoreContentConsensus_checkpoint_1324655(height) {}
+ protected:
+ ConsensusValidateResult ValidateBlocking(const string& contentAddress, const ScoreContentRef& ptx) override
+ {
+ auto[existsBlocking, blockingType] = PocketDb::ConsensusRepoInst.GetLastBlockingType(
+ contentAddress,
+ *ptx->GetAddress()
+ );
+
+ if (existsBlocking && blockingType == ACTION_BLOCKING)
+ return {false, SocialConsensusResult_Blocking};
+
+ return Success;
+ }
+ };
+
/*******************************************************************************************************************
* Factory for select actual rules version
*******************************************************************************************************************/
@@ -277,12 +297,13 @@ namespace PocketConsensus
{
private:
const vector> m_rules = {
- { 0, -1, [](int height) { return make_shared(height); }},
- { 430000, -1, [](int height) { return make_shared(height); }},
- { 514184, -1, [](int height) { return make_shared(height); }},
- { 1124000, -1, [](int height) { return make_shared(height); }},
- { 1180000, 0, [](int height) { return make_shared(height); }},
- { 1324655, 65000, [](int height) { return make_shared(height); }},
+ { 0, -1, [](int height) { return make_shared(height); }},
+ { 430000, -1, [](int height) { return make_shared(height); }},
+ { 514184, -1, [](int height) { return make_shared(height); }},
+ { 1124000, -1, [](int height) { return make_shared(height); }},
+ { 1180000, 0, [](int height) { return make_shared(height); }},
+ { 1324655, 65000, [](int height) { return make_shared(height); }},
+ { 1757000, 953000, [](int height) { return make_shared(height); }},
};
public:
shared_ptr Instance(int height)
diff --git a/src/pocketdb/consensus/social/Subscribe.hpp b/src/pocketdb/consensus/social/Subscribe.hpp
index f3a9cabe3..8178179c6 100644
--- a/src/pocketdb/consensus/social/Subscribe.hpp
+++ b/src/pocketdb/consensus/social/Subscribe.hpp
@@ -37,6 +37,10 @@ namespace PocketConsensus
return {false, SocialConsensusResult_DoubleSubscribe};
}
+ // Check Blocking
+ if (auto[ok, result] = ValidateBlocking(ptx); !ok)
+ return {false, result};
+
return Success;
}
ConsensusValidateResult Check(const CTransactionRef& tx, const SubscribeRef& ptx) override
@@ -94,6 +98,26 @@ namespace PocketConsensus
{
return {*ptx->GetAddress(), *ptx->GetAddressTo()};
}
+ virtual ConsensusValidateResult ValidateBlocking(const SubscribeRef& ptx)
+ {
+ return Success;
+ }
+ };
+
+ // Disable scores for blocked accounts
+ class SubscribeConsensus_checkpoint_disable_for_blocked : public SubscribeConsensus
+ {
+ public:
+ SubscribeConsensus_checkpoint_disable_for_blocked(int height) : SubscribeConsensus(height) {}
+ protected:
+ ConsensusValidateResult ValidateBlocking(const SubscribeRef& ptx) override
+ {
+ if (auto[existsBlocking, blockingType] = PocketDb::ConsensusRepoInst.GetLastBlockingType(
+ *ptx->GetAddressTo(), *ptx->GetAddress()); existsBlocking && blockingType == ACTION_BLOCKING)
+ return {false, SocialConsensusResult_Blocking};
+
+ return Success;
+ }
};
/*******************************************************************************************************************
@@ -103,7 +127,8 @@ namespace PocketConsensus
{
private:
const vector> m_rules = {
- { 0, 0, [](int height) { return make_shared(height); }},
+ { 0, 0, [](int height) { return make_shared(height); }},
+ { 1757000, 953000, [](int height) { return make_shared(height); }},
};
public:
shared_ptr Instance(int height)
diff --git a/src/pocketdb/consensus/social/SubscribePrivate.hpp b/src/pocketdb/consensus/social/SubscribePrivate.hpp
index eef03ae32..28c2148a1 100644
--- a/src/pocketdb/consensus/social/SubscribePrivate.hpp
+++ b/src/pocketdb/consensus/social/SubscribePrivate.hpp
@@ -37,6 +37,10 @@ namespace PocketConsensus
return {false, SocialConsensusResult_DoubleSubscribe};
}
+ // Check Blocking
+ if (auto[ok, result] = ValidateBlocking(ptx); !ok)
+ return {false, result};
+
return Success;
}
ConsensusValidateResult Check(const CTransactionRef& tx, const SubscribePrivateRef& ptx) override
@@ -94,6 +98,26 @@ namespace PocketConsensus
{
return {*ptx->GetAddress(), *ptx->GetAddressTo()};
}
+ virtual ConsensusValidateResult ValidateBlocking(const SubscribePrivateRef& ptx)
+ {
+ return Success;
+ }
+ };
+
+ // Disable scores for blocked accounts
+ class SubscribePrivateConsensus_checkpoint_disable_for_blocked : public SubscribePrivateConsensus
+ {
+ public:
+ SubscribePrivateConsensus_checkpoint_disable_for_blocked(int height) : SubscribePrivateConsensus(height) {}
+ protected:
+ ConsensusValidateResult ValidateBlocking(const SubscribePrivateRef& ptx) override
+ {
+ if (auto[existsBlocking, blockingType] = PocketDb::ConsensusRepoInst.GetLastBlockingType(
+ *ptx->GetAddressTo(), *ptx->GetAddress()); existsBlocking && blockingType == ACTION_BLOCKING)
+ return {false, SocialConsensusResult_Blocking};
+
+ return Success;
+ }
};
/*******************************************************************************************************************
@@ -103,7 +127,8 @@ namespace PocketConsensus
{
private:
const vector> m_rules = {
- { 0, 0, [](int height) { return make_shared(height); }},
+ { 0, 0, [](int height) { return make_shared(height); }},
+ { 1757000, 953000, [](int height) { return make_shared(height); }},
};
public:
shared_ptr Instance(int height)
diff --git a/src/pocketdb/helpers/TransactionHelper.h b/src/pocketdb/helpers/TransactionHelper.h
index e7c743e44..3ec89b51a 100644
--- a/src/pocketdb/helpers/TransactionHelper.h
+++ b/src/pocketdb/helpers/TransactionHelper.h
@@ -13,7 +13,7 @@
#include "primitives/transaction.h"
#include "utilstrencodings.h"
-#include "pocketdb/models/base/ReturnDtoModels.h"
+#include "pocketdb/models/base/DtoModels.h"
#include "pocketdb/models/base/PocketTypes.h"
#include "pocketdb/models/dto/Blocking.h"
diff --git a/src/pocketdb/migrations/main.cpp b/src/pocketdb/migrations/main.cpp
index 105a3ead3..24848c6d7 100644
--- a/src/pocketdb/migrations/main.cpp
+++ b/src/pocketdb/migrations/main.cpp
@@ -182,8 +182,8 @@ namespace PocketDb
primary key (Db)
);
)sql");
-
-
+
+
_preProcessing = R"sql(
insert or ignore into System (Db, Version) values ('main', 0);
)sql";
diff --git a/src/pocketdb/models/base/ReturnDtoModels.h b/src/pocketdb/models/base/DtoModels.h
similarity index 82%
rename from src/pocketdb/models/base/ReturnDtoModels.h
rename to src/pocketdb/models/base/DtoModels.h
index 1c7a00a41..abd319e69 100644
--- a/src/pocketdb/models/base/ReturnDtoModels.h
+++ b/src/pocketdb/models/base/DtoModels.h
@@ -85,6 +85,8 @@ namespace PocketTx
string ContentAddressHash;
int64_t ContentTime;
+ string String5;
+
shared_ptr Serialize() override
{
UniValue ret(UniValue::VOBJ);
@@ -102,6 +104,21 @@ namespace PocketTx
ret.pushKV("ContentTime", ContentTime);
return make_shared(ret);
}
+
+ RatingType LikerType(bool last)
+ {
+ if (ScoreType == ACTION_SCORE_CONTENT)
+ return last ? ACCOUNT_LIKERS_POST_LAST : ACCOUNT_LIKERS_POST;
+
+ if (ScoreType == ACTION_SCORE_COMMENT && String5.empty())
+ return last ? ACCOUNT_LIKERS_COMMENT_ROOT_LAST : ACCOUNT_LIKERS_COMMENT_ROOT;
+
+ if (ScoreType == ACTION_SCORE_COMMENT && !String5.empty())
+ return last ? ACCOUNT_LIKERS_COMMENT_ANSWER_LAST : ACCOUNT_LIKERS_COMMENT_ANSWER;
+
+ // You don't have to get to here
+ return ACCOUNT_LIKERS;
+ }
};
typedef shared_ptr ScoreDataDtoRef;
diff --git a/src/pocketdb/models/base/PocketTypes.h b/src/pocketdb/models/base/PocketTypes.h
index 0b6b96077..fe4d9ebdd 100644
--- a/src/pocketdb/models/base/PocketTypes.h
+++ b/src/pocketdb/models/base/PocketTypes.h
@@ -97,9 +97,20 @@ namespace PocketTx
enum RatingType
{
RATING_ACCOUNT = 0,
- RATING_ACCOUNT_LIKERS = 1,
RATING_CONTENT = 2,
RATING_COMMENT = 3,
+
+ ACCOUNT_LIKERS = 1,
+
+ ACCOUNT_LIKERS_POST = 101,
+ ACCOUNT_LIKERS_COMMENT_ROOT = 102,
+ ACCOUNT_LIKERS_COMMENT_ANSWER = 103,
+ ACCOUNT_DISLIKERS_COMMENT_ANSWER = 104,
+
+ ACCOUNT_LIKERS_POST_LAST = 111,
+ ACCOUNT_LIKERS_COMMENT_ROOT_LAST = 112,
+ ACCOUNT_LIKERS_COMMENT_ANSWER_LAST = 113,
+ ACCOUNT_DISLIKERS_COMMENT_ANSWER_LAST = 114,
};
// Content field types
diff --git a/src/pocketdb/pocketnet.cpp b/src/pocketdb/pocketnet.cpp
index 40c7bcd5a..0cb98e073 100644
--- a/src/pocketdb/pocketnet.cpp
+++ b/src/pocketdb/pocketnet.cpp
@@ -14,6 +14,7 @@ namespace PocketDb
NotifierRepository NotifierRepoInst(SQLiteDbInst);
ExplorerRepository ExplorerRepoInst(SQLiteDbInst);
SystemRepository SystemRepoInst(SQLiteDbInst);
+ MigrationRepository MigrationRepoInst(SQLiteDbInst);
SQLiteDatabase SQLiteDbCheckpointInst(true);
CheckpointRepository CheckpointRepoInst(SQLiteDbCheckpointInst);
diff --git a/src/pocketdb/pocketnet.h b/src/pocketdb/pocketnet.h
index 942028a82..d263b0ae6 100644
--- a/src/pocketdb/pocketnet.h
+++ b/src/pocketdb/pocketnet.h
@@ -19,6 +19,7 @@
#include "pocketdb/repositories/ConsensusRepository.h"
#include "pocketdb/repositories/SystemRepository.h"
#include "pocketdb/repositories/CheckpointRepository.h"
+#include "pocketdb/repositories/MigrationRepository.h"
#include "pocketdb/repositories/web/WebRpcRepository.h"
#include "pocketdb/repositories/web/ExplorerRepository.h"
@@ -37,6 +38,7 @@ namespace PocketDb
extern NotifierRepository NotifierRepoInst;
extern ExplorerRepository ExplorerRepoInst;
extern SystemRepository SystemRepoInst;
+ extern MigrationRepository MigrationRepoInst;
extern SQLiteDatabase SQLiteDbCheckpointInst;
extern CheckpointRepository CheckpointRepoInst;
diff --git a/src/pocketdb/repositories/BaseRepository.h b/src/pocketdb/repositories/BaseRepository.h
index bb83841ac..16871db0f 100644
--- a/src/pocketdb/repositories/BaseRepository.h
+++ b/src/pocketdb/repositories/BaseRepository.h
@@ -125,6 +125,18 @@ namespace PocketDb
throw std::runtime_error(strprintf("%s: Failed execute SQL statement\n", __func__));
}
+ void TryTransactionBulk(const string& func, const vector>& stmts)
+ {
+ if (!m_database.BeginTransaction())
+ throw std::runtime_error(strprintf("%s: can't begin transaction\n", func));
+
+ for (auto stmt : stmts)
+ TryStepStatement(stmt);
+
+ if (!m_database.CommitTransaction())
+ throw std::runtime_error(strprintf("%s: can't commit transaction\n", func));
+ }
+
shared_ptr SetupSqlStatement(const std::string& sql) const
{
sqlite3_stmt* stmt;
diff --git a/src/pocketdb/repositories/ChainRepository.cpp b/src/pocketdb/repositories/ChainRepository.cpp
index db0512457..a03142fb8 100644
--- a/src/pocketdb/repositories/ChainRepository.cpp
+++ b/src/pocketdb/repositories/ChainRepository.cpp
@@ -202,6 +202,7 @@ namespace PocketDb
) saldo
left join Balances b indexed by Balances_AddressHash_Last
on b.AddressHash = saldo.AddressHash and b.Last = 1
+ where saldo.AddressHash != ''
group by saldo.AddressHash
)sql");
TryBindStatementInt(stmt, 1, height);
@@ -455,10 +456,11 @@ namespace PocketDb
void ChainRepository::RestoreOldLast(int height)
{
- int64_t nTime1 = GetTimeMicros();
+ int64_t nTime0 = GetTimeMicros();
+ // ----------------------------------------
// Restore old Last transactions
- auto stmt = SetupSqlStatement(R"sql(
+ auto stmt1 = SetupSqlStatement(R"sql(
update Transactions indexed by Transactions_Height_Id
set Last=1
from (
@@ -471,13 +473,14 @@ namespace PocketDb
)t
where Transactions.Id = t.Id and Transactions.Height = t.Height
)sql");
- TryBindStatementInt(stmt, 1, height);
- TryBindStatementInt(stmt, 2, height);
- TryStepStatement(stmt);
+ TryBindStatementInt(stmt1, 1, height);
+ TryBindStatementInt(stmt1, 2, height);
+ TryStepStatement(stmt1);
- int64_t nTime2 = GetTimeMicros();
- LogPrint(BCLog::BENCH, " - RestoreOldLast (Transactions:Last = 1): %.2fms\n", 0.001 * (nTime2 - nTime1));
+ int64_t nTime1 = GetTimeMicros();
+ LogPrint(BCLog::BENCH, " - RestoreOldLast (Transactions): %.2fms\n", 0.001 * (nTime1 - nTime0));
+ // ----------------------------------------
// Restore Last for deleting ratings
auto stmt2 = SetupSqlStatement(R"sql(
update Ratings indexed by Ratings_Type_Id_Height_Value
@@ -485,7 +488,7 @@ namespace PocketDb
from (
select r1.Type, r1.Id, max(r2.Height)Height
from Ratings r1 indexed by Ratings_Type_Id_Last_Height
- join Ratings r2 indexed by Ratings_Last_Id_Height on r2.Last = 0 and r2.Id = r1.Id and r2.Height < ?
+ join Ratings r2 indexed by Ratings_Type_Id_Last_Height on r2.Type = r1.Type and r2.Id = r1.Id and r2.Last = 0 and r2.Height < ?
where r1.Height >= ?
and r1.Last = 1
group by r1.Type, r1.Id
@@ -498,35 +501,54 @@ namespace PocketDb
TryBindStatementInt(stmt2, 2, height);
TryStepStatement(stmt2);
- int64_t nTime3 = GetTimeMicros();
- LogPrint(BCLog::BENCH, " - RestoreOldLast (Ratings:Last = 1): %.2fms\n", 0.001 * (nTime3 - nTime2));
+ int64_t nTime2 = GetTimeMicros();
+ LogPrint(BCLog::BENCH, " - RestoreOldLast (Ratings): %.2fms\n", 0.001 * (nTime2 - nTime1));
+ // ----------------------------------------
// Restore Last for deleting balances
auto stmt3 = SetupSqlStatement(R"sql(
- update Balances set Last=1
+ update Balances set
+
+ Last = 1
+
from (
- select b1.AddressHash, max(b2.Height)Height
- from Balances b1 indexed by Balances_AddressHash_Last_Height
- join Balances b2 indexed by Balances_AddressHash_Last_Height on b2.Last = 0 and b2.AddressHash = b1.AddressHash and b2.Height < ?
+ select
+
+ b1.AddressHash
+ ,(
+ select max(b2.Height)
+ from Balances b2 indexed by Balances_AddressHash_Last_Height
+ where b2.AddressHash = b1.AddressHash
+ and b2.Last = 0
+ and b2.Height < ?
+ limit 1
+ )Height
+
+ from Balances b1 indexed by Balances_Height
+
where b1.Height >= ?
and b1.Last = 1
+ and b1.AddressHash != ''
+
group by b1.AddressHash
)b
- where Balances.AddressHash = b.AddressHash
+ where b.Height is not null
+ and Balances.AddressHash = b.AddressHash
and Balances.Height = b.Height
)sql");
TryBindStatementInt(stmt3, 1, height);
TryBindStatementInt(stmt3, 2, height);
TryStepStatement(stmt3);
- int64_t nTime4 = GetTimeMicros();
- LogPrint(BCLog::BENCH, " - RestoreOldLast (Balances:Last = 1): %.2fms\n", 0.001 * (nTime4 - nTime3));
+ int64_t nTime3 = GetTimeMicros();
+ LogPrint(BCLog::BENCH, " - RestoreOldLast (Balances): %.2fms\n", 0.001 * (nTime3 - nTime2));
}
void ChainRepository::RollbackHeight(int height)
{
- int64_t nTime1 = GetTimeMicros();
+ int64_t nTime0 = GetTimeMicros();
+ // ----------------------------------------
// Rollback general transaction information
auto stmt0 = SetupSqlStatement(R"sql(
UPDATE Transactions SET
@@ -540,61 +562,59 @@ namespace PocketDb
TryBindStatementInt(stmt0, 1, height);
TryStepStatement(stmt0);
- int64_t nTime2 = GetTimeMicros();
- LogPrint(BCLog::BENCH, " - RollbackHeight (Transactions:Height = null): %.2fms\n", 0.001 * (nTime2 - nTime1));
+ int64_t nTime1 = GetTimeMicros();
+ LogPrint(BCLog::BENCH, " - RollbackHeight (Transactions:Height = null): %.2fms\n", 0.001 * (nTime1 - nTime0));
// ----------------------------------------
-
// Rollback spent transaction outputs
- auto stmt1 = SetupSqlStatement(R"sql(
+ auto stmt2 = SetupSqlStatement(R"sql(
UPDATE TxOutputs SET
SpentHeight = null,
SpentTxHash = null
WHERE SpentHeight >= ?
)sql");
- TryBindStatementInt(stmt1, 1, height);
- TryStepStatement(stmt1);
+ TryBindStatementInt(stmt2, 1, height);
+ TryStepStatement(stmt2);
- int64_t nTime3 = GetTimeMicros();
- LogPrint(BCLog::BENCH, " - RollbackHeight (TxOutputs:SpentHeight = null): %.2fms\n", 0.001 * (nTime3 - nTime2));
+ int64_t nTime2 = GetTimeMicros();
+ LogPrint(BCLog::BENCH, " - RollbackHeight (TxOutputs:SpentHeight = null): %.2fms\n", 0.001 * (nTime2 - nTime1));
+ // ----------------------------------------
// Rollback transaction outputs height
- auto stmt11 = SetupSqlStatement(R"sql(
+ auto stmt3 = SetupSqlStatement(R"sql(
UPDATE TxOutputs SET
TxHeight = null
WHERE TxHeight >= ?
)sql");
- TryBindStatementInt(stmt11, 1, height);
- TryStepStatement(stmt11);
+ TryBindStatementInt(stmt3, 1, height);
+ TryStepStatement(stmt3);
- int64_t nTime4 = GetTimeMicros();
- LogPrint(BCLog::BENCH, " - RollbackHeight (TxOutputs:TxHeight = null): %.2fms\n", 0.001 * (nTime4 - nTime3));
+ int64_t nTime3 = GetTimeMicros();
+ LogPrint(BCLog::BENCH, " - RollbackHeight (TxOutputs:TxHeight = null): %.2fms\n", 0.001 * (nTime3 - nTime2));
// ----------------------------------------
-
// Remove ratings
- auto stmt21 = SetupSqlStatement(R"sql(
+ auto stmt4 = SetupSqlStatement(R"sql(
delete from Ratings
where Height >= ?
)sql");
- TryBindStatementInt(stmt21, 1, height);
- TryStepStatement(stmt21);
+ TryBindStatementInt(stmt4, 1, height);
+ TryStepStatement(stmt4);
- int64_t nTime5 = GetTimeMicros();
- LogPrint(BCLog::BENCH, " - RollbackHeight (Ratings delete): %.2fms\n", 0.001 * (nTime5 - nTime4));
+ int64_t nTime4 = GetTimeMicros();
+ LogPrint(BCLog::BENCH, " - RollbackHeight (Ratings delete): %.2fms\n", 0.001 * (nTime4 - nTime3));
// ----------------------------------------
-
// Remove balances
- auto stmt31 = SetupSqlStatement(R"sql(
+ auto stmt5 = SetupSqlStatement(R"sql(
delete from Balances
where Height >= ?
)sql");
- TryBindStatementInt(stmt31, 1, height);
- TryStepStatement(stmt31);
+ TryBindStatementInt(stmt5, 1, height);
+ TryStepStatement(stmt5);
- int64_t nTime6 = GetTimeMicros();
- LogPrint(BCLog::BENCH, " - RollbackHeight (Balances delete): %.2fms\n", 0.001 * (nTime6 - nTime5));
+ int64_t nTime5 = GetTimeMicros();
+ LogPrint(BCLog::BENCH, " - RollbackHeight (Balances delete): %.2fms\n", 0.001 * (nTime5 - nTime4));
}
diff --git a/src/pocketdb/repositories/ChainRepository.h b/src/pocketdb/repositories/ChainRepository.h
index 082ee7b3a..c29e839c1 100644
--- a/src/pocketdb/repositories/ChainRepository.h
+++ b/src/pocketdb/repositories/ChainRepository.h
@@ -11,7 +11,7 @@
#include "pocketdb/repositories/BaseRepository.h"
#include "pocketdb/models/base/Rating.h"
#include "pocketdb/models/base/PocketTypes.h"
-#include "pocketdb/models/base/ReturnDtoModels.h"
+#include "pocketdb/models/base/DtoModels.h"
#include
#include
diff --git a/src/pocketdb/repositories/ConsensusRepository.cpp b/src/pocketdb/repositories/ConsensusRepository.cpp
index 8f874ee35..e7e94cfac 100644
--- a/src/pocketdb/repositories/ConsensusRepository.cpp
+++ b/src/pocketdb/repositories/ConsensusRepository.cpp
@@ -434,7 +434,7 @@ namespace PocketDb
auto sql = R"sql(
select r.Value
from Ratings r
- where r.Type = ?
+ where r.Type = 0
and r.Id = (SELECT u.Id FROM Transactions u WHERE u.Type in (100, 101, 102) and u.Height is not null and u.Last = 1 and u.String1 = ? LIMIT 1)
and r.Last = 1
)sql";
@@ -442,8 +442,7 @@ namespace PocketDb
TryTransactionStep(__func__, [&]()
{
auto stmt = SetupSqlStatement(sql);
- TryBindStatementInt(stmt, 1, (int) RatingType::RATING_ACCOUNT);
- TryBindStatementText(stmt, 2, address);
+ TryBindStatementText(stmt, 1, address);
if (sqlite3_step(*stmt) == SQLITE_ROW)
if (auto[ok, value] = TryGetColumnInt(*stmt, 0); ok)
@@ -462,7 +461,7 @@ namespace PocketDb
string sql = R"sql(
select r.Value
from Ratings r
- where r.Type = ?
+ where r.Type = 0
and r.Id = ?
and r.Last = 1
)sql";
@@ -470,8 +469,7 @@ namespace PocketDb
TryTransactionStep(__func__, [&]()
{
auto stmt = SetupSqlStatement(sql);
- TryBindStatementInt(stmt, 1, (int) RatingType::RATING_ACCOUNT);
- TryBindStatementInt(stmt, 2, addressId);
+ TryBindStatementInt(stmt, 1, addressId);
if (sqlite3_step(*stmt) == SQLITE_ROW)
if (auto[ok, value] = TryGetColumnInt(*stmt, 0); ok)
@@ -540,31 +538,51 @@ namespace PocketDb
AccountData ConsensusRepository::GetAccountData(const string& address)
{
- AccountData result = {-1, 0, 0, 0};
+ AccountData result = {address,-1,0,0,0,0,0};
TryTransactionStep(__func__, [&]()
{
auto stmt = SetupSqlStatement(R"sql(
- select (u.Id)AddressId,
- ifnull(r.Value, 0)Reputation,
- (select min(uf.Height) from Transactions uf where uf.Id = u.Id)RegistrationBlock,
- (select count() from Ratings l where l.Type = 1 and l.Id = u.Id)LikersCount
+ select
+
+ (u.Id)AddressId,
+ reg.Time as RegistrationDate,
+ reg.Height as RegistrationHeight,
+ ifnull(b.Value,0)Balance,
+ ifnull(r.Value,0)Reputation,
+ ifnull(lp.Value,0)LikersContent,
+ ifnull(lc.Value,0)LikersComment,
+ ifnull(lca.Value,0)LikersCommentAnswer
+
from Transactions u indexed by Transactions_Type_Last_String1_Height_Id
+ cross join Transactions reg indexed by Transactions_Id
+ on reg.Id = u.Id and reg.Height = (select min(reg1.Height) from Transactions reg1 indexed by Transactions_Id where reg1.Id = reg.Id)
+ left join Balances b indexed by Balances_AddressHash_Last on b.AddressHash = u.String1 and b.Last = 1
left join Ratings r indexed by Ratings_Type_Id_Last_Value on r.Type = 0 and r.Id = u.Id and r.Last = 1
+ left join Ratings lp indexed by Ratings_Type_Id_Last_Value on lp.Type = 111 and lp.Id = u.Id and lp.Last = 1
+ left join Ratings lc indexed by Ratings_Type_Id_Last_Value on lc.Type = 112 and lc.Id = u.Id and lc.Last = 1
+ left join Ratings lca indexed by Ratings_Type_Id_Last_Value on lca.Type = 113 and lca.Id = u.Id and lca.Last = 1
+
where u.Type in (100)
and u.Last = 1
and u.String1 = ?
and u.Height > 0
+
limit 1
)sql");
TryBindStatementText(stmt, 1, address);
if (sqlite3_step(*stmt) == SQLITE_ROW)
{
- if (auto[ok, value] = TryGetColumnInt64(*stmt, 0); ok) result.AddressId = value;
- if (auto[ok, value] = TryGetColumnInt64(*stmt, 1); ok) result.Reputation = value;
- if (auto[ok, value] = TryGetColumnInt64(*stmt, 2); ok) result.RegistrationHeight = value;
- if (auto[ok, value] = TryGetColumnInt64(*stmt, 3); ok) result.LikersCount = value;
+ int i = 0;
+ if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.AddressId = value;
+ if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.RegistrationTime = value;
+ if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.RegistrationHeight = value;
+ if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.Balance = value;
+ if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.Reputation = value;
+ if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.LikersContent = value;
+ if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.LikersComment = value;
+ if (auto[ok, value] = TryGetColumnInt64(*stmt, i++); ok) result.LikersCommentAnswer = value;
}
FinalizeSqlStatement(*stmt);
@@ -592,7 +610,9 @@ namespace PocketDb
c.Time cTime,
c.Id cId,
ca.Id caId,
- ca.String1 caHash
+ ca.String1 caHash,
+
+ c.String5
from Transactions s indexed by Transactions_Hash_Height
@@ -633,6 +653,8 @@ namespace PocketDb
if (auto[ok, value] = TryGetColumnInt(*stmt, 9); ok) data.ContentId = value;
if (auto[ok, value] = TryGetColumnInt(*stmt, 10); ok) data.ContentAddressId = value;
if (auto[ok, value] = TryGetColumnString(*stmt, 11); ok) data.ContentAddressHash = value;
+
+ if (auto[ok, value] = TryGetColumnString(*stmt, 12); ok) data.String5 = value;
result = make_shared(data);
}
@@ -724,33 +746,6 @@ namespace PocketDb
return {result, referrer};
}
- int ConsensusRepository::GetUserLikersCount(int addressId)
- {
- int result = 0;
-
- string sql = R"sql(
- select count(1)
- from Ratings r
- where r.Type = ?
- and r.Id = ?
- )sql";
-
- TryTransactionStep(__func__, [&]()
- {
- auto stmt = SetupSqlStatement(sql);
- TryBindStatementInt(stmt, 1, (int) RatingType::RATING_ACCOUNT_LIKERS);
- TryBindStatementInt(stmt, 2, addressId);
-
- if (sqlite3_step(*stmt) == SQLITE_ROW)
- if (auto[ok, value] = TryGetColumnInt(*stmt, 0); ok)
- result = value;
-
- FinalizeSqlStatement(*stmt);
- });
-
- return result;
- }
-
int ConsensusRepository::GetScoreContentCount(
int height,
const shared_ptr& scoreData,
diff --git a/src/pocketdb/repositories/ConsensusRepository.h b/src/pocketdb/repositories/ConsensusRepository.h
index 849cf4646..a73a6fbac 100644
--- a/src/pocketdb/repositories/ConsensusRepository.h
+++ b/src/pocketdb/repositories/ConsensusRepository.h
@@ -26,10 +26,41 @@ namespace PocketDb
struct AccountData
{
+ string AddressHash;
int64_t AddressId;
int64_t Reputation;
+ int64_t RegistrationTime;
int64_t RegistrationHeight;
- int64_t LikersCount;
+ int64_t Balance;
+
+ int64_t LikersContent;
+ int64_t LikersComment;
+ int64_t LikersCommentAnswer;
+
+ int64_t LikersAll() const
+ {
+ return LikersContent + LikersComment + LikersCommentAnswer;
+ }
+ };
+
+ struct BadgeSet
+ {
+ bool Shark = false;
+ bool Whale = false;
+ bool Moderator = false;
+ bool Developer = false;
+
+ UniValue ToJson()
+ {
+ UniValue ret(UniValue::VARR);
+
+ if (Shark) ret.push_back("shark");
+ if (Whale) ret.push_back("whale");
+ if (Moderator) ret.push_back("moderator");
+ if (Developer) ret.push_back("developer");
+
+ return ret;
+ }
};
class ConsensusRepository : public TransactionRepository
@@ -62,7 +93,6 @@ namespace PocketDb
ScoreDataDtoRef GetScoreData(const string& txHash);
shared_ptr