Skip to content

Commit

Permalink
Merge pull request #786 from pocketnetteam:pip/111
Browse files Browse the repository at this point in the history
Implement ModerationVoteConsensus_pip_111 class in Vote.hpp: enhance moderation vote validation with additional checks for moderator status, jury existence, and duplicate votes, while maintaining delay acceptance for moderator votes.
  • Loading branch information
andyoknen authored Dec 13, 2024
2 parents e4e4fd2 + 55584a0 commit 0db6e39
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
10 changes: 10 additions & 0 deletions doc/pips.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,13 @@ Fork start at:
Changes:
- Redistribute lottery rewards: 87.5% for nodes, 2.5% for posts, 10% for moderation votes [PR #779](https://github.com/pocketnetteam/pocketnet.core/pull/779)


## `PIP 111`: Moderation votes check enable after jury creation

Fork start at:
- Main net: 3109300
- Test net: 3500000

Changes:
- Moderation votes check enable after jury creation [PR #786](https://github.com/pocketnetteam/pocketnet.core/pull/786)

44 changes: 42 additions & 2 deletions src/pocketdb/consensus/moderation/Vote.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,50 @@ namespace PocketConsensus
if (!ConsensusRepoInst.AllowJuryModerate(*ptx->GetAddress(), *ptx->GetJuryId()))
return {false, ConsensusResult_NotAllowed};


return Success;
}
};

class ModerationVoteConsensus_pip_111 : public ModerationVoteConsensus
{
public:
ModerationVoteConsensus_pip_111() : ModerationVoteConsensus() {}

ConsensusValidateResult Validate(const CTransactionRef& tx, const ModerationVoteRef& ptx, const PocketBlockRef& block) override
{
// Base validation with calling block or mempool check
if (auto[baseValidate, baseValidateCode] = SocialConsensus::Validate(tx, ptx, block); !baseValidate)
return {false, baseValidateCode};

auto reputationConsensus = ConsensusFactoryInst_Reputation.Instance(Height);
auto accountData = ConsensusRepoInst.GetAccountsData({ *ptx->GetAddress() });
auto badges = reputationConsensus->GetBadges(accountData[*ptx->GetAddress()]);

// Only moderator can set votes
if (!badges.Moderator)
return {false, ConsensusResult_NotAllowed};

// The jury must be exists
if (!ConsensusRepoInst.ExistsActiveJury(*ptx->GetJuryId()))
return {false, ConsensusResult_NotFound};

// The moderators' votes should be accepted with a delay, in case the jury gets into the orphan block
auto juryFlag = ConsensusRepoInst.Get(*ptx->GetJuryId());
if (!juryFlag || *juryFlag->GetType() != MODERATION_FLAG
|| !juryFlag->GetHeight() || (Height - *juryFlag->GetHeight() < 10))
return {false, ConsensusResult_NotAllowed};

// Votes allowed if moderator requested by system
if (!ConsensusRepoInst.AllowJuryModerate(*ptx->GetAddress(), *ptx->GetJuryId()))
return {false, ConsensusResult_NotAllowed};

// Double vote to one jury not allowed
if (ConsensusRepoInst.Exists_S1S2T(*ptx->GetAddress(), *ptx->GetJuryId(), { MODERATION_VOTE }))
return {false, ConsensusResult_Duplicate};

return Success;
}
};

// ----------------------------------------------------------------------------------------------
// Factory for select actual rules version
Expand All @@ -110,7 +149,8 @@ namespace PocketConsensus
public:
ModerationVoteConsensusFactory()
{
Checkpoint({ 2162400, 1531000, 0, make_shared<ModerationVoteConsensus>() });
Checkpoint({ 2162400, 1531000, -1, make_shared<ModerationVoteConsensus>() });
Checkpoint({ 3109300, 3500000, 0, make_shared<ModerationVoteConsensus_pip_111>() });
}
};

Expand Down

0 comments on commit 0db6e39

Please sign in to comment.