Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction implementation - moderation flag #260

Merged
merged 25 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15)

set(_CLIENT_VERSION_MAJOR 0)
set(_CLIENT_VERSION_MINOR 20)
set(_CLIENT_VERSION_REVISION 19)
set(_CLIENT_VERSION_REVISION 20)
set(_CLIENT_VERSION_BUILD 0)
set(_CLIENT_VERSION_IS_RELEASE false)
set(_COPYRIGHT_YEAR 2022)
Expand Down
6 changes: 3 additions & 3 deletions build_msvc/pocketcoin_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define CLIENT_VERSION_MINOR 20

/* Build revision */
#define CLIENT_VERSION_REVISION 19
#define CLIENT_VERSION_REVISION 20

/* Version Build */
#define CLIENT_VERSION_BUILD 0
Expand Down Expand Up @@ -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.19"
#define PACKAGE_STRING "Pocketnet Core 0.20.20"

/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "pocketcoin"
Expand All @@ -355,7 +355,7 @@
#define PACKAGE_URL "https://github.com/pocketnetteam"

/* Define to the version of this package. */
#define PACKAGE_VERSION "0.20.19"
#define PACKAGE_VERSION "0.20.20"

/* Define to necessary symbol if this constant uses a non-standard name on
your system. */
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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, 19)
define(_CLIENT_VERSION_REVISION, 20)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2022)
Expand Down
8 changes: 7 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ add_library(${POCKETDB}
pocketdb/models/base/Transaction.h
pocketdb/models/base/TransactionInput.h
pocketdb/models/base/TransactionOutput.h
pocketdb/models/base/SocialTransaction.h
pocketdb/models/base/Rating.h
pocketdb/models/base/ReturnDtoModels.h
pocketdb/models/dto/Default.h
Expand Down Expand Up @@ -388,6 +389,7 @@ add_library(${POCKETDB}
pocketdb/models/base/Transaction.cpp
pocketdb/models/base/TransactionInput.cpp
pocketdb/models/base/TransactionOutput.cpp
pocketdb/models/base/SocialTransaction.cpp
pocketdb/models/base/Rating.cpp
pocketdb/models/dto/Default.cpp
pocketdb/models/dto/Coinbase.cpp
Expand All @@ -413,6 +415,8 @@ add_library(${POCKETDB}
pocketdb/models/dto/Complain.cpp
pocketdb/models/dto/AccountSetting.cpp
pocketdb/models/dto/ContentDelete.cpp
pocketdb/models/dto/moderation/Flag.h
pocketdb/models/dto/moderation/Flag.cpp
pocketdb/models/web/WebTag.h
pocketdb/models/web/WebContent.h
pocketdb/models/dto/BoostContent.cpp
Expand Down Expand Up @@ -779,6 +783,8 @@ add_library(${POCKETCOIN_SERVER}
pocketdb/repositories/ConsensusRepository.cpp
pocketdb/repositories/CheckpointRepository.h
pocketdb/repositories/CheckpointRepository.cpp
pocketdb/repositories/SystemRepository.h
pocketdb/repositories/SystemRepository.cpp
pocketdb/repositories/web/NotifierRepository.h
pocketdb/repositories/web/NotifierRepository.cpp
pocketdb/repositories/web/WebRepository.h
Expand Down Expand Up @@ -811,10 +817,10 @@ add_library(${POCKETCOIN_SERVER}
pocketdb/consensus/social/AccountSetting.hpp
pocketdb/consensus/social/ContentDelete.hpp
pocketdb/consensus/social/BoostContent.hpp
pocketdb/consensus/moderation/Flag.hpp
pocketdb/consensus/Helper.cpp
pocketdb/consensus/Base.cpp
pocketdb/consensus/Lottery.cpp
pocketdb/consensus/Reputation.cpp
)
target_link_libraries(${POCKETCOIN_SERVER} PRIVATE ${POCKETCOIN_COMMON_RPC} ${POCKETCOIN_UTIL} ${POCKETCOIN_COMMON} ${POCKETCOIN_SYSTEM} ${POCKETCOIN_CONSENSUS} ${POCKETCOIN_CRYPTO} Event::event leveldb OpenSSL::Crypto ${CRYPT32} Boost::boost Boost::date_time)
target_include_directories(${POCKETCOIN_SERVER} PRIVATE ${OPENSSL_INCLUDE_DIR} ${Event_INCLUDE_DIRS})
Expand Down
11 changes: 9 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ POCKETDB_H = \
pocketdb/repositories/ConsensusRepository.h \
pocketdb/repositories/RatingsRepository.h \
pocketdb/repositories/CheckpointRepository.h \
pocketdb/repositories/SystemRepository.h \
pocketdb/repositories/web/WebRepository.h \
pocketdb/repositories/web/WebRpcRepository.h \
pocketdb/repositories/web/NotifierRepository.h \
Expand Down Expand Up @@ -163,12 +164,15 @@ POCKETDB_H = \
pocketdb/consensus/social/AccountSetting.hpp \
pocketdb/consensus/social/ContentDelete.hpp \
\
pocketdb/consensus/moderation/Flag.hpp \
\
pocketdb/models/base/PocketTypes.h \
pocketdb/models/base/Base.h \
pocketdb/models/base/Payload.h \
pocketdb/models/base/Transaction.h \
pocketdb/models/base/TransactionInput.h \
pocketdb/models/base/TransactionOutput.h \
pocketdb/models/base/SocialTransaction.h \
pocketdb/models/base/Rating.h \
pocketdb/models/base/Payload.h \
pocketdb/models/base/ReturnDtoModels.h \
Expand All @@ -195,6 +199,7 @@ POCKETDB_H = \
pocketdb/models/dto/Complain.h \
pocketdb/models/dto/Video.h \
pocketdb/models/dto/Article.h \
pocketdb/models/dto/moderation/Flag.h \
\
pocketdb/models/web/WebTag.h \
pocketdb/models/web/WebContent.h \
Expand Down Expand Up @@ -222,6 +227,7 @@ POCKETDB_CPP = \
pocketdb/repositories/TransactionRepository.cpp \
pocketdb/repositories/RatingsRepository.cpp \
pocketdb/repositories/CheckpointRepository.cpp \
pocketdb/repositories/SystemRepository.cpp \
pocketdb/repositories/web/WebRepository.cpp \
pocketdb/repositories/web/WebRpcRepository.cpp \
pocketdb/repositories/web/NotifierRepository.cpp \
Expand All @@ -231,13 +237,13 @@ POCKETDB_CPP = \
pocketdb/consensus/Helper.cpp \
pocketdb/consensus/Base.cpp \
pocketdb/consensus/Lottery.cpp \
pocketdb/consensus/Reputation.cpp \
\
pocketdb/models/base/Base.cpp \
pocketdb/models/base/Payload.cpp \
pocketdb/models/base/Transaction.cpp \
pocketdb/models/base/TransactionInput.cpp \
pocketdb/models/base/TransactionOutput.cpp \
pocketdb/models/base/SocialTransaction.cpp \
pocketdb/models/base/Rating.cpp \
pocketdb/models/base/Payload.cpp \
\
Expand Down Expand Up @@ -277,7 +283,8 @@ POCKETDB_CPP = \
pocketdb/models/dto/Complain.cpp \
pocketdb/models/dto/Video.cpp \
pocketdb/models/dto/BoostContent.cpp \
pocketdb/models/dto/Article.cpp
pocketdb/models/dto/Article.cpp \
pocketdb/models/dto/moderation/Flag.cpp

# CORE
POCKETCOIN_CORE_H = \
Expand Down
4 changes: 2 additions & 2 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ class CMainParams : public CChainParams
consensus.nHeight_version_1_0_0 = 108300;

// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000000341f03e8566c0f82ca"); // 1592575
consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000000373087dcec2d33b731"); // 1646826

// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0x945933ac93cbd50f5e9978e895cf8cfdbf4c242ecb6c81a13ef6d8baa8067139"); // 1592575
consensus.defaultAssumeValid = uint256S("0x4ad888723ed2c9702c3caaf273046312a0341e8612dcfb8b3bd870dfc387e339"); // 1646826

/**
* The message start string is designed to be unlikely to occur in normal data.
Expand Down
10 changes: 8 additions & 2 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,13 +779,15 @@ bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats)
CNodeState* state = State(nodeid);
if (state == nullptr)
return false;

stats.nMisbehavior = state->nMisbehavior;
stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1;
stats.nCommonHeight = state->pindexLastCommonBlock ? state->pindexLastCommonBlock->nHeight : -1;
for (const QueuedBlock& queue : state->vBlocksInFlight) {

for (const QueuedBlock& queue : state->vBlocksInFlight)
if (queue.pindex)
stats.vHeightInFlight.push_back(queue.pindex->nHeight);
}

return true;
}

Expand All @@ -801,6 +803,10 @@ bool GetNodeStateStatsView(NodeId nodeid, CNodeStateStats& stats)
stats.nSyncHeight = state->pindexBestKnownBlock ? state->pindexBestKnownBlock->nHeight : -1;
stats.nCommonHeight = state->pindexLastCommonBlock ? state->pindexLastCommonBlock->nHeight : -1;

for (const QueuedBlock& queue : state->vBlocksInFlight)
if (queue.pindex)
stats.vHeightInFlight.push_back(queue.pindex->nHeight);

return true;
}

Expand Down
1 change: 1 addition & 0 deletions src/pocketdb/SQLiteDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace PocketDb
RatingsRepoInst.Init();
ConsensusRepoInst.Init();
NotifierRepoInst.Init();
SystemRepoInst.Init();

// Open, create structure and close `web` db
PocketDbMigrationRef webDbMigration = std::make_shared<PocketDbWebMigration>();
Expand Down
1 change: 0 additions & 1 deletion src/pocketdb/SQLiteDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ namespace PocketDb
using namespace std;

void InitSQLite(fs::path path);

void InitSQLiteCheckpoints(fs::path path);

class SQLiteDatabase
Expand Down
49 changes: 30 additions & 19 deletions src/pocketdb/consensus/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ namespace PocketConsensus
SocialConsensusResult_BadPayload = 59,
SocialConsensusResult_ScoreLowReputation = 60,
SocialConsensusResult_ChangeInfoDoubleInMempool = 61,
SocialConsensusResult_Duplicate = 62,
SocialConsensusResult_NotImplemeted = 63,
SocialConsensusResult_SelfFlag = 64,
SocialConsensusResult_ExceededLimit = 65,
SocialConsensusResult_LowReputation = 66,
};

static inline string SocialConsensusResultString(SocialConsensusResult code)
Expand Down Expand Up @@ -141,6 +146,13 @@ namespace PocketConsensus
case (SocialConsensusResult_ScoreDeletedContent): return "ScoreDeletedContent";
case (SocialConsensusResult_RelayContentNotFound): return "RelayContentNotFound";
case (SocialConsensusResult_BadPayload): return "BadPayload";
case (SocialConsensusResult_ChangeInfoDoubleInMempool): return "ChangeInfoDoubleInMempool";
case (SocialConsensusResult_Duplicate): return "Duplicate";
case (SocialConsensusResult_NotImplemeted): return "NotImplemeted";
case (SocialConsensusResult_SelfFlag): return "SelfFlag";
case (SocialConsensusResult_ExceededLimit): return "ExceededLimit";
case (SocialConsensusResult_LowReputation): return "LowReputation";

default: return "Unknown";
}
}
Expand Down Expand Up @@ -210,6 +222,8 @@ namespace PocketConsensus
ConsensusLimit_lottery_referral_depth,

ConsensusLimit_bad_reputation,

ConsensusLimit_moderation_flag_count,
};

/*********************************************************************************************/
Expand Down Expand Up @@ -253,7 +267,8 @@ namespace PocketConsensus
{
NetworkTest,
{
{0, 100}
{0, 100},
{761000, 10}
}
}
}
Expand Down Expand Up @@ -337,24 +352,10 @@ namespace PocketConsensus
}
}
},
// ConsensusLimit_threshold_low_likers_count
{
ConsensusLimit_threshold_low_likers_count,
{
{
NetworkMain,
{
{0, 30}
}
},
{
NetworkTest,
{
{0, 30}
}
}
}
},
{ ConsensusLimit_threshold_low_likers_count, {
{ NetworkMain, { {0, 30} }},
{ NetworkTest, { {0, 30}, {761000, 0} }}
}},
// ConsensusLimit_threshold_low_likers_depth
{
ConsensusLimit_threshold_low_likers_depth,
Expand Down Expand Up @@ -1077,6 +1078,16 @@ namespace PocketConsensus
}
}
},

//
// MODERATION
//

{ ConsensusLimit_moderation_flag_count, {
{ NetworkMain, { {0, 30} }},
{ NetworkTest, { {0, 100} }}
}},

};

/*********************************************************************************************/
Expand Down
24 changes: 14 additions & 10 deletions src/pocketdb/consensus/Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace PocketConsensus
ComplainConsensusFactory SocialConsensusHelper::m_complainFactory;
ContentDeleteConsensusFactory SocialConsensusHelper::m_contentDeleteFactory;
BoostContentConsensusFactory SocialConsensusHelper::m_boostContentFactory;

ModerationFlagConsensusFactory SocialConsensusHelper::m_moderationFlagFactory;

tuple<bool, SocialConsensusResult> SocialConsensusHelper::Validate(const CBlock& block, const PocketBlockRef& pBlock, int height)
{
Expand Down Expand Up @@ -193,12 +195,13 @@ namespace PocketConsensus
return m_blockingCancelFactory.Instance(height)->Check(tx, static_pointer_cast<BlockingCancel>(ptx));
case ACTION_COMPLAIN:
return m_complainFactory.Instance(height)->Check(tx, static_pointer_cast<Complain>(ptx));
// TODO (brangr): future realize types
// case ACCOUNT_VIDEO_SERVER:
// case ACCOUNT_MESSAGE_SERVER:
// case CONTENT_SERVERPING:

// Moderation
case MODERATION_FLAG:
return m_moderationFlagFactory.Instance(height)->Check(tx, static_pointer_cast<ModerationFlag>(ptx));

default:
return {true, SocialConsensusResult_Success};
return {false, SocialConsensusResult_NotImplemeted};
}
}

Expand Down Expand Up @@ -247,12 +250,13 @@ namespace PocketConsensus
return m_blockingCancelFactory.Instance(height)->Validate(tx, static_pointer_cast<BlockingCancel>(ptx), pBlock);
case ACTION_COMPLAIN:
return m_complainFactory.Instance(height)->Validate(tx, static_pointer_cast<Complain>(ptx), pBlock);
// TODO (brangr): future realize types
// case ACCOUNT_VIDEO_SERVER:
// case ACCOUNT_MESSAGE_SERVER:
// case CONTENT_SERVERPING:

// Moderation
case MODERATION_FLAG:
return m_moderationFlagFactory.Instance(height)->Validate(tx, static_pointer_cast<ModerationFlag>(ptx), pBlock);

default:
return {true, SocialConsensusResult_Success};
return {false, SocialConsensusResult_NotImplemeted};
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/pocketdb/consensus/Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "pocketdb/consensus/social/AccountSetting.hpp"
#include "pocketdb/consensus/social/ContentDelete.hpp"

#include "pocketdb/consensus/moderation/Flag.hpp"

namespace PocketConsensus
{
using namespace std;
Expand Down Expand Up @@ -66,6 +68,8 @@ namespace PocketConsensus
static AccountSettingConsensusFactory m_accountSettingFactory;
static ContentDeleteConsensusFactory m_contentDeleteFactory;
static BoostContentConsensusFactory m_boostContentFactory;

static ModerationFlagConsensusFactory m_moderationFlagFactory;
};
}

Expand Down
Loading